Passed
Push — develop ( 3892e2...b1663d )
by Aristeides
03:47
created

modules/custom-sections/sections.js (13 issues)

1
jQuery( document ).ready( function() {
2
3
	wp.customize.section.each( function( section ) {
4
5
		// Get the pane element.
6
		var pane      = jQuery( '#sub-accordion-section-' + section.id ),
0 ignored issues
show
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
7
			sectionLi = jQuery( '#accordion-section-' + section.id );
8
9
		// Check if the section is expanded.
10
		if ( sectionLi.hasClass( 'control-section-kirki-expanded' ) ) {
11
12
			// Move element.
13
			pane.appendTo( sectionLi );
14
15
		}
16
17
	} );
18
19
} );
20
21
/**
22
 * @see https://wordpress.stackexchange.com/a/256103/17078
23
 */
24
( function() {
25
26
	var _panelEmbed,
0 ignored issues
show
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
27
		_panelIsContextuallyActive,
28
		_panelAttachEvents,
29
		_sectionEmbed,
30
		_sectionIsContextuallyActive,
31
		_sectionAttachEvents;
32
33
	wp.customize.bind( 'pane-contents-reflowed', function() {
34
35
		var panels   = [],
0 ignored issues
show
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
36
			sections = [];
37
38
		// Reflow Sections.
39
		wp.customize.section.each( function( section ) {
40
41
			if ( 'kirki-nested' !== section.params.type || _.isUndefined( section.params.section ) ) {
42
				return;
43
			}
44
			sections.push( section );
45
		} );
46
47
		sections.sort( wp.customize.utils.prioritySort ).reverse();
48
49
		jQuery.each( sections, function( i, section ) {
50
			var parentContainer = jQuery( '#sub-accordion-section-' + section.params.section );
0 ignored issues
show
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
51
52
			parentContainer.children( '.section-meta' ).after( section.headContainer );
53
		} );
54
55
		// Reflow Panels.
56
		wp.customize.panel.each( function( panel ) {
57
			if ( 'kirki-nested' !== panel.params.type || _.isUndefined( panel.params.panel ) ) {
58
				return;
59
			}
60
			panels.push( panel );
61
		} );
62
63
		panels.sort( wp.customize.utils.prioritySort ).reverse();
64
65
		jQuery.each( panels, function( i, panel ) {
66
			var parentContainer = jQuery( '#sub-accordion-panel-' + panel.params.panel );
0 ignored issues
show
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
67
68
			parentContainer.children( '.panel-meta' ).after( panel.headContainer );
69
		} );
70
	} );
71
72
	// Extend Panel.
73
	_panelEmbed = wp.customize.Panel.prototype.embed;
74
	_panelIsContextuallyActive = wp.customize.Panel.prototype.isContextuallyActive;
75
	_panelAttachEvents = wp.customize.Panel.prototype.attachEvents;
76
77
	wp.customize.Panel = wp.customize.Panel.extend( {
78
		attachEvents: function() {
79
			var panel;
0 ignored issues
show
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
80
81
			if ( 'kirki-nested' !== this.params.type || _.isUndefined( this.params.panel ) ) {
82
				_panelAttachEvents.call( this );
83
				return;
84
			}
85
86
			_panelAttachEvents.call( this );
87
88
			panel = this;
89
90
			panel.expanded.bind( function( expanded ) {
91
				var parent = wp.customize.panel( panel.params.panel );
0 ignored issues
show
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
92
93
				if ( expanded ) {
94
					parent.contentContainer.addClass( 'current-panel-parent' );
95
				} else {
96
					parent.contentContainer.removeClass( 'current-panel-parent' );
97
				}
98
			} );
99
100
			panel.container.find( '.customize-panel-back' ).off( 'click keydown' ).on( 'click keydown', function( event ) {
101
				if ( wp.customize.utils.isKeydownButNotEnterEvent( event ) ) {
102
					return;
103
				}
104
				event.preventDefault(); // Keep this AFTER the key filter above
105
106
				if ( panel.expanded() ) {
107
					wp.customize.panel( panel.params.panel ).expand();
108
				}
109
			} );
110
		},
111
112
		embed: function() {
113
114
			var panel = this,
0 ignored issues
show
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
115
				parentContainer;
116
			if ( 'kirki-nested' !== this.params.type || _.isUndefined( this.params.panel ) ) {
117
				_panelEmbed.call( this );
118
				return;
119
			}
120
121
			_panelEmbed.call( this );
122
123
			parentContainer = jQuery( '#sub-accordion-panel-' + this.params.panel );
124
125
			parentContainer.append( panel.headContainer );
126
		},
127
128
		isContextuallyActive: function() {
129
130
			var panel = this,
0 ignored issues
show
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
131
				children,
132
				activeCount = 0;
133
134
			if ( 'kirki-nested' !== this.params.type ) {
135
				return _panelIsContextuallyActive.call( this );
136
			}
137
138
			children = this._children( 'panel', 'section' );
139
140
			wp.customize.panel.each( function( child ) {
141
				if ( ! child.params.panel ) {
142
					return;
143
				}
144
145
				if ( child.params.panel !== panel.id ) {
146
					return;
147
				}
148
149
				children.push( child );
150
			} );
151
152
			children.sort( wp.customize.utils.prioritySort );
153
154
			_( children ).each( function( child ) {
155
				if ( child.active() && child.isContextuallyActive() ) {
156
					activeCount += 1;
157
				}
158
			} );
159
			return ( 0 !== activeCount );
160
		}
161
	} );
162
163
	// Extend Section.
164
	_sectionEmbed = wp.customize.Section.prototype.embed;
165
	_sectionIsContextuallyActive = wp.customize.Section.prototype.isContextuallyActive;
166
	_sectionAttachEvents = wp.customize.Section.prototype.attachEvents;
167
168
	wp.customize.Section = wp.customize.Section.extend( {
169
		attachEvents: function() {
170
171
			var section = this;
0 ignored issues
show
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
172
173
			if ( 'kirki-nested' !== this.params.type || _.isUndefined( this.params.section ) ) {
174
				_sectionAttachEvents.call( section );
175
				return;
176
			}
177
178
			_sectionAttachEvents.call( section );
179
180
			section.expanded.bind( function( expanded ) {
181
				var parent = wp.customize.section( section.params.section );
0 ignored issues
show
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
182
183
				if ( expanded ) {
184
					parent.contentContainer.addClass( 'current-section-parent' );
185
				} else {
186
					parent.contentContainer.removeClass( 'current-section-parent' );
187
				}
188
			} );
189
190
			section.container.find( '.customize-section-back' ).off( 'click keydown' ).on( 'click keydown', function( event ) {
191
				if ( wp.customize.utils.isKeydownButNotEnterEvent( event ) ) {
192
					return;
193
				}
194
				event.preventDefault(); // Keep this AFTER the key filter above
195
				if ( section.expanded() ) {
196
					wp.customize.section( section.params.section ).expand();
197
				}
198
			} );
199
		},
200
201
		embed: function() {
202
203
			var section = this,
0 ignored issues
show
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
204
				parentContainer;
205
206
			if ( 'kirki-nested' !== this.params.type || _.isUndefined( this.params.section ) ) {
207
				_sectionEmbed.call( section );
208
				return;
209
			}
210
211
			_sectionEmbed.call( section );
212
213
			parentContainer = jQuery( '#sub-accordion-section-' + this.params.section );
214
215
			parentContainer.append( section.headContainer );
216
		},
217
218
		isContextuallyActive: function() {
219
			var section = this,
0 ignored issues
show
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
220
				children,
221
				activeCount = 0;
222
			if ( 'kirki-nested' !== this.params.type ) {
223
				return _sectionIsContextuallyActive.call( this );
224
			}
225
226
			children = this._children( 'section', 'control' );
227
228
			wp.customize.section.each( function( child ) {
229
				if ( ! child.params.section ) {
230
					return;
231
				}
232
233
				if ( child.params.section !== section.id ) {
234
					return;
235
				}
236
				children.push( child );
237
			} );
238
239
			children.sort( wp.customize.utils.prioritySort );
240
241
			_( children ).each( function( child ) {
242
				if ( 'undefined' !== typeof child.isContextuallyActive ) {
243
					if ( child.active() && child.isContextuallyActive() ) {
244
						activeCount += 1;
245
					}
246
				} else {
247
					if ( child.active() ) {
248
						activeCount += 1;
249
					}
250
				}
251
			} );
252
253
			return ( 0 !== activeCount );
254
		}
255
	} );
256
}( jQuery ) );
257