|
1 var showNotice, adminMenu, columns, validateForm, screenMeta; |
|
2 (function($){ |
|
3 // Removed in 3.3. |
|
4 // (perhaps) needed for back-compat |
|
5 adminMenu = { |
|
6 init : function() {}, |
|
7 fold : function() {}, |
|
8 restoreMenuState : function() {}, |
|
9 toggle : function() {}, |
|
10 favorites : function() {} |
|
11 }; |
|
12 |
|
13 // show/hide/save table columns |
|
14 columns = { |
|
15 init : function() { |
|
16 var that = this; |
|
17 $('.hide-column-tog', '#adv-settings').click( function() { |
|
18 var $t = $(this), column = $t.val(); |
|
19 if ( $t.prop('checked') ) |
|
20 that.checked(column); |
|
21 else |
|
22 that.unchecked(column); |
|
23 |
|
24 columns.saveManageColumnsState(); |
|
25 }); |
|
26 }, |
|
27 |
|
28 saveManageColumnsState : function() { |
|
29 var hidden = this.hidden(); |
|
30 $.post(ajaxurl, { |
|
31 action: 'hidden-columns', |
|
32 hidden: hidden, |
|
33 screenoptionnonce: $('#screenoptionnonce').val(), |
|
34 page: pagenow |
|
35 }); |
|
36 }, |
|
37 |
|
38 checked : function(column) { |
|
39 $('.column-' + column).show(); |
|
40 this.colSpanChange(+1); |
|
41 }, |
|
42 |
|
43 unchecked : function(column) { |
|
44 $('.column-' + column).hide(); |
|
45 this.colSpanChange(-1); |
|
46 }, |
|
47 |
|
48 hidden : function() { |
|
49 return $('.manage-column').filter(':hidden').map(function() { return this.id; }).get().join(','); |
|
50 }, |
|
51 |
|
52 useCheckboxesForHidden : function() { |
|
53 this.hidden = function(){ |
|
54 return $('.hide-column-tog').not(':checked').map(function() { |
|
55 var id = this.id; |
|
56 return id.substring( id, id.length - 5 ); |
|
57 }).get().join(','); |
|
58 }; |
|
59 }, |
|
60 |
|
61 colSpanChange : function(diff) { |
|
62 var $t = $('table').find('.colspanchange'), n; |
|
63 if ( !$t.length ) |
|
64 return; |
|
65 n = parseInt( $t.attr('colspan'), 10 ) + diff; |
|
66 $t.attr('colspan', n.toString()); |
|
67 } |
|
68 } |
|
69 |
|
70 $(document).ready(function(){columns.init();}); |
|
71 |
|
72 validateForm = function( form ) { |
|
73 return !$( form ).find('.form-required').filter( function() { return $('input:visible', this).val() == ''; } ).addClass( 'form-invalid' ).find('input:visible').change( function() { $(this).closest('.form-invalid').removeClass( 'form-invalid' ); } ).size(); |
|
74 } |
|
75 |
|
76 // stub for doing better warnings |
|
77 showNotice = { |
|
78 warn : function() { |
|
79 var msg = commonL10n.warnDelete || ''; |
|
80 if ( confirm(msg) ) { |
|
81 return true; |
|
82 } |
|
83 |
|
84 return false; |
|
85 }, |
|
86 |
|
87 note : function(text) { |
|
88 alert(text); |
|
89 } |
|
90 }; |
|
91 |
|
92 screenMeta = { |
|
93 element: null, // #screen-meta |
|
94 toggles: null, // .screen-meta-toggle |
|
95 page: null, // #wpcontent |
|
96 |
|
97 init: function() { |
|
98 this.element = $('#screen-meta'); |
|
99 this.toggles = $('.screen-meta-toggle a'); |
|
100 this.page = $('#wpcontent'); |
|
101 |
|
102 this.toggles.click( this.toggleEvent ); |
|
103 }, |
|
104 |
|
105 toggleEvent: function( e ) { |
|
106 var panel = $( this.href.replace(/.+#/, '#') ); |
|
107 e.preventDefault(); |
|
108 |
|
109 if ( !panel.length ) |
|
110 return; |
|
111 |
|
112 if ( panel.is(':visible') ) |
|
113 screenMeta.close( panel, $(this) ); |
|
114 else |
|
115 screenMeta.open( panel, $(this) ); |
|
116 }, |
|
117 |
|
118 open: function( panel, link ) { |
|
119 |
|
120 $('.screen-meta-toggle').not( link.parent() ).css('visibility', 'hidden'); |
|
121 |
|
122 panel.parent().show(); |
|
123 panel.slideDown( 'fast', function() { |
|
124 panel.focus(); |
|
125 link.addClass('screen-meta-active').attr('aria-expanded', true); |
|
126 }); |
|
127 }, |
|
128 |
|
129 close: function( panel, link ) { |
|
130 panel.slideUp( 'fast', function() { |
|
131 link.removeClass('screen-meta-active').attr('aria-expanded', false); |
|
132 $('.screen-meta-toggle').css('visibility', ''); |
|
133 panel.parent().hide(); |
|
134 }); |
|
135 } |
|
136 }; |
|
137 |
|
138 /** |
|
139 * Help tabs. |
|
140 */ |
|
141 $('.contextual-help-tabs').delegate('a', 'click focus', function(e) { |
|
142 var link = $(this), |
|
143 panel; |
|
144 |
|
145 e.preventDefault(); |
|
146 |
|
147 // Don't do anything if the click is for the tab already showing. |
|
148 if ( link.is('.active a') ) |
|
149 return false; |
|
150 |
|
151 // Links |
|
152 $('.contextual-help-tabs .active').removeClass('active'); |
|
153 link.parent('li').addClass('active'); |
|
154 |
|
155 panel = $( link.attr('href') ); |
|
156 |
|
157 // Panels |
|
158 $('.help-tab-content').not( panel ).removeClass('active').hide(); |
|
159 panel.addClass('active').show(); |
|
160 }); |
|
161 |
|
162 $(document).ready( function() { |
|
163 var lastClicked = false, checks, first, last, checked, sliced, menu = $('#adminmenu'), mobileEvent, |
|
164 pageInput = $('input.current-page'), currentPage = pageInput.val(); |
|
165 |
|
166 // when the menu is folded, make the fly-out submenu header clickable |
|
167 menu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){ |
|
168 $(e.target).parent().siblings('a').get(0).click(); |
|
169 }); |
|
170 |
|
171 $('#collapse-menu').on('click.collapse-menu', function(e){ |
|
172 var body = $( document.body ), respWidth; |
|
173 |
|
174 // reset any compensation for submenus near the bottom of the screen |
|
175 $('#adminmenu div.wp-submenu').css('margin-top', ''); |
|
176 |
|
177 // WebKit excludes the width of the vertical scrollbar when applying the CSS "@media screen and (max-width: ...)" |
|
178 // and matches $(window).width(). |
|
179 // Firefox and IE > 8 include the scrollbar width, so after the jQuery normalization |
|
180 // $(window).width() is 884px but window.innerWidth is 900px. |
|
181 // (using window.innerWidth also excludes IE < 9) |
|
182 respWidth = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? $(window).width() : window.innerWidth; |
|
183 |
|
184 if ( respWidth && respWidth < 900 ) { |
|
185 if ( body.hasClass('auto-fold') ) { |
|
186 body.removeClass('auto-fold').removeClass('folded'); |
|
187 setUserSetting('unfold', 1); |
|
188 setUserSetting('mfold', 'o'); |
|
189 } else { |
|
190 body.addClass('auto-fold'); |
|
191 setUserSetting('unfold', 0); |
|
192 } |
|
193 } else { |
|
194 if ( body.hasClass('folded') ) { |
|
195 body.removeClass('folded'); |
|
196 setUserSetting('mfold', 'o'); |
|
197 } else { |
|
198 body.addClass('folded'); |
|
199 setUserSetting('mfold', 'f'); |
|
200 } |
|
201 } |
|
202 }); |
|
203 |
|
204 if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // touch screen device |
|
205 // iOS Safari works with touchstart, the rest work with click |
|
206 mobileEvent = /Mobile\/.+Safari/.test(navigator.userAgent) ? 'touchstart' : 'click'; |
|
207 |
|
208 // close any open submenus when touch/click is not on the menu |
|
209 $(document.body).on( mobileEvent+'.wp-mobile-hover', function(e) { |
|
210 if ( !$(e.target).closest('#adminmenu').length ) |
|
211 menu.find('li.wp-has-submenu.opensub').removeClass('opensub'); |
|
212 }); |
|
213 |
|
214 menu.find('a.wp-has-submenu').on( mobileEvent+'.wp-mobile-hover', function(e) { |
|
215 var el = $(this), parent = el.parent(); |
|
216 |
|
217 // Show the sub instead of following the link if: |
|
218 // - the submenu is not open |
|
219 // - the submenu is not shown inline or the menu is not folded |
|
220 if ( !parent.hasClass('opensub') && ( !parent.hasClass('wp-menu-open') || parent.width() < 40 ) ) { |
|
221 e.preventDefault(); |
|
222 menu.find('li.opensub').removeClass('opensub'); |
|
223 parent.addClass('opensub'); |
|
224 } |
|
225 }); |
|
226 } |
|
227 |
|
228 menu.find('li.wp-has-submenu').hoverIntent({ |
|
229 over: function(e){ |
|
230 var b, h, o, f, m = $(this).find('.wp-submenu'), menutop, wintop, maxtop, top = parseInt( m.css('top'), 10 ); |
|
231 |
|
232 if ( isNaN(top) || top > -5 ) // meaning the submenu is visible |
|
233 return; |
|
234 |
|
235 menutop = $(this).offset().top; |
|
236 wintop = $(window).scrollTop(); |
|
237 maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar |
|
238 |
|
239 b = menutop + m.height() + 1; // Bottom offset of the menu |
|
240 h = $('#wpwrap').height(); // Height of the entire page |
|
241 o = 60 + b - h; |
|
242 f = $(window).height() + wintop - 15; // The fold |
|
243 |
|
244 if ( f < (b - o) ) |
|
245 o = b - f; |
|
246 |
|
247 if ( o > maxtop ) |
|
248 o = maxtop; |
|
249 |
|
250 if ( o > 1 ) |
|
251 m.css('margin-top', '-'+o+'px'); |
|
252 else |
|
253 m.css('margin-top', ''); |
|
254 |
|
255 menu.find('li.menu-top').removeClass('opensub'); |
|
256 $(this).addClass('opensub'); |
|
257 }, |
|
258 out: function(){ |
|
259 $(this).removeClass('opensub').find('.wp-submenu').css('margin-top', ''); |
|
260 }, |
|
261 timeout: 200, |
|
262 sensitivity: 7, |
|
263 interval: 90 |
|
264 }); |
|
265 |
|
266 menu.on('focus.adminmenu', '.wp-submenu a', function(e){ |
|
267 $(e.target).closest('li.menu-top').addClass('opensub'); |
|
268 }).on('blur.adminmenu', '.wp-submenu a', function(e){ |
|
269 $(e.target).closest('li.menu-top').removeClass('opensub'); |
|
270 }); |
|
271 |
|
272 // Move .updated and .error alert boxes. Don't move boxes designed to be inline. |
|
273 $('div.wrap h2:first').nextAll('div.updated, div.error').addClass('below-h2'); |
|
274 $('div.updated, div.error').not('.below-h2, .inline').insertAfter( $('div.wrap h2:first') ); |
|
275 |
|
276 // Init screen meta |
|
277 screenMeta.init(); |
|
278 |
|
279 // check all checkboxes |
|
280 $('tbody').children().children('.check-column').find(':checkbox').click( function(e) { |
|
281 if ( 'undefined' == e.shiftKey ) { return true; } |
|
282 if ( e.shiftKey ) { |
|
283 if ( !lastClicked ) { return true; } |
|
284 checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' ); |
|
285 first = checks.index( lastClicked ); |
|
286 last = checks.index( this ); |
|
287 checked = $(this).prop('checked'); |
|
288 if ( 0 < first && 0 < last && first != last ) { |
|
289 sliced = ( last > first ) ? checks.slice( first, last ) : checks.slice( last, first ); |
|
290 sliced.prop( 'checked', function() { |
|
291 if ( $(this).closest('tr').is(':visible') ) |
|
292 return checked; |
|
293 |
|
294 return false; |
|
295 }); |
|
296 } |
|
297 } |
|
298 lastClicked = this; |
|
299 |
|
300 // toggle "check all" checkboxes |
|
301 var unchecked = $(this).closest('tbody').find(':checkbox').filter(':visible').not(':checked'); |
|
302 $(this).closest('table').children('thead, tfoot').find(':checkbox').prop('checked', function() { |
|
303 return ( 0 == unchecked.length ); |
|
304 }); |
|
305 |
|
306 return true; |
|
307 }); |
|
308 |
|
309 $('thead, tfoot').find('.check-column :checkbox').click( function(e) { |
|
310 var c = $(this).prop('checked'), |
|
311 kbtoggle = 'undefined' == typeof toggleWithKeyboard ? false : toggleWithKeyboard, |
|
312 toggle = e.shiftKey || kbtoggle; |
|
313 |
|
314 $(this).closest( 'table' ).children( 'tbody' ).filter(':visible') |
|
315 .children().children('.check-column').find(':checkbox') |
|
316 .prop('checked', function() { |
|
317 if ( $(this).is(':hidden') ) |
|
318 return false; |
|
319 if ( toggle ) |
|
320 return $(this).prop( 'checked' ); |
|
321 else if (c) |
|
322 return true; |
|
323 return false; |
|
324 }); |
|
325 |
|
326 $(this).closest('table').children('thead, tfoot').filter(':visible') |
|
327 .children().children('.check-column').find(':checkbox') |
|
328 .prop('checked', function() { |
|
329 if ( toggle ) |
|
330 return false; |
|
331 else if (c) |
|
332 return true; |
|
333 return false; |
|
334 }); |
|
335 }); |
|
336 |
|
337 // Show row actions on keyboard focus of its parent container element or any other elements contained within |
|
338 var transitionTimeout, focusedRowActions; |
|
339 $( 'td.post-title, td.title, td.comment, .bookmarks td.column-name, td.blogname, td.username, .dashboard-comment-wrap' ).focusin(function(){ |
|
340 clearTimeout( transitionTimeout ); |
|
341 focusedRowActions = $(this).find( '.row-actions' ); |
|
342 focusedRowActions.addClass( 'visible' ); |
|
343 }).focusout(function(){ |
|
344 // Tabbing between post title and .row-actions links needs a brief pause, otherwise |
|
345 // the .row-actions div gets hidden in transit in some browsers (ahem, Firefox). |
|
346 transitionTimeout = setTimeout(function(){ |
|
347 focusedRowActions.removeClass( 'visible' ); |
|
348 }, 30); |
|
349 }); |
|
350 |
|
351 $('#default-password-nag-no').click( function() { |
|
352 setUserSetting('default_password_nag', 'hide'); |
|
353 $('div.default-password-nag').hide(); |
|
354 return false; |
|
355 }); |
|
356 |
|
357 // tab in textareas |
|
358 $('#newcontent').bind('keydown.wpevent_InsertTab', function(e) { |
|
359 var el = e.target, selStart, selEnd, val, scroll, sel; |
|
360 |
|
361 if ( e.keyCode == 27 ) { // escape key |
|
362 $(el).data('tab-out', true); |
|
363 return; |
|
364 } |
|
365 |
|
366 if ( e.keyCode != 9 || e.ctrlKey || e.altKey || e.shiftKey ) // tab key |
|
367 return; |
|
368 |
|
369 if ( $(el).data('tab-out') ) { |
|
370 $(el).data('tab-out', false); |
|
371 return; |
|
372 } |
|
373 |
|
374 selStart = el.selectionStart; |
|
375 selEnd = el.selectionEnd; |
|
376 val = el.value; |
|
377 |
|
378 try { |
|
379 this.lastKey = 9; // not a standard DOM property, lastKey is to help stop Opera tab event. See blur handler below. |
|
380 } catch(err) {} |
|
381 |
|
382 if ( document.selection ) { |
|
383 el.focus(); |
|
384 sel = document.selection.createRange(); |
|
385 sel.text = '\t'; |
|
386 } else if ( selStart >= 0 ) { |
|
387 scroll = this.scrollTop; |
|
388 el.value = val.substring(0, selStart).concat('\t', val.substring(selEnd) ); |
|
389 el.selectionStart = el.selectionEnd = selStart + 1; |
|
390 this.scrollTop = scroll; |
|
391 } |
|
392 |
|
393 if ( e.stopPropagation ) |
|
394 e.stopPropagation(); |
|
395 if ( e.preventDefault ) |
|
396 e.preventDefault(); |
|
397 }); |
|
398 |
|
399 $('#newcontent').bind('blur.wpevent_InsertTab', function(e) { |
|
400 if ( this.lastKey && 9 == this.lastKey ) |
|
401 this.focus(); |
|
402 }); |
|
403 |
|
404 if ( pageInput.length ) { |
|
405 pageInput.closest('form').submit( function(e){ |
|
406 |
|
407 // Reset paging var for new filters/searches but not for bulk actions. See #17685. |
|
408 if ( $('select[name="action"]').val() == -1 && $('select[name="action2"]').val() == -1 && pageInput.val() == currentPage ) |
|
409 pageInput.val('1'); |
|
410 }); |
|
411 } |
|
412 |
|
413 $('.search-box input[type="search"], .search-box input[type="submit"]').mousedown(function () { |
|
414 $('select[name^="action"]').val('-1'); |
|
415 }); |
|
416 |
|
417 // Scroll into view when focused |
|
418 $('#contextual-help-link, #show-settings-link').on( 'focus.scroll-into-view', function(e){ |
|
419 if ( e.target.scrollIntoView ) |
|
420 e.target.scrollIntoView(false); |
|
421 }); |
|
422 |
|
423 // Disable upload buttons until files are selected |
|
424 (function(){ |
|
425 var button, input, form = $('form.wp-upload-form'); |
|
426 if ( ! form.length ) |
|
427 return; |
|
428 button = form.find('input[type="submit"]'); |
|
429 input = form.find('input[type="file"]'); |
|
430 |
|
431 function toggleUploadButton() { |
|
432 button.prop('disabled', '' === input.map( function() { |
|
433 return $(this).val(); |
|
434 }).get().join('')); |
|
435 } |
|
436 toggleUploadButton(); |
|
437 input.on('change', toggleUploadButton); |
|
438 })(); |
|
439 }); |
|
440 |
|
441 // internal use |
|
442 $(document).bind( 'wp_CloseOnEscape', function( e, data ) { |
|
443 if ( typeof(data.cb) != 'function' ) |
|
444 return; |
|
445 |
|
446 if ( typeof(data.condition) != 'function' || data.condition() ) |
|
447 data.cb(); |
|
448 |
|
449 return true; |
|
450 }); |
|
451 |
|
452 })(jQuery); |