Edit File by line
/home/barbar84/www/wp-admin/js/widgets
File: custom-html-widgets.js
/**
[0] Fix | Delete
* @output wp-admin/js/widgets/custom-html-widgets.js
[1] Fix | Delete
*/
[2] Fix | Delete
[3] Fix | Delete
/* global wp */
[4] Fix | Delete
/* eslint consistent-this: [ "error", "control" ] */
[5] Fix | Delete
/* eslint no-magic-numbers: ["error", { "ignore": [0,1,-1] }] */
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* @namespace wp.customHtmlWidget
[9] Fix | Delete
* @memberOf wp
[10] Fix | Delete
*/
[11] Fix | Delete
wp.customHtmlWidgets = ( function( $ ) {
[12] Fix | Delete
'use strict';
[13] Fix | Delete
[14] Fix | Delete
var component = {
[15] Fix | Delete
idBases: [ 'custom_html' ],
[16] Fix | Delete
codeEditorSettings: {},
[17] Fix | Delete
l10n: {
[18] Fix | Delete
errorNotice: {
[19] Fix | Delete
singular: '',
[20] Fix | Delete
plural: ''
[21] Fix | Delete
}
[22] Fix | Delete
}
[23] Fix | Delete
};
[24] Fix | Delete
[25] Fix | Delete
component.CustomHtmlWidgetControl = Backbone.View.extend(/** @lends wp.customHtmlWidgets.CustomHtmlWidgetControl.prototype */{
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* View events.
[29] Fix | Delete
*
[30] Fix | Delete
* @type {Object}
[31] Fix | Delete
*/
[32] Fix | Delete
events: {},
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Text widget control.
[36] Fix | Delete
*
[37] Fix | Delete
* @constructs wp.customHtmlWidgets.CustomHtmlWidgetControl
[38] Fix | Delete
* @augments Backbone.View
[39] Fix | Delete
* @abstract
[40] Fix | Delete
*
[41] Fix | Delete
* @param {Object} options - Options.
[42] Fix | Delete
* @param {jQuery} options.el - Control field container element.
[43] Fix | Delete
* @param {jQuery} options.syncContainer - Container element where fields are synced for the server.
[44] Fix | Delete
*
[45] Fix | Delete
* @return {void}
[46] Fix | Delete
*/
[47] Fix | Delete
initialize: function initialize( options ) {
[48] Fix | Delete
var control = this;
[49] Fix | Delete
[50] Fix | Delete
if ( ! options.el ) {
[51] Fix | Delete
throw new Error( 'Missing options.el' );
[52] Fix | Delete
}
[53] Fix | Delete
if ( ! options.syncContainer ) {
[54] Fix | Delete
throw new Error( 'Missing options.syncContainer' );
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
Backbone.View.prototype.initialize.call( control, options );
[58] Fix | Delete
control.syncContainer = options.syncContainer;
[59] Fix | Delete
control.widgetIdBase = control.syncContainer.parent().find( '.id_base' ).val();
[60] Fix | Delete
control.widgetNumber = control.syncContainer.parent().find( '.widget_number' ).val();
[61] Fix | Delete
control.customizeSettingId = 'widget_' + control.widgetIdBase + '[' + String( control.widgetNumber ) + ']';
[62] Fix | Delete
[63] Fix | Delete
control.$el.addClass( 'custom-html-widget-fields' );
[64] Fix | Delete
control.$el.html( wp.template( 'widget-custom-html-control-fields' )( { codeEditorDisabled: component.codeEditorSettings.disabled } ) );
[65] Fix | Delete
[66] Fix | Delete
control.errorNoticeContainer = control.$el.find( '.code-editor-error-container' );
[67] Fix | Delete
control.currentErrorAnnotations = [];
[68] Fix | Delete
control.saveButton = control.syncContainer.add( control.syncContainer.parent().find( '.widget-control-actions' ) ).find( '.widget-control-save, #savewidget' );
[69] Fix | Delete
control.saveButton.addClass( 'custom-html-widget-save-button' ); // To facilitate style targeting.
[70] Fix | Delete
[71] Fix | Delete
control.fields = {
[72] Fix | Delete
title: control.$el.find( '.title' ),
[73] Fix | Delete
content: control.$el.find( '.content' )
[74] Fix | Delete
};
[75] Fix | Delete
[76] Fix | Delete
// Sync input fields to hidden sync fields which actually get sent to the server.
[77] Fix | Delete
_.each( control.fields, function( fieldInput, fieldName ) {
[78] Fix | Delete
fieldInput.on( 'input change', function updateSyncField() {
[79] Fix | Delete
var syncInput = control.syncContainer.find( '.sync-input.' + fieldName );
[80] Fix | Delete
if ( syncInput.val() !== fieldInput.val() ) {
[81] Fix | Delete
syncInput.val( fieldInput.val() );
[82] Fix | Delete
syncInput.trigger( 'change' );
[83] Fix | Delete
}
[84] Fix | Delete
});
[85] Fix | Delete
[86] Fix | Delete
// Note that syncInput cannot be re-used because it will be destroyed with each widget-updated event.
[87] Fix | Delete
fieldInput.val( control.syncContainer.find( '.sync-input.' + fieldName ).val() );
[88] Fix | Delete
});
[89] Fix | Delete
},
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Update input fields from the sync fields.
[93] Fix | Delete
*
[94] Fix | Delete
* This function is called at the widget-updated and widget-synced events.
[95] Fix | Delete
* A field will only be updated if it is not currently focused, to avoid
[96] Fix | Delete
* overwriting content that the user is entering.
[97] Fix | Delete
*
[98] Fix | Delete
* @return {void}
[99] Fix | Delete
*/
[100] Fix | Delete
updateFields: function updateFields() {
[101] Fix | Delete
var control = this, syncInput;
[102] Fix | Delete
[103] Fix | Delete
if ( ! control.fields.title.is( document.activeElement ) ) {
[104] Fix | Delete
syncInput = control.syncContainer.find( '.sync-input.title' );
[105] Fix | Delete
control.fields.title.val( syncInput.val() );
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
/*
[109] Fix | Delete
* Prevent updating content when the editor is focused or if there are current error annotations,
[110] Fix | Delete
* to prevent the editor's contents from getting sanitized as soon as a user removes focus from
[111] Fix | Delete
* the editor. This is particularly important for users who cannot unfiltered_html.
[112] Fix | Delete
*/
[113] Fix | Delete
control.contentUpdateBypassed = control.fields.content.is( document.activeElement ) || control.editor && control.editor.codemirror.state.focused || 0 !== control.currentErrorAnnotations.length;
[114] Fix | Delete
if ( ! control.contentUpdateBypassed ) {
[115] Fix | Delete
syncInput = control.syncContainer.find( '.sync-input.content' );
[116] Fix | Delete
control.fields.content.val( syncInput.val() );
[117] Fix | Delete
}
[118] Fix | Delete
},
[119] Fix | Delete
[120] Fix | Delete
/**
[121] Fix | Delete
* Show linting error notice.
[122] Fix | Delete
*
[123] Fix | Delete
* @param {Array} errorAnnotations - Error annotations.
[124] Fix | Delete
* @return {void}
[125] Fix | Delete
*/
[126] Fix | Delete
updateErrorNotice: function( errorAnnotations ) {
[127] Fix | Delete
var control = this, errorNotice, message = '', customizeSetting;
[128] Fix | Delete
[129] Fix | Delete
if ( 1 === errorAnnotations.length ) {
[130] Fix | Delete
message = component.l10n.errorNotice.singular.replace( '%d', '1' );
[131] Fix | Delete
} else if ( errorAnnotations.length > 1 ) {
[132] Fix | Delete
message = component.l10n.errorNotice.plural.replace( '%d', String( errorAnnotations.length ) );
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
if ( control.fields.content[0].setCustomValidity ) {
[136] Fix | Delete
control.fields.content[0].setCustomValidity( message );
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
if ( wp.customize && wp.customize.has( control.customizeSettingId ) ) {
[140] Fix | Delete
customizeSetting = wp.customize( control.customizeSettingId );
[141] Fix | Delete
customizeSetting.notifications.remove( 'htmlhint_error' );
[142] Fix | Delete
if ( 0 !== errorAnnotations.length ) {
[143] Fix | Delete
customizeSetting.notifications.add( 'htmlhint_error', new wp.customize.Notification( 'htmlhint_error', {
[144] Fix | Delete
message: message,
[145] Fix | Delete
type: 'error'
[146] Fix | Delete
} ) );
[147] Fix | Delete
}
[148] Fix | Delete
} else if ( 0 !== errorAnnotations.length ) {
[149] Fix | Delete
errorNotice = $( '<div class="inline notice notice-error notice-alt"></div>' );
[150] Fix | Delete
errorNotice.append( $( '<p></p>', {
[151] Fix | Delete
text: message
[152] Fix | Delete
} ) );
[153] Fix | Delete
control.errorNoticeContainer.empty();
[154] Fix | Delete
control.errorNoticeContainer.append( errorNotice );
[155] Fix | Delete
control.errorNoticeContainer.slideDown( 'fast' );
[156] Fix | Delete
wp.a11y.speak( message );
[157] Fix | Delete
} else {
[158] Fix | Delete
control.errorNoticeContainer.slideUp( 'fast' );
[159] Fix | Delete
}
[160] Fix | Delete
},
[161] Fix | Delete
[162] Fix | Delete
/**
[163] Fix | Delete
* Initialize editor.
[164] Fix | Delete
*
[165] Fix | Delete
* @return {void}
[166] Fix | Delete
*/
[167] Fix | Delete
initializeEditor: function initializeEditor() {
[168] Fix | Delete
var control = this, settings;
[169] Fix | Delete
[170] Fix | Delete
if ( component.codeEditorSettings.disabled ) {
[171] Fix | Delete
return;
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
settings = _.extend( {}, component.codeEditorSettings, {
[175] Fix | Delete
[176] Fix | Delete
/**
[177] Fix | Delete
* Handle tabbing to the field before the editor.
[178] Fix | Delete
*
[179] Fix | Delete
* @ignore
[180] Fix | Delete
*
[181] Fix | Delete
* @return {void}
[182] Fix | Delete
*/
[183] Fix | Delete
onTabPrevious: function onTabPrevious() {
[184] Fix | Delete
control.fields.title.focus();
[185] Fix | Delete
},
[186] Fix | Delete
[187] Fix | Delete
/**
[188] Fix | Delete
* Handle tabbing to the field after the editor.
[189] Fix | Delete
*
[190] Fix | Delete
* @ignore
[191] Fix | Delete
*
[192] Fix | Delete
* @return {void}
[193] Fix | Delete
*/
[194] Fix | Delete
onTabNext: function onTabNext() {
[195] Fix | Delete
var tabbables = control.syncContainer.add( control.syncContainer.parent().find( '.widget-position, .widget-control-actions' ) ).find( ':tabbable' );
[196] Fix | Delete
tabbables.first().focus();
[197] Fix | Delete
},
[198] Fix | Delete
[199] Fix | Delete
/**
[200] Fix | Delete
* Disable save button and store linting errors for use in updateFields.
[201] Fix | Delete
*
[202] Fix | Delete
* @ignore
[203] Fix | Delete
*
[204] Fix | Delete
* @param {Array} errorAnnotations - Error notifications.
[205] Fix | Delete
* @return {void}
[206] Fix | Delete
*/
[207] Fix | Delete
onChangeLintingErrors: function onChangeLintingErrors( errorAnnotations ) {
[208] Fix | Delete
control.currentErrorAnnotations = errorAnnotations;
[209] Fix | Delete
},
[210] Fix | Delete
[211] Fix | Delete
/**
[212] Fix | Delete
* Update error notice.
[213] Fix | Delete
*
[214] Fix | Delete
* @ignore
[215] Fix | Delete
*
[216] Fix | Delete
* @param {Array} errorAnnotations - Error annotations.
[217] Fix | Delete
* @return {void}
[218] Fix | Delete
*/
[219] Fix | Delete
onUpdateErrorNotice: function onUpdateErrorNotice( errorAnnotations ) {
[220] Fix | Delete
control.saveButton.toggleClass( 'validation-blocked disabled', errorAnnotations.length > 0 );
[221] Fix | Delete
control.updateErrorNotice( errorAnnotations );
[222] Fix | Delete
}
[223] Fix | Delete
});
[224] Fix | Delete
[225] Fix | Delete
control.editor = wp.codeEditor.initialize( control.fields.content, settings );
[226] Fix | Delete
[227] Fix | Delete
// Improve the editor accessibility.
[228] Fix | Delete
$( control.editor.codemirror.display.lineDiv )
[229] Fix | Delete
.attr({
[230] Fix | Delete
role: 'textbox',
[231] Fix | Delete
'aria-multiline': 'true',
[232] Fix | Delete
'aria-labelledby': control.fields.content[0].id + '-label',
[233] Fix | Delete
'aria-describedby': 'editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4'
[234] Fix | Delete
});
[235] Fix | Delete
[236] Fix | Delete
// Focus the editor when clicking on its label.
[237] Fix | Delete
$( '#' + control.fields.content[0].id + '-label' ).on( 'click', function() {
[238] Fix | Delete
control.editor.codemirror.focus();
[239] Fix | Delete
});
[240] Fix | Delete
[241] Fix | Delete
control.fields.content.on( 'change', function() {
[242] Fix | Delete
if ( this.value !== control.editor.codemirror.getValue() ) {
[243] Fix | Delete
control.editor.codemirror.setValue( this.value );
[244] Fix | Delete
}
[245] Fix | Delete
});
[246] Fix | Delete
control.editor.codemirror.on( 'change', function() {
[247] Fix | Delete
var value = control.editor.codemirror.getValue();
[248] Fix | Delete
if ( value !== control.fields.content.val() ) {
[249] Fix | Delete
control.fields.content.val( value ).trigger( 'change' );
[250] Fix | Delete
}
[251] Fix | Delete
});
[252] Fix | Delete
[253] Fix | Delete
// Make sure the editor gets updated if the content was updated on the server (sanitization) but not updated in the editor since it was focused.
[254] Fix | Delete
control.editor.codemirror.on( 'blur', function() {
[255] Fix | Delete
if ( control.contentUpdateBypassed ) {
[256] Fix | Delete
control.syncContainer.find( '.sync-input.content' ).trigger( 'change' );
[257] Fix | Delete
}
[258] Fix | Delete
});
[259] Fix | Delete
[260] Fix | Delete
// Prevent hitting Esc from collapsing the widget control.
[261] Fix | Delete
if ( wp.customize ) {
[262] Fix | Delete
control.editor.codemirror.on( 'keydown', function onKeydown( codemirror, event ) {
[263] Fix | Delete
var escKeyCode = 27;
[264] Fix | Delete
if ( escKeyCode === event.keyCode ) {
[265] Fix | Delete
event.stopPropagation();
[266] Fix | Delete
}
[267] Fix | Delete
});
[268] Fix | Delete
}
[269] Fix | Delete
}
[270] Fix | Delete
});
[271] Fix | Delete
[272] Fix | Delete
/**
[273] Fix | Delete
* Mapping of widget ID to instances of CustomHtmlWidgetControl subclasses.
[274] Fix | Delete
*
[275] Fix | Delete
* @alias wp.customHtmlWidgets.widgetControls
[276] Fix | Delete
*
[277] Fix | Delete
* @type {Object.<string, wp.textWidgets.CustomHtmlWidgetControl>}
[278] Fix | Delete
*/
[279] Fix | Delete
component.widgetControls = {};
[280] Fix | Delete
[281] Fix | Delete
/**
[282] Fix | Delete
* Handle widget being added or initialized for the first time at the widget-added event.
[283] Fix | Delete
*
[284] Fix | Delete
* @alias wp.customHtmlWidgets.handleWidgetAdded
[285] Fix | Delete
*
[286] Fix | Delete
* @param {jQuery.Event} event - Event.
[287] Fix | Delete
* @param {jQuery} widgetContainer - Widget container element.
[288] Fix | Delete
*
[289] Fix | Delete
* @return {void}
[290] Fix | Delete
*/
[291] Fix | Delete
component.handleWidgetAdded = function handleWidgetAdded( event, widgetContainer ) {
[292] Fix | Delete
var widgetForm, idBase, widgetControl, widgetId, animatedCheckDelay = 50, renderWhenAnimationDone, fieldContainer, syncContainer;
[293] Fix | Delete
widgetForm = widgetContainer.find( '> .widget-inside > .form, > .widget-inside > form' ); // Note: '.form' appears in the customizer, whereas 'form' on the widgets admin screen.
[294] Fix | Delete
[295] Fix | Delete
idBase = widgetForm.find( '> .id_base' ).val();
[296] Fix | Delete
if ( -1 === component.idBases.indexOf( idBase ) ) {
[297] Fix | Delete
return;
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
// Prevent initializing already-added widgets.
[301] Fix | Delete
widgetId = widgetForm.find( '.widget-id' ).val();
[302] Fix | Delete
if ( component.widgetControls[ widgetId ] ) {
[303] Fix | Delete
return;
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
/*
[307] Fix | Delete
* Create a container element for the widget control fields.
[308] Fix | Delete
* This is inserted into the DOM immediately before the the .widget-content
[309] Fix | Delete
* element because the contents of this element are essentially "managed"
[310] Fix | Delete
* by PHP, where each widget update cause the entire element to be emptied
[311] Fix | Delete
* and replaced with the rendered output of WP_Widget::form() which is
[312] Fix | Delete
* sent back in Ajax request made to save/update the widget instance.
[313] Fix | Delete
* To prevent a "flash of replaced DOM elements and re-initialized JS
[314] Fix | Delete
* components", the JS template is rendered outside of the normal form
[315] Fix | Delete
* container.
[316] Fix | Delete
*/
[317] Fix | Delete
fieldContainer = $( '<div></div>' );
[318] Fix | Delete
syncContainer = widgetContainer.find( '.widget-content:first' );
[319] Fix | Delete
syncContainer.before( fieldContainer );
[320] Fix | Delete
[321] Fix | Delete
widgetControl = new component.CustomHtmlWidgetControl({
[322] Fix | Delete
el: fieldContainer,
[323] Fix | Delete
syncContainer: syncContainer
[324] Fix | Delete
});
[325] Fix | Delete
[326] Fix | Delete
component.widgetControls[ widgetId ] = widgetControl;
[327] Fix | Delete
[328] Fix | Delete
/*
[329] Fix | Delete
* Render the widget once the widget parent's container finishes animating,
[330] Fix | Delete
* as the widget-added event fires with a slideDown of the container.
[331] Fix | Delete
* This ensures that the textarea is visible and the editor can be initialized.
[332] Fix | Delete
*/
[333] Fix | Delete
renderWhenAnimationDone = function() {
[334] Fix | Delete
if ( ! ( wp.customize ? widgetContainer.parent().hasClass( 'expanded' ) : widgetContainer.hasClass( 'open' ) ) ) { // Core merge: The wp.customize condition can be eliminated with this change being in core: https://github.com/xwp/wordpress-develop/pull/247/commits/5322387d
[335] Fix | Delete
setTimeout( renderWhenAnimationDone, animatedCheckDelay );
[336] Fix | Delete
} else {
[337] Fix | Delete
widgetControl.initializeEditor();
[338] Fix | Delete
}
[339] Fix | Delete
};
[340] Fix | Delete
renderWhenAnimationDone();
[341] Fix | Delete
};
[342] Fix | Delete
[343] Fix | Delete
/**
[344] Fix | Delete
* Setup widget in accessibility mode.
[345] Fix | Delete
*
[346] Fix | Delete
* @alias wp.customHtmlWidgets.setupAccessibleMode
[347] Fix | Delete
*
[348] Fix | Delete
* @return {void}
[349] Fix | Delete
*/
[350] Fix | Delete
component.setupAccessibleMode = function setupAccessibleMode() {
[351] Fix | Delete
var widgetForm, idBase, widgetControl, fieldContainer, syncContainer;
[352] Fix | Delete
widgetForm = $( '.editwidget > form' );
[353] Fix | Delete
if ( 0 === widgetForm.length ) {
[354] Fix | Delete
return;
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
idBase = widgetForm.find( '> .widget-control-actions > .id_base' ).val();
[358] Fix | Delete
if ( -1 === component.idBases.indexOf( idBase ) ) {
[359] Fix | Delete
return;
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
fieldContainer = $( '<div></div>' );
[363] Fix | Delete
syncContainer = widgetForm.find( '> .widget-inside' );
[364] Fix | Delete
syncContainer.before( fieldContainer );
[365] Fix | Delete
[366] Fix | Delete
widgetControl = new component.CustomHtmlWidgetControl({
[367] Fix | Delete
el: fieldContainer,
[368] Fix | Delete
syncContainer: syncContainer
[369] Fix | Delete
});
[370] Fix | Delete
[371] Fix | Delete
widgetControl.initializeEditor();
[372] Fix | Delete
};
[373] Fix | Delete
[374] Fix | Delete
/**
[375] Fix | Delete
* Sync widget instance data sanitized from server back onto widget model.
[376] Fix | Delete
*
[377] Fix | Delete
* This gets called via the 'widget-updated' event when saving a widget from
[378] Fix | Delete
* the widgets admin screen and also via the 'widget-synced' event when making
[379] Fix | Delete
* a change to a widget in the customizer.
[380] Fix | Delete
*
[381] Fix | Delete
* @alias wp.customHtmlWidgets.handleWidgetUpdated
[382] Fix | Delete
*
[383] Fix | Delete
* @param {jQuery.Event} event - Event.
[384] Fix | Delete
* @param {jQuery} widgetContainer - Widget container element.
[385] Fix | Delete
* @return {void}
[386] Fix | Delete
*/
[387] Fix | Delete
component.handleWidgetUpdated = function handleWidgetUpdated( event, widgetContainer ) {
[388] Fix | Delete
var widgetForm, widgetId, widgetControl, idBase;
[389] Fix | Delete
widgetForm = widgetContainer.find( '> .widget-inside > .form, > .widget-inside > form' );
[390] Fix | Delete
[391] Fix | Delete
idBase = widgetForm.find( '> .id_base' ).val();
[392] Fix | Delete
if ( -1 === component.idBases.indexOf( idBase ) ) {
[393] Fix | Delete
return;
[394] Fix | Delete
}
[395] Fix | Delete
[396] Fix | Delete
widgetId = widgetForm.find( '> .widget-id' ).val();
[397] Fix | Delete
widgetControl = component.widgetControls[ widgetId ];
[398] Fix | Delete
if ( ! widgetControl ) {
[399] Fix | Delete
return;
[400] Fix | Delete
}
[401] Fix | Delete
[402] Fix | Delete
widgetControl.updateFields();
[403] Fix | Delete
};
[404] Fix | Delete
[405] Fix | Delete
/**
[406] Fix | Delete
* Initialize functionality.
[407] Fix | Delete
*
[408] Fix | Delete
* This function exists to prevent the JS file from having to boot itself.
[409] Fix | Delete
* When WordPress enqueues this script, it should have an inline script
[410] Fix | Delete
* attached which calls wp.textWidgets.init().
[411] Fix | Delete
*
[412] Fix | Delete
* @alias wp.customHtmlWidgets.init
[413] Fix | Delete
*
[414] Fix | Delete
* @param {Object} settings - Options for code editor, exported from PHP.
[415] Fix | Delete
*
[416] Fix | Delete
* @return {void}
[417] Fix | Delete
*/
[418] Fix | Delete
component.init = function init( settings ) {
[419] Fix | Delete
var $document = $( document );
[420] Fix | Delete
_.extend( component.codeEditorSettings, settings );
[421] Fix | Delete
[422] Fix | Delete
$document.on( 'widget-added', component.handleWidgetAdded );
[423] Fix | Delete
$document.on( 'widget-synced widget-updated', component.handleWidgetUpdated );
[424] Fix | Delete
[425] Fix | Delete
/*
[426] Fix | Delete
* Manually trigger widget-added events for media widgets on the admin
[427] Fix | Delete
* screen once they are expanded. The widget-added event is not triggered
[428] Fix | Delete
* for each pre-existing widget on the widgets admin screen like it is
[429] Fix | Delete
* on the customizer. Likewise, the customizer only triggers widget-added
[430] Fix | Delete
* when the widget is expanded to just-in-time construct the widget form
[431] Fix | Delete
* when it is actually going to be displayed. So the following implements
[432] Fix | Delete
* the same for the widgets admin screen, to invoke the widget-added
[433] Fix | Delete
* handler when a pre-existing media widget is expanded.
[434] Fix | Delete
*/
[435] Fix | Delete
$( function initializeExistingWidgetContainers() {
[436] Fix | Delete
var widgetContainers;
[437] Fix | Delete
if ( 'widgets' !== window.pagenow ) {
[438] Fix | Delete
return;
[439] Fix | Delete
}
[440] Fix | Delete
widgetContainers = $( '.widgets-holder-wrap:not(#available-widgets)' ).find( 'div.widget' );
[441] Fix | Delete
widgetContainers.one( 'click.toggle-widget-expanded', function toggleWidgetExpanded() {
[442] Fix | Delete
var widgetContainer = $( this );
[443] Fix | Delete
component.handleWidgetAdded( new jQuery.Event( 'widget-added' ), widgetContainer );
[444] Fix | Delete
});
[445] Fix | Delete
[446] Fix | Delete
// Accessibility mode.
[447] Fix | Delete
if ( document.readyState === 'complete' ) {
[448] Fix | Delete
// Page is fully loaded.
[449] Fix | Delete
component.setupAccessibleMode();
[450] Fix | Delete
} else {
[451] Fix | Delete
// Page is still loading.
[452] Fix | Delete
$( window ).on( 'load', function() {
[453] Fix | Delete
component.setupAccessibleMode();
[454] Fix | Delete
});
[455] Fix | Delete
}
[456] Fix | Delete
});
[457] Fix | Delete
};
[458] Fix | Delete
[459] Fix | Delete
return component;
[460] Fix | Delete
})( jQuery );
[461] Fix | Delete
[462] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function