]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/common.js
WordPress 4.3
[autoinstalls/wordpress.git] / wp-admin / js / common.js
index f4253b3a6bc7adbcb2b947b7b221e4ea38287936..5b5741c154867944c7ac93325afaec1d8d213eef 100644 (file)
@@ -37,17 +37,19 @@ columns = {
        },
 
        checked : function(column) {
-               $('.column-' + column).show();
+               $('.column-' + column).removeClass( 'hidden' );
                this.colSpanChange(+1);
        },
 
        unchecked : function(column) {
-               $('.column-' + column).hide();
+               $('.column-' + column).addClass( 'hidden' );
                this.colSpanChange(-1);
        },
 
        hidden : function() {
-               return $('.manage-column').filter(':hidden').map(function() { return this.id; }).get().join(',');
+               return $( '.manage-column[id]' ).filter( ':hidden' ).map(function() {
+                       return this.id;
+               }).get().join( ',' );
        },
 
        useCheckboxesForHidden : function() {
@@ -103,15 +105,14 @@ screenMeta = {
 
        init: function() {
                this.element = $('#screen-meta');
-               this.toggles = $('.screen-meta-toggle a');
+               this.toggles = $( '#screen-meta-links' ).find( '.show-settings' );
                this.page    = $('#wpcontent');
 
                this.toggles.click( this.toggleEvent );
        },
 
-       toggleEvent: function( e ) {
-               var panel = $( this.href.replace(/.+#/, '#') );
-               e.preventDefault();
+       toggleEvent: function() {
+               var panel = $( '#' + $( this ).attr( 'aria-controls' ) );
 
                if ( !panel.length )
                        return;
@@ -122,22 +123,22 @@ screenMeta = {
                        screenMeta.open( panel, $(this) );
        },
 
-       open: function( panel, link ) {
+       open: function( panel, button ) {
 
-               $('.screen-meta-toggle').not( link.parent() ).css('visibility', 'hidden');
+               $( '#screen-meta-links' ).find( '.screen-meta-toggle' ).not( button.parent() ).css( 'visibility', 'hidden' );
 
                panel.parent().show();
                panel.slideDown( 'fast', function() {
                        panel.focus();
-                       link.addClass('screen-meta-active').attr('aria-expanded', true);
+                       button.addClass( 'screen-meta-active' ).attr( 'aria-expanded', true );
                });
 
                $( document ).trigger( 'screen:options:open' );
        },
 
-       close: function( panel, link ) {
+       close: function( panel, button ) {
                panel.slideUp( 'fast', function() {
-                       link.removeClass('screen-meta-active').attr('aria-expanded', false);
+                       button.removeClass( 'screen-meta-active' ).attr( 'aria-expanded', false );
                        $('.screen-meta-toggle').css('visibility', '');
                        panel.parent().hide();
                });
@@ -369,10 +370,37 @@ $(document).ready( function() {
        }
 
        // Move .notice, .updated and .error alert boxes. Don't move boxes designed to be inline.
-       $firstHeading = $( 'div.wrap h2:first' );
+       $firstHeading = $( '.wrap > h1:first' );
+
+       // Back compatibility: if there is no H1, apply to first H2.
+       if ( ! $firstHeading.length ) {
+               $firstHeading = $( '.wrap h2:first' );
+       }
+
        $firstHeading.nextAll( 'div.updated, div.error, div.notice' ).addClass( 'below-h2' );
        $( 'div.updated, div.error, div.notice' ).not( '.below-h2, .inline' ).insertAfter( $firstHeading );
 
+       // Make notices dismissible
+       $( '.notice.is-dismissible' ).each( function() {
+               var $this = $( this ),
+                       $button = $( '<button type="button" class="notice-dismiss"><span class="screen-reader-text"></span></button>' ),
+                       btnText = commonL10n.dismiss || '';
+
+               // Ensure plain text
+               $button.find( '.screen-reader-text' ).text( btnText );
+
+               $this.append( $button );
+
+               $button.on( 'click.wp-dismiss-notice', function( event ) {
+                       event.preventDefault();
+                       $this.fadeTo( 100 , 0, function() {
+                               $(this).slideUp( 100, function() {
+                                       $(this).remove();
+                               });
+                       });
+               });
+       });
+
        // Init screen meta
        screenMeta.init();
 
@@ -442,16 +470,26 @@ $(document).ready( function() {
        });
 
        // Show row actions on keyboard focus of its parent container element or any other elements contained within
-       $( 'td.post-title, td.title, td.comment, .bookmarks td.column-name, td.blogname, td.username, .dashboard-comment-wrap' ).focusin(function(){
-               clearTimeout( transitionTimeout );
-               focusedRowActions = $(this).find( '.row-actions' );
-               focusedRowActions.addClass( 'visible' );
-       }).focusout(function(){
-               // Tabbing between post title and .row-actions links needs a brief pause, otherwise
-               // the .row-actions div gets hidden in transit in some browsers (ahem, Firefox).
-               transitionTimeout = setTimeout(function(){
-                       focusedRowActions.removeClass( 'visible' );
-               }, 30);
+       $( '#wpbody-content' ).on({
+               focusin: function() {
+                       clearTimeout( transitionTimeout );
+                       focusedRowActions = $( this ).find( '.row-actions' );
+                       // transitionTimeout is necessary for Firefox, but Chrome won't remove the CSS class without a little help.
+                       $( '.row-actions' ).not( this ).removeClass( 'visible' );
+                       focusedRowActions.addClass( 'visible' );
+               },
+               focusout: function() {
+                       // Tabbing between post title and .row-actions links needs a brief pause, otherwise
+                       // the .row-actions div gets hidden in transit in some browsers (ahem, Firefox).
+                       transitionTimeout = setTimeout( function() {
+                               focusedRowActions.removeClass( 'visible' );
+                       }, 30 );
+               }
+       }, '.has-row-actions' );
+
+       // Toggle list table rows on small screens
+       $( 'tbody' ).on( 'click', '.toggle-row', function() {
+               $( this ).closest( 'tr' ).toggleClass( 'is-expanded' );
        });
 
        $('#default-password-nag-no').click( function() {
@@ -465,6 +503,8 @@ $(document).ready( function() {
                var el = e.target, selStart, selEnd, val, scroll, sel;
 
                if ( e.keyCode == 27 ) { // escape key
+                       // when pressing Escape: Opera 12 and 27 blur form fields, IE 8 clears them
+                       e.preventDefault();
                        $(el).data('tab-out', true);
                        return;
                }
@@ -481,10 +521,6 @@ $(document).ready( function() {
                selEnd = el.selectionEnd;
                val = el.value;
 
-               try {
-                       this.lastKey = 9; // not a standard DOM property, lastKey is to help stop Opera tab event. See blur handler below.
-               } catch(err) {}
-
                if ( document.selection ) {
                        el.focus();
                        sel = document.selection.createRange();
@@ -502,11 +538,6 @@ $(document).ready( function() {
                        e.preventDefault();
        });
 
-       $('#newcontent').bind('blur.wpevent_InsertTab', function() {
-               if ( this.lastKey && 9 == this.lastKey )
-                       this.focus();
-       });
-
        if ( pageInput.length ) {
                pageInput.closest('form').submit( function() {
 
@@ -721,6 +752,10 @@ $(document).ready( function() {
                        // Toggle sidebar when toggle is clicked
                        $( '#wp-admin-bar-menu-toggle' ).on( 'click.wp-responsive', function( event ) {
                                event.preventDefault();
+
+                               // close any open toolbar submenus
+                               $adminbar.find( '.hover' ).removeClass( 'hover' );
+
                                $wpwrap.toggleClass( 'wp-responsive-open' );
                                if ( $wpwrap.hasClass( 'wp-responsive-open' ) ) {
                                        $(this).find('a').attr( 'aria-expanded', 'true' );
@@ -841,7 +876,7 @@ $(document).ready( function() {
        window.wpResponsive.init();
        setPinMenu();
 
-       $document.on( 'wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu wp-collapse-menu.pin-menu wp-scroll-start.pin-menu', setPinMenu );
+       $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 );
 });
 
 // Fire a custom jQuery event at the end of window resize