wp/wp-admin/js/widgets.js
changeset 18 be944660c56a
parent 16 a86126ab1dd4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    34 		$( '#widgets-right .sidebar-name' )
    34 		$( '#widgets-right .sidebar-name' )
    35 			/*
    35 			/*
    36 			 * Toggle the widgets containers when clicked and update the toggle
    36 			 * Toggle the widgets containers when clicked and update the toggle
    37 			 * button `aria-expanded` attribute value.
    37 			 * button `aria-expanded` attribute value.
    38 			 */
    38 			 */
    39 			.click( function() {
    39 			.on( 'click', function() {
    40 				var $this = $( this ),
    40 				var $this = $( this ),
    41 					$wrap = $this.closest( '.widgets-holder-wrap '),
    41 					$wrap = $this.closest( '.widgets-holder-wrap '),
    42 					$toggle = $this.find( '.handlediv' );
    42 					$toggle = $this.find( '.handlediv' );
    43 
    43 
    44 				if ( $wrap.hasClass( 'closed' ) ) {
    44 				if ( $wrap.hasClass( 'closed' ) ) {
    79 				unsavedWidgetsElements = $( '#widgets-right' ).find( '.widget' ).filter( function() {
    79 				unsavedWidgetsElements = $( '#widgets-right' ).find( '.widget' ).filter( function() {
    80 					return -1 !== dirtyWidgetIds.indexOf( $( this ).prop( 'id' ).replace( /^widget-\d+_/, '' ) );
    80 					return -1 !== dirtyWidgetIds.indexOf( $( this ).prop( 'id' ).replace( /^widget-\d+_/, '' ) );
    81 				});
    81 				});
    82 				unsavedWidgetsElements.each( function() {
    82 				unsavedWidgetsElements.each( function() {
    83 					if ( ! $( this ).hasClass( 'open' ) ) {
    83 					if ( ! $( this ).hasClass( 'open' ) ) {
    84 						$( this ).find( '.widget-title-action:first' ).click();
    84 						$( this ).find( '.widget-title-action:first' ).trigger( 'click' );
    85 					}
    85 					}
    86 				});
    86 				});
    87 
    87 
    88 				// Bring the first unsaved widget into view and focus on the first tabbable field.
    88 				// Bring the first unsaved widget into view and focus on the first tabbable field.
    89 				unsavedWidgetsElements.first().each( function() {
    89 				unsavedWidgetsElements.first().each( function() {
    90 					if ( this.scrollIntoViewIfNeeded ) {
    90 					if ( this.scrollIntoViewIfNeeded ) {
    91 						this.scrollIntoViewIfNeeded();
    91 						this.scrollIntoViewIfNeeded();
    92 					} else {
    92 					} else {
    93 						this.scrollIntoView();
    93 						this.scrollIntoView();
    94 					}
    94 					}
    95 					$( this ).find( '.widget-inside :tabbable:first' ).focus();
    95 					$( this ).find( '.widget-inside :tabbable:first' ).trigger( 'focus' );
    96 				} );
    96 				} );
    97 
    97 
    98 				event.returnValue = wp.i18n.__( 'The changes you made will be lost if you navigate away from this page.' );
    98 				event.returnValue = wp.i18n.__( 'The changes you made will be lost if you navigate away from this page.' );
    99 				return event.returnValue;
    99 				return event.returnValue;
   100 			}
   100 			}
   101 		});
   101 		});
   102 
   102 
   103 		// Handle the widgets containers in the left column.
   103 		// Handle the widgets containers in the left column.
   104 		$( '#widgets-left .sidebar-name' ).click( function() {
   104 		$( '#widgets-left .sidebar-name' ).on( 'click', function() {
   105 			var $wrap = $( this ).closest( '.widgets-holder-wrap' );
   105 			var $wrap = $( this ).closest( '.widgets-holder-wrap' );
   106 
   106 
   107 			$wrap
   107 			$wrap
   108 				.toggleClass( 'closed' )
   108 				.toggleClass( 'closed' )
   109 				.find( '.handlediv' ).attr( 'aria-expanded', ! $wrap.hasClass( 'closed' ) );
   109 				.find( '.handlediv' ).attr( 'aria-expanded', ! $wrap.hasClass( 'closed' ) );
   110 
   110 
   111 			// Update the admin menu "sticky" state.
   111 			// Update the admin menu "sticky" state.
   112 			$document.triggerHandler( 'wp-pin-menu' );
   112 			$document.triggerHandler( 'wp-pin-menu' );
   113 		});
   113 		});
   114 
   114 
   115 		$(document.body).bind('click.widgets-toggle', function(e) {
   115 		$(document.body).on('click.widgets-toggle', function(e) {
   116 			var target = $(e.target), css = {},
   116 			var target = $(e.target), css = {},
   117 				widget, inside, targetWidth, widgetWidth, margin, saveButton, widgetId,
   117 				widget, inside, targetWidth, widgetWidth, margin, saveButton, widgetId,
   118 				toggleBtn = target.closest( '.widget' ).find( '.widget-top button.widget-action' );
   118 				toggleBtn = target.closest( '.widget' ).find( '.widget-top button.widget-action' );
   119 
   119 
   120 			if ( target.parents('.widget-top').length && ! target.parents('#available-widgets').length ) {
   120 			if ( target.parents('.widget-top').length && ! target.parents('#available-widgets').length ) {
   417 		});
   417 		});
   418 
   418 
   419 		// Area Chooser.
   419 		// Area Chooser.
   420 		$( '#widgets-right .widgets-holder-wrap' ).each( function( index, element ) {
   420 		$( '#widgets-right .widgets-holder-wrap' ).each( function( index, element ) {
   421 			var $element = $( element ),
   421 			var $element = $( element ),
   422 				name = $element.find( '.sidebar-name h2' ).text(),
   422 				name = $element.find( '.sidebar-name h2' ).text() || '',
   423 				ariaLabel = $element.find( '.sidebar-name' ).data( 'add-to' ),
   423 				ariaLabel = $element.find( '.sidebar-name' ).data( 'add-to' ),
   424 				id = $element.find( '.widgets-sortables' ).attr( 'id' ),
   424 				id = $element.find( '.widgets-sortables' ).attr( 'id' ),
   425 				li = $( '<li>' ),
   425 				li = $( '<li>' ),
   426 				button = $( '<button>', {
   426 				button = $( '<button>', {
   427 					type: 'button',
   427 					type: 'button',
   428 					'aria-pressed': 'false',
   428 					'aria-pressed': 'false',
   429 					'class': 'widgets-chooser-button',
   429 					'class': 'widgets-chooser-button',
   430 					'aria-label': ariaLabel
   430 					'aria-label': ariaLabel
   431 				} ).text( $.trim( name ) );
   431 				} ).text( name.toString().trim() );
   432 
   432 
   433 			li.append( button );
   433 			li.append( button );
   434 
   434 
   435 			if ( index === 0 ) {
   435 			if ( index === 0 ) {
   436 				li.addClass( 'widgets-chooser-selected' );
   436 				li.addClass( 'widgets-chooser-selected' );
   739 		$( event.target ).css( 'min-height', '' );
   739 		$( event.target ).css( 'min-height', '' );
   740 		this.hoveredSidebar = null;
   740 		this.hoveredSidebar = null;
   741 	}
   741 	}
   742 };
   742 };
   743 
   743 
   744 $document.ready( function(){ wpWidgets.init(); } );
   744 $( function(){ wpWidgets.init(); } );
   745 
   745 
   746 })(jQuery);
   746 })(jQuery);
   747 
   747 
   748 /**
   748 /**
   749  * Removed in 5.5.0, needed for back-compatibility.
   749  * Removed in 5.5.0, needed for back-compatibility.
   758 	saved: '',
   758 	saved: '',
   759 	saveAlert: '',
   759 	saveAlert: '',
   760 	widgetAdded: ''
   760 	widgetAdded: ''
   761 };
   761 };
   762 
   762 
   763 wpWidgets.l10n = window.wp.deprecateL10nObject( 'wpWidgets.l10n', wpWidgets.l10n );
   763 wpWidgets.l10n = window.wp.deprecateL10nObject( 'wpWidgets.l10n', wpWidgets.l10n, '5.5.0' );