author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
9 | 1 |
/** |
2 |
* @output wp-admin/js/common.js |
|
3 |
*/ |
|
4 |
||
5 | 5 |
/* global setUserSetting, ajaxurl, commonL10n, alert, confirm, pagenow */ |
9 | 6 |
/* global columns, screenMeta */ |
7 |
||
8 |
/** |
|
9 |
* Adds common WordPress functionality to the window. |
|
10 |
* |
|
11 |
* @param {jQuery} $ jQuery object. |
|
12 |
* @param {Object} window The window object. |
|
13 |
* @param {mixed} undefined Unused. |
|
14 |
*/ |
|
5 | 15 |
( function( $, window, undefined ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
var $document = $( document ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
$window = $( window ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
$body = $( document.body ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
|
9 | 20 |
/** |
21 |
* Removed in 3.3.0, needed for back-compatibility. |
|
22 |
* |
|
23 |
* @since 2.7.0 |
|
24 |
* @deprecated 3.3.0 |
|
25 |
*/ |
|
26 |
window.adminMenu = { |
|
0 | 27 |
init : function() {}, |
28 |
fold : function() {}, |
|
29 |
restoreMenuState : function() {}, |
|
30 |
toggle : function() {}, |
|
31 |
favorites : function() {} |
|
32 |
}; |
|
33 |
||
9 | 34 |
// Show/hide/save table columns. |
35 |
window.columns = { |
|
36 |
||
37 |
/** |
|
38 |
* Initializes the column toggles in the screen options. |
|
39 |
* |
|
40 |
* Binds an onClick event to the checkboxes to show or hide the table columns |
|
41 |
* based on their toggled state. And persists the toggled state. |
|
42 |
* |
|
43 |
* @since 2.7.0 |
|
44 |
* |
|
45 |
* @returns {void} |
|
46 |
*/ |
|
0 | 47 |
init : function() { |
48 |
var that = this; |
|
49 |
$('.hide-column-tog', '#adv-settings').click( function() { |
|
50 |
var $t = $(this), column = $t.val(); |
|
51 |
if ( $t.prop('checked') ) |
|
52 |
that.checked(column); |
|
53 |
else |
|
54 |
that.unchecked(column); |
|
55 |
||
56 |
columns.saveManageColumnsState(); |
|
57 |
}); |
|
58 |
}, |
|
59 |
||
9 | 60 |
/** |
61 |
* Saves the toggled state for the columns. |
|
62 |
* |
|
63 |
* Saves whether the columns should be shown or hidden on a page. |
|
64 |
* |
|
65 |
* @since 3.0.0 |
|
66 |
* |
|
67 |
* @returns {void} |
|
68 |
*/ |
|
0 | 69 |
saveManageColumnsState : function() { |
70 |
var hidden = this.hidden(); |
|
71 |
$.post(ajaxurl, { |
|
72 |
action: 'hidden-columns', |
|
73 |
hidden: hidden, |
|
74 |
screenoptionnonce: $('#screenoptionnonce').val(), |
|
75 |
page: pagenow |
|
76 |
}); |
|
77 |
}, |
|
78 |
||
9 | 79 |
/** |
80 |
* Makes a column visible and adjusts the column span for the table. |
|
81 |
* |
|
82 |
* @since 3.0.0 |
|
83 |
* @param {string} column The column name. |
|
84 |
* |
|
85 |
* @returns {void} |
|
86 |
*/ |
|
0 | 87 |
checked : function(column) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
$('.column-' + column).removeClass( 'hidden' ); |
0 | 89 |
this.colSpanChange(+1); |
90 |
}, |
|
91 |
||
9 | 92 |
/** |
93 |
* Hides a column and adjusts the column span for the table. |
|
94 |
* |
|
95 |
* @since 3.0.0 |
|
96 |
* @param {string} column The column name. |
|
97 |
* |
|
98 |
* @returns {void} |
|
99 |
*/ |
|
0 | 100 |
unchecked : function(column) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
$('.column-' + column).addClass( 'hidden' ); |
0 | 102 |
this.colSpanChange(-1); |
103 |
}, |
|
104 |
||
9 | 105 |
/** |
106 |
* Gets all hidden columns. |
|
107 |
* |
|
108 |
* @since 3.0.0 |
|
109 |
* |
|
110 |
* @returns {string} The hidden column names separated by a comma. |
|
111 |
*/ |
|
0 | 112 |
hidden : function() { |
9 | 113 |
return $( '.manage-column[id]' ).filter( '.hidden' ).map(function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
return this.id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
}).get().join( ',' ); |
0 | 116 |
}, |
117 |
||
9 | 118 |
/** |
119 |
* Gets the checked column toggles from the screen options. |
|
120 |
* |
|
121 |
* @since 3.0.0 |
|
122 |
* |
|
123 |
* @returns {string} String containing the checked column names. |
|
124 |
*/ |
|
0 | 125 |
useCheckboxesForHidden : function() { |
126 |
this.hidden = function(){ |
|
127 |
return $('.hide-column-tog').not(':checked').map(function() { |
|
128 |
var id = this.id; |
|
129 |
return id.substring( id, id.length - 5 ); |
|
130 |
}).get().join(','); |
|
131 |
}; |
|
132 |
}, |
|
133 |
||
9 | 134 |
/** |
135 |
* Adjusts the column span for the table. |
|
136 |
* |
|
137 |
* @since 3.1.0 |
|
138 |
* |
|
139 |
* @param {int} diff The modifier for the column span. |
|
140 |
*/ |
|
0 | 141 |
colSpanChange : function(diff) { |
142 |
var $t = $('table').find('.colspanchange'), n; |
|
143 |
if ( !$t.length ) |
|
144 |
return; |
|
145 |
n = parseInt( $t.attr('colspan'), 10 ) + diff; |
|
146 |
$t.attr('colspan', n.toString()); |
|
147 |
} |
|
5 | 148 |
}; |
0 | 149 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
$document.ready(function(){columns.init();}); |
0 | 151 |
|
9 | 152 |
/** |
153 |
* Validates that the required form fields are not empty. |
|
154 |
* |
|
155 |
* @since 2.9.0 |
|
156 |
* |
|
157 |
* @param {jQuery} form The form to validate. |
|
158 |
* |
|
159 |
* @returns {boolean} Returns true if all required fields are not an empty string. |
|
160 |
*/ |
|
161 |
window.validateForm = function( form ) { |
|
5 | 162 |
return !$( form ) |
163 |
.find( '.form-required' ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
164 |
.filter( function() { return $( ':input:visible', this ).val() === ''; } ) |
5 | 165 |
.addClass( 'form-invalid' ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
166 |
.find( ':input:visible' ) |
5 | 167 |
.change( function() { $( this ).closest( '.form-invalid' ).removeClass( 'form-invalid' ); } ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
168 |
.length; |
5 | 169 |
}; |
0 | 170 |
|
171 |
// stub for doing better warnings |
|
9 | 172 |
/** |
173 |
* Shows message pop-up notice or confirmation message. |
|
174 |
* |
|
175 |
* @since 2.7.0 |
|
176 |
* |
|
177 |
* @type {{warn: showNotice.warn, note: showNotice.note}} |
|
178 |
* |
|
179 |
* @returns {void} |
|
180 |
*/ |
|
181 |
window.showNotice = { |
|
182 |
||
183 |
/** |
|
184 |
* Shows a delete confirmation pop-up message. |
|
185 |
* |
|
186 |
* @since 2.7.0 |
|
187 |
* |
|
188 |
* @returns {boolean} Returns true if the message is confirmed. |
|
189 |
*/ |
|
0 | 190 |
warn : function() { |
191 |
var msg = commonL10n.warnDelete || ''; |
|
192 |
if ( confirm(msg) ) { |
|
193 |
return true; |
|
194 |
} |
|
195 |
||
196 |
return false; |
|
197 |
}, |
|
198 |
||
9 | 199 |
/** |
200 |
* Shows an alert message. |
|
201 |
* |
|
202 |
* @since 2.7.0 |
|
203 |
* |
|
204 |
* @param text The text to display in the message. |
|
205 |
*/ |
|
0 | 206 |
note : function(text) { |
207 |
alert(text); |
|
208 |
} |
|
209 |
}; |
|
210 |
||
9 | 211 |
/** |
212 |
* Represents the functions for the meta screen options panel. |
|
213 |
* |
|
214 |
* @since 3.2.0 |
|
215 |
* |
|
216 |
* @type {{element: null, toggles: null, page: null, init: screenMeta.init, |
|
217 |
* toggleEvent: screenMeta.toggleEvent, open: screenMeta.open, |
|
218 |
* close: screenMeta.close}} |
|
219 |
* |
|
220 |
* @returns {void} |
|
221 |
*/ |
|
222 |
window.screenMeta = { |
|
0 | 223 |
element: null, // #screen-meta |
224 |
toggles: null, // .screen-meta-toggle |
|
225 |
page: null, // #wpcontent |
|
226 |
||
9 | 227 |
/** |
228 |
* Initializes the screen meta options panel. |
|
229 |
* |
|
230 |
* @since 3.2.0 |
|
231 |
* |
|
232 |
* @returns {void} |
|
233 |
*/ |
|
0 | 234 |
init: function() { |
235 |
this.element = $('#screen-meta'); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
this.toggles = $( '#screen-meta-links' ).find( '.show-settings' ); |
0 | 237 |
this.page = $('#wpcontent'); |
238 |
||
239 |
this.toggles.click( this.toggleEvent ); |
|
240 |
}, |
|
241 |
||
9 | 242 |
/** |
243 |
* Toggles the screen meta options panel. |
|
244 |
* |
|
245 |
* @since 3.2.0 |
|
246 |
* |
|
247 |
* @returns {void} |
|
248 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
249 |
toggleEvent: function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
var panel = $( '#' + $( this ).attr( 'aria-controls' ) ); |
0 | 251 |
|
252 |
if ( !panel.length ) |
|
253 |
return; |
|
254 |
||
255 |
if ( panel.is(':visible') ) |
|
256 |
screenMeta.close( panel, $(this) ); |
|
257 |
else |
|
258 |
screenMeta.open( panel, $(this) ); |
|
259 |
}, |
|
260 |
||
9 | 261 |
/** |
262 |
* Opens the screen meta options panel. |
|
263 |
* |
|
264 |
* @since 3.2.0 |
|
265 |
* |
|
266 |
* @param {jQuery} panel The screen meta options panel div. |
|
267 |
* @param {jQuery} button The toggle button. |
|
268 |
* |
|
269 |
* @returns {void} |
|
270 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
open: function( panel, button ) { |
0 | 272 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
$( '#screen-meta-links' ).find( '.screen-meta-toggle' ).not( button.parent() ).css( 'visibility', 'hidden' ); |
0 | 274 |
|
275 |
panel.parent().show(); |
|
9 | 276 |
|
277 |
/** |
|
278 |
* Sets the focus to the meta options panel and adds the necessary CSS classes. |
|
279 |
* |
|
280 |
* @since 3.2.0 |
|
281 |
* |
|
282 |
* @returns {void} |
|
283 |
*/ |
|
0 | 284 |
panel.slideDown( 'fast', function() { |
285 |
panel.focus(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
286 |
button.addClass( 'screen-meta-active' ).attr( 'aria-expanded', true ); |
0 | 287 |
}); |
5 | 288 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
$document.trigger( 'screen:options:open' ); |
0 | 290 |
}, |
291 |
||
9 | 292 |
/** |
293 |
* Closes the screen meta options panel. |
|
294 |
* |
|
295 |
* @since 3.2.0 |
|
296 |
* |
|
297 |
* @param {jQuery} panel The screen meta options panel div. |
|
298 |
* @param {jQuery} button The toggle button. |
|
299 |
* |
|
300 |
* @returns {void} |
|
301 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
close: function( panel, button ) { |
9 | 303 |
/** |
304 |
* Hides the screen meta options panel. |
|
305 |
* |
|
306 |
* @since 3.2.0 |
|
307 |
* |
|
308 |
* @returns {void} |
|
309 |
*/ |
|
0 | 310 |
panel.slideUp( 'fast', function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
311 |
button.removeClass( 'screen-meta-active' ).attr( 'aria-expanded', false ); |
0 | 312 |
$('.screen-meta-toggle').css('visibility', ''); |
313 |
panel.parent().hide(); |
|
314 |
}); |
|
5 | 315 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
$document.trigger( 'screen:options:close' ); |
0 | 317 |
} |
318 |
}; |
|
319 |
||
320 |
/** |
|
9 | 321 |
* Initializes the help tabs in the help panel. |
322 |
* |
|
323 |
* @param {Event} e The event object. |
|
324 |
* |
|
325 |
* @returns {void} |
|
0 | 326 |
*/ |
5 | 327 |
$('.contextual-help-tabs').delegate('a', 'click', function(e) { |
0 | 328 |
var link = $(this), |
329 |
panel; |
|
330 |
||
331 |
e.preventDefault(); |
|
332 |
||
333 |
// Don't do anything if the click is for the tab already showing. |
|
334 |
if ( link.is('.active a') ) |
|
335 |
return false; |
|
336 |
||
337 |
// Links |
|
338 |
$('.contextual-help-tabs .active').removeClass('active'); |
|
339 |
link.parent('li').addClass('active'); |
|
340 |
||
341 |
panel = $( link.attr('href') ); |
|
342 |
||
343 |
// Panels |
|
344 |
$('.help-tab-content').not( panel ).removeClass('active').hide(); |
|
345 |
panel.addClass('active').show(); |
|
346 |
}); |
|
347 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
349 |
* Update custom permalink structure via buttons. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
351 |
var permalinkStructureFocused = false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
352 |
$permalinkStructure = $( '#permalink_structure' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
353 |
$permalinkStructureInputs = $( '.permalink-structure input:radio' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
354 |
$permalinkCustomSelection = $( '#custom_selection' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
355 |
$availableStructureTags = $( '.form-table.permalink-structure .available-structure-tags button' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
357 |
// Change permalink structure input when selecting one of the common structures. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
$permalinkStructureInputs.on( 'change', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
if ( 'custom' === this.value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
361 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
362 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
$permalinkStructure.val( this.value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
364 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
// Update button states after selection. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
$availableStructureTags.each( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
367 |
changeStructureTagButtonState( $( this ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
368 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
369 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
$permalinkStructure.on( 'click input', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
$permalinkCustomSelection.prop( 'checked', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
// Check if the permalink structure input field has had focus at least once. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
$permalinkStructure.on( 'focus', function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
permalinkStructureFocused = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
$( this ).off( event ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
379 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
* Enables or disables a structure tag button depending on its usage. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
* If the structure is already used in the custom permalink structure, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
* it will be disabled. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
* @param {object} button Button jQuery object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
function changeStructureTagButtonState( button ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
if ( -1 !== $permalinkStructure.val().indexOf( button.text().trim() ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
button.attr( 'data-label', button.attr( 'aria-label' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
button.attr( 'aria-label', button.attr( 'data-used' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
button.attr( 'aria-pressed', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
button.addClass( 'active' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
} else if ( button.attr( 'data-label' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
button.attr( 'aria-label', button.attr( 'data-label' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
button.attr( 'aria-pressed', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
398 |
button.removeClass( 'active' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
400 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
// Check initial button state. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
403 |
$availableStructureTags.each( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
404 |
changeStructureTagButtonState( $( this ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
// Observe permalink structure field and disable buttons of tags that are already present. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
$permalinkStructure.on( 'change', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
$availableStructureTags.each( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
410 |
changeStructureTagButtonState( $( this ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
$availableStructureTags.on( 'click', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
var permalinkStructureValue = $permalinkStructure.val(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
selectionStart = $permalinkStructure[ 0 ].selectionStart, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
selectionEnd = $permalinkStructure[ 0 ].selectionEnd, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
textToAppend = $( this ).text().trim(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
419 |
textToAnnounce = $( this ).attr( 'data-added' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
newSelectionStart; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
421 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
// Remove structure tag if already part of the structure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
if ( -1 !== permalinkStructureValue.indexOf( textToAppend ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
permalinkStructureValue = permalinkStructureValue.replace( textToAppend + '/', '' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
$permalinkStructure.val( '/' === permalinkStructureValue ? '' : permalinkStructureValue ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
// Announce change to screen readers. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
$( '#custom_selection_updated' ).text( textToAnnounce ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
// Disable button. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
changeStructureTagButtonState( $( this ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
434 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
435 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
// Input field never had focus, move selection to end of input. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
if ( ! permalinkStructureFocused && 0 === selectionStart && 0 === selectionEnd ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
selectionStart = selectionEnd = permalinkStructureValue.length; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
$permalinkCustomSelection.prop( 'checked', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
// Prepend and append slashes if necessary. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
if ( '/' !== permalinkStructureValue.substr( 0, selectionStart ).substr( -1 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
textToAppend = '/' + textToAppend; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
if ( '/' !== permalinkStructureValue.substr( selectionEnd, 1 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
textToAppend = textToAppend + '/'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
// Insert structure tag at the specified position. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
$permalinkStructure.val( permalinkStructureValue.substr( 0, selectionStart ) + textToAppend + permalinkStructureValue.substr( selectionEnd ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
// Announce change to screen readers. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
$( '#custom_selection_updated' ).text( textToAnnounce ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
// Disable button. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
460 |
changeStructureTagButtonState( $( this ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
461 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
462 |
// If input had focus give it back with cursor right after appended text. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
if ( permalinkStructureFocused && $permalinkStructure[0].setSelectionRange ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
464 |
newSelectionStart = ( permalinkStructureValue.substr( 0, selectionStart ) + textToAppend ).length; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
$permalinkStructure[0].setSelectionRange( newSelectionStart, newSelectionStart ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
466 |
$permalinkStructure.focus(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
467 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
468 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
469 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
470 |
$document.ready( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
471 |
var checks, first, last, checked, sliced, mobileEvent, transitionTimeout, focusedRowActions, |
5 | 472 |
lastClicked = false, |
473 |
pageInput = $('input.current-page'), |
|
474 |
currentPage = pageInput.val(), |
|
475 |
isIOS = /iPhone|iPad|iPod/.test( navigator.userAgent ), |
|
476 |
isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1, |
|
477 |
isIE8 = $( document.documentElement ).hasClass( 'ie8' ), |
|
478 |
$adminMenuWrap = $( '#adminmenuwrap' ), |
|
479 |
$wpwrap = $( '#wpwrap' ), |
|
480 |
$adminmenu = $( '#adminmenu' ), |
|
481 |
$overlay = $( '#wp-responsive-overlay' ), |
|
482 |
$toolbar = $( '#wp-toolbar' ), |
|
483 |
$toolbarPopups = $toolbar.find( 'a[aria-haspopup="true"]' ), |
|
484 |
$sortables = $('.meta-box-sortables'), |
|
485 |
wpResponsiveActive = false, |
|
486 |
$adminbar = $( '#wpadminbar' ), |
|
487 |
lastScrollPosition = 0, |
|
488 |
pinnedMenuTop = false, |
|
489 |
pinnedMenuBottom = false, |
|
490 |
menuTop = 0, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
menuState, |
5 | 492 |
menuIsPinned = false, |
493 |
height = { |
|
494 |
window: $window.height(), |
|
495 |
wpwrap: $wpwrap.height(), |
|
496 |
adminbar: $adminbar.height(), |
|
497 |
menu: $adminMenuWrap.height() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
$headerEnd = $( '.wp-header-end' ); |
5 | 500 |
|
9 | 501 |
/** |
502 |
* Makes the fly-out submenu header clickable, when the menu is folded. |
|
503 |
* |
|
504 |
* @param {Event} e The event object. |
|
505 |
* |
|
506 |
* @returns {void} |
|
507 |
*/ |
|
5 | 508 |
$adminmenu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){ |
0 | 509 |
$(e.target).parent().siblings('a').get(0).click(); |
510 |
}); |
|
511 |
||
9 | 512 |
/** |
513 |
* Collapses the admin menu. |
|
514 |
* |
|
515 |
* @returns {void} |
|
516 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
$( '#collapse-button' ).on( 'click.collapse-menu', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
var viewportWidth = getViewportWidth() || 961; |
0 | 519 |
|
520 |
// reset any compensation for submenus near the bottom of the screen |
|
521 |
$('#adminmenu div.wp-submenu').css('margin-top', ''); |
|
522 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
if ( viewportWidth < 960 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
if ( $body.hasClass('auto-fold') ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
$body.removeClass('auto-fold').removeClass('folded'); |
0 | 526 |
setUserSetting('unfold', 1); |
527 |
setUserSetting('mfold', 'o'); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
menuState = 'open'; |
0 | 529 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
$body.addClass('auto-fold'); |
0 | 531 |
setUserSetting('unfold', 0); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
menuState = 'folded'; |
0 | 533 |
} |
534 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
535 |
if ( $body.hasClass('folded') ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
$body.removeClass('folded'); |
0 | 537 |
setUserSetting('mfold', 'o'); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
menuState = 'open'; |
0 | 539 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
$body.addClass('folded'); |
0 | 541 |
setUserSetting('mfold', 'f'); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
menuState = 'folded'; |
0 | 543 |
} |
544 |
} |
|
5 | 545 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
$document.trigger( 'wp-collapse-menu', { state: menuState } ); |
0 | 547 |
}); |
548 |
||
9 | 549 |
/** |
550 |
* Handles the `aria-haspopup` attribute on the current menu item when it has a submenu. |
|
551 |
* |
|
552 |
* @since 4.4.0 |
|
553 |
* |
|
554 |
* @returns {void} |
|
555 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
556 |
function currentMenuItemHasPopup() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
var $current = $( 'a.wp-has-current-submenu' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
558 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
559 |
if ( 'folded' === menuState ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
560 |
// When folded or auto-folded and not responsive view, the current menu item does have a fly-out sub-menu. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
561 |
$current.attr( 'aria-haspopup', 'true' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
562 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
563 |
// When expanded or in responsive view, reset aria-haspopup. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
$current.attr( 'aria-haspopup', 'false' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
566 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
567 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
568 |
$document.on( 'wp-menu-state-set wp-collapse-menu wp-responsive-activate wp-responsive-deactivate', currentMenuItemHasPopup ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
569 |
|
5 | 570 |
/** |
9 | 571 |
* Ensures an admin submenu is within the visual viewport. |
5 | 572 |
* |
573 |
* @since 4.1.0 |
|
574 |
* |
|
575 |
* @param {jQuery} $menuItem The parent menu item containing the submenu. |
|
9 | 576 |
* |
577 |
* @returns {void} |
|
5 | 578 |
*/ |
579 |
function adjustSubmenu( $menuItem ) { |
|
580 |
var bottomOffset, pageHeight, adjustment, theFold, menutop, wintop, maxtop, |
|
581 |
$submenu = $menuItem.find( '.wp-submenu' ); |
|
582 |
||
583 |
menutop = $menuItem.offset().top; |
|
584 |
wintop = $window.scrollTop(); |
|
585 |
maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar |
|
586 |
||
587 |
bottomOffset = menutop + $submenu.height() + 1; // Bottom offset of the menu |
|
588 |
pageHeight = $wpwrap.height(); // Height of the entire page |
|
589 |
adjustment = 60 + bottomOffset - pageHeight; |
|
590 |
theFold = $window.height() + wintop - 50; // The fold |
|
591 |
||
592 |
if ( theFold < ( bottomOffset - adjustment ) ) { |
|
593 |
adjustment = bottomOffset - theFold; |
|
594 |
} |
|
595 |
||
596 |
if ( adjustment > maxtop ) { |
|
597 |
adjustment = maxtop; |
|
598 |
} |
|
599 |
||
600 |
if ( adjustment > 1 ) { |
|
601 |
$submenu.css( 'margin-top', '-' + adjustment + 'px' ); |
|
602 |
} else { |
|
603 |
$submenu.css( 'margin-top', '' ); |
|
604 |
} |
|
605 |
} |
|
606 |
||
0 | 607 |
if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // touch screen device |
608 |
// iOS Safari works with touchstart, the rest work with click |
|
5 | 609 |
mobileEvent = isIOS ? 'touchstart' : 'click'; |
0 | 610 |
|
9 | 611 |
/** |
612 |
* Closes any open submenus when touch/click is not on the menu. |
|
613 |
* |
|
614 |
* @param {Event} e The event object. |
|
615 |
* |
|
616 |
* @returns {void} |
|
617 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
$body.on( mobileEvent+'.wp-mobile-hover', function(e) { |
5 | 619 |
if ( $adminmenu.data('wp-responsive') ) { |
620 |
return; |
|
621 |
} |
|
622 |
||
623 |
if ( ! $( e.target ).closest( '#adminmenu' ).length ) { |
|
624 |
$adminmenu.find( 'li.opensub' ).removeClass( 'opensub' ); |
|
625 |
} |
|
0 | 626 |
}); |
627 |
||
9 | 628 |
/** |
629 |
* Handles the opening or closing the submenu based on the mobile click|touch event. |
|
630 |
* |
|
631 |
* @param {Event} event The event object. |
|
632 |
* |
|
633 |
* @returns {void} |
|
634 |
*/ |
|
5 | 635 |
$adminmenu.find( 'a.wp-has-submenu' ).on( mobileEvent + '.wp-mobile-hover', function( event ) { |
636 |
var $menuItem = $(this).parent(); |
|
637 |
||
638 |
if ( $adminmenu.data( 'wp-responsive' ) ) { |
|
639 |
return; |
|
640 |
} |
|
0 | 641 |
|
642 |
// Show the sub instead of following the link if: |
|
643 |
// - the submenu is not open |
|
644 |
// - the submenu is not shown inline or the menu is not folded |
|
5 | 645 |
if ( ! $menuItem.hasClass( 'opensub' ) && ( ! $menuItem.hasClass( 'wp-menu-open' ) || $menuItem.width() < 40 ) ) { |
646 |
event.preventDefault(); |
|
647 |
adjustSubmenu( $menuItem ); |
|
648 |
$adminmenu.find( 'li.opensub' ).removeClass( 'opensub' ); |
|
649 |
$menuItem.addClass('opensub'); |
|
0 | 650 |
} |
651 |
}); |
|
652 |
} |
|
653 |
||
5 | 654 |
if ( ! isIOS && ! isAndroid ) { |
655 |
$adminmenu.find( 'li.wp-has-submenu' ).hoverIntent({ |
|
9 | 656 |
|
657 |
/** |
|
658 |
* Opens the submenu when hovered over the menu item for desktops. |
|
659 |
* |
|
660 |
* @returns {void} |
|
661 |
*/ |
|
5 | 662 |
over: function() { |
663 |
var $menuItem = $( this ), |
|
664 |
$submenu = $menuItem.find( '.wp-submenu' ), |
|
665 |
top = parseInt( $submenu.css( 'top' ), 10 ); |
|
0 | 666 |
|
5 | 667 |
if ( isNaN( top ) || top > -5 ) { // the submenu is visible |
668 |
return; |
|
669 |
} |
|
0 | 670 |
|
5 | 671 |
if ( $adminmenu.data( 'wp-responsive' ) ) { |
672 |
// The menu is in responsive mode, bail |
|
673 |
return; |
|
674 |
} |
|
0 | 675 |
|
5 | 676 |
adjustSubmenu( $menuItem ); |
677 |
$adminmenu.find( 'li.opensub' ).removeClass( 'opensub' ); |
|
678 |
$menuItem.addClass( 'opensub' ); |
|
679 |
}, |
|
9 | 680 |
|
681 |
/** |
|
682 |
* Closes the submenu when no longer hovering the menu item. |
|
683 |
* |
|
684 |
* @returns {void} |
|
685 |
*/ |
|
5 | 686 |
out: function(){ |
687 |
if ( $adminmenu.data( 'wp-responsive' ) ) { |
|
688 |
// The menu is in responsive mode, bail |
|
689 |
return; |
|
690 |
} |
|
0 | 691 |
|
5 | 692 |
$( this ).removeClass( 'opensub' ).find( '.wp-submenu' ).css( 'margin-top', '' ); |
693 |
}, |
|
694 |
timeout: 200, |
|
695 |
sensitivity: 7, |
|
696 |
interval: 90 |
|
697 |
}); |
|
0 | 698 |
|
9 | 699 |
/** |
700 |
* Opens the submenu on when focused on the menu item. |
|
701 |
* |
|
702 |
* @param {Event} event The event object. |
|
703 |
* |
|
704 |
* @returns {void} |
|
705 |
*/ |
|
5 | 706 |
$adminmenu.on( 'focus.adminmenu', '.wp-submenu a', function( event ) { |
707 |
if ( $adminmenu.data( 'wp-responsive' ) ) { |
|
708 |
// The menu is in responsive mode, bail |
|
709 |
return; |
|
710 |
} |
|
711 |
||
712 |
$( event.target ).closest( 'li.menu-top' ).addClass( 'opensub' ); |
|
9 | 713 |
|
714 |
/** |
|
715 |
* Closes the submenu on blur from the menu item. |
|
716 |
* |
|
717 |
* @param {Event} event The event object. |
|
718 |
* |
|
719 |
* @returns {void} |
|
720 |
*/ |
|
5 | 721 |
}).on( 'blur.adminmenu', '.wp-submenu a', function( event ) { |
722 |
if ( $adminmenu.data( 'wp-responsive' ) ) { |
|
723 |
return; |
|
724 |
} |
|
725 |
||
726 |
$( event.target ).closest( 'li.menu-top' ).removeClass( 'opensub' ); |
|
9 | 727 |
|
728 |
/** |
|
729 |
* Adjusts the size for the submenu. |
|
730 |
* |
|
731 |
* @returns {void} |
|
732 |
*/ |
|
5 | 733 |
}).find( 'li.wp-has-submenu.wp-not-current-submenu' ).on( 'focusin.adminmenu', function() { |
734 |
adjustSubmenu( $( this ) ); |
|
735 |
}); |
|
736 |
} |
|
0 | 737 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
738 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
* The `.below-h2` class is here just for backward compatibility with plugins |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
* that are (incorrectly) using it. Do not use. Use `.inline` instead. See #34570. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
741 |
* If '.wp-header-end' is found, append the notices after it otherwise |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
742 |
* after the first h1 or h2 heading found within the main content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
743 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
744 |
if ( ! $headerEnd.length ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
745 |
$headerEnd = $( '.wrap h1, .wrap h2' ).first(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
746 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
747 |
$( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' ).insertAfter( $headerEnd ); |
5 | 748 |
|
9 | 749 |
/** |
750 |
* Makes notices dismissible. |
|
751 |
* |
|
752 |
* @since 4.4.0 |
|
753 |
* |
|
754 |
* @returns {void} |
|
755 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
756 |
function makeNoticesDismissible() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
757 |
$( '.notice.is-dismissible' ).each( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
758 |
var $el = $( this ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
$button = $( '<button type="button" class="notice-dismiss"><span class="screen-reader-text"></span></button>' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
760 |
btnText = commonL10n.dismiss || ''; |
5 | 761 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
762 |
// Ensure plain text |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
763 |
$button.find( '.screen-reader-text' ).text( btnText ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
764 |
$button.on( 'click.wp-dismiss-notice', function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
765 |
event.preventDefault(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
766 |
$el.fadeTo( 100, 0, function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
767 |
$el.slideUp( 100, function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
768 |
$el.remove(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
769 |
}); |
5 | 770 |
}); |
771 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
772 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
773 |
$el.append( $button ); |
5 | 774 |
}); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
775 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
776 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
777 |
$document.on( 'wp-updates-notice-added wp-plugin-install-error wp-plugin-update-error wp-plugin-delete-error wp-theme-install-error wp-theme-delete-error', makeNoticesDismissible ); |
0 | 778 |
|
779 |
// Init screen meta |
|
780 |
screenMeta.init(); |
|
781 |
||
9 | 782 |
/** |
783 |
* Checks a checkbox. |
|
784 |
* |
|
785 |
* This event needs to be delegated. Ticket #37973. |
|
786 |
* |
|
787 |
* @returns {boolean} Returns whether a checkbox is checked or not. |
|
788 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
789 |
$body.on( 'click', 'tbody > tr > .check-column :checkbox', function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
// Shift click to select a range of checkboxes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
791 |
if ( 'undefined' == event.shiftKey ) { return true; } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
792 |
if ( event.shiftKey ) { |
0 | 793 |
if ( !lastClicked ) { return true; } |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
794 |
checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' ).filter( ':visible:enabled' ); |
0 | 795 |
first = checks.index( lastClicked ); |
796 |
last = checks.index( this ); |
|
797 |
checked = $(this).prop('checked'); |
|
798 |
if ( 0 < first && 0 < last && first != last ) { |
|
799 |
sliced = ( last > first ) ? checks.slice( first, last ) : checks.slice( last, first ); |
|
800 |
sliced.prop( 'checked', function() { |
|
801 |
if ( $(this).closest('tr').is(':visible') ) |
|
802 |
return checked; |
|
803 |
||
804 |
return false; |
|
805 |
}); |
|
806 |
} |
|
807 |
} |
|
808 |
lastClicked = this; |
|
809 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
810 |
// Toggle the "Select all" checkboxes depending if the other ones are all checked or not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
811 |
var unchecked = $(this).closest('tbody').find(':checkbox').filter(':visible:enabled').not(':checked'); |
9 | 812 |
|
813 |
/** |
|
814 |
* Determines if all checkboxes are checked. |
|
815 |
* |
|
816 |
* @returns {boolean} Returns true if there are no unchecked checkboxes. |
|
817 |
*/ |
|
0 | 818 |
$(this).closest('table').children('thead, tfoot').find(':checkbox').prop('checked', function() { |
5 | 819 |
return ( 0 === unchecked.length ); |
0 | 820 |
}); |
821 |
||
822 |
return true; |
|
823 |
}); |
|
824 |
||
9 | 825 |
/** |
826 |
* Controls all the toggles on bulk toggle change. |
|
827 |
* |
|
828 |
* When the bulk checkbox is changed, all the checkboxes in the tables are changed accordingly. |
|
829 |
* When the shift-button is pressed while changing the bulk checkbox the checkboxes in the table are inverted. |
|
830 |
* |
|
831 |
* This event needs to be delegated. Ticket #37973. |
|
832 |
* |
|
833 |
* @param {Event} event The event object. |
|
834 |
* |
|
835 |
* @returns {boolean} |
|
836 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
837 |
$body.on( 'click.wp-toggle-checkboxes', 'thead .check-column :checkbox, tfoot .check-column :checkbox', function( event ) { |
5 | 838 |
var $this = $(this), |
839 |
$table = $this.closest( 'table' ), |
|
840 |
controlChecked = $this.prop('checked'), |
|
841 |
toggle = event.shiftKey || $this.data('wp-toggle'); |
|
0 | 842 |
|
5 | 843 |
$table.children( 'tbody' ).filter(':visible') |
844 |
.children().children('.check-column').find(':checkbox') |
|
9 | 845 |
/** |
846 |
* Updates the checked state on the checkbox in the table. |
|
847 |
* |
|
848 |
* @returns {boolean} True checks the checkbox, False unchecks the checkbox. |
|
849 |
*/ |
|
5 | 850 |
.prop('checked', function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
851 |
if ( $(this).is(':hidden,:disabled') ) { |
5 | 852 |
return false; |
853 |
} |
|
854 |
||
855 |
if ( toggle ) { |
|
856 |
return ! $(this).prop( 'checked' ); |
|
857 |
} else if ( controlChecked ) { |
|
858 |
return true; |
|
859 |
} |
|
860 |
||
0 | 861 |
return false; |
5 | 862 |
}); |
0 | 863 |
|
5 | 864 |
$table.children('thead, tfoot').filter(':visible') |
865 |
.children().children('.check-column').find(':checkbox') |
|
9 | 866 |
|
867 |
/** |
|
868 |
* Syncs the bulk checkboxes on the top and bottom of the table. |
|
869 |
* |
|
870 |
* @returns {boolean} True checks the checkbox, False unchecks the checkbox. |
|
871 |
*/ |
|
5 | 872 |
.prop('checked', function() { |
873 |
if ( toggle ) { |
|
874 |
return false; |
|
875 |
} else if ( controlChecked ) { |
|
876 |
return true; |
|
877 |
} |
|
878 |
||
0 | 879 |
return false; |
5 | 880 |
}); |
0 | 881 |
}); |
882 |
||
9 | 883 |
/** |
884 |
* Shows row actions on focus of its parent container element or any other elements contained within. |
|
885 |
* |
|
886 |
* @returns {void} |
|
887 |
*/ |
|
5 | 888 |
$( '#wpbody-content' ).on({ |
889 |
focusin: function() { |
|
890 |
clearTimeout( transitionTimeout ); |
|
891 |
focusedRowActions = $( this ).find( '.row-actions' ); |
|
892 |
// transitionTimeout is necessary for Firefox, but Chrome won't remove the CSS class without a little help. |
|
893 |
$( '.row-actions' ).not( this ).removeClass( 'visible' ); |
|
894 |
focusedRowActions.addClass( 'visible' ); |
|
895 |
}, |
|
896 |
focusout: function() { |
|
897 |
// Tabbing between post title and .row-actions links needs a brief pause, otherwise |
|
898 |
// the .row-actions div gets hidden in transit in some browsers (ahem, Firefox). |
|
899 |
transitionTimeout = setTimeout( function() { |
|
900 |
focusedRowActions.removeClass( 'visible' ); |
|
901 |
}, 30 ); |
|
902 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
903 |
}, '.has-row-actions' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
904 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
905 |
// Toggle list table rows on small screens |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
906 |
$( 'tbody' ).on( 'click', '.toggle-row', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
$( this ).closest( 'tr' ).toggleClass( 'is-expanded' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
908 |
}); |
0 | 909 |
|
910 |
$('#default-password-nag-no').click( function() { |
|
911 |
setUserSetting('default_password_nag', 'hide'); |
|
912 |
$('div.default-password-nag').hide(); |
|
913 |
return false; |
|
914 |
}); |
|
915 |
||
9 | 916 |
/** |
917 |
* Handles tab keypresses in theme and plugin editor textareas. |
|
918 |
* |
|
919 |
* @param {Event} e The event object. |
|
920 |
* |
|
921 |
* @returns {void} |
|
922 |
*/ |
|
0 | 923 |
$('#newcontent').bind('keydown.wpevent_InsertTab', function(e) { |
924 |
var el = e.target, selStart, selEnd, val, scroll, sel; |
|
925 |
||
9 | 926 |
// After pressing escape key (keyCode: 27), the tab key should tab out of the textarea. |
927 |
if ( e.keyCode == 27 ) { |
|
5 | 928 |
// when pressing Escape: Opera 12 and 27 blur form fields, IE 8 clears them |
929 |
e.preventDefault(); |
|
0 | 930 |
$(el).data('tab-out', true); |
931 |
return; |
|
932 |
} |
|
933 |
||
9 | 934 |
// Only listen for plain tab key (keyCode: 9) without any modifiers. |
935 |
if ( e.keyCode != 9 || e.ctrlKey || e.altKey || e.shiftKey ) |
|
0 | 936 |
return; |
937 |
||
9 | 938 |
// After tabbing out, reset it so next time the tab key can be used again. |
0 | 939 |
if ( $(el).data('tab-out') ) { |
940 |
$(el).data('tab-out', false); |
|
941 |
return; |
|
942 |
} |
|
943 |
||
944 |
selStart = el.selectionStart; |
|
945 |
selEnd = el.selectionEnd; |
|
946 |
val = el.value; |
|
947 |
||
9 | 948 |
// If any text is selected, replace the selection with a tab character. |
0 | 949 |
if ( document.selection ) { |
950 |
el.focus(); |
|
951 |
sel = document.selection.createRange(); |
|
952 |
sel.text = '\t'; |
|
953 |
} else if ( selStart >= 0 ) { |
|
954 |
scroll = this.scrollTop; |
|
955 |
el.value = val.substring(0, selStart).concat('\t', val.substring(selEnd) ); |
|
956 |
el.selectionStart = el.selectionEnd = selStart + 1; |
|
957 |
this.scrollTop = scroll; |
|
958 |
} |
|
959 |
||
9 | 960 |
// Cancel the regular tab functionality, to prevent losing focus of the textarea. |
0 | 961 |
if ( e.stopPropagation ) |
962 |
e.stopPropagation(); |
|
963 |
if ( e.preventDefault ) |
|
964 |
e.preventDefault(); |
|
965 |
}); |
|
966 |
||
9 | 967 |
// Reset page number variable for new filters/searches but not for bulk actions. See #17685. |
0 | 968 |
if ( pageInput.length ) { |
9 | 969 |
|
970 |
/** |
|
971 |
* Handles pagination variable when filtering the list table. |
|
972 |
* |
|
973 |
* Set the pagination argument to the first page when the post-filter form is submitted. |
|
974 |
* This happens when pressing the 'filter' button on the list table page. |
|
975 |
* |
|
976 |
* The pagination argument should not be touched when the bulk action dropdowns are set to do anything. |
|
977 |
* |
|
978 |
* The form closest to the pageInput is the post-filter form. |
|
979 |
* |
|
980 |
* @returns {void} |
|
981 |
*/ |
|
5 | 982 |
pageInput.closest('form').submit( function() { |
9 | 983 |
/* |
984 |
* action = bulk action dropdown at the top of the table |
|
985 |
* action2 = bulk action dropdow at the bottom of the table |
|
986 |
*/ |
|
0 | 987 |
if ( $('select[name="action"]').val() == -1 && $('select[name="action2"]').val() == -1 && pageInput.val() == currentPage ) |
988 |
pageInput.val('1'); |
|
989 |
}); |
|
990 |
} |
|
991 |
||
9 | 992 |
/** |
993 |
* Resets the bulk actions when the search button is clicked. |
|
994 |
* |
|
995 |
* @returns {void} |
|
996 |
*/ |
|
0 | 997 |
$('.search-box input[type="search"], .search-box input[type="submit"]').mousedown(function () { |
998 |
$('select[name^="action"]').val('-1'); |
|
999 |
}); |
|
1000 |
||
9 | 1001 |
/** |
1002 |
* Scrolls into view when focus.scroll-into-view is triggered. |
|
1003 |
* |
|
1004 |
* @param {Event} e The event object. |
|
1005 |
* |
|
1006 |
* @returns {void} |
|
1007 |
*/ |
|
0 | 1008 |
$('#contextual-help-link, #show-settings-link').on( 'focus.scroll-into-view', function(e){ |
1009 |
if ( e.target.scrollIntoView ) |
|
1010 |
e.target.scrollIntoView(false); |
|
1011 |
}); |
|
1012 |
||
9 | 1013 |
/** |
1014 |
* Disables the submit upload buttons when no data is entered. |
|
1015 |
* |
|
1016 |
* @returns {void} |
|
1017 |
*/ |
|
0 | 1018 |
(function(){ |
1019 |
var button, input, form = $('form.wp-upload-form'); |
|
9 | 1020 |
|
1021 |
// Exit when no upload form is found. |
|
0 | 1022 |
if ( ! form.length ) |
1023 |
return; |
|
9 | 1024 |
|
0 | 1025 |
button = form.find('input[type="submit"]'); |
1026 |
input = form.find('input[type="file"]'); |
|
1027 |
||
9 | 1028 |
/** |
1029 |
* Determines if any data is entered in any file upload input. |
|
1030 |
* |
|
1031 |
* @since 3.5.0 |
|
1032 |
* |
|
1033 |
* @returns {void} |
|
1034 |
*/ |
|
0 | 1035 |
function toggleUploadButton() { |
9 | 1036 |
// When no inputs have a value, disable the upload buttons. |
0 | 1037 |
button.prop('disabled', '' === input.map( function() { |
1038 |
return $(this).val(); |
|
1039 |
}).get().join('')); |
|
1040 |
} |
|
9 | 1041 |
|
1042 |
// Update the status initially. |
|
0 | 1043 |
toggleUploadButton(); |
9 | 1044 |
// Update the status when any file input changes. |
0 | 1045 |
input.on('change', toggleUploadButton); |
1046 |
})(); |
|
5 | 1047 |
|
9 | 1048 |
/** |
1049 |
* Pins the menu while distraction-free writing is enabled. |
|
1050 |
* |
|
1051 |
* @param {Event} event Event data. |
|
1052 |
* |
|
1053 |
* @since 4.1.0 |
|
1054 |
* |
|
1055 |
* @returns {void} |
|
1056 |
*/ |
|
5 | 1057 |
function pinMenu( event ) { |
1058 |
var windowPos = $window.scrollTop(), |
|
1059 |
resizing = ! event || event.type !== 'scroll'; |
|
1060 |
||
1061 |
if ( isIOS || isIE8 || $adminmenu.data( 'wp-responsive' ) ) { |
|
1062 |
return; |
|
1063 |
} |
|
1064 |
||
9 | 1065 |
/* |
1066 |
* When the menu is higher than the window and smaller than the entire page. |
|
1067 |
* It should be adjusted to be able to see the entire menu. |
|
1068 |
* |
|
1069 |
* Otherwise it can be accessed normally. |
|
1070 |
*/ |
|
5 | 1071 |
if ( height.menu + height.adminbar < height.window || |
1072 |
height.menu + height.adminbar + 20 > height.wpwrap ) { |
|
1073 |
unpinMenu(); |
|
1074 |
return; |
|
1075 |
} |
|
1076 |
||
1077 |
menuIsPinned = true; |
|
1078 |
||
9 | 1079 |
// If the menu is higher than the window, compensate on scroll. |
5 | 1080 |
if ( height.menu + height.adminbar > height.window ) { |
9 | 1081 |
// Check for overscrolling, this happens when swiping up at the top of the document in modern browsers. |
5 | 1082 |
if ( windowPos < 0 ) { |
9 | 1083 |
// Stick the menu to the top. |
5 | 1084 |
if ( ! pinnedMenuTop ) { |
1085 |
pinnedMenuTop = true; |
|
1086 |
pinnedMenuBottom = false; |
|
1087 |
||
1088 |
$adminMenuWrap.css({ |
|
1089 |
position: 'fixed', |
|
1090 |
top: '', |
|
1091 |
bottom: '' |
|
1092 |
}); |
|
1093 |
} |
|
1094 |
||
1095 |
return; |
|
1096 |
} else if ( windowPos + height.window > $document.height() - 1 ) { |
|
9 | 1097 |
// When overscrolling at the bottom, stick the menu to the bottom. |
5 | 1098 |
if ( ! pinnedMenuBottom ) { |
1099 |
pinnedMenuBottom = true; |
|
1100 |
pinnedMenuTop = false; |
|
1101 |
||
1102 |
$adminMenuWrap.css({ |
|
1103 |
position: 'fixed', |
|
1104 |
top: '', |
|
1105 |
bottom: 0 |
|
1106 |
}); |
|
1107 |
} |
|
1108 |
||
1109 |
return; |
|
1110 |
} |
|
1111 |
||
1112 |
if ( windowPos > lastScrollPosition ) { |
|
9 | 1113 |
// When a down scroll has been detected. |
1114 |
||
1115 |
// If it was pinned to the top, unpin and calculate relative scroll. |
|
5 | 1116 |
if ( pinnedMenuTop ) { |
1117 |
pinnedMenuTop = false; |
|
9 | 1118 |
// Calculate new offset position. |
5 | 1119 |
menuTop = $adminMenuWrap.offset().top - height.adminbar - ( windowPos - lastScrollPosition ); |
1120 |
||
1121 |
if ( menuTop + height.menu + height.adminbar < windowPos + height.window ) { |
|
1122 |
menuTop = windowPos + height.window - height.menu - height.adminbar; |
|
1123 |
} |
|
1124 |
||
1125 |
$adminMenuWrap.css({ |
|
1126 |
position: 'absolute', |
|
1127 |
top: menuTop, |
|
1128 |
bottom: '' |
|
1129 |
}); |
|
1130 |
} else if ( ! pinnedMenuBottom && $adminMenuWrap.offset().top + height.menu < windowPos + height.window ) { |
|
9 | 1131 |
// Pin it to the bottom. |
5 | 1132 |
pinnedMenuBottom = true; |
1133 |
||
1134 |
$adminMenuWrap.css({ |
|
1135 |
position: 'fixed', |
|
1136 |
top: '', |
|
1137 |
bottom: 0 |
|
1138 |
}); |
|
1139 |
} |
|
1140 |
} else if ( windowPos < lastScrollPosition ) { |
|
9 | 1141 |
// When a scroll up is detected. |
1142 |
||
1143 |
// If it was pinned to the bottom, unpin and calculate relative scroll. |
|
5 | 1144 |
if ( pinnedMenuBottom ) { |
1145 |
pinnedMenuBottom = false; |
|
9 | 1146 |
|
1147 |
// Calculate new offset position. |
|
5 | 1148 |
menuTop = $adminMenuWrap.offset().top - height.adminbar + ( lastScrollPosition - windowPos ); |
1149 |
||
1150 |
if ( menuTop + height.menu > windowPos + height.window ) { |
|
1151 |
menuTop = windowPos; |
|
1152 |
} |
|
1153 |
||
1154 |
$adminMenuWrap.css({ |
|
1155 |
position: 'absolute', |
|
1156 |
top: menuTop, |
|
1157 |
bottom: '' |
|
1158 |
}); |
|
1159 |
} else if ( ! pinnedMenuTop && $adminMenuWrap.offset().top >= windowPos + height.adminbar ) { |
|
9 | 1160 |
|
1161 |
// Pin it to the top. |
|
5 | 1162 |
pinnedMenuTop = true; |
1163 |
||
1164 |
$adminMenuWrap.css({ |
|
1165 |
position: 'fixed', |
|
1166 |
top: '', |
|
1167 |
bottom: '' |
|
1168 |
}); |
|
1169 |
} |
|
1170 |
} else if ( resizing ) { |
|
9 | 1171 |
// Window is being resized. |
1172 |
||
5 | 1173 |
pinnedMenuTop = pinnedMenuBottom = false; |
9 | 1174 |
|
1175 |
// Calculate the new offset. |
|
5 | 1176 |
menuTop = windowPos + height.window - height.menu - height.adminbar - 1; |
1177 |
||
1178 |
if ( menuTop > 0 ) { |
|
1179 |
$adminMenuWrap.css({ |
|
1180 |
position: 'absolute', |
|
1181 |
top: menuTop, |
|
1182 |
bottom: '' |
|
1183 |
}); |
|
1184 |
} else { |
|
1185 |
unpinMenu(); |
|
1186 |
} |
|
1187 |
} |
|
1188 |
} |
|
1189 |
||
1190 |
lastScrollPosition = windowPos; |
|
1191 |
} |
|
1192 |
||
9 | 1193 |
/** |
1194 |
* Determines the height of certain elements. |
|
1195 |
* |
|
1196 |
* @since 4.1.0 |
|
1197 |
* |
|
1198 |
* @returns {void} |
|
1199 |
*/ |
|
5 | 1200 |
function resetHeights() { |
1201 |
height = { |
|
1202 |
window: $window.height(), |
|
1203 |
wpwrap: $wpwrap.height(), |
|
1204 |
adminbar: $adminbar.height(), |
|
1205 |
menu: $adminMenuWrap.height() |
|
1206 |
}; |
|
1207 |
} |
|
1208 |
||
9 | 1209 |
/** |
1210 |
* Unpins the menu. |
|
1211 |
* |
|
1212 |
* @since 4.1.0 |
|
1213 |
* |
|
1214 |
* @returns {void} |
|
1215 |
*/ |
|
5 | 1216 |
function unpinMenu() { |
1217 |
if ( isIOS || ! menuIsPinned ) { |
|
1218 |
return; |
|
1219 |
} |
|
1220 |
||
1221 |
pinnedMenuTop = pinnedMenuBottom = menuIsPinned = false; |
|
1222 |
$adminMenuWrap.css({ |
|
1223 |
position: '', |
|
1224 |
top: '', |
|
1225 |
bottom: '' |
|
1226 |
}); |
|
1227 |
} |
|
1228 |
||
9 | 1229 |
/** |
1230 |
* Pins and unpins the menu when applicable. |
|
1231 |
* |
|
1232 |
* @since 4.1.0 |
|
1233 |
* |
|
1234 |
* @returns {void} |
|
1235 |
*/ |
|
5 | 1236 |
function setPinMenu() { |
1237 |
resetHeights(); |
|
1238 |
||
1239 |
if ( $adminmenu.data('wp-responsive') ) { |
|
1240 |
$body.removeClass( 'sticky-menu' ); |
|
1241 |
unpinMenu(); |
|
1242 |
} else if ( height.menu + height.adminbar > height.window ) { |
|
1243 |
pinMenu(); |
|
1244 |
$body.removeClass( 'sticky-menu' ); |
|
1245 |
} else { |
|
1246 |
$body.addClass( 'sticky-menu' ); |
|
1247 |
unpinMenu(); |
|
1248 |
} |
|
1249 |
} |
|
1250 |
||
1251 |
if ( ! isIOS ) { |
|
1252 |
$window.on( 'scroll.pin-menu', pinMenu ); |
|
1253 |
$document.on( 'tinymce-editor-init.pin-menu', function( event, editor ) { |
|
1254 |
editor.on( 'wp-autoresize', resetHeights ); |
|
1255 |
}); |
|
1256 |
} |
|
1257 |
||
9 | 1258 |
/** |
1259 |
* Changes the sortables and responsiveness of metaboxes. |
|
1260 |
* |
|
1261 |
* @since 3.8.0 |
|
1262 |
* |
|
1263 |
*@returns {void} |
|
1264 |
*/ |
|
5 | 1265 |
window.wpResponsive = { |
9 | 1266 |
|
1267 |
/** |
|
1268 |
* Initializes the wpResponsive object. |
|
1269 |
* |
|
1270 |
* @since 3.8.0 |
|
1271 |
* |
|
1272 |
* @returns {void} |
|
1273 |
*/ |
|
5 | 1274 |
init: function() { |
1275 |
var self = this; |
|
1276 |
||
1277 |
// Modify functionality based on custom activate/deactivate event |
|
1278 |
$document.on( 'wp-responsive-activate.wp-responsive', function() { |
|
1279 |
self.activate(); |
|
1280 |
}).on( 'wp-responsive-deactivate.wp-responsive', function() { |
|
1281 |
self.deactivate(); |
|
1282 |
}); |
|
1283 |
||
1284 |
$( '#wp-admin-bar-menu-toggle a' ).attr( 'aria-expanded', 'false' ); |
|
1285 |
||
9 | 1286 |
// Toggle sidebar when toggle is clicked. |
5 | 1287 |
$( '#wp-admin-bar-menu-toggle' ).on( 'click.wp-responsive', function( event ) { |
1288 |
event.preventDefault(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1289 |
|
9 | 1290 |
// close any open toolbar submenus. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1291 |
$adminbar.find( '.hover' ).removeClass( 'hover' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1292 |
|
5 | 1293 |
$wpwrap.toggleClass( 'wp-responsive-open' ); |
1294 |
if ( $wpwrap.hasClass( 'wp-responsive-open' ) ) { |
|
1295 |
$(this).find('a').attr( 'aria-expanded', 'true' ); |
|
1296 |
$( '#adminmenu a:first' ).focus(); |
|
1297 |
} else { |
|
1298 |
$(this).find('a').attr( 'aria-expanded', 'false' ); |
|
1299 |
} |
|
1300 |
} ); |
|
1301 |
||
9 | 1302 |
// Add menu events. |
5 | 1303 |
$adminmenu.on( 'click.wp-responsive', 'li.wp-has-submenu > a', function( event ) { |
1304 |
if ( ! $adminmenu.data('wp-responsive') ) { |
|
1305 |
return; |
|
1306 |
} |
|
1307 |
||
1308 |
$( this ).parent( 'li' ).toggleClass( 'selected' ); |
|
1309 |
event.preventDefault(); |
|
1310 |
}); |
|
1311 |
||
1312 |
self.trigger(); |
|
1313 |
$document.on( 'wp-window-resized.wp-responsive', $.proxy( this.trigger, this ) ); |
|
1314 |
||
9 | 1315 |
// This needs to run later as UI Sortable may be initialized later on $(document).ready(). |
5 | 1316 |
$window.on( 'load.wp-responsive', function() { |
1317 |
var width = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? $window.width() : window.innerWidth; |
|
1318 |
||
1319 |
if ( width <= 782 ) { |
|
1320 |
self.disableSortables(); |
|
1321 |
} |
|
1322 |
}); |
|
1323 |
}, |
|
1324 |
||
9 | 1325 |
/** |
1326 |
* Changes properties of body and admin menu. |
|
1327 |
* |
|
1328 |
* Pins and unpins the menu and adds the auto-fold class to the body. |
|
1329 |
* Makes the admin menu responsive and disables the metabox sortables. |
|
1330 |
* |
|
1331 |
* @since 3.8.0 |
|
1332 |
* |
|
1333 |
* @returns {void} |
|
1334 |
*/ |
|
5 | 1335 |
activate: function() { |
1336 |
setPinMenu(); |
|
1337 |
||
1338 |
if ( ! $body.hasClass( 'auto-fold' ) ) { |
|
1339 |
$body.addClass( 'auto-fold' ); |
|
1340 |
} |
|
1341 |
||
1342 |
$adminmenu.data( 'wp-responsive', 1 ); |
|
1343 |
this.disableSortables(); |
|
1344 |
}, |
|
1345 |
||
9 | 1346 |
/** |
1347 |
* Changes properties of admin menu and enables metabox sortables. |
|
1348 |
* |
|
1349 |
* Pin and unpin the menu. |
|
1350 |
* Removes the responsiveness of the admin menu and enables the metabox sortables. |
|
1351 |
* |
|
1352 |
* @since 3.8.0 |
|
1353 |
* |
|
1354 |
* @returns {void} |
|
1355 |
*/ |
|
5 | 1356 |
deactivate: function() { |
1357 |
setPinMenu(); |
|
1358 |
$adminmenu.removeData('wp-responsive'); |
|
1359 |
this.enableSortables(); |
|
1360 |
}, |
|
1361 |
||
9 | 1362 |
/** |
1363 |
* Sets the responsiveness and enables the overlay based on the viewport width. |
|
1364 |
* |
|
1365 |
* @since 3.8.0 |
|
1366 |
* |
|
1367 |
* @returns {void} |
|
1368 |
*/ |
|
5 | 1369 |
trigger: function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1370 |
var viewportWidth = getViewportWidth(); |
5 | 1371 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1372 |
// Exclude IE < 9, it doesn't support @media CSS rules. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1373 |
if ( ! viewportWidth ) { |
5 | 1374 |
return; |
1375 |
} |
|
1376 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1377 |
if ( viewportWidth <= 782 ) { |
5 | 1378 |
if ( ! wpResponsiveActive ) { |
1379 |
$document.trigger( 'wp-responsive-activate' ); |
|
1380 |
wpResponsiveActive = true; |
|
1381 |
} |
|
1382 |
} else { |
|
1383 |
if ( wpResponsiveActive ) { |
|
1384 |
$document.trigger( 'wp-responsive-deactivate' ); |
|
1385 |
wpResponsiveActive = false; |
|
1386 |
} |
|
1387 |
} |
|
1388 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1389 |
if ( viewportWidth <= 480 ) { |
5 | 1390 |
this.enableOverlay(); |
1391 |
} else { |
|
1392 |
this.disableOverlay(); |
|
1393 |
} |
|
1394 |
}, |
|
1395 |
||
9 | 1396 |
/** |
1397 |
* Inserts a responsive overlay and toggles the window. |
|
1398 |
* |
|
1399 |
* @since 3.8.0 |
|
1400 |
* |
|
1401 |
* @returns {void} |
|
1402 |
*/ |
|
5 | 1403 |
enableOverlay: function() { |
1404 |
if ( $overlay.length === 0 ) { |
|
1405 |
$overlay = $( '<div id="wp-responsive-overlay"></div>' ) |
|
1406 |
.insertAfter( '#wpcontent' ) |
|
1407 |
.hide() |
|
1408 |
.on( 'click.wp-responsive', function() { |
|
1409 |
$toolbar.find( '.menupop.hover' ).removeClass( 'hover' ); |
|
1410 |
$( this ).hide(); |
|
1411 |
}); |
|
1412 |
} |
|
1413 |
||
1414 |
$toolbarPopups.on( 'click.wp-responsive', function() { |
|
1415 |
$overlay.show(); |
|
1416 |
}); |
|
1417 |
}, |
|
1418 |
||
9 | 1419 |
/** |
1420 |
* Disables the responsive overlay and removes the overlay. |
|
1421 |
* |
|
1422 |
* @since 3.8.0 |
|
1423 |
* |
|
1424 |
* @returns {void} |
|
1425 |
*/ |
|
5 | 1426 |
disableOverlay: function() { |
1427 |
$toolbarPopups.off( 'click.wp-responsive' ); |
|
1428 |
$overlay.hide(); |
|
1429 |
}, |
|
1430 |
||
9 | 1431 |
/** |
1432 |
* Disables sortables. |
|
1433 |
* |
|
1434 |
* @since 3.8.0 |
|
1435 |
* |
|
1436 |
* @returns {void} |
|
1437 |
*/ |
|
5 | 1438 |
disableSortables: function() { |
1439 |
if ( $sortables.length ) { |
|
1440 |
try { |
|
9 | 1441 |
$sortables.sortable( 'disable' ); |
1442 |
} catch ( e ) {} |
|
5 | 1443 |
} |
1444 |
}, |
|
1445 |
||
9 | 1446 |
/** |
1447 |
* Enables sortables. |
|
1448 |
* |
|
1449 |
* @since 3.8.0 |
|
1450 |
* |
|
1451 |
* @returns {void} |
|
1452 |
*/ |
|
5 | 1453 |
enableSortables: function() { |
1454 |
if ( $sortables.length ) { |
|
1455 |
try { |
|
9 | 1456 |
$sortables.sortable( 'enable' ); |
1457 |
} catch ( e ) {} |
|
5 | 1458 |
} |
1459 |
} |
|
1460 |
}; |
|
1461 |
||
9 | 1462 |
/** |
1463 |
* Add an ARIA role `button` to elements that behave like UI controls when JavaScript is on. |
|
1464 |
* |
|
1465 |
* @since 4.5.0 |
|
1466 |
* |
|
1467 |
* @returns {void} |
|
1468 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1469 |
function aria_button_if_js() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1470 |
$( '.aria-button-if-js' ).attr( 'role', 'button' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1471 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1472 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1473 |
$( document ).ajaxComplete( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1474 |
aria_button_if_js(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1475 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1476 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1477 |
/** |
9 | 1478 |
* Get the viewport width. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1479 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1480 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1481 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1482 |
* @returns {number|boolean} The current viewport width or false if the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1483 |
* browser doesn't support innerWidth (IE < 9). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1484 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1485 |
function getViewportWidth() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1486 |
var viewportWidth = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1487 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1488 |
if ( window.innerWidth ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1489 |
// On phones, window.innerWidth is affected by zooming. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1490 |
viewportWidth = Math.max( window.innerWidth, document.documentElement.clientWidth ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1491 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1492 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1493 |
return viewportWidth; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1494 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1495 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1496 |
/** |
9 | 1497 |
* Sets the admin menu collapsed/expanded state. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1498 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1499 |
* Sets the global variable `menuState` and triggers a custom event passing |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1500 |
* the current menu state. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1501 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1502 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1503 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1504 |
* @returns {void} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1505 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1506 |
function setMenuState() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1507 |
var viewportWidth = getViewportWidth() || 961; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1508 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1509 |
if ( viewportWidth <= 782 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1510 |
menuState = 'responsive'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1511 |
} else if ( $body.hasClass( 'folded' ) || ( $body.hasClass( 'auto-fold' ) && viewportWidth <= 960 && viewportWidth > 782 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1512 |
menuState = 'folded'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1513 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1514 |
menuState = 'open'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1515 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1516 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1517 |
$document.trigger( 'wp-menu-state-set', { state: menuState } ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1518 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1519 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1520 |
// Set the menu state when the window gets resized. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1521 |
$document.on( 'wp-window-resized.set-menu-state', setMenuState ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1522 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1523 |
/** |
9 | 1524 |
* Sets ARIA attributes on the collapse/expand menu button. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1525 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1526 |
* When the admin menu is open or folded, updates the `aria-expanded` and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1527 |
* `aria-label` attributes of the button to give feedback to assistive |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1528 |
* technologies. In the responsive view, the button is always hidden. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1529 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1530 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1531 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1532 |
* @returns {void} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1533 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1534 |
$document.on( 'wp-menu-state-set wp-collapse-menu', function( event, eventData ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1535 |
var $collapseButton = $( '#collapse-button' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1536 |
ariaExpanded = 'true', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1537 |
ariaLabelText = commonL10n.collapseMenu; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1538 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1539 |
if ( 'folded' === eventData.state ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1540 |
ariaExpanded = 'false'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1541 |
ariaLabelText = commonL10n.expandMenu; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1542 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1543 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1544 |
$collapseButton.attr({ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1545 |
'aria-expanded': ariaExpanded, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1546 |
'aria-label': ariaLabelText |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1547 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1548 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1549 |
|
5 | 1550 |
window.wpResponsive.init(); |
1551 |
setPinMenu(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1552 |
setMenuState(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1553 |
currentMenuItemHasPopup(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1554 |
makeNoticesDismissible(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1555 |
aria_button_if_js(); |
5 | 1556 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1557 |
$document.on( 'wp-pin-menu wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu wp-collapse-menu.pin-menu wp-scroll-start.pin-menu', setPinMenu ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1558 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1559 |
// Set initial focus on a specific element. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1560 |
$( '.wp-initial-focus' ).focus(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1561 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1562 |
// Toggle update details on update-core.php. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1563 |
$body.on( 'click', '.js-update-details-toggle', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1564 |
var $updateNotice = $( this ).closest( '.js-update-details' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1565 |
$progressDiv = $( '#' + $updateNotice.data( 'update-details' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1566 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1567 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1568 |
* When clicking on "Show details" move the progress div below the update |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1569 |
* notice. Make sure it gets moved just the first time. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1570 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1571 |
if ( ! $progressDiv.hasClass( 'update-details-moved' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1572 |
$progressDiv.insertAfter( $updateNotice ).addClass( 'update-details-moved' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1573 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1574 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1575 |
// Toggle the progress div visibility. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1576 |
$progressDiv.toggle(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1577 |
// Toggle the Show Details button expanded state. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1578 |
$( this ).attr( 'aria-expanded', $progressDiv.is( ':visible' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1579 |
}); |
0 | 1580 |
}); |
1581 |
||
9 | 1582 |
// Fire a custom jQuery event at the end of window resize. |
5 | 1583 |
( function() { |
1584 |
var timeout; |
|
1585 |
||
9 | 1586 |
/** |
1587 |
* Triggers the WP window-resize event. |
|
1588 |
* |
|
1589 |
* @since 3.8.0 |
|
1590 |
* |
|
1591 |
* @returns {void} |
|
1592 |
*/ |
|
5 | 1593 |
function triggerEvent() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1594 |
$document.trigger( 'wp-window-resized' ); |
5 | 1595 |
} |
1596 |
||
9 | 1597 |
/** |
1598 |
* Fires the trigger event again after 200 ms. |
|
1599 |
* |
|
1600 |
* @since 3.8.0 |
|
1601 |
* |
|
1602 |
* @returns {void} |
|
1603 |
*/ |
|
5 | 1604 |
function fireOnce() { |
1605 |
window.clearTimeout( timeout ); |
|
1606 |
timeout = window.setTimeout( triggerEvent, 200 ); |
|
1607 |
} |
|
0 | 1608 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1609 |
$window.on( 'resize.wp-fire-once', fireOnce ); |
5 | 1610 |
}()); |
0 | 1611 |
|
5 | 1612 |
// Make Windows 8 devices play along nicely. |
1613 |
(function(){ |
|
1614 |
if ( '-ms-user-select' in document.documentElement.style && navigator.userAgent.match(/IEMobile\/10\.0/) ) { |
|
1615 |
var msViewportStyle = document.createElement( 'style' ); |
|
1616 |
msViewportStyle.appendChild( |
|
1617 |
document.createTextNode( '@-ms-viewport{width:auto!important}' ) |
|
1618 |
); |
|
1619 |
document.getElementsByTagName( 'head' )[0].appendChild( msViewportStyle ); |
|
1620 |
} |
|
1621 |
})(); |
|
0 | 1622 |
|
5 | 1623 |
}( jQuery, window )); |