|
1 /** |
|
2 * @output wp-admin/js/widgets/text-widgets.js |
|
3 */ |
|
4 |
1 /* global tinymce, switchEditors */ |
5 /* global tinymce, switchEditors */ |
2 /* eslint consistent-this: [ "error", "control" ] */ |
6 /* eslint consistent-this: [ "error", "control" ] */ |
|
7 |
|
8 /** |
|
9 * @namespace wp.textWidgets |
|
10 */ |
3 wp.textWidgets = ( function( $ ) { |
11 wp.textWidgets = ( function( $ ) { |
4 'use strict'; |
12 'use strict'; |
5 |
13 |
6 var component = { |
14 var component = { |
7 dismissedPointers: [], |
15 dismissedPointers: [], |
8 idBases: [ 'text' ] |
16 idBases: [ 'text' ] |
9 }; |
17 }; |
10 |
18 |
11 /** |
19 component.TextWidgetControl = Backbone.View.extend(/** @lends wp.textWidgets.TextWidgetControl.prototype */{ |
12 * Text widget control. |
|
13 * |
|
14 * @class TextWidgetControl |
|
15 * @constructor |
|
16 * @abstract |
|
17 */ |
|
18 component.TextWidgetControl = Backbone.View.extend({ |
|
19 |
20 |
20 /** |
21 /** |
21 * View events. |
22 * View events. |
22 * |
23 * |
23 * @type {Object} |
24 * @type {Object} |
24 */ |
25 */ |
25 events: {}, |
26 events: {}, |
26 |
27 |
27 /** |
28 /** |
28 * Initialize. |
29 * Text widget control. |
|
30 * |
|
31 * @constructs wp.textWidgets.TextWidgetControl |
|
32 * @augments Backbone.View |
|
33 * @abstract |
29 * |
34 * |
30 * @param {Object} options - Options. |
35 * @param {Object} options - Options. |
31 * @param {jQuery} options.el - Control field container element. |
36 * @param {jQuery} options.el - Control field container element. |
32 * @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 * |
33 * @returns {void} |
39 * @returns {void} |
34 */ |
40 */ |
35 initialize: function initialize( options ) { |
41 initialize: function initialize( options ) { |
36 var control = this; |
42 var control = this; |
37 |
43 |
355 }); |
361 }); |
356 |
362 |
357 /** |
363 /** |
358 * Mapping of widget ID to instances of TextWidgetControl subclasses. |
364 * Mapping of widget ID to instances of TextWidgetControl subclasses. |
359 * |
365 * |
|
366 * @memberOf wp.textWidgets |
|
367 * |
360 * @type {Object.<string, wp.textWidgets.TextWidgetControl>} |
368 * @type {Object.<string, wp.textWidgets.TextWidgetControl>} |
361 */ |
369 */ |
362 component.widgetControls = {}; |
370 component.widgetControls = {}; |
363 |
371 |
364 /** |
372 /** |
365 * Handle widget being added or initialized for the first time at the widget-added event. |
373 * Handle widget being added or initialized for the first time at the widget-added event. |
366 * |
374 * |
|
375 * @memberOf wp.textWidgets |
|
376 * |
367 * @param {jQuery.Event} event - Event. |
377 * @param {jQuery.Event} event - Event. |
368 * @param {jQuery} widgetContainer - Widget container element. |
378 * @param {jQuery} widgetContainer - Widget container element. |
|
379 * |
369 * @returns {void} |
380 * @returns {void} |
370 */ |
381 */ |
371 component.handleWidgetAdded = function handleWidgetAdded( event, widgetContainer ) { |
382 component.handleWidgetAdded = function handleWidgetAdded( event, widgetContainer ) { |
372 var widgetForm, idBase, widgetControl, widgetId, animatedCheckDelay = 50, renderWhenAnimationDone, fieldContainer, syncContainer; |
383 var widgetForm, idBase, widgetControl, widgetId, animatedCheckDelay = 50, renderWhenAnimationDone, fieldContainer, syncContainer; |
373 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. |
427 }; |
438 }; |
428 |
439 |
429 /** |
440 /** |
430 * Setup widget in accessibility mode. |
441 * Setup widget in accessibility mode. |
431 * |
442 * |
|
443 * @memberOf wp.textWidgets |
|
444 * |
432 * @returns {void} |
445 * @returns {void} |
433 */ |
446 */ |
434 component.setupAccessibleMode = function setupAccessibleMode() { |
447 component.setupAccessibleMode = function setupAccessibleMode() { |
435 var widgetForm, idBase, widgetControl, fieldContainer, syncContainer; |
448 var widgetForm, idBase, widgetControl, fieldContainer, syncContainer; |
436 widgetForm = $( '.editwidget > form' ); |
449 widgetForm = $( '.editwidget > form' ); |
464 * Sync widget instance data sanitized from server back onto widget model. |
477 * Sync widget instance data sanitized from server back onto widget model. |
465 * |
478 * |
466 * This gets called via the 'widget-updated' event when saving a widget from |
479 * This gets called via the 'widget-updated' event when saving a widget from |
467 * the widgets admin screen and also via the 'widget-synced' event when making |
480 * the widgets admin screen and also via the 'widget-synced' event when making |
468 * a change to a widget in the customizer. |
481 * a change to a widget in the customizer. |
|
482 * |
|
483 * @memberOf wp.textWidgets |
469 * |
484 * |
470 * @param {jQuery.Event} event - Event. |
485 * @param {jQuery.Event} event - Event. |
471 * @param {jQuery} widgetContainer - Widget container element. |
486 * @param {jQuery} widgetContainer - Widget container element. |
472 * @returns {void} |
487 * @returns {void} |
473 */ |
488 */ |
493 * Initialize functionality. |
508 * Initialize functionality. |
494 * |
509 * |
495 * This function exists to prevent the JS file from having to boot itself. |
510 * This function exists to prevent the JS file from having to boot itself. |
496 * When WordPress enqueues this script, it should have an inline script |
511 * When WordPress enqueues this script, it should have an inline script |
497 * attached which calls wp.textWidgets.init(). |
512 * attached which calls wp.textWidgets.init(). |
|
513 * |
|
514 * @memberOf wp.textWidgets |
498 * |
515 * |
499 * @returns {void} |
516 * @returns {void} |
500 */ |
517 */ |
501 component.init = function init() { |
518 component.init = function init() { |
502 var $document = $( document ); |
519 var $document = $( document ); |