Edit File by line
/home/barbar84/public_h.../wp-admin/js/widgets
File: text-widgets.js
/**
[0] Fix | Delete
* @output wp-admin/js/widgets/text-widgets.js
[1] Fix | Delete
*/
[2] Fix | Delete
[3] Fix | Delete
/* global tinymce, switchEditors */
[4] Fix | Delete
/* eslint consistent-this: [ "error", "control" ] */
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* @namespace wp.textWidgets
[8] Fix | Delete
*/
[9] Fix | Delete
wp.textWidgets = ( function( $ ) {
[10] Fix | Delete
'use strict';
[11] Fix | Delete
[12] Fix | Delete
var component = {
[13] Fix | Delete
dismissedPointers: [],
[14] Fix | Delete
idBases: [ 'text' ]
[15] Fix | Delete
};
[16] Fix | Delete
[17] Fix | Delete
component.TextWidgetControl = Backbone.View.extend(/** @lends wp.textWidgets.TextWidgetControl.prototype */{
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* View events.
[21] Fix | Delete
*
[22] Fix | Delete
* @type {Object}
[23] Fix | Delete
*/
[24] Fix | Delete
events: {},
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Text widget control.
[28] Fix | Delete
*
[29] Fix | Delete
* @constructs wp.textWidgets.TextWidgetControl
[30] Fix | Delete
* @augments Backbone.View
[31] Fix | Delete
* @abstract
[32] Fix | Delete
*
[33] Fix | Delete
* @param {Object} options - Options.
[34] Fix | Delete
* @param {jQuery} options.el - Control field container element.
[35] Fix | Delete
* @param {jQuery} options.syncContainer - Container element where fields are synced for the server.
[36] Fix | Delete
*
[37] Fix | Delete
* @return {void}
[38] Fix | Delete
*/
[39] Fix | Delete
initialize: function initialize( options ) {
[40] Fix | Delete
var control = this;
[41] Fix | Delete
[42] Fix | Delete
if ( ! options.el ) {
[43] Fix | Delete
throw new Error( 'Missing options.el' );
[44] Fix | Delete
}
[45] Fix | Delete
if ( ! options.syncContainer ) {
[46] Fix | Delete
throw new Error( 'Missing options.syncContainer' );
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
Backbone.View.prototype.initialize.call( control, options );
[50] Fix | Delete
control.syncContainer = options.syncContainer;
[51] Fix | Delete
[52] Fix | Delete
control.$el.addClass( 'text-widget-fields' );
[53] Fix | Delete
control.$el.html( wp.template( 'widget-text-control-fields' ) );
[54] Fix | Delete
[55] Fix | Delete
control.customHtmlWidgetPointer = control.$el.find( '.wp-pointer.custom-html-widget-pointer' );
[56] Fix | Delete
if ( control.customHtmlWidgetPointer.length ) {
[57] Fix | Delete
control.customHtmlWidgetPointer.find( '.close' ).on( 'click', function( event ) {
[58] Fix | Delete
event.preventDefault();
[59] Fix | Delete
control.customHtmlWidgetPointer.hide();
[60] Fix | Delete
$( '#' + control.fields.text.attr( 'id' ) + '-html' ).trigger( 'focus' );
[61] Fix | Delete
control.dismissPointers( [ 'text_widget_custom_html' ] );
[62] Fix | Delete
});
[63] Fix | Delete
control.customHtmlWidgetPointer.find( '.add-widget' ).on( 'click', function( event ) {
[64] Fix | Delete
event.preventDefault();
[65] Fix | Delete
control.customHtmlWidgetPointer.hide();
[66] Fix | Delete
control.openAvailableWidgetsPanel();
[67] Fix | Delete
});
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
control.pasteHtmlPointer = control.$el.find( '.wp-pointer.paste-html-pointer' );
[71] Fix | Delete
if ( control.pasteHtmlPointer.length ) {
[72] Fix | Delete
control.pasteHtmlPointer.find( '.close' ).on( 'click', function( event ) {
[73] Fix | Delete
event.preventDefault();
[74] Fix | Delete
control.pasteHtmlPointer.hide();
[75] Fix | Delete
control.editor.focus();
[76] Fix | Delete
control.dismissPointers( [ 'text_widget_custom_html', 'text_widget_paste_html' ] );
[77] Fix | Delete
});
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
control.fields = {
[81] Fix | Delete
title: control.$el.find( '.title' ),
[82] Fix | Delete
text: control.$el.find( '.text' )
[83] Fix | Delete
};
[84] Fix | Delete
[85] Fix | Delete
// Sync input fields to hidden sync fields which actually get sent to the server.
[86] Fix | Delete
_.each( control.fields, function( fieldInput, fieldName ) {
[87] Fix | Delete
fieldInput.on( 'input change', function updateSyncField() {
[88] Fix | Delete
var syncInput = control.syncContainer.find( '.sync-input.' + fieldName );
[89] Fix | Delete
if ( syncInput.val() !== fieldInput.val() ) {
[90] Fix | Delete
syncInput.val( fieldInput.val() );
[91] Fix | Delete
syncInput.trigger( 'change' );
[92] Fix | Delete
}
[93] Fix | Delete
});
[94] Fix | Delete
[95] Fix | Delete
// Note that syncInput cannot be re-used because it will be destroyed with each widget-updated event.
[96] Fix | Delete
fieldInput.val( control.syncContainer.find( '.sync-input.' + fieldName ).val() );
[97] Fix | Delete
});
[98] Fix | Delete
},
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* Dismiss pointers for Custom HTML widget.
[102] Fix | Delete
*
[103] Fix | Delete
* @since 4.8.1
[104] Fix | Delete
*
[105] Fix | Delete
* @param {Array} pointers Pointer IDs to dismiss.
[106] Fix | Delete
* @return {void}
[107] Fix | Delete
*/
[108] Fix | Delete
dismissPointers: function dismissPointers( pointers ) {
[109] Fix | Delete
_.each( pointers, function( pointer ) {
[110] Fix | Delete
wp.ajax.post( 'dismiss-wp-pointer', {
[111] Fix | Delete
pointer: pointer
[112] Fix | Delete
});
[113] Fix | Delete
component.dismissedPointers.push( pointer );
[114] Fix | Delete
});
[115] Fix | Delete
},
[116] Fix | Delete
[117] Fix | Delete
/**
[118] Fix | Delete
* Open available widgets panel.
[119] Fix | Delete
*
[120] Fix | Delete
* @since 4.8.1
[121] Fix | Delete
* @return {void}
[122] Fix | Delete
*/
[123] Fix | Delete
openAvailableWidgetsPanel: function openAvailableWidgetsPanel() {
[124] Fix | Delete
var sidebarControl;
[125] Fix | Delete
wp.customize.section.each( function( section ) {
[126] Fix | Delete
if ( section.extended( wp.customize.Widgets.SidebarSection ) && section.expanded() ) {
[127] Fix | Delete
sidebarControl = wp.customize.control( 'sidebars_widgets[' + section.params.sidebarId + ']' );
[128] Fix | Delete
}
[129] Fix | Delete
});
[130] Fix | Delete
if ( ! sidebarControl ) {
[131] Fix | Delete
return;
[132] Fix | Delete
}
[133] Fix | Delete
setTimeout( function() { // Timeout to prevent click event from causing panel to immediately collapse.
[134] Fix | Delete
wp.customize.Widgets.availableWidgetsPanel.open( sidebarControl );
[135] Fix | Delete
wp.customize.Widgets.availableWidgetsPanel.$search.val( 'HTML' ).trigger( 'keyup' );
[136] Fix | Delete
});
[137] Fix | Delete
},
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Update input fields from the sync fields.
[141] Fix | Delete
*
[142] Fix | Delete
* This function is called at the widget-updated and widget-synced events.
[143] Fix | Delete
* A field will only be updated if it is not currently focused, to avoid
[144] Fix | Delete
* overwriting content that the user is entering.
[145] Fix | Delete
*
[146] Fix | Delete
* @return {void}
[147] Fix | Delete
*/
[148] Fix | Delete
updateFields: function updateFields() {
[149] Fix | Delete
var control = this, syncInput;
[150] Fix | Delete
[151] Fix | Delete
if ( ! control.fields.title.is( document.activeElement ) ) {
[152] Fix | Delete
syncInput = control.syncContainer.find( '.sync-input.title' );
[153] Fix | Delete
control.fields.title.val( syncInput.val() );
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
syncInput = control.syncContainer.find( '.sync-input.text' );
[157] Fix | Delete
if ( control.fields.text.is( ':visible' ) ) {
[158] Fix | Delete
if ( ! control.fields.text.is( document.activeElement ) ) {
[159] Fix | Delete
control.fields.text.val( syncInput.val() );
[160] Fix | Delete
}
[161] Fix | Delete
} else if ( control.editor && ! control.editorFocused && syncInput.val() !== control.fields.text.val() ) {
[162] Fix | Delete
control.editor.setContent( wp.editor.autop( syncInput.val() ) );
[163] Fix | Delete
}
[164] Fix | Delete
},
[165] Fix | Delete
[166] Fix | Delete
/**
[167] Fix | Delete
* Initialize editor.
[168] Fix | Delete
*
[169] Fix | Delete
* @return {void}
[170] Fix | Delete
*/
[171] Fix | Delete
initializeEditor: function initializeEditor() {
[172] Fix | Delete
var control = this, changeDebounceDelay = 1000, id, textarea, triggerChangeIfDirty, restoreTextMode = false, needsTextareaChangeTrigger = false, previousValue;
[173] Fix | Delete
textarea = control.fields.text;
[174] Fix | Delete
id = textarea.attr( 'id' );
[175] Fix | Delete
previousValue = textarea.val();
[176] Fix | Delete
[177] Fix | Delete
/**
[178] Fix | Delete
* Trigger change if dirty.
[179] Fix | Delete
*
[180] Fix | Delete
* @return {void}
[181] Fix | Delete
*/
[182] Fix | Delete
triggerChangeIfDirty = function() {
[183] Fix | Delete
var updateWidgetBuffer = 300; // See wp.customize.Widgets.WidgetControl._setupUpdateUI() which uses 250ms for updateWidgetDebounced.
[184] Fix | Delete
if ( control.editor.isDirty() ) {
[185] Fix | Delete
[186] Fix | Delete
/*
[187] Fix | Delete
* Account for race condition in customizer where user clicks Save & Publish while
[188] Fix | Delete
* focus was just previously given to the editor. Since updates to the editor
[189] Fix | Delete
* are debounced at 1 second and since widget input changes are only synced to
[190] Fix | Delete
* settings after 250ms, the customizer needs to be put into the processing
[191] Fix | Delete
* state during the time between the change event is triggered and updateWidget
[192] Fix | Delete
* logic starts. Note that the debounced update-widget request should be able
[193] Fix | Delete
* to be removed with the removal of the update-widget request entirely once
[194] Fix | Delete
* widgets are able to mutate their own instance props directly in JS without
[195] Fix | Delete
* having to make server round-trips to call the respective WP_Widget::update()
[196] Fix | Delete
* callbacks. See <https://core.trac.wordpress.org/ticket/33507>.
[197] Fix | Delete
*/
[198] Fix | Delete
if ( wp.customize && wp.customize.state ) {
[199] Fix | Delete
wp.customize.state( 'processing' ).set( wp.customize.state( 'processing' ).get() + 1 );
[200] Fix | Delete
_.delay( function() {
[201] Fix | Delete
wp.customize.state( 'processing' ).set( wp.customize.state( 'processing' ).get() - 1 );
[202] Fix | Delete
}, updateWidgetBuffer );
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
if ( ! control.editor.isHidden() ) {
[206] Fix | Delete
control.editor.save();
[207] Fix | Delete
}
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
// Trigger change on textarea when it has changed so the widget can enter a dirty state.
[211] Fix | Delete
if ( needsTextareaChangeTrigger && previousValue !== textarea.val() ) {
[212] Fix | Delete
textarea.trigger( 'change' );
[213] Fix | Delete
needsTextareaChangeTrigger = false;
[214] Fix | Delete
previousValue = textarea.val();
[215] Fix | Delete
}
[216] Fix | Delete
};
[217] Fix | Delete
[218] Fix | Delete
// Just-in-time force-update the hidden input fields.
[219] Fix | Delete
control.syncContainer.closest( '.widget' ).find( '[name=savewidget]:first' ).on( 'click', function onClickSaveButton() {
[220] Fix | Delete
triggerChangeIfDirty();
[221] Fix | Delete
});
[222] Fix | Delete
[223] Fix | Delete
/**
[224] Fix | Delete
* Build (or re-build) the visual editor.
[225] Fix | Delete
*
[226] Fix | Delete
* @return {void}
[227] Fix | Delete
*/
[228] Fix | Delete
function buildEditor() {
[229] Fix | Delete
var editor, onInit, showPointerElement;
[230] Fix | Delete
[231] Fix | Delete
// Abort building if the textarea is gone, likely due to the widget having been deleted entirely.
[232] Fix | Delete
if ( ! document.getElementById( id ) ) {
[233] Fix | Delete
return;
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
// The user has disabled TinyMCE.
[237] Fix | Delete
if ( typeof window.tinymce === 'undefined' ) {
[238] Fix | Delete
wp.editor.initialize( id, {
[239] Fix | Delete
quicktags: true,
[240] Fix | Delete
mediaButtons: true
[241] Fix | Delete
});
[242] Fix | Delete
[243] Fix | Delete
return;
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
// Destroy any existing editor so that it can be re-initialized after a widget-updated event.
[247] Fix | Delete
if ( tinymce.get( id ) ) {
[248] Fix | Delete
restoreTextMode = tinymce.get( id ).isHidden();
[249] Fix | Delete
wp.editor.remove( id );
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
// Add or enable the `wpview` plugin.
[253] Fix | Delete
$( document ).one( 'wp-before-tinymce-init.text-widget-init', function( event, init ) {
[254] Fix | Delete
// If somebody has removed all plugins, they must have a good reason.
[255] Fix | Delete
// Keep it that way.
[256] Fix | Delete
if ( ! init.plugins ) {
[257] Fix | Delete
return;
[258] Fix | Delete
} else if ( ! /\bwpview\b/.test( init.plugins ) ) {
[259] Fix | Delete
init.plugins += ',wpview';
[260] Fix | Delete
}
[261] Fix | Delete
} );
[262] Fix | Delete
[263] Fix | Delete
wp.editor.initialize( id, {
[264] Fix | Delete
tinymce: {
[265] Fix | Delete
wpautop: true
[266] Fix | Delete
},
[267] Fix | Delete
quicktags: true,
[268] Fix | Delete
mediaButtons: true
[269] Fix | Delete
});
[270] Fix | Delete
[271] Fix | Delete
/**
[272] Fix | Delete
* Show a pointer, focus on dismiss, and speak the contents for a11y.
[273] Fix | Delete
*
[274] Fix | Delete
* @param {jQuery} pointerElement Pointer element.
[275] Fix | Delete
* @return {void}
[276] Fix | Delete
*/
[277] Fix | Delete
showPointerElement = function( pointerElement ) {
[278] Fix | Delete
pointerElement.show();
[279] Fix | Delete
pointerElement.find( '.close' ).trigger( 'focus' );
[280] Fix | Delete
wp.a11y.speak( pointerElement.find( 'h3, p' ).map( function() {
[281] Fix | Delete
return $( this ).text();
[282] Fix | Delete
} ).get().join( '\n\n' ) );
[283] Fix | Delete
};
[284] Fix | Delete
[285] Fix | Delete
editor = window.tinymce.get( id );
[286] Fix | Delete
if ( ! editor ) {
[287] Fix | Delete
throw new Error( 'Failed to initialize editor' );
[288] Fix | Delete
}
[289] Fix | Delete
onInit = function() {
[290] Fix | Delete
[291] Fix | Delete
// When a widget is moved in the DOM the dynamically-created TinyMCE iframe will be destroyed and has to be re-built.
[292] Fix | Delete
$( editor.getWin() ).on( 'unload', function() {
[293] Fix | Delete
_.defer( buildEditor );
[294] Fix | Delete
});
[295] Fix | Delete
[296] Fix | Delete
// If a prior mce instance was replaced, and it was in text mode, toggle to text mode.
[297] Fix | Delete
if ( restoreTextMode ) {
[298] Fix | Delete
switchEditors.go( id, 'html' );
[299] Fix | Delete
}
[300] Fix | Delete
[301] Fix | Delete
// Show the pointer.
[302] Fix | Delete
$( '#' + id + '-html' ).on( 'click', function() {
[303] Fix | Delete
control.pasteHtmlPointer.hide(); // Hide the HTML pasting pointer.
[304] Fix | Delete
[305] Fix | Delete
if ( -1 !== component.dismissedPointers.indexOf( 'text_widget_custom_html' ) ) {
[306] Fix | Delete
return;
[307] Fix | Delete
}
[308] Fix | Delete
showPointerElement( control.customHtmlWidgetPointer );
[309] Fix | Delete
});
[310] Fix | Delete
[311] Fix | Delete
// Hide the pointer when switching tabs.
[312] Fix | Delete
$( '#' + id + '-tmce' ).on( 'click', function() {
[313] Fix | Delete
control.customHtmlWidgetPointer.hide();
[314] Fix | Delete
});
[315] Fix | Delete
[316] Fix | Delete
// Show pointer when pasting HTML.
[317] Fix | Delete
editor.on( 'pastepreprocess', function( event ) {
[318] Fix | Delete
var content = event.content;
[319] Fix | Delete
if ( -1 !== component.dismissedPointers.indexOf( 'text_widget_paste_html' ) || ! content || ! /&lt;\w+.*?&gt;/.test( content ) ) {
[320] Fix | Delete
return;
[321] Fix | Delete
}
[322] Fix | Delete
[323] Fix | Delete
// Show the pointer after a slight delay so the user sees what they pasted.
[324] Fix | Delete
_.delay( function() {
[325] Fix | Delete
showPointerElement( control.pasteHtmlPointer );
[326] Fix | Delete
}, 250 );
[327] Fix | Delete
});
[328] Fix | Delete
};
[329] Fix | Delete
[330] Fix | Delete
if ( editor.initialized ) {
[331] Fix | Delete
onInit();
[332] Fix | Delete
} else {
[333] Fix | Delete
editor.on( 'init', onInit );
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
control.editorFocused = false;
[337] Fix | Delete
[338] Fix | Delete
editor.on( 'focus', function onEditorFocus() {
[339] Fix | Delete
control.editorFocused = true;
[340] Fix | Delete
});
[341] Fix | Delete
editor.on( 'paste', function onEditorPaste() {
[342] Fix | Delete
editor.setDirty( true ); // Because pasting doesn't currently set the dirty state.
[343] Fix | Delete
triggerChangeIfDirty();
[344] Fix | Delete
});
[345] Fix | Delete
editor.on( 'NodeChange', function onNodeChange() {
[346] Fix | Delete
needsTextareaChangeTrigger = true;
[347] Fix | Delete
});
[348] Fix | Delete
editor.on( 'NodeChange', _.debounce( triggerChangeIfDirty, changeDebounceDelay ) );
[349] Fix | Delete
editor.on( 'blur hide', function onEditorBlur() {
[350] Fix | Delete
control.editorFocused = false;
[351] Fix | Delete
triggerChangeIfDirty();
[352] Fix | Delete
});
[353] Fix | Delete
[354] Fix | Delete
control.editor = editor;
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
buildEditor();
[358] Fix | Delete
}
[359] Fix | Delete
});
[360] Fix | Delete
[361] Fix | Delete
/**
[362] Fix | Delete
* Mapping of widget ID to instances of TextWidgetControl subclasses.
[363] Fix | Delete
*
[364] Fix | Delete
* @memberOf wp.textWidgets
[365] Fix | Delete
*
[366] Fix | Delete
* @type {Object.<string, wp.textWidgets.TextWidgetControl>}
[367] Fix | Delete
*/
[368] Fix | Delete
component.widgetControls = {};
[369] Fix | Delete
[370] Fix | Delete
/**
[371] Fix | Delete
* Handle widget being added or initialized for the first time at the widget-added event.
[372] Fix | Delete
*
[373] Fix | Delete
* @memberOf wp.textWidgets
[374] Fix | Delete
*
[375] Fix | Delete
* @param {jQuery.Event} event - Event.
[376] Fix | Delete
* @param {jQuery} widgetContainer - Widget container element.
[377] Fix | Delete
*
[378] Fix | Delete
* @return {void}
[379] Fix | Delete
*/
[380] Fix | Delete
component.handleWidgetAdded = function handleWidgetAdded( event, widgetContainer ) {
[381] Fix | Delete
var widgetForm, idBase, widgetControl, widgetId, animatedCheckDelay = 50, renderWhenAnimationDone, fieldContainer, syncContainer;
[382] Fix | Delete
widgetForm = widgetContainer.find( '> .widget-inside > .form, > .widget-inside > form' ); // Note: '.form' appears in the customizer, whereas 'form' on the widgets admin screen.
[383] Fix | Delete
[384] Fix | Delete
idBase = widgetForm.find( '> .id_base' ).val();
[385] Fix | Delete
if ( -1 === component.idBases.indexOf( idBase ) ) {
[386] Fix | Delete
return;
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
// Prevent initializing already-added widgets.
[390] Fix | Delete
widgetId = widgetForm.find( '.widget-id' ).val();
[391] Fix | Delete
if ( component.widgetControls[ widgetId ] ) {
[392] Fix | Delete
return;
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
// Bypass using TinyMCE when widget is in legacy mode.
[396] Fix | Delete
if ( ! widgetForm.find( '.visual' ).val() ) {
[397] Fix | Delete
return;
[398] Fix | Delete
}
[399] Fix | Delete
[400] Fix | Delete
/*
[401] Fix | Delete
* Create a container element for the widget control fields.
[402] Fix | Delete
* This is inserted into the DOM immediately before the .widget-content
[403] Fix | Delete
* element because the contents of this element are essentially "managed"
[404] Fix | Delete
* by PHP, where each widget update cause the entire element to be emptied
[405] Fix | Delete
* and replaced with the rendered output of WP_Widget::form() which is
[406] Fix | Delete
* sent back in Ajax request made to save/update the widget instance.
[407] Fix | Delete
* To prevent a "flash of replaced DOM elements and re-initialized JS
[408] Fix | Delete
* components", the JS template is rendered outside of the normal form
[409] Fix | Delete
* container.
[410] Fix | Delete
*/
[411] Fix | Delete
fieldContainer = $( '<div></div>' );
[412] Fix | Delete
syncContainer = widgetContainer.find( '.widget-content:first' );
[413] Fix | Delete
syncContainer.before( fieldContainer );
[414] Fix | Delete
[415] Fix | Delete
widgetControl = new component.TextWidgetControl({
[416] Fix | Delete
el: fieldContainer,
[417] Fix | Delete
syncContainer: syncContainer
[418] Fix | Delete
});
[419] Fix | Delete
[420] Fix | Delete
component.widgetControls[ widgetId ] = widgetControl;
[421] Fix | Delete
[422] Fix | Delete
/*
[423] Fix | Delete
* Render the widget once the widget parent's container finishes animating,
[424] Fix | Delete
* as the widget-added event fires with a slideDown of the container.
[425] Fix | Delete
* This ensures that the textarea is visible and an iframe can be embedded
[426] Fix | Delete
* with TinyMCE being able to set contenteditable on it.
[427] Fix | Delete
*/
[428] Fix | Delete
renderWhenAnimationDone = function() {
[429] Fix | Delete
if ( ! widgetContainer.hasClass( 'open' ) ) {
[430] Fix | Delete
setTimeout( renderWhenAnimationDone, animatedCheckDelay );
[431] Fix | Delete
} else {
[432] Fix | Delete
widgetControl.initializeEditor();
[433] Fix | Delete
}
[434] Fix | Delete
};
[435] Fix | Delete
renderWhenAnimationDone();
[436] Fix | Delete
};
[437] Fix | Delete
[438] Fix | Delete
/**
[439] Fix | Delete
* Setup widget in accessibility mode.
[440] Fix | Delete
*
[441] Fix | Delete
* @memberOf wp.textWidgets
[442] Fix | Delete
*
[443] Fix | Delete
* @return {void}
[444] Fix | Delete
*/
[445] Fix | Delete
component.setupAccessibleMode = function setupAccessibleMode() {
[446] Fix | Delete
var widgetForm, idBase, widgetControl, fieldContainer, syncContainer;
[447] Fix | Delete
widgetForm = $( '.editwidget > form' );
[448] Fix | Delete
if ( 0 === widgetForm.length ) {
[449] Fix | Delete
return;
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
idBase = widgetForm.find( '.id_base' ).val();
[453] Fix | Delete
if ( -1 === component.idBases.indexOf( idBase ) ) {
[454] Fix | Delete
return;
[455] Fix | Delete
}
[456] Fix | Delete
[457] Fix | Delete
// Bypass using TinyMCE when widget is in legacy mode.
[458] Fix | Delete
if ( ! widgetForm.find( '.visual' ).val() ) {
[459] Fix | Delete
return;
[460] Fix | Delete
}
[461] Fix | Delete
[462] Fix | Delete
fieldContainer = $( '<div></div>' );
[463] Fix | Delete
syncContainer = widgetForm.find( '> .widget-inside' );
[464] Fix | Delete
syncContainer.before( fieldContainer );
[465] Fix | Delete
[466] Fix | Delete
widgetControl = new component.TextWidgetControl({
[467] Fix | Delete
el: fieldContainer,
[468] Fix | Delete
syncContainer: syncContainer
[469] Fix | Delete
});
[470] Fix | Delete
[471] Fix | Delete
widgetControl.initializeEditor();
[472] Fix | Delete
};
[473] Fix | Delete
[474] Fix | Delete
/**
[475] Fix | Delete
* Sync widget instance data sanitized from server back onto widget model.
[476] Fix | Delete
*
[477] Fix | Delete
* This gets called via the 'widget-updated' event when saving a widget from
[478] Fix | Delete
* the widgets admin screen and also via the 'widget-synced' event when making
[479] Fix | Delete
* a change to a widget in the customizer.
[480] Fix | Delete
*
[481] Fix | Delete
* @memberOf wp.textWidgets
[482] Fix | Delete
*
[483] Fix | Delete
* @param {jQuery.Event} event - Event.
[484] Fix | Delete
* @param {jQuery} widgetContainer - Widget container element.
[485] Fix | Delete
* @return {void}
[486] Fix | Delete
*/
[487] Fix | Delete
component.handleWidgetUpdated = function handleWidgetUpdated( event, widgetContainer ) {
[488] Fix | Delete
var widgetForm, widgetId, widgetControl, idBase;
[489] Fix | Delete
widgetForm = widgetContainer.find( '> .widget-inside > .form, > .widget-inside > form' );
[490] Fix | Delete
[491] Fix | Delete
idBase = widgetForm.find( '> .id_base' ).val();
[492] Fix | Delete
if ( -1 === component.idBases.indexOf( idBase ) ) {
[493] Fix | Delete
return;
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
widgetId = widgetForm.find( '> .widget-id' ).val();
[497] Fix | Delete
widgetControl = component.widgetControls[ widgetId ];
[498] Fix | Delete
if ( ! widgetControl ) {
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function