author | ymh <ymh.work@gmail.com> |
Tue, 15 Dec 2020 13:49:49 +0100 | |
changeset 16 | a86126ab1dd4 |
parent 9 | 177826044cd9 |
child 18 | be944660c56a |
permissions | -rw-r--r-- |
9 | 1 |
/** |
2 |
* @output wp-admin/js/common.js |
|
3 |
*/ |
|
4 |
||
16 | 5 |
/* global setUserSetting, ajaxurl, 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 ), |
16 | 18 |
$body = $( document.body ), |
19 |
__ = wp.i18n.__, |
|
20 |
sprintf = wp.i18n.sprintf; |
|
21 |
||
22 |
/** |
|
23 |
* Throws an error for a deprecated property. |
|
24 |
* |
|
25 |
* @since 5.5.1 |
|
26 |
* |
|
27 |
* @param {string} propName The property that was used. |
|
28 |
* @param {string} version The version of WordPress that deprecated the property. |
|
29 |
* @param {string} replacement The property that should have been used. |
|
30 |
*/ |
|
31 |
function deprecatedProperty( propName, version, replacement ) { |
|
32 |
var message; |
|
33 |
||
34 |
if ( 'undefined' !== typeof replacement ) { |
|
35 |
message = sprintf( |
|
36 |
/* translators: 1: Deprecated property name, 2: Version number, 3: Alternative property name. */ |
|
37 |
__( '%1$s is deprecated since version %2$s! Use %3$s instead.' ), |
|
38 |
propName, |
|
39 |
version, |
|
40 |
replacement |
|
41 |
); |
|
42 |
} else { |
|
43 |
message = sprintf( |
|
44 |
/* translators: 1: Deprecated property name, 2: Version number. */ |
|
45 |
__( '%1$s is deprecated since version %2$s with no alternative available.' ), |
|
46 |
propName, |
|
47 |
version |
|
48 |
); |
|
49 |
} |
|
50 |
||
51 |
window.console.warn( message ); |
|
52 |
} |
|
53 |
||
54 |
/** |
|
55 |
* Deprecate all properties on an object. |
|
56 |
* |
|
57 |
* @since 5.5.1 |
|
58 |
* |
|
59 |
* @param {string} name The name of the object, i.e. commonL10n. |
|
60 |
* @param {object} l10nObject The object to deprecate the properties on. |
|
61 |
* |
|
62 |
* @return {object} The object with all its properties deprecated. |
|
63 |
*/ |
|
64 |
function deprecateL10nObject( name, l10nObject ) { |
|
65 |
var deprecatedObject = {}; |
|
66 |
||
67 |
Object.keys( l10nObject ).forEach( function( key ) { |
|
68 |
var prop = l10nObject[ key ]; |
|
69 |
var propName = name + '.' + key; |
|
70 |
||
71 |
if ( 'object' === typeof prop ) { |
|
72 |
Object.defineProperty( deprecatedObject, key, { get: function() { |
|
73 |
deprecatedProperty( propName, '5.5.0', prop.alternative ); |
|
74 |
return prop.func(); |
|
75 |
} } ); |
|
76 |
} else { |
|
77 |
Object.defineProperty( deprecatedObject, key, { get: function() { |
|
78 |
deprecatedProperty( propName, '5.5.0', 'wp.i18n' ); |
|
79 |
return prop; |
|
80 |
} } ); |
|
81 |
} |
|
82 |
} ); |
|
83 |
||
84 |
return deprecatedObject; |
|
85 |
} |
|
86 |
||
87 |
window.wp.deprecateL10nObject = deprecateL10nObject; |
|
88 |
||
89 |
/** |
|
90 |
* Removed in 5.5.0, needed for back-compatibility. |
|
91 |
* |
|
92 |
* @since 2.6.0 |
|
93 |
* @deprecated 5.5.0 |
|
94 |
*/ |
|
95 |
window.commonL10n = window.commonL10n || { |
|
96 |
warnDelete: '', |
|
97 |
dismiss: '', |
|
98 |
collapseMenu: '', |
|
99 |
expandMenu: '' |
|
100 |
}; |
|
101 |
||
102 |
window.commonL10n = deprecateL10nObject( 'commonL10n', window.commonL10n ); |
|
103 |
||
104 |
/** |
|
105 |
* Removed in 5.5.0, needed for back-compatibility. |
|
106 |
* |
|
107 |
* @since 3.3.0 |
|
108 |
* @deprecated 5.5.0 |
|
109 |
*/ |
|
110 |
window.wpPointerL10n = window.wpPointerL10n || { |
|
111 |
dismiss: '' |
|
112 |
}; |
|
113 |
||
114 |
window.wpPointerL10n = deprecateL10nObject( 'wpPointerL10n', window.wpPointerL10n ); |
|
115 |
||
116 |
/** |
|
117 |
* Removed in 5.5.0, needed for back-compatibility. |
|
118 |
* |
|
119 |
* @since 4.3.0 |
|
120 |
* @deprecated 5.5.0 |
|
121 |
*/ |
|
122 |
window.userProfileL10n = window.userProfileL10n || { |
|
123 |
warn: '', |
|
124 |
warnWeak: '', |
|
125 |
show: '', |
|
126 |
hide: '', |
|
127 |
cancel: '', |
|
128 |
ariaShow: '', |
|
129 |
ariaHide: '' |
|
130 |
}; |
|
131 |
||
132 |
window.userProfileL10n = deprecateL10nObject( 'userProfileL10n', window.userProfileL10n ); |
|
133 |
||
134 |
/** |
|
135 |
* Removed in 5.5.0, needed for back-compatibility. |
|
136 |
* |
|
137 |
* @since 4.9.6 |
|
138 |
* @deprecated 5.5.0 |
|
139 |
*/ |
|
140 |
window.privacyToolsL10n = window.privacyToolsL10n || { |
|
141 |
noDataFound: '', |
|
142 |
foundAndRemoved: '', |
|
143 |
noneRemoved: '', |
|
144 |
someNotRemoved: '', |
|
145 |
removalError: '', |
|
146 |
emailSent: '', |
|
147 |
noExportFile: '', |
|
148 |
exportError: '' |
|
149 |
}; |
|
150 |
||
151 |
window.privacyToolsL10n = deprecateL10nObject( 'privacyToolsL10n', window.privacyToolsL10n ); |
|
152 |
||
153 |
/** |
|
154 |
* Removed in 5.5.0, needed for back-compatibility. |
|
155 |
* |
|
156 |
* @since 3.6.0 |
|
157 |
* @deprecated 5.5.0 |
|
158 |
*/ |
|
159 |
window.authcheckL10n = { |
|
160 |
beforeunload: '' |
|
161 |
}; |
|
162 |
||
163 |
window.authcheckL10n = window.authcheckL10n || deprecateL10nObject( 'authcheckL10n', window.authcheckL10n ); |
|
164 |
||
165 |
/** |
|
166 |
* Removed in 5.5.0, needed for back-compatibility. |
|
167 |
* |
|
168 |
* @since 2.8.0 |
|
169 |
* @deprecated 5.5.0 |
|
170 |
*/ |
|
171 |
window.tagsl10n = { |
|
172 |
noPerm: '', |
|
173 |
broken: '' |
|
174 |
}; |
|
175 |
||
176 |
window.tagsl10n = window.tagsl10n || deprecateL10nObject( 'tagsl10n', window.tagsl10n ); |
|
177 |
||
178 |
/** |
|
179 |
* Removed in 5.5.0, needed for back-compatibility. |
|
180 |
* |
|
181 |
* @since 2.5.0 |
|
182 |
* @deprecated 5.5.0 |
|
183 |
*/ |
|
184 |
window.adminCommentsL10n = window.adminCommentsL10n || { |
|
185 |
hotkeys_highlight_first: { |
|
186 |
alternative: 'window.adminCommentsSettings.hotkeys_highlight_first', |
|
187 |
func: function() { return window.adminCommentsSettings.hotkeys_highlight_first; } |
|
188 |
}, |
|
189 |
hotkeys_highlight_last: { |
|
190 |
alternative: 'window.adminCommentsSettings.hotkeys_highlight_last', |
|
191 |
func: function() { return window.adminCommentsSettings.hotkeys_highlight_last; } |
|
192 |
}, |
|
193 |
replyApprove: '', |
|
194 |
reply: '', |
|
195 |
warnQuickEdit: '', |
|
196 |
warnCommentChanges: '', |
|
197 |
docTitleComments: '', |
|
198 |
docTitleCommentsCount: '' |
|
199 |
}; |
|
200 |
||
201 |
window.adminCommentsL10n = deprecateL10nObject( 'adminCommentsL10n', window.adminCommentsL10n ); |
|
202 |
||
203 |
/** |
|
204 |
* Removed in 5.5.0, needed for back-compatibility. |
|
205 |
* |
|
206 |
* @since 2.5.0 |
|
207 |
* @deprecated 5.5.0 |
|
208 |
*/ |
|
209 |
window.tagsSuggestL10n = window.tagsSuggestL10n || { |
|
210 |
tagDelimiter: '', |
|
211 |
removeTerm: '', |
|
212 |
termSelected: '', |
|
213 |
termAdded: '', |
|
214 |
termRemoved: '' |
|
215 |
}; |
|
216 |
||
217 |
window.tagsSuggestL10n = deprecateL10nObject( 'tagsSuggestL10n', window.tagsSuggestL10n ); |
|
218 |
||
219 |
/** |
|
220 |
* Removed in 5.5.0, needed for back-compatibility. |
|
221 |
* |
|
222 |
* @since 3.5.0 |
|
223 |
* @deprecated 5.5.0 |
|
224 |
*/ |
|
225 |
window.wpColorPickerL10n = window.wpColorPickerL10n || { |
|
226 |
clear: '', |
|
227 |
clearAriaLabel: '', |
|
228 |
defaultString: '', |
|
229 |
defaultAriaLabel: '', |
|
230 |
pick: '', |
|
231 |
defaultLabel: '' |
|
232 |
}; |
|
233 |
||
234 |
window.wpColorPickerL10n = deprecateL10nObject( 'wpColorPickerL10n', window.wpColorPickerL10n ); |
|
235 |
||
236 |
/** |
|
237 |
* Removed in 5.5.0, needed for back-compatibility. |
|
238 |
* |
|
239 |
* @since 2.7.0 |
|
240 |
* @deprecated 5.5.0 |
|
241 |
*/ |
|
242 |
window.attachMediaBoxL10n = window.attachMediaBoxL10n || { |
|
243 |
error: '' |
|
244 |
}; |
|
245 |
||
246 |
window.attachMediaBoxL10n = deprecateL10nObject( 'attachMediaBoxL10n', window.attachMediaBoxL10n ); |
|
247 |
||
248 |
/** |
|
249 |
* Removed in 5.5.0, needed for back-compatibility. |
|
250 |
* |
|
251 |
* @since 2.5.0 |
|
252 |
* @deprecated 5.5.0 |
|
253 |
*/ |
|
254 |
window.postL10n = window.postL10n || { |
|
255 |
ok: '', |
|
256 |
cancel: '', |
|
257 |
publishOn: '', |
|
258 |
publishOnFuture: '', |
|
259 |
publishOnPast: '', |
|
260 |
dateFormat: '', |
|
261 |
showcomm: '', |
|
262 |
endcomm: '', |
|
263 |
publish: '', |
|
264 |
schedule: '', |
|
265 |
update: '', |
|
266 |
savePending: '', |
|
267 |
saveDraft: '', |
|
268 |
'private': '', |
|
269 |
'public': '', |
|
270 |
publicSticky: '', |
|
271 |
password: '', |
|
272 |
privatelyPublished: '', |
|
273 |
published: '', |
|
274 |
saveAlert: '', |
|
275 |
savingText: '', |
|
276 |
permalinkSaved: '' |
|
277 |
}; |
|
278 |
||
279 |
window.postL10n = deprecateL10nObject( 'postL10n', window.postL10n ); |
|
280 |
||
281 |
/** |
|
282 |
* Removed in 5.5.0, needed for back-compatibility. |
|
283 |
* |
|
284 |
* @since 2.7.0 |
|
285 |
* @deprecated 5.5.0 |
|
286 |
*/ |
|
287 |
window.inlineEditL10n = window.inlineEditL10n || { |
|
288 |
error: '', |
|
289 |
ntdeltitle: '', |
|
290 |
notitle: '', |
|
291 |
comma: '', |
|
292 |
saved: '' |
|
293 |
}; |
|
294 |
||
295 |
window.inlineEditL10n = deprecateL10nObject( 'inlineEditL10n', window.inlineEditL10n ); |
|
296 |
||
297 |
/** |
|
298 |
* Removed in 5.5.0, needed for back-compatibility. |
|
299 |
* |
|
300 |
* @since 2.7.0 |
|
301 |
* @deprecated 5.5.0 |
|
302 |
*/ |
|
303 |
window.plugininstallL10n = window.plugininstallL10n || { |
|
304 |
plugin_information: '', |
|
305 |
plugin_modal_label: '', |
|
306 |
ays: '' |
|
307 |
}; |
|
308 |
||
309 |
window.plugininstallL10n = deprecateL10nObject( 'plugininstallL10n', window.plugininstallL10n ); |
|
310 |
||
311 |
/** |
|
312 |
* Removed in 5.5.0, needed for back-compatibility. |
|
313 |
* |
|
314 |
* @since 3.0.0 |
|
315 |
* @deprecated 5.5.0 |
|
316 |
*/ |
|
317 |
window.navMenuL10n = window.navMenuL10n || { |
|
318 |
noResultsFound: '', |
|
319 |
warnDeleteMenu: '', |
|
320 |
saveAlert: '', |
|
321 |
untitled: '' |
|
322 |
}; |
|
323 |
||
324 |
window.navMenuL10n = deprecateL10nObject( 'navMenuL10n', window.navMenuL10n ); |
|
325 |
||
326 |
/** |
|
327 |
* Removed in 5.5.0, needed for back-compatibility. |
|
328 |
* |
|
329 |
* @since 2.5.0 |
|
330 |
* @deprecated 5.5.0 |
|
331 |
*/ |
|
332 |
window.commentL10n = window.commentL10n || { |
|
333 |
submittedOn: '', |
|
334 |
dateFormat: '' |
|
335 |
}; |
|
336 |
||
337 |
window.commentL10n = deprecateL10nObject( 'commentL10n', window.commentL10n ); |
|
338 |
||
339 |
/** |
|
340 |
* Removed in 5.5.0, needed for back-compatibility. |
|
341 |
* |
|
342 |
* @since 2.9.0 |
|
343 |
* @deprecated 5.5.0 |
|
344 |
*/ |
|
345 |
window.setPostThumbnailL10n = window.setPostThumbnailL10n || { |
|
346 |
setThumbnail: '', |
|
347 |
saving: '', |
|
348 |
error: '', |
|
349 |
done: '' |
|
350 |
}; |
|
351 |
||
352 |
window.setPostThumbnailL10n = deprecateL10nObject( 'setPostThumbnailL10n', window.setPostThumbnailL10n ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
353 |
|
9 | 354 |
/** |
355 |
* Removed in 3.3.0, needed for back-compatibility. |
|
356 |
* |
|
357 |
* @since 2.7.0 |
|
358 |
* @deprecated 3.3.0 |
|
359 |
*/ |
|
360 |
window.adminMenu = { |
|
0 | 361 |
init : function() {}, |
362 |
fold : function() {}, |
|
363 |
restoreMenuState : function() {}, |
|
364 |
toggle : function() {}, |
|
365 |
favorites : function() {} |
|
366 |
}; |
|
367 |
||
9 | 368 |
// Show/hide/save table columns. |
369 |
window.columns = { |
|
370 |
||
371 |
/** |
|
372 |
* Initializes the column toggles in the screen options. |
|
373 |
* |
|
374 |
* Binds an onClick event to the checkboxes to show or hide the table columns |
|
375 |
* based on their toggled state. And persists the toggled state. |
|
376 |
* |
|
377 |
* @since 2.7.0 |
|
378 |
* |
|
16 | 379 |
* @return {void} |
9 | 380 |
*/ |
0 | 381 |
init : function() { |
382 |
var that = this; |
|
383 |
$('.hide-column-tog', '#adv-settings').click( function() { |
|
384 |
var $t = $(this), column = $t.val(); |
|
385 |
if ( $t.prop('checked') ) |
|
386 |
that.checked(column); |
|
387 |
else |
|
388 |
that.unchecked(column); |
|
389 |
||
390 |
columns.saveManageColumnsState(); |
|
391 |
}); |
|
392 |
}, |
|
393 |
||
9 | 394 |
/** |
395 |
* Saves the toggled state for the columns. |
|
396 |
* |
|
397 |
* Saves whether the columns should be shown or hidden on a page. |
|
398 |
* |
|
399 |
* @since 3.0.0 |
|
400 |
* |
|
16 | 401 |
* @return {void} |
9 | 402 |
*/ |
0 | 403 |
saveManageColumnsState : function() { |
404 |
var hidden = this.hidden(); |
|
405 |
$.post(ajaxurl, { |
|
406 |
action: 'hidden-columns', |
|
407 |
hidden: hidden, |
|
408 |
screenoptionnonce: $('#screenoptionnonce').val(), |
|
409 |
page: pagenow |
|
410 |
}); |
|
411 |
}, |
|
412 |
||
9 | 413 |
/** |
414 |
* Makes a column visible and adjusts the column span for the table. |
|
415 |
* |
|
416 |
* @since 3.0.0 |
|
417 |
* @param {string} column The column name. |
|
418 |
* |
|
16 | 419 |
* @return {void} |
9 | 420 |
*/ |
0 | 421 |
checked : function(column) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
$('.column-' + column).removeClass( 'hidden' ); |
0 | 423 |
this.colSpanChange(+1); |
424 |
}, |
|
425 |
||
9 | 426 |
/** |
427 |
* Hides a column and adjusts the column span for the table. |
|
428 |
* |
|
429 |
* @since 3.0.0 |
|
430 |
* @param {string} column The column name. |
|
431 |
* |
|
16 | 432 |
* @return {void} |
9 | 433 |
*/ |
0 | 434 |
unchecked : function(column) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
435 |
$('.column-' + column).addClass( 'hidden' ); |
0 | 436 |
this.colSpanChange(-1); |
437 |
}, |
|
438 |
||
9 | 439 |
/** |
440 |
* Gets all hidden columns. |
|
441 |
* |
|
442 |
* @since 3.0.0 |
|
443 |
* |
|
16 | 444 |
* @return {string} The hidden column names separated by a comma. |
9 | 445 |
*/ |
0 | 446 |
hidden : function() { |
9 | 447 |
return $( '.manage-column[id]' ).filter( '.hidden' ).map(function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
return this.id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
}).get().join( ',' ); |
0 | 450 |
}, |
451 |
||
9 | 452 |
/** |
453 |
* Gets the checked column toggles from the screen options. |
|
454 |
* |
|
455 |
* @since 3.0.0 |
|
456 |
* |
|
16 | 457 |
* @return {string} String containing the checked column names. |
9 | 458 |
*/ |
0 | 459 |
useCheckboxesForHidden : function() { |
460 |
this.hidden = function(){ |
|
461 |
return $('.hide-column-tog').not(':checked').map(function() { |
|
462 |
var id = this.id; |
|
463 |
return id.substring( id, id.length - 5 ); |
|
464 |
}).get().join(','); |
|
465 |
}; |
|
466 |
}, |
|
467 |
||
9 | 468 |
/** |
469 |
* Adjusts the column span for the table. |
|
470 |
* |
|
471 |
* @since 3.1.0 |
|
472 |
* |
|
16 | 473 |
* @param {number} diff The modifier for the column span. |
9 | 474 |
*/ |
0 | 475 |
colSpanChange : function(diff) { |
476 |
var $t = $('table').find('.colspanchange'), n; |
|
477 |
if ( !$t.length ) |
|
478 |
return; |
|
479 |
n = parseInt( $t.attr('colspan'), 10 ) + diff; |
|
480 |
$t.attr('colspan', n.toString()); |
|
481 |
} |
|
5 | 482 |
}; |
0 | 483 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
484 |
$document.ready(function(){columns.init();}); |
0 | 485 |
|
9 | 486 |
/** |
487 |
* Validates that the required form fields are not empty. |
|
488 |
* |
|
489 |
* @since 2.9.0 |
|
490 |
* |
|
491 |
* @param {jQuery} form The form to validate. |
|
492 |
* |
|
16 | 493 |
* @return {boolean} Returns true if all required fields are not an empty string. |
9 | 494 |
*/ |
495 |
window.validateForm = function( form ) { |
|
5 | 496 |
return !$( form ) |
497 |
.find( '.form-required' ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
.filter( function() { return $( ':input:visible', this ).val() === ''; } ) |
5 | 499 |
.addClass( 'form-invalid' ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
.find( ':input:visible' ) |
5 | 501 |
.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
|
502 |
.length; |
5 | 503 |
}; |
0 | 504 |
|
16 | 505 |
// Stub for doing better warnings. |
9 | 506 |
/** |
507 |
* Shows message pop-up notice or confirmation message. |
|
508 |
* |
|
509 |
* @since 2.7.0 |
|
510 |
* |
|
511 |
* @type {{warn: showNotice.warn, note: showNotice.note}} |
|
512 |
* |
|
16 | 513 |
* @return {void} |
9 | 514 |
*/ |
515 |
window.showNotice = { |
|
516 |
||
517 |
/** |
|
518 |
* Shows a delete confirmation pop-up message. |
|
519 |
* |
|
520 |
* @since 2.7.0 |
|
521 |
* |
|
16 | 522 |
* @return {boolean} Returns true if the message is confirmed. |
9 | 523 |
*/ |
0 | 524 |
warn : function() { |
16 | 525 |
if ( confirm( __( 'You are about to permanently delete these items from your site.\nThis action cannot be undone.\n\'Cancel\' to stop, \'OK\' to delete.' ) ) ) { |
0 | 526 |
return true; |
527 |
} |
|
528 |
||
529 |
return false; |
|
530 |
}, |
|
531 |
||
9 | 532 |
/** |
533 |
* Shows an alert message. |
|
534 |
* |
|
535 |
* @since 2.7.0 |
|
536 |
* |
|
537 |
* @param text The text to display in the message. |
|
538 |
*/ |
|
0 | 539 |
note : function(text) { |
540 |
alert(text); |
|
541 |
} |
|
542 |
}; |
|
543 |
||
9 | 544 |
/** |
545 |
* Represents the functions for the meta screen options panel. |
|
546 |
* |
|
547 |
* @since 3.2.0 |
|
548 |
* |
|
549 |
* @type {{element: null, toggles: null, page: null, init: screenMeta.init, |
|
550 |
* toggleEvent: screenMeta.toggleEvent, open: screenMeta.open, |
|
551 |
* close: screenMeta.close}} |
|
552 |
* |
|
16 | 553 |
* @return {void} |
9 | 554 |
*/ |
555 |
window.screenMeta = { |
|
0 | 556 |
element: null, // #screen-meta |
557 |
toggles: null, // .screen-meta-toggle |
|
558 |
page: null, // #wpcontent |
|
559 |
||
9 | 560 |
/** |
561 |
* Initializes the screen meta options panel. |
|
562 |
* |
|
563 |
* @since 3.2.0 |
|
564 |
* |
|
16 | 565 |
* @return {void} |
9 | 566 |
*/ |
0 | 567 |
init: function() { |
568 |
this.element = $('#screen-meta'); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
569 |
this.toggles = $( '#screen-meta-links' ).find( '.show-settings' ); |
0 | 570 |
this.page = $('#wpcontent'); |
571 |
||
572 |
this.toggles.click( this.toggleEvent ); |
|
573 |
}, |
|
574 |
||
9 | 575 |
/** |
576 |
* Toggles the screen meta options panel. |
|
577 |
* |
|
578 |
* @since 3.2.0 |
|
579 |
* |
|
16 | 580 |
* @return {void} |
9 | 581 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
582 |
toggleEvent: function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
583 |
var panel = $( '#' + $( this ).attr( 'aria-controls' ) ); |
0 | 584 |
|
585 |
if ( !panel.length ) |
|
586 |
return; |
|
587 |
||
588 |
if ( panel.is(':visible') ) |
|
589 |
screenMeta.close( panel, $(this) ); |
|
590 |
else |
|
591 |
screenMeta.open( panel, $(this) ); |
|
592 |
}, |
|
593 |
||
9 | 594 |
/** |
595 |
* Opens the screen meta options panel. |
|
596 |
* |
|
597 |
* @since 3.2.0 |
|
598 |
* |
|
599 |
* @param {jQuery} panel The screen meta options panel div. |
|
600 |
* @param {jQuery} button The toggle button. |
|
601 |
* |
|
16 | 602 |
* @return {void} |
9 | 603 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
open: function( panel, button ) { |
0 | 605 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
606 |
$( '#screen-meta-links' ).find( '.screen-meta-toggle' ).not( button.parent() ).css( 'visibility', 'hidden' ); |
0 | 607 |
|
608 |
panel.parent().show(); |
|
9 | 609 |
|
610 |
/** |
|
611 |
* Sets the focus to the meta options panel and adds the necessary CSS classes. |
|
612 |
* |
|
613 |
* @since 3.2.0 |
|
614 |
* |
|
16 | 615 |
* @return {void} |
9 | 616 |
*/ |
0 | 617 |
panel.slideDown( 'fast', function() { |
618 |
panel.focus(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
button.addClass( 'screen-meta-active' ).attr( 'aria-expanded', true ); |
0 | 620 |
}); |
5 | 621 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
$document.trigger( 'screen:options:open' ); |
0 | 623 |
}, |
624 |
||
9 | 625 |
/** |
626 |
* Closes the screen meta options panel. |
|
627 |
* |
|
628 |
* @since 3.2.0 |
|
629 |
* |
|
630 |
* @param {jQuery} panel The screen meta options panel div. |
|
631 |
* @param {jQuery} button The toggle button. |
|
632 |
* |
|
16 | 633 |
* @return {void} |
9 | 634 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
635 |
close: function( panel, button ) { |
9 | 636 |
/** |
637 |
* Hides the screen meta options panel. |
|
638 |
* |
|
639 |
* @since 3.2.0 |
|
640 |
* |
|
16 | 641 |
* @return {void} |
9 | 642 |
*/ |
0 | 643 |
panel.slideUp( 'fast', function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
644 |
button.removeClass( 'screen-meta-active' ).attr( 'aria-expanded', false ); |
0 | 645 |
$('.screen-meta-toggle').css('visibility', ''); |
646 |
panel.parent().hide(); |
|
647 |
}); |
|
5 | 648 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
$document.trigger( 'screen:options:close' ); |
0 | 650 |
} |
651 |
}; |
|
652 |
||
653 |
/** |
|
9 | 654 |
* Initializes the help tabs in the help panel. |
655 |
* |
|
656 |
* @param {Event} e The event object. |
|
657 |
* |
|
16 | 658 |
* @return {void} |
0 | 659 |
*/ |
5 | 660 |
$('.contextual-help-tabs').delegate('a', 'click', function(e) { |
0 | 661 |
var link = $(this), |
662 |
panel; |
|
663 |
||
664 |
e.preventDefault(); |
|
665 |
||
666 |
// Don't do anything if the click is for the tab already showing. |
|
667 |
if ( link.is('.active a') ) |
|
668 |
return false; |
|
669 |
||
16 | 670 |
// Links. |
0 | 671 |
$('.contextual-help-tabs .active').removeClass('active'); |
672 |
link.parent('li').addClass('active'); |
|
673 |
||
674 |
panel = $( link.attr('href') ); |
|
675 |
||
16 | 676 |
// Panels. |
0 | 677 |
$('.help-tab-content').not( panel ).removeClass('active').hide(); |
678 |
panel.addClass('active').show(); |
|
679 |
}); |
|
680 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
681 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
682 |
* Update custom permalink structure via buttons. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
683 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
var permalinkStructureFocused = false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
$permalinkStructure = $( '#permalink_structure' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
$permalinkStructureInputs = $( '.permalink-structure input:radio' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
$permalinkCustomSelection = $( '#custom_selection' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
$availableStructureTags = $( '.form-table.permalink-structure .available-structure-tags button' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
689 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
// 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
|
691 |
$permalinkStructureInputs.on( 'change', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
692 |
if ( 'custom' === this.value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
693 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
695 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
696 |
$permalinkStructure.val( this.value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
697 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
698 |
// Update button states after selection. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
699 |
$availableStructureTags.each( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
changeStructureTagButtonState( $( this ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
701 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
703 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
704 |
$permalinkStructure.on( 'click input', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
705 |
$permalinkCustomSelection.prop( 'checked', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
706 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
707 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
708 |
// 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
|
709 |
$permalinkStructure.on( 'focus', function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
710 |
permalinkStructureFocused = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
711 |
$( this ).off( event ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
712 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
713 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
715 |
* 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
|
716 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
717 |
* 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
|
718 |
* it will be disabled. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
719 |
* |
16 | 720 |
* @param {Object} button Button jQuery object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
721 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
722 |
function changeStructureTagButtonState( button ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
723 |
if ( -1 !== $permalinkStructure.val().indexOf( button.text().trim() ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
724 |
button.attr( 'data-label', button.attr( 'aria-label' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
725 |
button.attr( 'aria-label', button.attr( 'data-used' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
726 |
button.attr( 'aria-pressed', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
727 |
button.addClass( 'active' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
728 |
} else if ( button.attr( 'data-label' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
729 |
button.attr( 'aria-label', button.attr( 'data-label' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
730 |
button.attr( 'aria-pressed', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
731 |
button.removeClass( 'active' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
732 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
733 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
734 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
735 |
// Check initial button state. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
736 |
$availableStructureTags.each( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
737 |
changeStructureTagButtonState( $( this ) ); |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
// 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
|
741 |
$permalinkStructure.on( 'change', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
742 |
$availableStructureTags.each( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
743 |
changeStructureTagButtonState( $( this ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
744 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
745 |
} ); |
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 |
$availableStructureTags.on( 'click', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
748 |
var permalinkStructureValue = $permalinkStructure.val(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
749 |
selectionStart = $permalinkStructure[ 0 ].selectionStart, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
750 |
selectionEnd = $permalinkStructure[ 0 ].selectionEnd, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
751 |
textToAppend = $( this ).text().trim(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
752 |
textToAnnounce = $( this ).attr( 'data-added' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
753 |
newSelectionStart; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
754 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
755 |
// Remove structure tag if already part of the structure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
756 |
if ( -1 !== permalinkStructureValue.indexOf( textToAppend ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
757 |
permalinkStructureValue = permalinkStructureValue.replace( textToAppend + '/', '' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
758 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
$permalinkStructure.val( '/' === permalinkStructureValue ? '' : permalinkStructureValue ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
760 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
761 |
// Announce change to screen readers. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
762 |
$( '#custom_selection_updated' ).text( textToAnnounce ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
763 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
764 |
// Disable button. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
765 |
changeStructureTagButtonState( $( this ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
766 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
767 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
768 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
769 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
770 |
// 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
|
771 |
if ( ! permalinkStructureFocused && 0 === selectionStart && 0 === selectionEnd ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
772 |
selectionStart = selectionEnd = permalinkStructureValue.length; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
773 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
774 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
775 |
$permalinkCustomSelection.prop( 'checked', true ); |
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 |
// Prepend and append slashes if necessary. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
778 |
if ( '/' !== permalinkStructureValue.substr( 0, selectionStart ).substr( -1 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
779 |
textToAppend = '/' + textToAppend; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
780 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
781 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
782 |
if ( '/' !== permalinkStructureValue.substr( selectionEnd, 1 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
783 |
textToAppend = textToAppend + '/'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
784 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
785 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
786 |
// Insert structure tag at the specified position. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
787 |
$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
|
788 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
789 |
// Announce change to screen readers. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
$( '#custom_selection_updated' ).text( textToAnnounce ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
791 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
792 |
// Disable button. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
793 |
changeStructureTagButtonState( $( this ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
794 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
795 |
// 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
|
796 |
if ( permalinkStructureFocused && $permalinkStructure[0].setSelectionRange ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
797 |
newSelectionStart = ( permalinkStructureValue.substr( 0, selectionStart ) + textToAppend ).length; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
798 |
$permalinkStructure[0].setSelectionRange( newSelectionStart, newSelectionStart ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
799 |
$permalinkStructure.focus(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
800 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
801 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
802 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
803 |
$document.ready( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
804 |
var checks, first, last, checked, sliced, mobileEvent, transitionTimeout, focusedRowActions, |
5 | 805 |
lastClicked = false, |
806 |
pageInput = $('input.current-page'), |
|
807 |
currentPage = pageInput.val(), |
|
808 |
isIOS = /iPhone|iPad|iPod/.test( navigator.userAgent ), |
|
809 |
isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1, |
|
810 |
$adminMenuWrap = $( '#adminmenuwrap' ), |
|
811 |
$wpwrap = $( '#wpwrap' ), |
|
812 |
$adminmenu = $( '#adminmenu' ), |
|
813 |
$overlay = $( '#wp-responsive-overlay' ), |
|
814 |
$toolbar = $( '#wp-toolbar' ), |
|
815 |
$toolbarPopups = $toolbar.find( 'a[aria-haspopup="true"]' ), |
|
816 |
$sortables = $('.meta-box-sortables'), |
|
817 |
wpResponsiveActive = false, |
|
818 |
$adminbar = $( '#wpadminbar' ), |
|
819 |
lastScrollPosition = 0, |
|
820 |
pinnedMenuTop = false, |
|
821 |
pinnedMenuBottom = false, |
|
822 |
menuTop = 0, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
823 |
menuState, |
5 | 824 |
menuIsPinned = false, |
825 |
height = { |
|
826 |
window: $window.height(), |
|
827 |
wpwrap: $wpwrap.height(), |
|
828 |
adminbar: $adminbar.height(), |
|
829 |
menu: $adminMenuWrap.height() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
830 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
831 |
$headerEnd = $( '.wp-header-end' ); |
5 | 832 |
|
9 | 833 |
/** |
834 |
* Makes the fly-out submenu header clickable, when the menu is folded. |
|
835 |
* |
|
836 |
* @param {Event} e The event object. |
|
837 |
* |
|
16 | 838 |
* @return {void} |
9 | 839 |
*/ |
5 | 840 |
$adminmenu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){ |
0 | 841 |
$(e.target).parent().siblings('a').get(0).click(); |
842 |
}); |
|
843 |
||
9 | 844 |
/** |
845 |
* Collapses the admin menu. |
|
846 |
* |
|
16 | 847 |
* @return {void} |
9 | 848 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
849 |
$( '#collapse-button' ).on( 'click.collapse-menu', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
850 |
var viewportWidth = getViewportWidth() || 961; |
0 | 851 |
|
16 | 852 |
// Reset any compensation for submenus near the bottom of the screen. |
0 | 853 |
$('#adminmenu div.wp-submenu').css('margin-top', ''); |
854 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
855 |
if ( viewportWidth < 960 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
856 |
if ( $body.hasClass('auto-fold') ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
857 |
$body.removeClass('auto-fold').removeClass('folded'); |
0 | 858 |
setUserSetting('unfold', 1); |
859 |
setUserSetting('mfold', 'o'); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
menuState = 'open'; |
0 | 861 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
$body.addClass('auto-fold'); |
0 | 863 |
setUserSetting('unfold', 0); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
864 |
menuState = 'folded'; |
0 | 865 |
} |
866 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
867 |
if ( $body.hasClass('folded') ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
868 |
$body.removeClass('folded'); |
0 | 869 |
setUserSetting('mfold', 'o'); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
870 |
menuState = 'open'; |
0 | 871 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
$body.addClass('folded'); |
0 | 873 |
setUserSetting('mfold', 'f'); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
874 |
menuState = 'folded'; |
0 | 875 |
} |
876 |
} |
|
5 | 877 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
878 |
$document.trigger( 'wp-collapse-menu', { state: menuState } ); |
0 | 879 |
}); |
880 |
||
9 | 881 |
/** |
882 |
* Handles the `aria-haspopup` attribute on the current menu item when it has a submenu. |
|
883 |
* |
|
884 |
* @since 4.4.0 |
|
885 |
* |
|
16 | 886 |
* @return {void} |
9 | 887 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
888 |
function currentMenuItemHasPopup() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
889 |
var $current = $( 'a.wp-has-current-submenu' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
890 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
891 |
if ( 'folded' === menuState ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
892 |
// 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
|
893 |
$current.attr( 'aria-haspopup', 'true' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
895 |
// When expanded or in responsive view, reset aria-haspopup. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
896 |
$current.attr( 'aria-haspopup', 'false' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
897 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
898 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
899 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
900 |
$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
|
901 |
|
5 | 902 |
/** |
9 | 903 |
* Ensures an admin submenu is within the visual viewport. |
5 | 904 |
* |
905 |
* @since 4.1.0 |
|
906 |
* |
|
907 |
* @param {jQuery} $menuItem The parent menu item containing the submenu. |
|
9 | 908 |
* |
16 | 909 |
* @return {void} |
5 | 910 |
*/ |
911 |
function adjustSubmenu( $menuItem ) { |
|
912 |
var bottomOffset, pageHeight, adjustment, theFold, menutop, wintop, maxtop, |
|
913 |
$submenu = $menuItem.find( '.wp-submenu' ); |
|
914 |
||
915 |
menutop = $menuItem.offset().top; |
|
916 |
wintop = $window.scrollTop(); |
|
16 | 917 |
maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar. |
5 | 918 |
|
16 | 919 |
bottomOffset = menutop + $submenu.height() + 1; // Bottom offset of the menu. |
920 |
pageHeight = $wpwrap.height(); // Height of the entire page. |
|
5 | 921 |
adjustment = 60 + bottomOffset - pageHeight; |
16 | 922 |
theFold = $window.height() + wintop - 50; // The fold. |
5 | 923 |
|
924 |
if ( theFold < ( bottomOffset - adjustment ) ) { |
|
925 |
adjustment = bottomOffset - theFold; |
|
926 |
} |
|
927 |
||
928 |
if ( adjustment > maxtop ) { |
|
929 |
adjustment = maxtop; |
|
930 |
} |
|
931 |
||
932 |
if ( adjustment > 1 ) { |
|
933 |
$submenu.css( 'margin-top', '-' + adjustment + 'px' ); |
|
934 |
} else { |
|
935 |
$submenu.css( 'margin-top', '' ); |
|
936 |
} |
|
937 |
} |
|
938 |
||
16 | 939 |
if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // Touch screen device. |
940 |
// iOS Safari works with touchstart, the rest work with click. |
|
5 | 941 |
mobileEvent = isIOS ? 'touchstart' : 'click'; |
0 | 942 |
|
9 | 943 |
/** |
944 |
* Closes any open submenus when touch/click is not on the menu. |
|
945 |
* |
|
946 |
* @param {Event} e The event object. |
|
947 |
* |
|
16 | 948 |
* @return {void} |
9 | 949 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
950 |
$body.on( mobileEvent+'.wp-mobile-hover', function(e) { |
5 | 951 |
if ( $adminmenu.data('wp-responsive') ) { |
952 |
return; |
|
953 |
} |
|
954 |
||
955 |
if ( ! $( e.target ).closest( '#adminmenu' ).length ) { |
|
956 |
$adminmenu.find( 'li.opensub' ).removeClass( 'opensub' ); |
|
957 |
} |
|
0 | 958 |
}); |
959 |
||
9 | 960 |
/** |
961 |
* Handles the opening or closing the submenu based on the mobile click|touch event. |
|
962 |
* |
|
963 |
* @param {Event} event The event object. |
|
964 |
* |
|
16 | 965 |
* @return {void} |
9 | 966 |
*/ |
5 | 967 |
$adminmenu.find( 'a.wp-has-submenu' ).on( mobileEvent + '.wp-mobile-hover', function( event ) { |
968 |
var $menuItem = $(this).parent(); |
|
969 |
||
970 |
if ( $adminmenu.data( 'wp-responsive' ) ) { |
|
971 |
return; |
|
972 |
} |
|
0 | 973 |
|
16 | 974 |
/* |
975 |
* Show the sub instead of following the link if: |
|
976 |
* - the submenu is not open. |
|
977 |
* - the submenu is not shown inline or the menu is not folded. |
|
978 |
*/ |
|
5 | 979 |
if ( ! $menuItem.hasClass( 'opensub' ) && ( ! $menuItem.hasClass( 'wp-menu-open' ) || $menuItem.width() < 40 ) ) { |
980 |
event.preventDefault(); |
|
981 |
adjustSubmenu( $menuItem ); |
|
982 |
$adminmenu.find( 'li.opensub' ).removeClass( 'opensub' ); |
|
983 |
$menuItem.addClass('opensub'); |
|
0 | 984 |
} |
985 |
}); |
|
986 |
} |
|
987 |
||
5 | 988 |
if ( ! isIOS && ! isAndroid ) { |
989 |
$adminmenu.find( 'li.wp-has-submenu' ).hoverIntent({ |
|
9 | 990 |
|
991 |
/** |
|
992 |
* Opens the submenu when hovered over the menu item for desktops. |
|
993 |
* |
|
16 | 994 |
* @return {void} |
9 | 995 |
*/ |
5 | 996 |
over: function() { |
997 |
var $menuItem = $( this ), |
|
998 |
$submenu = $menuItem.find( '.wp-submenu' ), |
|
999 |
top = parseInt( $submenu.css( 'top' ), 10 ); |
|
0 | 1000 |
|
16 | 1001 |
if ( isNaN( top ) || top > -5 ) { // The submenu is visible. |
5 | 1002 |
return; |
1003 |
} |
|
0 | 1004 |
|
5 | 1005 |
if ( $adminmenu.data( 'wp-responsive' ) ) { |
16 | 1006 |
// The menu is in responsive mode, bail. |
5 | 1007 |
return; |
1008 |
} |
|
0 | 1009 |
|
5 | 1010 |
adjustSubmenu( $menuItem ); |
1011 |
$adminmenu.find( 'li.opensub' ).removeClass( 'opensub' ); |
|
1012 |
$menuItem.addClass( 'opensub' ); |
|
1013 |
}, |
|
9 | 1014 |
|
1015 |
/** |
|
1016 |
* Closes the submenu when no longer hovering the menu item. |
|
1017 |
* |
|
16 | 1018 |
* @return {void} |
9 | 1019 |
*/ |
5 | 1020 |
out: function(){ |
1021 |
if ( $adminmenu.data( 'wp-responsive' ) ) { |
|
16 | 1022 |
// The menu is in responsive mode, bail. |
5 | 1023 |
return; |
1024 |
} |
|
0 | 1025 |
|
5 | 1026 |
$( this ).removeClass( 'opensub' ).find( '.wp-submenu' ).css( 'margin-top', '' ); |
1027 |
}, |
|
1028 |
timeout: 200, |
|
1029 |
sensitivity: 7, |
|
1030 |
interval: 90 |
|
1031 |
}); |
|
0 | 1032 |
|
9 | 1033 |
/** |
1034 |
* Opens the submenu on when focused on the menu item. |
|
1035 |
* |
|
1036 |
* @param {Event} event The event object. |
|
1037 |
* |
|
16 | 1038 |
* @return {void} |
9 | 1039 |
*/ |
5 | 1040 |
$adminmenu.on( 'focus.adminmenu', '.wp-submenu a', function( event ) { |
1041 |
if ( $adminmenu.data( 'wp-responsive' ) ) { |
|
16 | 1042 |
// The menu is in responsive mode, bail. |
5 | 1043 |
return; |
1044 |
} |
|
1045 |
||
1046 |
$( event.target ).closest( 'li.menu-top' ).addClass( 'opensub' ); |
|
9 | 1047 |
|
1048 |
/** |
|
1049 |
* Closes the submenu on blur from the menu item. |
|
1050 |
* |
|
1051 |
* @param {Event} event The event object. |
|
1052 |
* |
|
16 | 1053 |
* @return {void} |
9 | 1054 |
*/ |
5 | 1055 |
}).on( 'blur.adminmenu', '.wp-submenu a', function( event ) { |
1056 |
if ( $adminmenu.data( 'wp-responsive' ) ) { |
|
1057 |
return; |
|
1058 |
} |
|
1059 |
||
1060 |
$( event.target ).closest( 'li.menu-top' ).removeClass( 'opensub' ); |
|
9 | 1061 |
|
1062 |
/** |
|
1063 |
* Adjusts the size for the submenu. |
|
1064 |
* |
|
16 | 1065 |
* @return {void} |
9 | 1066 |
*/ |
5 | 1067 |
}).find( 'li.wp-has-submenu.wp-not-current-submenu' ).on( 'focusin.adminmenu', function() { |
1068 |
adjustSubmenu( $( this ) ); |
|
1069 |
}); |
|
1070 |
} |
|
0 | 1071 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1072 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1073 |
* 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
|
1074 |
* 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
|
1075 |
* 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
|
1076 |
* 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
|
1077 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1078 |
if ( ! $headerEnd.length ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1079 |
$headerEnd = $( '.wrap h1, .wrap h2' ).first(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1080 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1081 |
$( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' ).insertAfter( $headerEnd ); |
5 | 1082 |
|
9 | 1083 |
/** |
1084 |
* Makes notices dismissible. |
|
1085 |
* |
|
1086 |
* @since 4.4.0 |
|
1087 |
* |
|
16 | 1088 |
* @return {void} |
9 | 1089 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1090 |
function makeNoticesDismissible() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
$( '.notice.is-dismissible' ).each( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1092 |
var $el = $( this ), |
16 | 1093 |
$button = $( '<button type="button" class="notice-dismiss"><span class="screen-reader-text"></span></button>' ); |
5 | 1094 |
|
16 | 1095 |
// Ensure plain text. |
1096 |
$button.find( '.screen-reader-text' ).text( __( 'Dismiss this notice.' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1097 |
$button.on( 'click.wp-dismiss-notice', function( event ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
event.preventDefault(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
$el.fadeTo( 100, 0, function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
$el.slideUp( 100, function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
$el.remove(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
}); |
5 | 1103 |
}); |
1104 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1105 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1106 |
$el.append( $button ); |
5 | 1107 |
}); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1108 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1109 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1110 |
$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 | 1111 |
|
16 | 1112 |
// Init screen meta. |
0 | 1113 |
screenMeta.init(); |
1114 |
||
9 | 1115 |
/** |
1116 |
* Checks a checkbox. |
|
1117 |
* |
|
1118 |
* This event needs to be delegated. Ticket #37973. |
|
1119 |
* |
|
16 | 1120 |
* @return {boolean} Returns whether a checkbox is checked or not. |
9 | 1121 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1122 |
$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
|
1123 |
// Shift click to select a range of checkboxes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
if ( 'undefined' == event.shiftKey ) { return true; } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
if ( event.shiftKey ) { |
0 | 1126 |
if ( !lastClicked ) { return true; } |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1127 |
checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' ).filter( ':visible:enabled' ); |
0 | 1128 |
first = checks.index( lastClicked ); |
1129 |
last = checks.index( this ); |
|
1130 |
checked = $(this).prop('checked'); |
|
1131 |
if ( 0 < first && 0 < last && first != last ) { |
|
1132 |
sliced = ( last > first ) ? checks.slice( first, last ) : checks.slice( last, first ); |
|
1133 |
sliced.prop( 'checked', function() { |
|
1134 |
if ( $(this).closest('tr').is(':visible') ) |
|
1135 |
return checked; |
|
1136 |
||
1137 |
return false; |
|
1138 |
}); |
|
1139 |
} |
|
1140 |
} |
|
1141 |
lastClicked = this; |
|
1142 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1143 |
// 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
|
1144 |
var unchecked = $(this).closest('tbody').find(':checkbox').filter(':visible:enabled').not(':checked'); |
9 | 1145 |
|
1146 |
/** |
|
1147 |
* Determines if all checkboxes are checked. |
|
1148 |
* |
|
16 | 1149 |
* @return {boolean} Returns true if there are no unchecked checkboxes. |
9 | 1150 |
*/ |
0 | 1151 |
$(this).closest('table').children('thead, tfoot').find(':checkbox').prop('checked', function() { |
5 | 1152 |
return ( 0 === unchecked.length ); |
0 | 1153 |
}); |
1154 |
||
1155 |
return true; |
|
1156 |
}); |
|
1157 |
||
9 | 1158 |
/** |
1159 |
* Controls all the toggles on bulk toggle change. |
|
1160 |
* |
|
1161 |
* When the bulk checkbox is changed, all the checkboxes in the tables are changed accordingly. |
|
1162 |
* When the shift-button is pressed while changing the bulk checkbox the checkboxes in the table are inverted. |
|
1163 |
* |
|
1164 |
* This event needs to be delegated. Ticket #37973. |
|
1165 |
* |
|
1166 |
* @param {Event} event The event object. |
|
1167 |
* |
|
16 | 1168 |
* @return {boolean} |
9 | 1169 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1170 |
$body.on( 'click.wp-toggle-checkboxes', 'thead .check-column :checkbox, tfoot .check-column :checkbox', function( event ) { |
5 | 1171 |
var $this = $(this), |
1172 |
$table = $this.closest( 'table' ), |
|
1173 |
controlChecked = $this.prop('checked'), |
|
1174 |
toggle = event.shiftKey || $this.data('wp-toggle'); |
|
0 | 1175 |
|
5 | 1176 |
$table.children( 'tbody' ).filter(':visible') |
1177 |
.children().children('.check-column').find(':checkbox') |
|
9 | 1178 |
/** |
1179 |
* Updates the checked state on the checkbox in the table. |
|
1180 |
* |
|
16 | 1181 |
* @return {boolean} True checks the checkbox, False unchecks the checkbox. |
9 | 1182 |
*/ |
5 | 1183 |
.prop('checked', function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1184 |
if ( $(this).is(':hidden,:disabled') ) { |
5 | 1185 |
return false; |
1186 |
} |
|
1187 |
||
1188 |
if ( toggle ) { |
|
1189 |
return ! $(this).prop( 'checked' ); |
|
1190 |
} else if ( controlChecked ) { |
|
1191 |
return true; |
|
1192 |
} |
|
1193 |
||
0 | 1194 |
return false; |
5 | 1195 |
}); |
0 | 1196 |
|
5 | 1197 |
$table.children('thead, tfoot').filter(':visible') |
1198 |
.children().children('.check-column').find(':checkbox') |
|
9 | 1199 |
|
1200 |
/** |
|
1201 |
* Syncs the bulk checkboxes on the top and bottom of the table. |
|
1202 |
* |
|
16 | 1203 |
* @return {boolean} True checks the checkbox, False unchecks the checkbox. |
9 | 1204 |
*/ |
5 | 1205 |
.prop('checked', function() { |
1206 |
if ( toggle ) { |
|
1207 |
return false; |
|
1208 |
} else if ( controlChecked ) { |
|
1209 |
return true; |
|
1210 |
} |
|
1211 |
||
0 | 1212 |
return false; |
5 | 1213 |
}); |
0 | 1214 |
}); |
1215 |
||
9 | 1216 |
/** |
1217 |
* Shows row actions on focus of its parent container element or any other elements contained within. |
|
1218 |
* |
|
16 | 1219 |
* @return {void} |
9 | 1220 |
*/ |
5 | 1221 |
$( '#wpbody-content' ).on({ |
1222 |
focusin: function() { |
|
1223 |
clearTimeout( transitionTimeout ); |
|
1224 |
focusedRowActions = $( this ).find( '.row-actions' ); |
|
1225 |
// transitionTimeout is necessary for Firefox, but Chrome won't remove the CSS class without a little help. |
|
1226 |
$( '.row-actions' ).not( this ).removeClass( 'visible' ); |
|
1227 |
focusedRowActions.addClass( 'visible' ); |
|
1228 |
}, |
|
1229 |
focusout: function() { |
|
1230 |
// Tabbing between post title and .row-actions links needs a brief pause, otherwise |
|
1231 |
// the .row-actions div gets hidden in transit in some browsers (ahem, Firefox). |
|
1232 |
transitionTimeout = setTimeout( function() { |
|
1233 |
focusedRowActions.removeClass( 'visible' ); |
|
1234 |
}, 30 ); |
|
1235 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1236 |
}, '.has-row-actions' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1237 |
|
16 | 1238 |
// Toggle list table rows on small screens. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1239 |
$( 'tbody' ).on( 'click', '.toggle-row', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1240 |
$( this ).closest( 'tr' ).toggleClass( 'is-expanded' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1241 |
}); |
0 | 1242 |
|
1243 |
$('#default-password-nag-no').click( function() { |
|
1244 |
setUserSetting('default_password_nag', 'hide'); |
|
1245 |
$('div.default-password-nag').hide(); |
|
1246 |
return false; |
|
1247 |
}); |
|
1248 |
||
9 | 1249 |
/** |
1250 |
* Handles tab keypresses in theme and plugin editor textareas. |
|
1251 |
* |
|
1252 |
* @param {Event} e The event object. |
|
1253 |
* |
|
16 | 1254 |
* @return {void} |
9 | 1255 |
*/ |
0 | 1256 |
$('#newcontent').bind('keydown.wpevent_InsertTab', function(e) { |
1257 |
var el = e.target, selStart, selEnd, val, scroll, sel; |
|
1258 |
||
9 | 1259 |
// After pressing escape key (keyCode: 27), the tab key should tab out of the textarea. |
1260 |
if ( e.keyCode == 27 ) { |
|
16 | 1261 |
// When pressing Escape: Opera 12 and 27 blur form fields, IE 8 clears them. |
5 | 1262 |
e.preventDefault(); |
0 | 1263 |
$(el).data('tab-out', true); |
1264 |
return; |
|
1265 |
} |
|
1266 |
||
9 | 1267 |
// Only listen for plain tab key (keyCode: 9) without any modifiers. |
1268 |
if ( e.keyCode != 9 || e.ctrlKey || e.altKey || e.shiftKey ) |
|
0 | 1269 |
return; |
1270 |
||
9 | 1271 |
// After tabbing out, reset it so next time the tab key can be used again. |
0 | 1272 |
if ( $(el).data('tab-out') ) { |
1273 |
$(el).data('tab-out', false); |
|
1274 |
return; |
|
1275 |
} |
|
1276 |
||
1277 |
selStart = el.selectionStart; |
|
1278 |
selEnd = el.selectionEnd; |
|
1279 |
val = el.value; |
|
1280 |
||
9 | 1281 |
// If any text is selected, replace the selection with a tab character. |
0 | 1282 |
if ( document.selection ) { |
1283 |
el.focus(); |
|
1284 |
sel = document.selection.createRange(); |
|
1285 |
sel.text = '\t'; |
|
1286 |
} else if ( selStart >= 0 ) { |
|
1287 |
scroll = this.scrollTop; |
|
1288 |
el.value = val.substring(0, selStart).concat('\t', val.substring(selEnd) ); |
|
1289 |
el.selectionStart = el.selectionEnd = selStart + 1; |
|
1290 |
this.scrollTop = scroll; |
|
1291 |
} |
|
1292 |
||
9 | 1293 |
// Cancel the regular tab functionality, to prevent losing focus of the textarea. |
0 | 1294 |
if ( e.stopPropagation ) |
1295 |
e.stopPropagation(); |
|
1296 |
if ( e.preventDefault ) |
|
1297 |
e.preventDefault(); |
|
1298 |
}); |
|
1299 |
||
9 | 1300 |
// Reset page number variable for new filters/searches but not for bulk actions. See #17685. |
0 | 1301 |
if ( pageInput.length ) { |
9 | 1302 |
|
1303 |
/** |
|
1304 |
* Handles pagination variable when filtering the list table. |
|
1305 |
* |
|
1306 |
* Set the pagination argument to the first page when the post-filter form is submitted. |
|
1307 |
* This happens when pressing the 'filter' button on the list table page. |
|
1308 |
* |
|
1309 |
* The pagination argument should not be touched when the bulk action dropdowns are set to do anything. |
|
1310 |
* |
|
1311 |
* The form closest to the pageInput is the post-filter form. |
|
1312 |
* |
|
16 | 1313 |
* @return {void} |
9 | 1314 |
*/ |
5 | 1315 |
pageInput.closest('form').submit( function() { |
9 | 1316 |
/* |
1317 |
* action = bulk action dropdown at the top of the table |
|
1318 |
* action2 = bulk action dropdow at the bottom of the table |
|
1319 |
*/ |
|
0 | 1320 |
if ( $('select[name="action"]').val() == -1 && $('select[name="action2"]').val() == -1 && pageInput.val() == currentPage ) |
1321 |
pageInput.val('1'); |
|
1322 |
}); |
|
1323 |
} |
|
1324 |
||
9 | 1325 |
/** |
1326 |
* Resets the bulk actions when the search button is clicked. |
|
1327 |
* |
|
16 | 1328 |
* @return {void} |
9 | 1329 |
*/ |
0 | 1330 |
$('.search-box input[type="search"], .search-box input[type="submit"]').mousedown(function () { |
1331 |
$('select[name^="action"]').val('-1'); |
|
1332 |
}); |
|
1333 |
||
9 | 1334 |
/** |
1335 |
* Scrolls into view when focus.scroll-into-view is triggered. |
|
1336 |
* |
|
1337 |
* @param {Event} e The event object. |
|
1338 |
* |
|
16 | 1339 |
* @return {void} |
9 | 1340 |
*/ |
0 | 1341 |
$('#contextual-help-link, #show-settings-link').on( 'focus.scroll-into-view', function(e){ |
1342 |
if ( e.target.scrollIntoView ) |
|
1343 |
e.target.scrollIntoView(false); |
|
1344 |
}); |
|
1345 |
||
9 | 1346 |
/** |
1347 |
* Disables the submit upload buttons when no data is entered. |
|
1348 |
* |
|
16 | 1349 |
* @return {void} |
9 | 1350 |
*/ |
0 | 1351 |
(function(){ |
1352 |
var button, input, form = $('form.wp-upload-form'); |
|
9 | 1353 |
|
1354 |
// Exit when no upload form is found. |
|
0 | 1355 |
if ( ! form.length ) |
1356 |
return; |
|
9 | 1357 |
|
0 | 1358 |
button = form.find('input[type="submit"]'); |
1359 |
input = form.find('input[type="file"]'); |
|
1360 |
||
9 | 1361 |
/** |
1362 |
* Determines if any data is entered in any file upload input. |
|
1363 |
* |
|
1364 |
* @since 3.5.0 |
|
1365 |
* |
|
16 | 1366 |
* @return {void} |
9 | 1367 |
*/ |
0 | 1368 |
function toggleUploadButton() { |
9 | 1369 |
// When no inputs have a value, disable the upload buttons. |
0 | 1370 |
button.prop('disabled', '' === input.map( function() { |
1371 |
return $(this).val(); |
|
1372 |
}).get().join('')); |
|
1373 |
} |
|
9 | 1374 |
|
1375 |
// Update the status initially. |
|
0 | 1376 |
toggleUploadButton(); |
9 | 1377 |
// Update the status when any file input changes. |
0 | 1378 |
input.on('change', toggleUploadButton); |
1379 |
})(); |
|
5 | 1380 |
|
9 | 1381 |
/** |
1382 |
* Pins the menu while distraction-free writing is enabled. |
|
1383 |
* |
|
1384 |
* @param {Event} event Event data. |
|
1385 |
* |
|
1386 |
* @since 4.1.0 |
|
1387 |
* |
|
16 | 1388 |
* @return {void} |
9 | 1389 |
*/ |
5 | 1390 |
function pinMenu( event ) { |
1391 |
var windowPos = $window.scrollTop(), |
|
1392 |
resizing = ! event || event.type !== 'scroll'; |
|
1393 |
||
16 | 1394 |
if ( isIOS || $adminmenu.data( 'wp-responsive' ) ) { |
5 | 1395 |
return; |
1396 |
} |
|
1397 |
||
9 | 1398 |
/* |
1399 |
* When the menu is higher than the window and smaller than the entire page. |
|
1400 |
* It should be adjusted to be able to see the entire menu. |
|
1401 |
* |
|
1402 |
* Otherwise it can be accessed normally. |
|
1403 |
*/ |
|
5 | 1404 |
if ( height.menu + height.adminbar < height.window || |
1405 |
height.menu + height.adminbar + 20 > height.wpwrap ) { |
|
1406 |
unpinMenu(); |
|
1407 |
return; |
|
1408 |
} |
|
1409 |
||
1410 |
menuIsPinned = true; |
|
1411 |
||
9 | 1412 |
// If the menu is higher than the window, compensate on scroll. |
5 | 1413 |
if ( height.menu + height.adminbar > height.window ) { |
9 | 1414 |
// Check for overscrolling, this happens when swiping up at the top of the document in modern browsers. |
5 | 1415 |
if ( windowPos < 0 ) { |
9 | 1416 |
// Stick the menu to the top. |
5 | 1417 |
if ( ! pinnedMenuTop ) { |
1418 |
pinnedMenuTop = true; |
|
1419 |
pinnedMenuBottom = false; |
|
1420 |
||
1421 |
$adminMenuWrap.css({ |
|
1422 |
position: 'fixed', |
|
1423 |
top: '', |
|
1424 |
bottom: '' |
|
1425 |
}); |
|
1426 |
} |
|
1427 |
||
1428 |
return; |
|
1429 |
} else if ( windowPos + height.window > $document.height() - 1 ) { |
|
9 | 1430 |
// When overscrolling at the bottom, stick the menu to the bottom. |
5 | 1431 |
if ( ! pinnedMenuBottom ) { |
1432 |
pinnedMenuBottom = true; |
|
1433 |
pinnedMenuTop = false; |
|
1434 |
||
1435 |
$adminMenuWrap.css({ |
|
1436 |
position: 'fixed', |
|
1437 |
top: '', |
|
1438 |
bottom: 0 |
|
1439 |
}); |
|
1440 |
} |
|
1441 |
||
1442 |
return; |
|
1443 |
} |
|
1444 |
||
1445 |
if ( windowPos > lastScrollPosition ) { |
|
9 | 1446 |
// When a down scroll has been detected. |
1447 |
||
1448 |
// If it was pinned to the top, unpin and calculate relative scroll. |
|
5 | 1449 |
if ( pinnedMenuTop ) { |
1450 |
pinnedMenuTop = false; |
|
9 | 1451 |
// Calculate new offset position. |
5 | 1452 |
menuTop = $adminMenuWrap.offset().top - height.adminbar - ( windowPos - lastScrollPosition ); |
1453 |
||
1454 |
if ( menuTop + height.menu + height.adminbar < windowPos + height.window ) { |
|
1455 |
menuTop = windowPos + height.window - height.menu - height.adminbar; |
|
1456 |
} |
|
1457 |
||
1458 |
$adminMenuWrap.css({ |
|
1459 |
position: 'absolute', |
|
1460 |
top: menuTop, |
|
1461 |
bottom: '' |
|
1462 |
}); |
|
1463 |
} else if ( ! pinnedMenuBottom && $adminMenuWrap.offset().top + height.menu < windowPos + height.window ) { |
|
9 | 1464 |
// Pin it to the bottom. |
5 | 1465 |
pinnedMenuBottom = true; |
1466 |
||
1467 |
$adminMenuWrap.css({ |
|
1468 |
position: 'fixed', |
|
1469 |
top: '', |
|
1470 |
bottom: 0 |
|
1471 |
}); |
|
1472 |
} |
|
1473 |
} else if ( windowPos < lastScrollPosition ) { |
|
9 | 1474 |
// When a scroll up is detected. |
1475 |
||
1476 |
// If it was pinned to the bottom, unpin and calculate relative scroll. |
|
5 | 1477 |
if ( pinnedMenuBottom ) { |
1478 |
pinnedMenuBottom = false; |
|
9 | 1479 |
|
1480 |
// Calculate new offset position. |
|
5 | 1481 |
menuTop = $adminMenuWrap.offset().top - height.adminbar + ( lastScrollPosition - windowPos ); |
1482 |
||
1483 |
if ( menuTop + height.menu > windowPos + height.window ) { |
|
1484 |
menuTop = windowPos; |
|
1485 |
} |
|
1486 |
||
1487 |
$adminMenuWrap.css({ |
|
1488 |
position: 'absolute', |
|
1489 |
top: menuTop, |
|
1490 |
bottom: '' |
|
1491 |
}); |
|
1492 |
} else if ( ! pinnedMenuTop && $adminMenuWrap.offset().top >= windowPos + height.adminbar ) { |
|
9 | 1493 |
|
1494 |
// Pin it to the top. |
|
5 | 1495 |
pinnedMenuTop = true; |
1496 |
||
1497 |
$adminMenuWrap.css({ |
|
1498 |
position: 'fixed', |
|
1499 |
top: '', |
|
1500 |
bottom: '' |
|
1501 |
}); |
|
1502 |
} |
|
1503 |
} else if ( resizing ) { |
|
9 | 1504 |
// Window is being resized. |
1505 |
||
5 | 1506 |
pinnedMenuTop = pinnedMenuBottom = false; |
9 | 1507 |
|
1508 |
// Calculate the new offset. |
|
5 | 1509 |
menuTop = windowPos + height.window - height.menu - height.adminbar - 1; |
1510 |
||
1511 |
if ( menuTop > 0 ) { |
|
1512 |
$adminMenuWrap.css({ |
|
1513 |
position: 'absolute', |
|
1514 |
top: menuTop, |
|
1515 |
bottom: '' |
|
1516 |
}); |
|
1517 |
} else { |
|
1518 |
unpinMenu(); |
|
1519 |
} |
|
1520 |
} |
|
1521 |
} |
|
1522 |
||
1523 |
lastScrollPosition = windowPos; |
|
1524 |
} |
|
1525 |
||
9 | 1526 |
/** |
1527 |
* Determines the height of certain elements. |
|
1528 |
* |
|
1529 |
* @since 4.1.0 |
|
1530 |
* |
|
16 | 1531 |
* @return {void} |
9 | 1532 |
*/ |
5 | 1533 |
function resetHeights() { |
1534 |
height = { |
|
1535 |
window: $window.height(), |
|
1536 |
wpwrap: $wpwrap.height(), |
|
1537 |
adminbar: $adminbar.height(), |
|
1538 |
menu: $adminMenuWrap.height() |
|
1539 |
}; |
|
1540 |
} |
|
1541 |
||
9 | 1542 |
/** |
1543 |
* Unpins the menu. |
|
1544 |
* |
|
1545 |
* @since 4.1.0 |
|
1546 |
* |
|
16 | 1547 |
* @return {void} |
9 | 1548 |
*/ |
5 | 1549 |
function unpinMenu() { |
1550 |
if ( isIOS || ! menuIsPinned ) { |
|
1551 |
return; |
|
1552 |
} |
|
1553 |
||
1554 |
pinnedMenuTop = pinnedMenuBottom = menuIsPinned = false; |
|
1555 |
$adminMenuWrap.css({ |
|
1556 |
position: '', |
|
1557 |
top: '', |
|
1558 |
bottom: '' |
|
1559 |
}); |
|
1560 |
} |
|
1561 |
||
9 | 1562 |
/** |
1563 |
* Pins and unpins the menu when applicable. |
|
1564 |
* |
|
1565 |
* @since 4.1.0 |
|
1566 |
* |
|
16 | 1567 |
* @return {void} |
9 | 1568 |
*/ |
5 | 1569 |
function setPinMenu() { |
1570 |
resetHeights(); |
|
1571 |
||
1572 |
if ( $adminmenu.data('wp-responsive') ) { |
|
1573 |
$body.removeClass( 'sticky-menu' ); |
|
1574 |
unpinMenu(); |
|
1575 |
} else if ( height.menu + height.adminbar > height.window ) { |
|
1576 |
pinMenu(); |
|
1577 |
$body.removeClass( 'sticky-menu' ); |
|
1578 |
} else { |
|
1579 |
$body.addClass( 'sticky-menu' ); |
|
1580 |
unpinMenu(); |
|
1581 |
} |
|
1582 |
} |
|
1583 |
||
1584 |
if ( ! isIOS ) { |
|
1585 |
$window.on( 'scroll.pin-menu', pinMenu ); |
|
1586 |
$document.on( 'tinymce-editor-init.pin-menu', function( event, editor ) { |
|
1587 |
editor.on( 'wp-autoresize', resetHeights ); |
|
1588 |
}); |
|
1589 |
} |
|
1590 |
||
9 | 1591 |
/** |
1592 |
* Changes the sortables and responsiveness of metaboxes. |
|
1593 |
* |
|
1594 |
* @since 3.8.0 |
|
1595 |
* |
|
16 | 1596 |
* @return {void} |
9 | 1597 |
*/ |
5 | 1598 |
window.wpResponsive = { |
9 | 1599 |
|
1600 |
/** |
|
1601 |
* Initializes the wpResponsive object. |
|
1602 |
* |
|
1603 |
* @since 3.8.0 |
|
1604 |
* |
|
16 | 1605 |
* @return {void} |
9 | 1606 |
*/ |
5 | 1607 |
init: function() { |
1608 |
var self = this; |
|
1609 |
||
16 | 1610 |
this.maybeDisableSortables = this.maybeDisableSortables.bind( this ); |
1611 |
||
1612 |
// Modify functionality based on custom activate/deactivate event. |
|
5 | 1613 |
$document.on( 'wp-responsive-activate.wp-responsive', function() { |
1614 |
self.activate(); |
|
1615 |
}).on( 'wp-responsive-deactivate.wp-responsive', function() { |
|
1616 |
self.deactivate(); |
|
1617 |
}); |
|
1618 |
||
1619 |
$( '#wp-admin-bar-menu-toggle a' ).attr( 'aria-expanded', 'false' ); |
|
1620 |
||
9 | 1621 |
// Toggle sidebar when toggle is clicked. |
5 | 1622 |
$( '#wp-admin-bar-menu-toggle' ).on( 'click.wp-responsive', function( event ) { |
1623 |
event.preventDefault(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1624 |
|
16 | 1625 |
// Close any open toolbar submenus. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1626 |
$adminbar.find( '.hover' ).removeClass( 'hover' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1627 |
|
5 | 1628 |
$wpwrap.toggleClass( 'wp-responsive-open' ); |
1629 |
if ( $wpwrap.hasClass( 'wp-responsive-open' ) ) { |
|
1630 |
$(this).find('a').attr( 'aria-expanded', 'true' ); |
|
1631 |
$( '#adminmenu a:first' ).focus(); |
|
1632 |
} else { |
|
1633 |
$(this).find('a').attr( 'aria-expanded', 'false' ); |
|
1634 |
} |
|
1635 |
} ); |
|
1636 |
||
9 | 1637 |
// Add menu events. |
5 | 1638 |
$adminmenu.on( 'click.wp-responsive', 'li.wp-has-submenu > a', function( event ) { |
1639 |
if ( ! $adminmenu.data('wp-responsive') ) { |
|
1640 |
return; |
|
1641 |
} |
|
1642 |
||
1643 |
$( this ).parent( 'li' ).toggleClass( 'selected' ); |
|
1644 |
event.preventDefault(); |
|
1645 |
}); |
|
1646 |
||
1647 |
self.trigger(); |
|
1648 |
$document.on( 'wp-window-resized.wp-responsive', $.proxy( this.trigger, this ) ); |
|
1649 |
||
9 | 1650 |
// This needs to run later as UI Sortable may be initialized later on $(document).ready(). |
16 | 1651 |
$window.on( 'load.wp-responsive', this.maybeDisableSortables ); |
1652 |
$document.on( 'postbox-toggled', this.maybeDisableSortables ); |
|
1653 |
||
1654 |
// When the screen columns are changed, potentially disable sortables. |
|
1655 |
$( '#screen-options-wrap input' ).on( 'click', this.maybeDisableSortables ); |
|
1656 |
}, |
|
5 | 1657 |
|
16 | 1658 |
/** |
1659 |
* Disable sortables if there is only one metabox, or the screen is in one column mode. Otherwise, enable sortables. |
|
1660 |
* |
|
1661 |
* @since 5.3.0 |
|
1662 |
* |
|
1663 |
* @return {void} |
|
1664 |
*/ |
|
1665 |
maybeDisableSortables: function() { |
|
1666 |
var width = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? $window.width() : window.innerWidth; |
|
1667 |
||
1668 |
if ( |
|
1669 |
( width <= 782 ) || |
|
1670 |
( 1 >= $sortables.find( '.ui-sortable-handle:visible' ).length && jQuery( '.columns-prefs-1 input' ).prop( 'checked' ) ) |
|
1671 |
) { |
|
1672 |
this.disableSortables(); |
|
1673 |
} else { |
|
1674 |
this.enableSortables(); |
|
1675 |
} |
|
5 | 1676 |
}, |
1677 |
||
9 | 1678 |
/** |
1679 |
* Changes properties of body and admin menu. |
|
1680 |
* |
|
1681 |
* Pins and unpins the menu and adds the auto-fold class to the body. |
|
1682 |
* Makes the admin menu responsive and disables the metabox sortables. |
|
1683 |
* |
|
1684 |
* @since 3.8.0 |
|
1685 |
* |
|
16 | 1686 |
* @return {void} |
9 | 1687 |
*/ |
5 | 1688 |
activate: function() { |
1689 |
setPinMenu(); |
|
1690 |
||
1691 |
if ( ! $body.hasClass( 'auto-fold' ) ) { |
|
1692 |
$body.addClass( 'auto-fold' ); |
|
1693 |
} |
|
1694 |
||
1695 |
$adminmenu.data( 'wp-responsive', 1 ); |
|
1696 |
this.disableSortables(); |
|
1697 |
}, |
|
1698 |
||
9 | 1699 |
/** |
1700 |
* Changes properties of admin menu and enables metabox sortables. |
|
1701 |
* |
|
1702 |
* Pin and unpin the menu. |
|
1703 |
* Removes the responsiveness of the admin menu and enables the metabox sortables. |
|
1704 |
* |
|
1705 |
* @since 3.8.0 |
|
1706 |
* |
|
16 | 1707 |
* @return {void} |
9 | 1708 |
*/ |
5 | 1709 |
deactivate: function() { |
1710 |
setPinMenu(); |
|
1711 |
$adminmenu.removeData('wp-responsive'); |
|
16 | 1712 |
|
1713 |
this.maybeDisableSortables(); |
|
5 | 1714 |
}, |
1715 |
||
9 | 1716 |
/** |
1717 |
* Sets the responsiveness and enables the overlay based on the viewport width. |
|
1718 |
* |
|
1719 |
* @since 3.8.0 |
|
1720 |
* |
|
16 | 1721 |
* @return {void} |
9 | 1722 |
*/ |
5 | 1723 |
trigger: function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1724 |
var viewportWidth = getViewportWidth(); |
5 | 1725 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1726 |
// 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
|
1727 |
if ( ! viewportWidth ) { |
5 | 1728 |
return; |
1729 |
} |
|
1730 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1731 |
if ( viewportWidth <= 782 ) { |
5 | 1732 |
if ( ! wpResponsiveActive ) { |
1733 |
$document.trigger( 'wp-responsive-activate' ); |
|
1734 |
wpResponsiveActive = true; |
|
1735 |
} |
|
1736 |
} else { |
|
1737 |
if ( wpResponsiveActive ) { |
|
1738 |
$document.trigger( 'wp-responsive-deactivate' ); |
|
1739 |
wpResponsiveActive = false; |
|
1740 |
} |
|
1741 |
} |
|
1742 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1743 |
if ( viewportWidth <= 480 ) { |
5 | 1744 |
this.enableOverlay(); |
1745 |
} else { |
|
1746 |
this.disableOverlay(); |
|
1747 |
} |
|
16 | 1748 |
|
1749 |
this.maybeDisableSortables(); |
|
5 | 1750 |
}, |
1751 |
||
9 | 1752 |
/** |
1753 |
* Inserts a responsive overlay and toggles the window. |
|
1754 |
* |
|
1755 |
* @since 3.8.0 |
|
1756 |
* |
|
16 | 1757 |
* @return {void} |
9 | 1758 |
*/ |
5 | 1759 |
enableOverlay: function() { |
1760 |
if ( $overlay.length === 0 ) { |
|
1761 |
$overlay = $( '<div id="wp-responsive-overlay"></div>' ) |
|
1762 |
.insertAfter( '#wpcontent' ) |
|
1763 |
.hide() |
|
1764 |
.on( 'click.wp-responsive', function() { |
|
1765 |
$toolbar.find( '.menupop.hover' ).removeClass( 'hover' ); |
|
1766 |
$( this ).hide(); |
|
1767 |
}); |
|
1768 |
} |
|
1769 |
||
1770 |
$toolbarPopups.on( 'click.wp-responsive', function() { |
|
1771 |
$overlay.show(); |
|
1772 |
}); |
|
1773 |
}, |
|
1774 |
||
9 | 1775 |
/** |
1776 |
* Disables the responsive overlay and removes the overlay. |
|
1777 |
* |
|
1778 |
* @since 3.8.0 |
|
1779 |
* |
|
16 | 1780 |
* @return {void} |
9 | 1781 |
*/ |
5 | 1782 |
disableOverlay: function() { |
1783 |
$toolbarPopups.off( 'click.wp-responsive' ); |
|
1784 |
$overlay.hide(); |
|
1785 |
}, |
|
1786 |
||
9 | 1787 |
/** |
1788 |
* Disables sortables. |
|
1789 |
* |
|
1790 |
* @since 3.8.0 |
|
1791 |
* |
|
16 | 1792 |
* @return {void} |
9 | 1793 |
*/ |
5 | 1794 |
disableSortables: function() { |
1795 |
if ( $sortables.length ) { |
|
1796 |
try { |
|
9 | 1797 |
$sortables.sortable( 'disable' ); |
16 | 1798 |
$sortables.find( '.ui-sortable-handle' ).addClass( 'is-non-sortable' ); |
9 | 1799 |
} catch ( e ) {} |
5 | 1800 |
} |
1801 |
}, |
|
1802 |
||
9 | 1803 |
/** |
1804 |
* Enables sortables. |
|
1805 |
* |
|
1806 |
* @since 3.8.0 |
|
1807 |
* |
|
16 | 1808 |
* @return {void} |
9 | 1809 |
*/ |
5 | 1810 |
enableSortables: function() { |
1811 |
if ( $sortables.length ) { |
|
1812 |
try { |
|
9 | 1813 |
$sortables.sortable( 'enable' ); |
16 | 1814 |
$sortables.find( '.ui-sortable-handle' ).removeClass( 'is-non-sortable' ); |
9 | 1815 |
} catch ( e ) {} |
5 | 1816 |
} |
1817 |
} |
|
1818 |
}; |
|
1819 |
||
9 | 1820 |
/** |
1821 |
* Add an ARIA role `button` to elements that behave like UI controls when JavaScript is on. |
|
1822 |
* |
|
1823 |
* @since 4.5.0 |
|
1824 |
* |
|
16 | 1825 |
* @return {void} |
9 | 1826 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1827 |
function aria_button_if_js() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1828 |
$( '.aria-button-if-js' ).attr( 'role', 'button' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1829 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1830 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1831 |
$( document ).ajaxComplete( function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1832 |
aria_button_if_js(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1833 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1834 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1835 |
/** |
9 | 1836 |
* Get the viewport width. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1837 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1838 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1839 |
* |
16 | 1840 |
* @return {number|boolean} The current viewport width or false if the |
1841 |
* browser doesn't support innerWidth (IE < 9). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1842 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1843 |
function getViewportWidth() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1844 |
var viewportWidth = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1845 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1846 |
if ( window.innerWidth ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1847 |
// On phones, window.innerWidth is affected by zooming. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1848 |
viewportWidth = Math.max( window.innerWidth, document.documentElement.clientWidth ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1849 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1850 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1851 |
return viewportWidth; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1852 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1853 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1854 |
/** |
9 | 1855 |
* Sets the admin menu collapsed/expanded state. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1856 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1857 |
* 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
|
1858 |
* the current menu state. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1859 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1860 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1861 |
* |
16 | 1862 |
* @return {void} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1863 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1864 |
function setMenuState() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1865 |
var viewportWidth = getViewportWidth() || 961; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1866 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1867 |
if ( viewportWidth <= 782 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1868 |
menuState = 'responsive'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1869 |
} 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
|
1870 |
menuState = 'folded'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1871 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1872 |
menuState = 'open'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1873 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1874 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1875 |
$document.trigger( 'wp-menu-state-set', { state: menuState } ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1876 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1877 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1878 |
// Set the menu state when the window gets resized. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1879 |
$document.on( 'wp-window-resized.set-menu-state', setMenuState ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1880 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1881 |
/** |
9 | 1882 |
* 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
|
1883 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1884 |
* 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
|
1885 |
* `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
|
1886 |
* 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
|
1887 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1888 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1889 |
* |
16 | 1890 |
* @return {void} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1891 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1892 |
$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
|
1893 |
var $collapseButton = $( '#collapse-button' ), |
16 | 1894 |
ariaExpanded, ariaLabelText; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1895 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1896 |
if ( 'folded' === eventData.state ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1897 |
ariaExpanded = 'false'; |
16 | 1898 |
ariaLabelText = __( 'Expand Main menu' ); |
1899 |
} else { |
|
1900 |
ariaExpanded = 'true'; |
|
1901 |
ariaLabelText = __( 'Collapse Main menu' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1902 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1903 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1904 |
$collapseButton.attr({ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1905 |
'aria-expanded': ariaExpanded, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1906 |
'aria-label': ariaLabelText |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1907 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1908 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1909 |
|
5 | 1910 |
window.wpResponsive.init(); |
1911 |
setPinMenu(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1912 |
setMenuState(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1913 |
currentMenuItemHasPopup(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1914 |
makeNoticesDismissible(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1915 |
aria_button_if_js(); |
5 | 1916 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1917 |
$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
|
1918 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1919 |
// Set initial focus on a specific element. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1920 |
$( '.wp-initial-focus' ).focus(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1921 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1922 |
// Toggle update details on update-core.php. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1923 |
$body.on( 'click', '.js-update-details-toggle', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1924 |
var $updateNotice = $( this ).closest( '.js-update-details' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1925 |
$progressDiv = $( '#' + $updateNotice.data( 'update-details' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1926 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1927 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1928 |
* 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
|
1929 |
* 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
|
1930 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1931 |
if ( ! $progressDiv.hasClass( 'update-details-moved' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1932 |
$progressDiv.insertAfter( $updateNotice ).addClass( 'update-details-moved' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1933 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1934 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1935 |
// Toggle the progress div visibility. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1936 |
$progressDiv.toggle(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1937 |
// Toggle the Show Details button expanded state. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1938 |
$( this ).attr( 'aria-expanded', $progressDiv.is( ':visible' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1939 |
}); |
0 | 1940 |
}); |
1941 |
||
16 | 1942 |
/** |
1943 |
* Hides the update button for expired plugin or theme uploads. |
|
1944 |
* |
|
1945 |
* On the "Update plugin/theme from uploaded zip" screen, once the upload has expired, |
|
1946 |
* hides the "Replace current with uploaded" button and displays a warning. |
|
1947 |
* |
|
1948 |
* @since 5.5.0 |
|
1949 |
*/ |
|
1950 |
$document.ready( function( $ ) { |
|
1951 |
var $overwrite, $warning; |
|
1952 |
||
1953 |
if ( ! $body.hasClass( 'update-php' ) ) { |
|
1954 |
return; |
|
1955 |
} |
|
1956 |
||
1957 |
$overwrite = $( 'a.update-from-upload-overwrite' ); |
|
1958 |
$warning = $( '.update-from-upload-expired' ); |
|
1959 |
||
1960 |
if ( ! $overwrite.length || ! $warning.length ) { |
|
1961 |
return; |
|
1962 |
} |
|
1963 |
||
1964 |
window.setTimeout( |
|
1965 |
function() { |
|
1966 |
$overwrite.hide(); |
|
1967 |
$warning.removeClass( 'hidden' ); |
|
1968 |
||
1969 |
if ( window.wp && window.wp.a11y ) { |
|
1970 |
window.wp.a11y.speak( $warning.text() ); |
|
1971 |
} |
|
1972 |
}, |
|
1973 |
7140000 // 119 minutes. The uploaded file is deleted after 2 hours. |
|
1974 |
); |
|
1975 |
} ); |
|
1976 |
||
9 | 1977 |
// Fire a custom jQuery event at the end of window resize. |
5 | 1978 |
( function() { |
1979 |
var timeout; |
|
1980 |
||
9 | 1981 |
/** |
1982 |
* Triggers the WP window-resize event. |
|
1983 |
* |
|
1984 |
* @since 3.8.0 |
|
1985 |
* |
|
16 | 1986 |
* @return {void} |
9 | 1987 |
*/ |
5 | 1988 |
function triggerEvent() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1989 |
$document.trigger( 'wp-window-resized' ); |
5 | 1990 |
} |
1991 |
||
9 | 1992 |
/** |
1993 |
* Fires the trigger event again after 200 ms. |
|
1994 |
* |
|
1995 |
* @since 3.8.0 |
|
1996 |
* |
|
16 | 1997 |
* @return {void} |
9 | 1998 |
*/ |
5 | 1999 |
function fireOnce() { |
2000 |
window.clearTimeout( timeout ); |
|
2001 |
timeout = window.setTimeout( triggerEvent, 200 ); |
|
2002 |
} |
|
0 | 2003 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2004 |
$window.on( 'resize.wp-fire-once', fireOnce ); |
5 | 2005 |
}()); |
0 | 2006 |
|
5 | 2007 |
// Make Windows 8 devices play along nicely. |
2008 |
(function(){ |
|
2009 |
if ( '-ms-user-select' in document.documentElement.style && navigator.userAgent.match(/IEMobile\/10\.0/) ) { |
|
2010 |
var msViewportStyle = document.createElement( 'style' ); |
|
2011 |
msViewportStyle.appendChild( |
|
2012 |
document.createTextNode( '@-ms-viewport{width:auto!important}' ) |
|
2013 |
); |
|
2014 |
document.getElementsByTagName( 'head' )[0].appendChild( msViewportStyle ); |
|
2015 |
} |
|
2016 |
})(); |
|
0 | 2017 |
|
5 | 2018 |
}( jQuery, window )); |