X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/0461a5f2e55c8d5f1fde96ca2e83117152573c7d..9e77185fafaf4e60e2b73821e0e4b9b1a11fb85f:/wp-admin/js/customize-widgets.js diff --git a/wp-admin/js/customize-widgets.js b/wp-admin/js/customize-widgets.js index 47505dd3..0a3909a5 100644 --- a/wp-admin/js/customize-widgets.js +++ b/wp-admin/js/customize-widgets.js @@ -5,7 +5,7 @@ // Set up our namespace... var api = wp.customize, - l10n, OldPreviewer; + l10n; api.Widgets = api.Widgets || {}; @@ -185,7 +185,7 @@ } ); // Close the panel if the URL in the preview changes - api.Widgets.Previewer.bind( 'url', this.close ); + api.previewer.bind( 'url', this.close ); }, // Performs a search and handles selected widget @@ -316,10 +316,13 @@ isEsc = ( event.which === 27 ), isDown = ( event.which === 40 ), isUp = ( event.which === 38 ), + isTab = ( event.which === 9 ), + isShift = ( event.shiftKey ), selected = null, firstVisible = this.$el.find( '> .widget-tpl:visible:first' ), lastVisible = this.$el.find( '> .widget-tpl:visible:last' ), - isSearchFocused = $( event.target ).is( this.$search ); + isSearchFocused = $( event.target ).is( this.$search ), + isLastWidgetFocused = $( event.target ).is( '.widget-tpl:visible:last' ); if ( isDown || isUp ) { if ( isDown ) { @@ -357,6 +360,11 @@ } else if ( isEsc ) { this.close( { returnFocus: true } ); } + + if ( isTab && ( isShift && isSearchFocused || ! isShift && isLastWidgetFocused ) ) { + this.currentSidebarControl.container.find( '.add-new-widget' ).focus(); + event.preventDefault(); + } } }); @@ -615,7 +623,9 @@ * Handle clicks for up/down/move on the reorder nav */ $reorderNav = this.container.find( '.widget-reorder-nav' ); - $reorderNav.find( '.move-widget, .move-widget-down, .move-widget-up' ).on( 'click keypress', function( event ) { + $reorderNav.find( '.move-widget, .move-widget-down, .move-widget-up' ).each( function() { + $( this ).prepend( self.container.find( '.widget-title' ).text() + ': ' ); + } ).on( 'click keypress', function( event ) { if ( event.type === 'keypress' && ( event.which !== 13 && event.which !== 32 ) ) { return; } @@ -745,19 +755,12 @@ self.container.removeClass( 'previewer-loading' ); } ); - api.Widgets.Previewer.bind( 'widget-updated', function( updatedWidgetId ) { + api.previewer.bind( 'widget-updated', function( updatedWidgetId ) { if ( updatedWidgetId === self.params.widget_id ) { self.container.removeClass( 'previewer-loading' ); } } ); - // Update widget control to indicate whether it is currently rendered - api.Widgets.Previewer.bind( 'rendered-widgets', function( renderedWidgets ) { - var isRendered = !! renderedWidgets[self.params.widget_id]; - - self.container.toggleClass( 'widget-rendered', isRendered ); - } ); - formSyncHandler = api.Widgets.formSyncHandlers[ this.params.widget_id_base ]; if ( formSyncHandler ) { $( document ).on( 'widget-synced', function( e, widget ) { @@ -768,6 +771,17 @@ } }, + /** + * Update widget control to indicate whether it is currently rendered. + * + * Overrides api.Control.toggle() + * + * @param {Boolean} active + */ + toggle: function ( active ) { + this.container.toggleClass( 'widget-rendered', active ); + }, + /** * Set up event handlers for widget removal */ @@ -971,17 +985,17 @@ // Check if the user is logged out. if ( '0' === r ) { - api.Widgets.Previewer.preview.iframe.hide(); - api.Widgets.Previewer.login().done( function() { + api.previewer.preview.iframe.hide(); + api.previewer.login().done( function() { self.updateWidget( args ); - api.Widgets.Previewer.preview.iframe.show(); + api.previewer.preview.iframe.show(); } ); return; } // Check for cheaters. if ( '-1' === r ) { - api.Widgets.Previewer.cheatin(); + api.previewer.cheatin(); return; } @@ -1418,32 +1432,38 @@ } ); // Update the model with whether or not the sidebar is rendered - api.Widgets.Previewer.bind( 'rendered-sidebars', function( renderedSidebars ) { - var isRendered = !! renderedSidebars[self.params.sidebar_id]; - - registeredSidebar.set( 'is_rendered', isRendered ); + self.active.bind( function ( active ) { + registeredSidebar.set( 'is_rendered', active ); } ); + }, - // Show the sidebar section when it becomes visible - registeredSidebar.on( 'change:is_rendered', function( ) { - var sectionSelector = '#accordion-section-sidebar-widgets-' + this.get( 'id' ), $section; + /** + * Show the sidebar section when it becomes visible. + * + * Overrides api.Control.toggle() + * + * @param {Boolean} active + */ + toggle: function ( active ) { + var $section, sectionSelector; - $section = $( sectionSelector ); - if ( this.get( 'is_rendered' ) ) { - $section.stop().slideDown( function() { - $( this ).css( 'height', 'auto' ); // so that the .accordion-section-content won't overflow - } ); + sectionSelector = '#accordion-section-sidebar-widgets-' + this.params.sidebar_id; + $section = $( sectionSelector ); - } else { - // Make sure that hidden sections get closed first - if ( $section.hasClass( 'open' ) ) { - // it would be nice if accordionSwitch() in accordion.js was public - $section.find( '.accordion-section-title' ).trigger( 'click' ); - } + if ( active ) { + $section.stop().slideDown( function() { + $( this ).css( 'height', 'auto' ); // so that the .accordion-section-content won't overflow + } ); - $section.stop().slideUp(); + } else { + // Make sure that hidden sections get closed first + if ( $section.hasClass( 'open' ) ) { + // it would be nice if accordionSwitch() in accordion.js was public + $section.find( '.accordion-section-title' ).trigger( 'click' ); } - } ); + + $section.stop().slideUp(); + } }, /** @@ -1566,6 +1586,11 @@ _( this.getWidgetFormControls() ).each( function( formControl ) { formControl.collapseForm(); } ); + + this.$sectionContent.find( '.first-widget .move-widget' ).focus(); + this.$sectionContent.find( '.add-new-widget' ).prop( 'tabIndex', -1 ); + } else { + this.$sectionContent.find( '.add-new-widget' ).prop( 'tabIndex', 0 ); } }, @@ -1738,18 +1763,6 @@ sidebar_widgets: api.Widgets.SidebarControl }); - /** - * Capture the instance of the Previewer since it is private - */ - OldPreviewer = api.Previewer; - api.Previewer = OldPreviewer.extend({ - initialize: function( params, options ) { - api.Widgets.Previewer = this; - OldPreviewer.prototype.initialize.call( this, params, options ); - this.bind( 'refresh', this.refresh ); - } - } ); - /** * Init Customizer for widgets. */ @@ -1760,10 +1773,10 @@ }); // Highlight widget control - api.Widgets.Previewer.bind( 'highlight-widget-control', api.Widgets.highlightWidgetFormControl ); + api.previewer.bind( 'highlight-widget-control', api.Widgets.highlightWidgetFormControl ); // Open and focus widget control - api.Widgets.Previewer.bind( 'focus-widget-control', api.Widgets.focusWidgetFormControl ); + api.previewer.bind( 'focus-widget-control', api.Widgets.focusWidgetFormControl ); } ); /**