forked from MjHead/jet-hide-empty-items
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
120 lines (89 loc) · 3.43 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
( function( $ ) {
"use strict";
var hideHandler = function() {
var $jetAccodion = $( '.jet-accordion__item' );
var $jetTabs = $( '.jet-tabs__control' );
var $elAccodion = $( '.elementor-accordion-item' );
var $elTabs = $( '.elementor-tab-title.elementor-tab-desktop-title' );
var maybeHideElement = function( $el, $content ) {
var text = $content.text(),
template = $( '.elementor', $content );
if( template[0] ) {
return false;
}
text = text.replace( /\t/g, '' );
text = text.replace( /\r?\n|\r/g, '' );
if ( ! text ) {
$el.css( 'display', 'none' );
return true;
} else if ( $content.find( '.jet-listing-not-found' ).length ) {
$el.css( 'display', 'none' );
return true;
}
return false;
};
if ( $jetAccodion.length ) {
$jetAccodion.each( function( index, el ) {
var $el = $( el ),
$content = $el.find( '.jet-toggle__content' );
maybeHideElement( $el, $content );
} );
}
if ( $elAccodion.length ) {
$elAccodion.each( function( index, el ) {
var $el = $( el ),
$content = $el.find( '.elementor-tab-content' );
if ( ! maybeHideElement( $el, $content ) ) {
var $prev = $el.prev();
var borderTop = $el.css( 'border-top' );
var borderBottom = $el.css( 'border-bottom' );
if ( borderTop && ( -1 !== borderTop.indexOf( 'none' ) ) && borderBottom && 'none' === $prev.css( 'display' ) ) {
$el.css( 'border-top', borderBottom );
}
}
} );
}
if ( $jetTabs.length ) {
$jetTabs.each( function( index, el ) {
var $el = $( el ),
$tabs = $el.closest( '.jet-tabs' ),
$content = $tabs.find( '.jet-tabs__content[data-tab="' + $el.data( 'tab' ) + '"]' );
if ( maybeHideElement( $el, $content ) ) {
if ( $el.hasClass( 'active-tab' ) ) {
var $next = $el.next();
if ( $next.length ) {
var $controlList = $tabs.find( '.jet-tabs__control' ),
$contentWrapper = $tabs.find( '.jet-tabs__content-wrapper' ),
$contentList = $tabs.find( '.jet-tabs__content' ),
curentIndex = $next.data( 'tab' ),
$activeControl = $tabs.find( '.jet-tabs__control[data-tab="' + curentIndex + '"]' ),
$activeContent = $tabs.find( '.jet-tabs__content[data-tab="' + curentIndex + '"]' ),
activeContentHeight = 'auto';
$contentWrapper.css( { 'height': $contentWrapper.outerHeight( true ) } );
$controlList.removeClass( 'active-tab' );
$activeControl.addClass( 'active-tab' );
$controlList.attr( 'aria-expanded', 'false' );
$activeControl.attr( 'aria-expanded', 'true' );
$contentList.removeClass( 'active-content' );
activeContentHeight = $activeContent.outerHeight( true );
activeContentHeight += parseInt( $contentWrapper.css( 'border-top-width' ), 10 ) + parseInt( $contentWrapper.css( 'border-bottom-width' ), 10 );
$activeContent.addClass( 'active-content' );
$contentList.attr( 'aria-hidden', 'true' );
$activeContent.attr( 'aria-hidden', 'false' );
$contentWrapper.css( { 'height': activeContentHeight } );
}
}
}
} );
}
if ( $elTabs.length ) {
$elTabs.each( function( index, el ) {
var $el = $( el ),
$tabs = $el.closest( '.elementor-tabs' ),
$content = $tabs.find( '.elementor-tab-content[data-tab="' + $el.data( 'tab' ) + '"]' );
maybeHideElement( $el, $content );
} );
}
};
$( window ).on( 'elementor/frontend/init', hideHandler );
}( jQuery ) );