1 /* global setUserSetting, ajaxurl, commonL10n, alert, confirm, toggleWithKeyboard, pagenow */
2 var showNotice, adminMenu, columns, validateForm, screenMeta;
3 ( function( $, window, undefined ) {
5 // (perhaps) needed for back-compat
9 restoreMenuState : function() {},
10 toggle : function() {},
11 favorites : function() {}
14 // show/hide/save table columns
18 $('.hide-column-tog', '#adv-settings').click( function() {
19 var $t = $(this), column = $t.val();
20 if ( $t.prop('checked') )
23 that.unchecked(column);
25 columns.saveManageColumnsState();
29 saveManageColumnsState : function() {
30 var hidden = this.hidden();
32 action: 'hidden-columns',
34 screenoptionnonce: $('#screenoptionnonce').val(),
39 checked : function(column) {
40 $('.column-' + column).show();
41 this.colSpanChange(+1);
44 unchecked : function(column) {
45 $('.column-' + column).hide();
46 this.colSpanChange(-1);
50 return $('.manage-column').filter(':hidden').map(function() { return this.id; }).get().join(',');
53 useCheckboxesForHidden : function() {
54 this.hidden = function(){
55 return $('.hide-column-tog').not(':checked').map(function() {
57 return id.substring( id, id.length - 5 );
62 colSpanChange : function(diff) {
63 var $t = $('table').find('.colspanchange'), n;
66 n = parseInt( $t.attr('colspan'), 10 ) + diff;
67 $t.attr('colspan', n.toString());
71 $(document).ready(function(){columns.init();});
73 validateForm = function( form ) {
75 .find( '.form-required' )
76 .filter( function() { return $( 'input:visible', this ).val() === ''; } )
77 .addClass( 'form-invalid' )
78 .find( 'input:visible' )
79 .change( function() { $( this ).closest( '.form-invalid' ).removeClass( 'form-invalid' ); } )
83 // stub for doing better warnings
86 var msg = commonL10n.warnDelete || '';
94 note : function(text) {
100 element: null, // #screen-meta
101 toggles: null, // .screen-meta-toggle
102 page: null, // #wpcontent
105 this.element = $('#screen-meta');
106 this.toggles = $('.screen-meta-toggle a');
107 this.page = $('#wpcontent');
109 this.toggles.click( this.toggleEvent );
112 toggleEvent: function( e ) {
113 var panel = $( this.href.replace(/.+#/, '#') );
119 if ( panel.is(':visible') )
120 screenMeta.close( panel, $(this) );
122 screenMeta.open( panel, $(this) );
125 open: function( panel, link ) {
127 $('.screen-meta-toggle').not( link.parent() ).css('visibility', 'hidden');
129 panel.parent().show();
130 panel.slideDown( 'fast', function() {
132 link.addClass('screen-meta-active').attr('aria-expanded', true);
136 close: function( panel, link ) {
137 panel.slideUp( 'fast', function() {
138 link.removeClass('screen-meta-active').attr('aria-expanded', false);
139 $('.screen-meta-toggle').css('visibility', '');
140 panel.parent().hide();
148 $('.contextual-help-tabs').delegate('a', 'click focus', function(e) {
154 // Don't do anything if the click is for the tab already showing.
155 if ( link.is('.active a') )
159 $('.contextual-help-tabs .active').removeClass('active');
160 link.parent('li').addClass('active');
162 panel = $( link.attr('href') );
165 $('.help-tab-content').not( panel ).removeClass('active').hide();
166 panel.addClass('active').show();
169 $(document).ready( function() {
170 var checks, first, last, checked, sliced, mobileEvent, transitionTimeout, focusedRowActions,
172 menu = $('#adminmenu'),
173 pageInput = $('input.current-page'),
174 currentPage = pageInput.val();
176 // when the menu is folded, make the fly-out submenu header clickable
177 menu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){
178 $(e.target).parent().siblings('a').get(0).click();
181 $('#collapse-menu').on('click.collapse-menu', function() {
182 var body = $( document.body ), respWidth;
184 // reset any compensation for submenus near the bottom of the screen
185 $('#adminmenu div.wp-submenu').css('margin-top', '');
187 if ( window.innerWidth ) {
188 // window.innerWidth is affected by zooming on phones
189 respWidth = Math.max( window.innerWidth, document.documentElement.clientWidth );
191 // IE < 9 doesn't support @media CSS rules
195 if ( respWidth && respWidth < 900 ) {
196 if ( body.hasClass('auto-fold') ) {
197 body.removeClass('auto-fold').removeClass('folded');
198 setUserSetting('unfold', 1);
199 setUserSetting('mfold', 'o');
201 body.addClass('auto-fold');
202 setUserSetting('unfold', 0);
205 if ( body.hasClass('folded') ) {
206 body.removeClass('folded');
207 setUserSetting('mfold', 'o');
209 body.addClass('folded');
210 setUserSetting('mfold', 'f');
215 if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // touch screen device
216 // iOS Safari works with touchstart, the rest work with click
217 mobileEvent = /Mobile\/.+Safari/.test(navigator.userAgent) ? 'touchstart' : 'click';
219 // close any open submenus when touch/click is not on the menu
220 $(document.body).on( mobileEvent+'.wp-mobile-hover', function(e) {
221 if ( menu.data('wp-responsive') ) {
225 if ( ! $(e.target).closest('#adminmenu').length ) {
226 menu.find('li.wp-has-submenu.opensub').removeClass('opensub');
230 menu.find('a.wp-has-submenu').on( mobileEvent+'.wp-mobile-hover', function(e) {
231 var el = $(this), parent = el.parent();
233 if ( menu.data('wp-responsive') ) {
237 // Show the sub instead of following the link if:
238 // - the submenu is not open
239 // - the submenu is not shown inline or the menu is not folded
240 if ( !parent.hasClass('opensub') && ( !parent.hasClass('wp-menu-open') || parent.width() < 40 ) ) {
242 menu.find('li.opensub').removeClass('opensub');
243 parent.addClass('opensub');
248 menu.find('li.wp-has-submenu').hoverIntent({
250 var b, h, o, f, m = $(this).find('.wp-submenu'), menutop, wintop, maxtop, top = parseInt( m.css('top'), 10 );
252 if ( isNaN(top) || top > -5 ) // meaning the submenu is visible
255 if ( menu.data('wp-responsive') ) {
256 // The menu is in responsive mode, bail
260 menutop = $(this).offset().top;
261 wintop = $(window).scrollTop();
262 maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar
264 b = menutop + m.height() + 1; // Bottom offset of the menu
265 h = $('#wpwrap').height(); // Height of the entire page
267 f = $(window).height() + wintop - 15; // The fold
276 m.css('margin-top', '-'+o+'px');
278 m.css('margin-top', '');
280 menu.find('li.menu-top').removeClass('opensub');
281 $(this).addClass('opensub');
284 if ( menu.data('wp-responsive') ) {
285 // The menu is in responsive mode, bail
289 $(this).removeClass('opensub').find('.wp-submenu').css('margin-top', '');
296 menu.on('focus.adminmenu', '.wp-submenu a', function(e){
297 if ( menu.data('wp-responsive') ) {
298 // The menu is in responsive mode, bail
302 $(e.target).closest('li.menu-top').addClass('opensub');
303 }).on('blur.adminmenu', '.wp-submenu a', function(e){
304 if ( menu.data('wp-responsive') ) {
305 // The menu is in responsive mode, bail
309 $(e.target).closest('li.menu-top').removeClass('opensub');
312 // Move .updated and .error alert boxes. Don't move boxes designed to be inline.
313 $('div.wrap h2:first').nextAll('div.updated, div.error').addClass('below-h2');
314 $('div.updated, div.error').not('.below-h2, .inline').insertAfter( $('div.wrap h2:first') );
319 // check all checkboxes
320 $('tbody').children().children('.check-column').find(':checkbox').click( function(e) {
321 if ( 'undefined' == e.shiftKey ) { return true; }
323 if ( !lastClicked ) { return true; }
324 checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' );
325 first = checks.index( lastClicked );
326 last = checks.index( this );
327 checked = $(this).prop('checked');
328 if ( 0 < first && 0 < last && first != last ) {
329 sliced = ( last > first ) ? checks.slice( first, last ) : checks.slice( last, first );
330 sliced.prop( 'checked', function() {
331 if ( $(this).closest('tr').is(':visible') )
340 // toggle "check all" checkboxes
341 var unchecked = $(this).closest('tbody').find(':checkbox').filter(':visible').not(':checked');
342 $(this).closest('table').children('thead, tfoot').find(':checkbox').prop('checked', function() {
343 return ( 0 === unchecked.length );
349 $('thead, tfoot').find('.check-column :checkbox').click( function(e) {
350 var c = $(this).prop('checked'),
351 kbtoggle = 'undefined' == typeof toggleWithKeyboard ? false : toggleWithKeyboard,
352 toggle = e.shiftKey || kbtoggle;
354 $(this).closest( 'table' ).children( 'tbody' ).filter(':visible')
355 .children().children('.check-column').find(':checkbox')
356 .prop('checked', function() {
357 if ( $(this).is(':hidden') )
360 return $(this).prop( 'checked' );
366 $(this).closest('table').children('thead, tfoot').filter(':visible')
367 .children().children('.check-column').find(':checkbox')
368 .prop('checked', function() {
377 // Show row actions on keyboard focus of its parent container element or any other elements contained within
378 $( 'td.post-title, td.title, td.comment, .bookmarks td.column-name, td.blogname, td.username, .dashboard-comment-wrap' ).focusin(function(){
379 clearTimeout( transitionTimeout );
380 focusedRowActions = $(this).find( '.row-actions' );
381 focusedRowActions.addClass( 'visible' );
382 }).focusout(function(){
383 // Tabbing between post title and .row-actions links needs a brief pause, otherwise
384 // the .row-actions div gets hidden in transit in some browsers (ahem, Firefox).
385 transitionTimeout = setTimeout(function(){
386 focusedRowActions.removeClass( 'visible' );
390 $('#default-password-nag-no').click( function() {
391 setUserSetting('default_password_nag', 'hide');
392 $('div.default-password-nag').hide();
397 $('#newcontent').bind('keydown.wpevent_InsertTab', function(e) {
398 var el = e.target, selStart, selEnd, val, scroll, sel;
400 if ( e.keyCode == 27 ) { // escape key
401 $(el).data('tab-out', true);
405 if ( e.keyCode != 9 || e.ctrlKey || e.altKey || e.shiftKey ) // tab key
408 if ( $(el).data('tab-out') ) {
409 $(el).data('tab-out', false);
413 selStart = el.selectionStart;
414 selEnd = el.selectionEnd;
418 this.lastKey = 9; // not a standard DOM property, lastKey is to help stop Opera tab event. See blur handler below.
421 if ( document.selection ) {
423 sel = document.selection.createRange();
425 } else if ( selStart >= 0 ) {
426 scroll = this.scrollTop;
427 el.value = val.substring(0, selStart).concat('\t', val.substring(selEnd) );
428 el.selectionStart = el.selectionEnd = selStart + 1;
429 this.scrollTop = scroll;
432 if ( e.stopPropagation )
434 if ( e.preventDefault )
438 $('#newcontent').bind('blur.wpevent_InsertTab', function() {
439 if ( this.lastKey && 9 == this.lastKey )
443 if ( pageInput.length ) {
444 pageInput.closest('form').submit( function() {
446 // Reset paging var for new filters/searches but not for bulk actions. See #17685.
447 if ( $('select[name="action"]').val() == -1 && $('select[name="action2"]').val() == -1 && pageInput.val() == currentPage )
452 $('.search-box input[type="search"], .search-box input[type="submit"]').mousedown(function () {
453 $('select[name^="action"]').val('-1');
456 // Scroll into view when focused
457 $('#contextual-help-link, #show-settings-link').on( 'focus.scroll-into-view', function(e){
458 if ( e.target.scrollIntoView )
459 e.target.scrollIntoView(false);
462 // Disable upload buttons until files are selected
464 var button, input, form = $('form.wp-upload-form');
467 button = form.find('input[type="submit"]');
468 input = form.find('input[type="file"]');
470 function toggleUploadButton() {
471 button.prop('disabled', '' === input.map( function() {
472 return $(this).val();
475 toggleUploadButton();
476 input.on('change', toggleUploadButton);
480 // Fire a custom jQuery event at the end of window resize
484 function triggerEvent() {
485 $(document).trigger( 'wp-window-resized' );
488 function fireOnce() {
489 window.clearTimeout( timeout );
490 timeout = window.setTimeout( triggerEvent, 200 );
493 $(window).on( 'resize.wp-fire-once', fireOnce );
496 $(document).ready( function() {
497 var $document = $( document ),
498 $window = $( window ),
499 $body = $( document.body ),
500 $adminMenuWrap = $( '#adminmenuwrap' ),
501 $collapseMenu = $( '#collapse-menu' ),
502 $wpwrap = $( '#wpwrap' ),
503 $adminmenu = $( '#adminmenu' ),
504 $overlay = $( '#wp-responsive-overlay' ),
505 $toolbar = $( '#wp-toolbar' ),
506 $toolbarPopups = $toolbar.find( 'a[aria-haspopup="true"]' ),
507 $sortables = $('.meta-box-sortables'),
508 stickyMenuActive = false,
509 wpResponsiveActive = false;
511 window.stickyMenu = {
513 if ( ! stickyMenuActive ) {
514 $document.on( 'wp-window-resized.sticky-menu', $.proxy( this.update, this ) );
515 $collapseMenu.on( 'click.sticky-menu', $.proxy( this.update, this ) );
517 stickyMenuActive = true;
521 disable: function() {
522 if ( stickyMenuActive ) {
523 $window.off( 'resize.sticky-menu' );
524 $collapseMenu.off( 'click.sticky-menu' );
525 $body.removeClass( 'sticky-menu' );
526 stickyMenuActive = false;
531 // Make the admin menu sticky if the viewport is taller than it
532 if ( $window.height() > $adminMenuWrap.height() + 32 ) {
533 if ( ! $body.hasClass( 'sticky-menu' ) ) {
534 $body.addClass( 'sticky-menu' );
537 if ( $body.hasClass( 'sticky-menu' ) ) {
538 $body.removeClass( 'sticky-menu' );
544 window.wpResponsive = {
549 // Modify functionality based on custom activate/deactivate event
550 $document.on( 'wp-responsive-activate.wp-responsive', function() {
552 }).on( 'wp-responsive-deactivate.wp-responsive', function() {
556 // Toggle sidebar when toggle is clicked
557 $( '#wp-admin-bar-menu-toggle' ).on( 'click.wp-responsive', function( event ) {
558 event.preventDefault();
559 $wpwrap.toggleClass( 'wp-responsive-open' );
563 $adminmenu.on( 'touchstart.wp-responsive', 'li.wp-has-submenu > a', function() {
564 scrollStart = $window.scrollTop();
565 }).on( 'touchend.wp-responsive click.wp-responsive', 'li.wp-has-submenu > a', function( event ) {
566 if ( ! $adminmenu.data('wp-responsive') ||
567 ( event.type === 'touchend' && $window.scrollTop() !== scrollStart ) ) {
572 $( this ).parent( 'li' ).toggleClass( 'selected' );
573 event.preventDefault();
577 $document.on( 'wp-window-resized.wp-responsive', $.proxy( this.trigger, this ) );
579 // This needs to run later as UI Sortable may be initialized later on $(document).ready()
580 $window.on( 'load.wp-responsive', function() {
581 var width = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? $window.width() : window.innerWidth;
583 if ( width <= 782 ) {
584 self.disableSortables();
589 activate: function() {
590 window.stickyMenu.disable();
592 if ( ! $body.hasClass( 'auto-fold' ) ) {
593 $body.addClass( 'auto-fold' );
596 $adminmenu.data( 'wp-responsive', 1 );
597 this.disableSortables();
600 deactivate: function() {
601 window.stickyMenu.enable();
602 $adminmenu.removeData('wp-responsive');
603 this.enableSortables();
606 trigger: function() {
609 if ( window.innerWidth ) {
610 // window.innerWidth is affected by zooming on phones
611 width = Math.max( window.innerWidth, document.documentElement.clientWidth );
613 // Exclude IE < 9, it doesn't support @media CSS rules
617 if ( width <= 782 ) {
618 if ( ! wpResponsiveActive ) {
619 $document.trigger( 'wp-responsive-activate' );
620 wpResponsiveActive = true;
623 if ( wpResponsiveActive ) {
624 $document.trigger( 'wp-responsive-deactivate' );
625 wpResponsiveActive = false;
629 if ( width <= 480 ) {
630 this.enableOverlay();
632 this.disableOverlay();
636 enableOverlay: function() {
637 if ( $overlay.length === 0 ) {
638 $overlay = $( '<div id="wp-responsive-overlay"></div>' )
639 .insertAfter( '#wpcontent' )
641 .on( 'click.wp-responsive', function() {
642 $toolbar.find( '.menupop.hover' ).removeClass( 'hover' );
647 $toolbarPopups.on( 'click.wp-responsive', function() {
652 disableOverlay: function() {
653 $toolbarPopups.off( 'click.wp-responsive' );
657 disableSortables: function() {
658 if ( $sortables.length ) {
660 $sortables.sortable('disable');
665 enableSortables: function() {
666 if ( $sortables.length ) {
668 $sortables.sortable('enable');
674 window.stickyMenu.enable();
675 window.wpResponsive.init();
678 // make Windows 8 devices playing along nicely
680 if ( '-ms-user-select' in document.documentElement.style && navigator.userAgent.match(/IEMobile\/10\.0/) ) {
681 var msViewportStyle = document.createElement( 'style' );
682 msViewportStyle.appendChild(
683 document.createTextNode( '@-ms-viewport{width:auto!important}' )
685 document.getElementsByTagName( 'head' )[0].appendChild( msViewportStyle );
690 $(document).bind( 'wp_CloseOnEscape', function( e, data ) {
691 if ( typeof(data.cb) != 'function' )
694 if ( typeof(data.condition) != 'function' || data.condition() )
700 }( jQuery, window ));