1 /* global setUserSetting, ajaxurl, commonL10n, alert, confirm, 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);
135 $( document ).trigger( 'screen:options:open' );
138 close: function( panel, link ) {
139 panel.slideUp( 'fast', function() {
140 link.removeClass('screen-meta-active').attr('aria-expanded', false);
141 $('.screen-meta-toggle').css('visibility', '');
142 panel.parent().hide();
145 $( document ).trigger( 'screen:options:close' );
152 $('.contextual-help-tabs').delegate('a', 'click', function(e) {
158 // Don't do anything if the click is for the tab already showing.
159 if ( link.is('.active a') )
163 $('.contextual-help-tabs .active').removeClass('active');
164 link.parent('li').addClass('active');
166 panel = $( link.attr('href') );
169 $('.help-tab-content').not( panel ).removeClass('active').hide();
170 panel.addClass('active').show();
173 $(document).ready( function() {
174 var checks, first, last, checked, sliced, mobileEvent, transitionTimeout, focusedRowActions,
176 menu = $('#adminmenu'),
177 pageInput = $('input.current-page'),
178 currentPage = pageInput.val();
180 // when the menu is folded, make the fly-out submenu header clickable
181 menu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){
182 $(e.target).parent().siblings('a').get(0).click();
185 $('#collapse-menu').on('click.collapse-menu', function() {
186 var body = $( document.body ), respWidth, state;
188 // reset any compensation for submenus near the bottom of the screen
189 $('#adminmenu div.wp-submenu').css('margin-top', '');
191 if ( window.innerWidth ) {
192 // window.innerWidth is affected by zooming on phones
193 respWidth = Math.max( window.innerWidth, document.documentElement.clientWidth );
195 // IE < 9 doesn't support @media CSS rules
199 if ( respWidth && respWidth < 960 ) {
200 if ( body.hasClass('auto-fold') ) {
201 body.removeClass('auto-fold').removeClass('folded');
202 setUserSetting('unfold', 1);
203 setUserSetting('mfold', 'o');
206 body.addClass('auto-fold');
207 setUserSetting('unfold', 0);
211 if ( body.hasClass('folded') ) {
212 body.removeClass('folded');
213 setUserSetting('mfold', 'o');
216 body.addClass('folded');
217 setUserSetting('mfold', 'f');
222 $( document ).trigger( 'wp-collapse-menu', { state: state } );
225 if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // touch screen device
226 // iOS Safari works with touchstart, the rest work with click
227 mobileEvent = /Mobile\/.+Safari/.test(navigator.userAgent) ? 'touchstart' : 'click';
229 // close any open submenus when touch/click is not on the menu
230 $(document.body).on( mobileEvent+'.wp-mobile-hover', function(e) {
231 if ( menu.data('wp-responsive') ) {
235 if ( ! $(e.target).closest('#adminmenu').length ) {
236 menu.find('li.wp-has-submenu.opensub').removeClass('opensub');
240 menu.find('a.wp-has-submenu').on( mobileEvent+'.wp-mobile-hover', function(e) {
241 var b, h, o, f, menutop, wintop, maxtop,
243 parent = el.parent(),
244 m = parent.find('.wp-submenu');
246 if ( menu.data('wp-responsive') ) {
250 // Show the sub instead of following the link if:
251 // - the submenu is not open
252 // - the submenu is not shown inline or the menu is not folded
253 if ( !parent.hasClass('opensub') && ( !parent.hasClass('wp-menu-open') || parent.width() < 40 ) ) {
256 menutop = parent.offset().top;
257 wintop = $(window).scrollTop();
258 maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar
260 b = menutop + m.height() + 1; // Bottom offset of the menu
261 h = $('#wpwrap').height(); // Height of the entire page
263 f = $(window).height() + wintop - 50; // The fold
274 m.css('margin-top', '-'+o+'px');
276 m.css('margin-top', '');
279 menu.find('li.opensub').removeClass('opensub');
280 parent.addClass('opensub');
285 menu.find('li.wp-has-submenu').hoverIntent({
287 var b, h, o, f, m = $(this).find('.wp-submenu'), menutop, wintop, maxtop, top = parseInt( m.css('top'), 10 );
289 if ( isNaN(top) || top > -5 ) { // meaning the submenu is visible
293 if ( menu.data('wp-responsive') ) {
294 // The menu is in responsive mode, bail
298 menutop = $(this).offset().top;
299 wintop = $(window).scrollTop();
300 maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar
302 b = menutop + m.height() + 1; // Bottom offset of the menu
303 h = $('#wpwrap').height(); // Height of the entire page
305 f = $(window).height() + wintop - 15; // The fold
316 m.css('margin-top', '-'+o+'px');
318 m.css('margin-top', '');
321 menu.find('li.menu-top').removeClass('opensub');
322 $(this).addClass('opensub');
325 if ( menu.data('wp-responsive') ) {
326 // The menu is in responsive mode, bail
330 $(this).removeClass('opensub').find('.wp-submenu').css('margin-top', '');
337 menu.on('focus.adminmenu', '.wp-submenu a', function(e){
338 if ( menu.data('wp-responsive') ) {
339 // The menu is in responsive mode, bail
343 $(e.target).closest('li.menu-top').addClass('opensub');
344 }).on('blur.adminmenu', '.wp-submenu a', function(e){
345 if ( menu.data('wp-responsive') ) {
346 // The menu is in responsive mode, bail
350 $(e.target).closest('li.menu-top').removeClass('opensub');
353 // Move .updated and .error alert boxes. Don't move boxes designed to be inline.
354 $('div.wrap h2:first').nextAll('div.updated, div.error').addClass('below-h2');
355 $('div.updated, div.error').not('.below-h2, .inline').insertAfter( $('div.wrap h2:first') );
360 // check all checkboxes
361 $('tbody').children().children('.check-column').find(':checkbox').click( function(e) {
362 if ( 'undefined' == e.shiftKey ) { return true; }
364 if ( !lastClicked ) { return true; }
365 checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' );
366 first = checks.index( lastClicked );
367 last = checks.index( this );
368 checked = $(this).prop('checked');
369 if ( 0 < first && 0 < last && first != last ) {
370 sliced = ( last > first ) ? checks.slice( first, last ) : checks.slice( last, first );
371 sliced.prop( 'checked', function() {
372 if ( $(this).closest('tr').is(':visible') )
381 // toggle "check all" checkboxes
382 var unchecked = $(this).closest('tbody').find(':checkbox').filter(':visible').not(':checked');
383 $(this).closest('table').children('thead, tfoot').find(':checkbox').prop('checked', function() {
384 return ( 0 === unchecked.length );
390 $('thead, tfoot').find('.check-column :checkbox').on( 'click.wp-toggle-checkboxes', function( event ) {
392 $table = $this.closest( 'table' ),
393 controlChecked = $this.prop('checked'),
394 toggle = event.shiftKey || $this.data('wp-toggle');
396 $table.children( 'tbody' ).filter(':visible')
397 .children().children('.check-column').find(':checkbox')
398 .prop('checked', function() {
399 if ( $(this).is(':hidden') ) {
404 return ! $(this).prop( 'checked' );
405 } else if ( controlChecked ) {
412 $table.children('thead, tfoot').filter(':visible')
413 .children().children('.check-column').find(':checkbox')
414 .prop('checked', function() {
417 } else if ( controlChecked ) {
425 // Show row actions on keyboard focus of its parent container element or any other elements contained within
426 $( 'td.post-title, td.title, td.comment, .bookmarks td.column-name, td.blogname, td.username, .dashboard-comment-wrap' ).focusin(function(){
427 clearTimeout( transitionTimeout );
428 focusedRowActions = $(this).find( '.row-actions' );
429 focusedRowActions.addClass( 'visible' );
430 }).focusout(function(){
431 // Tabbing between post title and .row-actions links needs a brief pause, otherwise
432 // the .row-actions div gets hidden in transit in some browsers (ahem, Firefox).
433 transitionTimeout = setTimeout(function(){
434 focusedRowActions.removeClass( 'visible' );
438 $('#default-password-nag-no').click( function() {
439 setUserSetting('default_password_nag', 'hide');
440 $('div.default-password-nag').hide();
445 $('#newcontent').bind('keydown.wpevent_InsertTab', function(e) {
446 var el = e.target, selStart, selEnd, val, scroll, sel;
448 if ( e.keyCode == 27 ) { // escape key
449 $(el).data('tab-out', true);
453 if ( e.keyCode != 9 || e.ctrlKey || e.altKey || e.shiftKey ) // tab key
456 if ( $(el).data('tab-out') ) {
457 $(el).data('tab-out', false);
461 selStart = el.selectionStart;
462 selEnd = el.selectionEnd;
466 this.lastKey = 9; // not a standard DOM property, lastKey is to help stop Opera tab event. See blur handler below.
469 if ( document.selection ) {
471 sel = document.selection.createRange();
473 } else if ( selStart >= 0 ) {
474 scroll = this.scrollTop;
475 el.value = val.substring(0, selStart).concat('\t', val.substring(selEnd) );
476 el.selectionStart = el.selectionEnd = selStart + 1;
477 this.scrollTop = scroll;
480 if ( e.stopPropagation )
482 if ( e.preventDefault )
486 $('#newcontent').bind('blur.wpevent_InsertTab', function() {
487 if ( this.lastKey && 9 == this.lastKey )
491 if ( pageInput.length ) {
492 pageInput.closest('form').submit( function() {
494 // Reset paging var for new filters/searches but not for bulk actions. See #17685.
495 if ( $('select[name="action"]').val() == -1 && $('select[name="action2"]').val() == -1 && pageInput.val() == currentPage )
500 $('.search-box input[type="search"], .search-box input[type="submit"]').mousedown(function () {
501 $('select[name^="action"]').val('-1');
504 // Scroll into view when focused
505 $('#contextual-help-link, #show-settings-link').on( 'focus.scroll-into-view', function(e){
506 if ( e.target.scrollIntoView )
507 e.target.scrollIntoView(false);
510 // Disable upload buttons until files are selected
512 var button, input, form = $('form.wp-upload-form');
515 button = form.find('input[type="submit"]');
516 input = form.find('input[type="file"]');
518 function toggleUploadButton() {
519 button.prop('disabled', '' === input.map( function() {
520 return $(this).val();
523 toggleUploadButton();
524 input.on('change', toggleUploadButton);
528 // Fire a custom jQuery event at the end of window resize
532 function triggerEvent() {
533 $(document).trigger( 'wp-window-resized' );
536 function fireOnce() {
537 window.clearTimeout( timeout );
538 timeout = window.setTimeout( triggerEvent, 200 );
541 $(window).on( 'resize.wp-fire-once', fireOnce );
544 $(document).ready( function() {
545 var $document = $( document ),
546 $window = $( window ),
547 $body = $( document.body ),
548 $adminMenuWrap = $( '#adminmenuwrap' ),
549 $collapseMenu = $( '#collapse-menu' ),
550 $wpwrap = $( '#wpwrap' ),
551 $adminmenu = $( '#adminmenu' ),
552 $overlay = $( '#wp-responsive-overlay' ),
553 $toolbar = $( '#wp-toolbar' ),
554 $toolbarPopups = $toolbar.find( 'a[aria-haspopup="true"]' ),
555 $sortables = $('.meta-box-sortables'),
556 stickyMenuActive = false,
557 wpResponsiveActive = false;
559 window.stickyMenu = {
561 if ( ! stickyMenuActive ) {
562 $document.on( 'wp-window-resized.sticky-menu', $.proxy( this.update, this ) );
563 $collapseMenu.on( 'click.sticky-menu', $.proxy( this.update, this ) );
565 stickyMenuActive = true;
569 disable: function() {
570 if ( stickyMenuActive ) {
571 $window.off( 'resize.sticky-menu' );
572 $collapseMenu.off( 'click.sticky-menu' );
573 $body.removeClass( 'sticky-menu' );
574 stickyMenuActive = false;
579 // Make the admin menu sticky if the viewport is taller than it
580 if ( $window.height() > $adminMenuWrap.height() + 32 ) {
581 if ( ! $body.hasClass( 'sticky-menu' ) ) {
582 $body.addClass( 'sticky-menu' );
585 if ( $body.hasClass( 'sticky-menu' ) ) {
586 $body.removeClass( 'sticky-menu' );
592 window.wpResponsive = {
596 // Modify functionality based on custom activate/deactivate event
597 $document.on( 'wp-responsive-activate.wp-responsive', function() {
599 }).on( 'wp-responsive-deactivate.wp-responsive', function() {
603 $( '#wp-admin-bar-menu-toggle a' ).attr( 'aria-expanded', 'false' );
605 // Toggle sidebar when toggle is clicked
606 $( '#wp-admin-bar-menu-toggle' ).on( 'click.wp-responsive', function( event ) {
607 event.preventDefault();
608 $wpwrap.toggleClass( 'wp-responsive-open' );
609 if ( $wpwrap.hasClass( 'wp-responsive-open' ) ) {
610 $(this).find('a').attr( 'aria-expanded', 'true' );
611 $( '#adminmenu a:first' ).focus();
613 $(this).find('a').attr( 'aria-expanded', 'false' );
618 $adminmenu.on( 'click.wp-responsive', 'li.wp-has-submenu > a', function( event ) {
619 if ( ! $adminmenu.data('wp-responsive') ) {
623 $( this ).parent( 'li' ).toggleClass( 'selected' );
624 event.preventDefault();
628 $document.on( 'wp-window-resized.wp-responsive', $.proxy( this.trigger, this ) );
630 // This needs to run later as UI Sortable may be initialized later on $(document).ready()
631 $window.on( 'load.wp-responsive', function() {
632 var width = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? $window.width() : window.innerWidth;
634 if ( width <= 782 ) {
635 self.disableSortables();
640 activate: function() {
641 window.stickyMenu.disable();
643 if ( ! $body.hasClass( 'auto-fold' ) ) {
644 $body.addClass( 'auto-fold' );
647 $adminmenu.data( 'wp-responsive', 1 );
648 this.disableSortables();
651 deactivate: function() {
652 window.stickyMenu.enable();
653 $adminmenu.removeData('wp-responsive');
654 this.enableSortables();
657 trigger: function() {
660 if ( window.innerWidth ) {
661 // window.innerWidth is affected by zooming on phones
662 width = Math.max( window.innerWidth, document.documentElement.clientWidth );
664 // Exclude IE < 9, it doesn't support @media CSS rules
668 if ( width <= 782 ) {
669 if ( ! wpResponsiveActive ) {
670 $document.trigger( 'wp-responsive-activate' );
671 wpResponsiveActive = true;
674 if ( wpResponsiveActive ) {
675 $document.trigger( 'wp-responsive-deactivate' );
676 wpResponsiveActive = false;
680 if ( width <= 480 ) {
681 this.enableOverlay();
683 this.disableOverlay();
687 enableOverlay: function() {
688 if ( $overlay.length === 0 ) {
689 $overlay = $( '<div id="wp-responsive-overlay"></div>' )
690 .insertAfter( '#wpcontent' )
692 .on( 'click.wp-responsive', function() {
693 $toolbar.find( '.menupop.hover' ).removeClass( 'hover' );
698 $toolbarPopups.on( 'click.wp-responsive', function() {
703 disableOverlay: function() {
704 $toolbarPopups.off( 'click.wp-responsive' );
708 disableSortables: function() {
709 if ( $sortables.length ) {
711 $sortables.sortable('disable');
716 enableSortables: function() {
717 if ( $sortables.length ) {
719 $sortables.sortable('enable');
725 window.stickyMenu.enable();
726 window.wpResponsive.init();
729 // Make Windows 8 devices play along nicely.
731 if ( '-ms-user-select' in document.documentElement.style && navigator.userAgent.match(/IEMobile\/10\.0/) ) {
732 var msViewportStyle = document.createElement( 'style' );
733 msViewportStyle.appendChild(
734 document.createTextNode( '@-ms-viewport{width:auto!important}' )
736 document.getElementsByTagName( 'head' )[0].appendChild( msViewportStyle );
740 }( jQuery, window ));