wp/wp-admin/js/widgets/text-widgets.js
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    34 		 *
    34 		 *
    35 		 * @param {Object} options - Options.
    35 		 * @param {Object} options - Options.
    36 		 * @param {jQuery} options.el - Control field container element.
    36 		 * @param {jQuery} options.el - Control field container element.
    37 		 * @param {jQuery} options.syncContainer - Container element where fields are synced for the server.
    37 		 * @param {jQuery} options.syncContainer - Container element where fields are synced for the server.
    38 		 *
    38 		 *
    39 		 * @returns {void}
    39 		 * @return {void}
    40 		 */
    40 		 */
    41 		initialize: function initialize( options ) {
    41 		initialize: function initialize( options ) {
    42 			var control = this;
    42 			var control = this;
    43 
    43 
    44 			if ( ! options.el ) {
    44 			if ( ! options.el ) {
   103 		 * Dismiss pointers for Custom HTML widget.
   103 		 * Dismiss pointers for Custom HTML widget.
   104 		 *
   104 		 *
   105 		 * @since 4.8.1
   105 		 * @since 4.8.1
   106 		 *
   106 		 *
   107 		 * @param {Array} pointers Pointer IDs to dismiss.
   107 		 * @param {Array} pointers Pointer IDs to dismiss.
   108 		 * @returns {void}
   108 		 * @return {void}
   109 		 */
   109 		 */
   110 		dismissPointers: function dismissPointers( pointers ) {
   110 		dismissPointers: function dismissPointers( pointers ) {
   111 			_.each( pointers, function( pointer ) {
   111 			_.each( pointers, function( pointer ) {
   112 				wp.ajax.post( 'dismiss-wp-pointer', {
   112 				wp.ajax.post( 'dismiss-wp-pointer', {
   113 					pointer: pointer
   113 					pointer: pointer
   118 
   118 
   119 		/**
   119 		/**
   120 		 * Open available widgets panel.
   120 		 * Open available widgets panel.
   121 		 *
   121 		 *
   122 		 * @since 4.8.1
   122 		 * @since 4.8.1
   123 		 * @returns {void}
   123 		 * @return {void}
   124 		 */
   124 		 */
   125 		openAvailableWidgetsPanel: function openAvailableWidgetsPanel() {
   125 		openAvailableWidgetsPanel: function openAvailableWidgetsPanel() {
   126 			var sidebarControl;
   126 			var sidebarControl;
   127 			wp.customize.section.each( function( section ) {
   127 			wp.customize.section.each( function( section ) {
   128 				if ( section.extended( wp.customize.Widgets.SidebarSection ) && section.expanded() ) {
   128 				if ( section.extended( wp.customize.Widgets.SidebarSection ) && section.expanded() ) {
   143 		 *
   143 		 *
   144 		 * This function is called at the widget-updated and widget-synced events.
   144 		 * This function is called at the widget-updated and widget-synced events.
   145 		 * A field will only be updated if it is not currently focused, to avoid
   145 		 * A field will only be updated if it is not currently focused, to avoid
   146 		 * overwriting content that the user is entering.
   146 		 * overwriting content that the user is entering.
   147 		 *
   147 		 *
   148 		 * @returns {void}
   148 		 * @return {void}
   149 		 */
   149 		 */
   150 		updateFields: function updateFields() {
   150 		updateFields: function updateFields() {
   151 			var control = this, syncInput;
   151 			var control = this, syncInput;
   152 
   152 
   153 			if ( ! control.fields.title.is( document.activeElement ) ) {
   153 			if ( ! control.fields.title.is( document.activeElement ) ) {
   166 		},
   166 		},
   167 
   167 
   168 		/**
   168 		/**
   169 		 * Initialize editor.
   169 		 * Initialize editor.
   170 		 *
   170 		 *
   171 		 * @returns {void}
   171 		 * @return {void}
   172 		 */
   172 		 */
   173 		initializeEditor: function initializeEditor() {
   173 		initializeEditor: function initializeEditor() {
   174 			var control = this, changeDebounceDelay = 1000, id, textarea, triggerChangeIfDirty, restoreTextMode = false, needsTextareaChangeTrigger = false, previousValue;
   174 			var control = this, changeDebounceDelay = 1000, id, textarea, triggerChangeIfDirty, restoreTextMode = false, needsTextareaChangeTrigger = false, previousValue;
   175 			textarea = control.fields.text;
   175 			textarea = control.fields.text;
   176 			id = textarea.attr( 'id' );
   176 			id = textarea.attr( 'id' );
   177 			previousValue = textarea.val();
   177 			previousValue = textarea.val();
   178 
   178 
   179 			/**
   179 			/**
   180 			 * Trigger change if dirty.
   180 			 * Trigger change if dirty.
   181 			 *
   181 			 *
   182 			 * @returns {void}
   182 			 * @return {void}
   183 			 */
   183 			 */
   184 			triggerChangeIfDirty = function() {
   184 			triggerChangeIfDirty = function() {
   185 				var updateWidgetBuffer = 300; // See wp.customize.Widgets.WidgetControl._setupUpdateUI() which uses 250ms for updateWidgetDebounced.
   185 				var updateWidgetBuffer = 300; // See wp.customize.Widgets.WidgetControl._setupUpdateUI() which uses 250ms for updateWidgetDebounced.
   186 				if ( control.editor.isDirty() ) {
   186 				if ( control.editor.isDirty() ) {
   187 
   187 
   223 			});
   223 			});
   224 
   224 
   225 			/**
   225 			/**
   226 			 * Build (or re-build) the visual editor.
   226 			 * Build (or re-build) the visual editor.
   227 			 *
   227 			 *
   228 			 * @returns {void}
   228 			 * @return {void}
   229 			 */
   229 			 */
   230 			function buildEditor() {
   230 			function buildEditor() {
   231 				var editor, onInit, showPointerElement;
   231 				var editor, onInit, showPointerElement;
   232 
   232 
   233 				// Abort building if the textarea is gone, likely due to the widget having been deleted entirely.
   233 				// Abort building if the textarea is gone, likely due to the widget having been deleted entirely.
   272 
   272 
   273 				/**
   273 				/**
   274 				 * Show a pointer, focus on dismiss, and speak the contents for a11y.
   274 				 * Show a pointer, focus on dismiss, and speak the contents for a11y.
   275 				 *
   275 				 *
   276 				 * @param {jQuery} pointerElement Pointer element.
   276 				 * @param {jQuery} pointerElement Pointer element.
   277 				 * @returns {void}
   277 				 * @return {void}
   278 				 */
   278 				 */
   279 				showPointerElement = function( pointerElement ) {
   279 				showPointerElement = function( pointerElement ) {
   280 					pointerElement.show();
   280 					pointerElement.show();
   281 					pointerElement.find( '.close' ).focus();
   281 					pointerElement.find( '.close' ).focus();
   282 					wp.a11y.speak( pointerElement.find( 'h3, p' ).map( function() {
   282 					wp.a11y.speak( pointerElement.find( 'h3, p' ).map( function() {
   375 	 * @memberOf wp.textWidgets
   375 	 * @memberOf wp.textWidgets
   376 	 *
   376 	 *
   377 	 * @param {jQuery.Event} event - Event.
   377 	 * @param {jQuery.Event} event - Event.
   378 	 * @param {jQuery}       widgetContainer - Widget container element.
   378 	 * @param {jQuery}       widgetContainer - Widget container element.
   379 	 *
   379 	 *
   380 	 * @returns {void}
   380 	 * @return {void}
   381 	 */
   381 	 */
   382 	component.handleWidgetAdded = function handleWidgetAdded( event, widgetContainer ) {
   382 	component.handleWidgetAdded = function handleWidgetAdded( event, widgetContainer ) {
   383 		var widgetForm, idBase, widgetControl, widgetId, animatedCheckDelay = 50, renderWhenAnimationDone, fieldContainer, syncContainer;
   383 		var widgetForm, idBase, widgetControl, widgetId, animatedCheckDelay = 50, renderWhenAnimationDone, fieldContainer, syncContainer;
   384 		widgetForm = widgetContainer.find( '> .widget-inside > .form, > .widget-inside > form' ); // Note: '.form' appears in the customizer, whereas 'form' on the widgets admin screen.
   384 		widgetForm = widgetContainer.find( '> .widget-inside > .form, > .widget-inside > form' ); // Note: '.form' appears in the customizer, whereas 'form' on the widgets admin screen.
   385 
   385 
   440 	/**
   440 	/**
   441 	 * Setup widget in accessibility mode.
   441 	 * Setup widget in accessibility mode.
   442 	 *
   442 	 *
   443 	 * @memberOf wp.textWidgets
   443 	 * @memberOf wp.textWidgets
   444 	 *
   444 	 *
   445 	 * @returns {void}
   445 	 * @return {void}
   446 	 */
   446 	 */
   447 	component.setupAccessibleMode = function setupAccessibleMode() {
   447 	component.setupAccessibleMode = function setupAccessibleMode() {
   448 		var widgetForm, idBase, widgetControl, fieldContainer, syncContainer;
   448 		var widgetForm, idBase, widgetControl, fieldContainer, syncContainer;
   449 		widgetForm = $( '.editwidget > form' );
   449 		widgetForm = $( '.editwidget > form' );
   450 		if ( 0 === widgetForm.length ) {
   450 		if ( 0 === widgetForm.length ) {
   482 	 *
   482 	 *
   483 	 * @memberOf wp.textWidgets
   483 	 * @memberOf wp.textWidgets
   484 	 *
   484 	 *
   485 	 * @param {jQuery.Event} event - Event.
   485 	 * @param {jQuery.Event} event - Event.
   486 	 * @param {jQuery}       widgetContainer - Widget container element.
   486 	 * @param {jQuery}       widgetContainer - Widget container element.
   487 	 * @returns {void}
   487 	 * @return {void}
   488 	 */
   488 	 */
   489 	component.handleWidgetUpdated = function handleWidgetUpdated( event, widgetContainer ) {
   489 	component.handleWidgetUpdated = function handleWidgetUpdated( event, widgetContainer ) {
   490 		var widgetForm, widgetId, widgetControl, idBase;
   490 		var widgetForm, widgetId, widgetControl, idBase;
   491 		widgetForm = widgetContainer.find( '> .widget-inside > .form, > .widget-inside > form' );
   491 		widgetForm = widgetContainer.find( '> .widget-inside > .form, > .widget-inside > form' );
   492 
   492 
   511 	 * When WordPress enqueues this script, it should have an inline script
   511 	 * When WordPress enqueues this script, it should have an inline script
   512 	 * attached which calls wp.textWidgets.init().
   512 	 * attached which calls wp.textWidgets.init().
   513 	 *
   513 	 *
   514 	 * @memberOf wp.textWidgets
   514 	 * @memberOf wp.textWidgets
   515 	 *
   515 	 *
   516 	 * @returns {void}
   516 	 * @return {void}
   517 	 */
   517 	 */
   518 	component.init = function init() {
   518 	component.init = function init() {
   519 		var $document = $( document );
   519 		var $document = $( document );
   520 		$document.on( 'widget-added', component.handleWidgetAdded );
   520 		$document.on( 'widget-added', component.handleWidgetAdded );
   521 		$document.on( 'widget-synced widget-updated', component.handleWidgetUpdated );
   521 		$document.on( 'widget-synced widget-updated', component.handleWidgetUpdated );