Edit File by line
/home/barbar84/public_h.../wp-admin/js
File: widgets.js
/**
[0] Fix | Delete
* @output wp-admin/js/widgets.js
[1] Fix | Delete
*/
[2] Fix | Delete
[3] Fix | Delete
/* global ajaxurl, isRtl, wpWidgets */
[4] Fix | Delete
[5] Fix | Delete
(function($) {
[6] Fix | Delete
var $document = $( document );
[7] Fix | Delete
[8] Fix | Delete
window.wpWidgets = {
[9] Fix | Delete
/**
[10] Fix | Delete
* A closed Sidebar that gets a Widget dragged over it.
[11] Fix | Delete
*
[12] Fix | Delete
* @var {element|null}
[13] Fix | Delete
*/
[14] Fix | Delete
hoveredSidebar: null,
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Lookup of which widgets have had change events triggered.
[18] Fix | Delete
*
[19] Fix | Delete
* @var {object}
[20] Fix | Delete
*/
[21] Fix | Delete
dirtyWidgets: {},
[22] Fix | Delete
[23] Fix | Delete
init : function() {
[24] Fix | Delete
var rem, the_id,
[25] Fix | Delete
self = this,
[26] Fix | Delete
chooser = $('.widgets-chooser'),
[27] Fix | Delete
selectSidebar = chooser.find('.widgets-chooser-sidebars'),
[28] Fix | Delete
sidebars = $('div.widgets-sortables'),
[29] Fix | Delete
isRTL = !! ( 'undefined' !== typeof isRtl && isRtl );
[30] Fix | Delete
[31] Fix | Delete
// Handle the widgets containers in the right column.
[32] Fix | Delete
$( '#widgets-right .sidebar-name' )
[33] Fix | Delete
/*
[34] Fix | Delete
* Toggle the widgets containers when clicked and update the toggle
[35] Fix | Delete
* button `aria-expanded` attribute value.
[36] Fix | Delete
*/
[37] Fix | Delete
.on( 'click', function() {
[38] Fix | Delete
var $this = $( this ),
[39] Fix | Delete
$wrap = $this.closest( '.widgets-holder-wrap '),
[40] Fix | Delete
$toggle = $this.find( '.handlediv' );
[41] Fix | Delete
[42] Fix | Delete
if ( $wrap.hasClass( 'closed' ) ) {
[43] Fix | Delete
$wrap.removeClass( 'closed' );
[44] Fix | Delete
$toggle.attr( 'aria-expanded', 'true' );
[45] Fix | Delete
// Refresh the jQuery UI sortable items.
[46] Fix | Delete
$this.parent().sortable( 'refresh' );
[47] Fix | Delete
} else {
[48] Fix | Delete
$wrap.addClass( 'closed' );
[49] Fix | Delete
$toggle.attr( 'aria-expanded', 'false' );
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
// Update the admin menu "sticky" state.
[53] Fix | Delete
$document.triggerHandler( 'wp-pin-menu' );
[54] Fix | Delete
})
[55] Fix | Delete
/*
[56] Fix | Delete
* Set the initial `aria-expanded` attribute value on the widgets
[57] Fix | Delete
* containers toggle button. The first one is expanded by default.
[58] Fix | Delete
*/
[59] Fix | Delete
.find( '.handlediv' ).each( function( index ) {
[60] Fix | Delete
if ( 0 === index ) {
[61] Fix | Delete
// jQuery equivalent of `continue` within an `each()` loop.
[62] Fix | Delete
return;
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
$( this ).attr( 'aria-expanded', 'false' );
[66] Fix | Delete
});
[67] Fix | Delete
[68] Fix | Delete
// Show AYS dialog when there are unsaved widget changes.
[69] Fix | Delete
$( window ).on( 'beforeunload.widgets', function( event ) {
[70] Fix | Delete
var dirtyWidgetIds = [], unsavedWidgetsElements;
[71] Fix | Delete
$.each( self.dirtyWidgets, function( widgetId, dirty ) {
[72] Fix | Delete
if ( dirty ) {
[73] Fix | Delete
dirtyWidgetIds.push( widgetId );
[74] Fix | Delete
}
[75] Fix | Delete
});
[76] Fix | Delete
if ( 0 !== dirtyWidgetIds.length ) {
[77] Fix | Delete
unsavedWidgetsElements = $( '#widgets-right' ).find( '.widget' ).filter( function() {
[78] Fix | Delete
return -1 !== dirtyWidgetIds.indexOf( $( this ).prop( 'id' ).replace( /^widget-\d+_/, '' ) );
[79] Fix | Delete
});
[80] Fix | Delete
unsavedWidgetsElements.each( function() {
[81] Fix | Delete
if ( ! $( this ).hasClass( 'open' ) ) {
[82] Fix | Delete
$( this ).find( '.widget-title-action:first' ).trigger( 'click' );
[83] Fix | Delete
}
[84] Fix | Delete
});
[85] Fix | Delete
[86] Fix | Delete
// Bring the first unsaved widget into view and focus on the first tabbable field.
[87] Fix | Delete
unsavedWidgetsElements.first().each( function() {
[88] Fix | Delete
if ( this.scrollIntoViewIfNeeded ) {
[89] Fix | Delete
this.scrollIntoViewIfNeeded();
[90] Fix | Delete
} else {
[91] Fix | Delete
this.scrollIntoView();
[92] Fix | Delete
}
[93] Fix | Delete
$( this ).find( '.widget-inside :tabbable:first' ).trigger( 'focus' );
[94] Fix | Delete
} );
[95] Fix | Delete
[96] Fix | Delete
event.returnValue = wp.i18n.__( 'The changes you made will be lost if you navigate away from this page.' );
[97] Fix | Delete
return event.returnValue;
[98] Fix | Delete
}
[99] Fix | Delete
});
[100] Fix | Delete
[101] Fix | Delete
// Handle the widgets containers in the left column.
[102] Fix | Delete
$( '#widgets-left .sidebar-name' ).on( 'click', function() {
[103] Fix | Delete
var $wrap = $( this ).closest( '.widgets-holder-wrap' );
[104] Fix | Delete
[105] Fix | Delete
$wrap
[106] Fix | Delete
.toggleClass( 'closed' )
[107] Fix | Delete
.find( '.handlediv' ).attr( 'aria-expanded', ! $wrap.hasClass( 'closed' ) );
[108] Fix | Delete
[109] Fix | Delete
// Update the admin menu "sticky" state.
[110] Fix | Delete
$document.triggerHandler( 'wp-pin-menu' );
[111] Fix | Delete
});
[112] Fix | Delete
[113] Fix | Delete
$(document.body).on('click.widgets-toggle', function(e) {
[114] Fix | Delete
var target = $(e.target), css = {},
[115] Fix | Delete
widget, inside, targetWidth, widgetWidth, margin, saveButton, widgetId,
[116] Fix | Delete
toggleBtn = target.closest( '.widget' ).find( '.widget-top button.widget-action' );
[117] Fix | Delete
[118] Fix | Delete
if ( target.parents('.widget-top').length && ! target.parents('#available-widgets').length ) {
[119] Fix | Delete
widget = target.closest('div.widget');
[120] Fix | Delete
inside = widget.children('.widget-inside');
[121] Fix | Delete
targetWidth = parseInt( widget.find('input.widget-width').val(), 10 );
[122] Fix | Delete
widgetWidth = widget.parent().width();
[123] Fix | Delete
widgetId = inside.find( '.widget-id' ).val();
[124] Fix | Delete
[125] Fix | Delete
// Save button is initially disabled, but is enabled when a field is changed.
[126] Fix | Delete
if ( ! widget.data( 'dirty-state-initialized' ) ) {
[127] Fix | Delete
saveButton = inside.find( '.widget-control-save' );
[128] Fix | Delete
saveButton.prop( 'disabled', true ).val( wp.i18n.__( 'Saved' ) );
[129] Fix | Delete
inside.on( 'input change', function() {
[130] Fix | Delete
self.dirtyWidgets[ widgetId ] = true;
[131] Fix | Delete
widget.addClass( 'widget-dirty' );
[132] Fix | Delete
saveButton.prop( 'disabled', false ).val( wp.i18n.__( 'Save' ) );
[133] Fix | Delete
});
[134] Fix | Delete
widget.data( 'dirty-state-initialized', true );
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
if ( inside.is(':hidden') ) {
[138] Fix | Delete
if ( targetWidth > 250 && ( targetWidth + 30 > widgetWidth ) && widget.closest('div.widgets-sortables').length ) {
[139] Fix | Delete
if ( widget.closest('div.widget-liquid-right').length ) {
[140] Fix | Delete
margin = isRTL ? 'margin-right' : 'margin-left';
[141] Fix | Delete
} else {
[142] Fix | Delete
margin = isRTL ? 'margin-left' : 'margin-right';
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
css[ margin ] = widgetWidth - ( targetWidth + 30 ) + 'px';
[146] Fix | Delete
widget.css( css );
[147] Fix | Delete
}
[148] Fix | Delete
/*
[149] Fix | Delete
* Don't change the order of attributes changes and animation:
[150] Fix | Delete
* it's important for screen readers, see ticket #31476.
[151] Fix | Delete
*/
[152] Fix | Delete
toggleBtn.attr( 'aria-expanded', 'true' );
[153] Fix | Delete
inside.slideDown( 'fast', function() {
[154] Fix | Delete
widget.addClass( 'open' );
[155] Fix | Delete
});
[156] Fix | Delete
} else {
[157] Fix | Delete
/*
[158] Fix | Delete
* Don't change the order of attributes changes and animation:
[159] Fix | Delete
* it's important for screen readers, see ticket #31476.
[160] Fix | Delete
*/
[161] Fix | Delete
toggleBtn.attr( 'aria-expanded', 'false' );
[162] Fix | Delete
inside.slideUp( 'fast', function() {
[163] Fix | Delete
widget.attr( 'style', '' );
[164] Fix | Delete
widget.removeClass( 'open' );
[165] Fix | Delete
});
[166] Fix | Delete
}
[167] Fix | Delete
} else if ( target.hasClass('widget-control-save') ) {
[168] Fix | Delete
wpWidgets.save( target.closest('div.widget'), 0, 1, 0 );
[169] Fix | Delete
e.preventDefault();
[170] Fix | Delete
} else if ( target.hasClass('widget-control-remove') ) {
[171] Fix | Delete
wpWidgets.save( target.closest('div.widget'), 1, 1, 0 );
[172] Fix | Delete
} else if ( target.hasClass('widget-control-close') ) {
[173] Fix | Delete
widget = target.closest('div.widget');
[174] Fix | Delete
widget.removeClass( 'open' );
[175] Fix | Delete
toggleBtn.attr( 'aria-expanded', 'false' );
[176] Fix | Delete
wpWidgets.close( widget );
[177] Fix | Delete
} else if ( target.attr( 'id' ) === 'inactive-widgets-control-remove' ) {
[178] Fix | Delete
wpWidgets.removeInactiveWidgets();
[179] Fix | Delete
e.preventDefault();
[180] Fix | Delete
}
[181] Fix | Delete
});
[182] Fix | Delete
[183] Fix | Delete
sidebars.children('.widget').each( function() {
[184] Fix | Delete
var $this = $(this);
[185] Fix | Delete
[186] Fix | Delete
wpWidgets.appendTitle( this );
[187] Fix | Delete
[188] Fix | Delete
if ( $this.find( 'p.widget-error' ).length ) {
[189] Fix | Delete
$this.find( '.widget-action' ).trigger( 'click' ).attr( 'aria-expanded', 'true' );
[190] Fix | Delete
}
[191] Fix | Delete
});
[192] Fix | Delete
[193] Fix | Delete
$('#widget-list').children('.widget').draggable({
[194] Fix | Delete
connectToSortable: 'div.widgets-sortables',
[195] Fix | Delete
handle: '> .widget-top > .widget-title',
[196] Fix | Delete
distance: 2,
[197] Fix | Delete
helper: 'clone',
[198] Fix | Delete
zIndex: 101,
[199] Fix | Delete
containment: '#wpwrap',
[200] Fix | Delete
refreshPositions: true,
[201] Fix | Delete
start: function( event, ui ) {
[202] Fix | Delete
var chooser = $(this).find('.widgets-chooser');
[203] Fix | Delete
[204] Fix | Delete
ui.helper.find('div.widget-description').hide();
[205] Fix | Delete
the_id = this.id;
[206] Fix | Delete
[207] Fix | Delete
if ( chooser.length ) {
[208] Fix | Delete
// Hide the chooser and move it out of the widget.
[209] Fix | Delete
$( '#wpbody-content' ).append( chooser.hide() );
[210] Fix | Delete
// Delete the cloned chooser from the drag helper.
[211] Fix | Delete
ui.helper.find('.widgets-chooser').remove();
[212] Fix | Delete
self.clearWidgetSelection();
[213] Fix | Delete
}
[214] Fix | Delete
},
[215] Fix | Delete
stop: function() {
[216] Fix | Delete
if ( rem ) {
[217] Fix | Delete
$(rem).hide();
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
rem = '';
[221] Fix | Delete
}
[222] Fix | Delete
});
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* Opens and closes previously closed Sidebars when Widgets are dragged over/out of them.
[226] Fix | Delete
*/
[227] Fix | Delete
sidebars.droppable( {
[228] Fix | Delete
tolerance: 'intersect',
[229] Fix | Delete
[230] Fix | Delete
/**
[231] Fix | Delete
* Open Sidebar when a Widget gets dragged over it.
[232] Fix | Delete
*
[233] Fix | Delete
* @ignore
[234] Fix | Delete
*
[235] Fix | Delete
* @param {Object} event jQuery event object.
[236] Fix | Delete
*/
[237] Fix | Delete
over: function( event ) {
[238] Fix | Delete
var $wrap = $( event.target ).parent();
[239] Fix | Delete
[240] Fix | Delete
if ( wpWidgets.hoveredSidebar && ! $wrap.is( wpWidgets.hoveredSidebar ) ) {
[241] Fix | Delete
// Close the previous Sidebar as the Widget has been dragged onto another Sidebar.
[242] Fix | Delete
wpWidgets.closeSidebar( event );
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
if ( $wrap.hasClass( 'closed' ) ) {
[246] Fix | Delete
wpWidgets.hoveredSidebar = $wrap;
[247] Fix | Delete
$wrap
[248] Fix | Delete
.removeClass( 'closed' )
[249] Fix | Delete
.find( '.handlediv' ).attr( 'aria-expanded', 'true' );
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
$( this ).sortable( 'refresh' );
[253] Fix | Delete
},
[254] Fix | Delete
[255] Fix | Delete
/**
[256] Fix | Delete
* Close Sidebar when the Widget gets dragged out of it.
[257] Fix | Delete
*
[258] Fix | Delete
* @ignore
[259] Fix | Delete
*
[260] Fix | Delete
* @param {Object} event jQuery event object.
[261] Fix | Delete
*/
[262] Fix | Delete
out: function( event ) {
[263] Fix | Delete
if ( wpWidgets.hoveredSidebar ) {
[264] Fix | Delete
wpWidgets.closeSidebar( event );
[265] Fix | Delete
}
[266] Fix | Delete
}
[267] Fix | Delete
} );
[268] Fix | Delete
[269] Fix | Delete
sidebars.sortable({
[270] Fix | Delete
placeholder: 'widget-placeholder',
[271] Fix | Delete
items: '> .widget',
[272] Fix | Delete
handle: '> .widget-top > .widget-title',
[273] Fix | Delete
cursor: 'move',
[274] Fix | Delete
distance: 2,
[275] Fix | Delete
containment: '#wpwrap',
[276] Fix | Delete
tolerance: 'pointer',
[277] Fix | Delete
refreshPositions: true,
[278] Fix | Delete
start: function( event, ui ) {
[279] Fix | Delete
var height, $this = $(this),
[280] Fix | Delete
$wrap = $this.parent(),
[281] Fix | Delete
inside = ui.item.children('.widget-inside');
[282] Fix | Delete
[283] Fix | Delete
if ( inside.css('display') === 'block' ) {
[284] Fix | Delete
ui.item.removeClass('open');
[285] Fix | Delete
ui.item.find( '.widget-top button.widget-action' ).attr( 'aria-expanded', 'false' );
[286] Fix | Delete
inside.hide();
[287] Fix | Delete
$(this).sortable('refreshPositions');
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
if ( ! $wrap.hasClass('closed') ) {
[291] Fix | Delete
// Lock all open sidebars min-height when starting to drag.
[292] Fix | Delete
// Prevents jumping when dragging a widget from an open sidebar to a closed sidebar below.
[293] Fix | Delete
height = ui.item.hasClass('ui-draggable') ? $this.height() : 1 + $this.height();
[294] Fix | Delete
$this.css( 'min-height', height + 'px' );
[295] Fix | Delete
}
[296] Fix | Delete
},
[297] Fix | Delete
[298] Fix | Delete
stop: function( event, ui ) {
[299] Fix | Delete
var addNew, widgetNumber, $sidebar, $children, child, item,
[300] Fix | Delete
$widget = ui.item,
[301] Fix | Delete
id = the_id;
[302] Fix | Delete
[303] Fix | Delete
// Reset the var to hold a previously closed sidebar.
[304] Fix | Delete
wpWidgets.hoveredSidebar = null;
[305] Fix | Delete
[306] Fix | Delete
if ( $widget.hasClass('deleting') ) {
[307] Fix | Delete
wpWidgets.save( $widget, 1, 0, 1 ); // Delete widget.
[308] Fix | Delete
$widget.remove();
[309] Fix | Delete
return;
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
addNew = $widget.find('input.add_new').val();
[313] Fix | Delete
widgetNumber = $widget.find('input.multi_number').val();
[314] Fix | Delete
[315] Fix | Delete
$widget.attr( 'style', '' ).removeClass('ui-draggable');
[316] Fix | Delete
the_id = '';
[317] Fix | Delete
[318] Fix | Delete
if ( addNew ) {
[319] Fix | Delete
if ( 'multi' === addNew ) {
[320] Fix | Delete
$widget.html(
[321] Fix | Delete
$widget.html().replace( /<[^<>]+>/g, function( tag ) {
[322] Fix | Delete
return tag.replace( /__i__|%i%/g, widgetNumber );
[323] Fix | Delete
})
[324] Fix | Delete
);
[325] Fix | Delete
[326] Fix | Delete
$widget.attr( 'id', id.replace( '__i__', widgetNumber ) );
[327] Fix | Delete
widgetNumber++;
[328] Fix | Delete
[329] Fix | Delete
$( 'div#' + id ).find( 'input.multi_number' ).val( widgetNumber );
[330] Fix | Delete
} else if ( 'single' === addNew ) {
[331] Fix | Delete
$widget.attr( 'id', 'new-' + id );
[332] Fix | Delete
rem = 'div#' + id;
[333] Fix | Delete
}
[334] Fix | Delete
[335] Fix | Delete
wpWidgets.save( $widget, 0, 0, 1 );
[336] Fix | Delete
$widget.find('input.add_new').val('');
[337] Fix | Delete
$document.trigger( 'widget-added', [ $widget ] );
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
$sidebar = $widget.parent();
[341] Fix | Delete
[342] Fix | Delete
if ( $sidebar.parent().hasClass('closed') ) {
[343] Fix | Delete
$sidebar.parent()
[344] Fix | Delete
.removeClass( 'closed' )
[345] Fix | Delete
.find( '.handlediv' ).attr( 'aria-expanded', 'true' );
[346] Fix | Delete
[347] Fix | Delete
$children = $sidebar.children('.widget');
[348] Fix | Delete
[349] Fix | Delete
// Make sure the dropped widget is at the top.
[350] Fix | Delete
if ( $children.length > 1 ) {
[351] Fix | Delete
child = $children.get(0);
[352] Fix | Delete
item = $widget.get(0);
[353] Fix | Delete
[354] Fix | Delete
if ( child.id && item.id && child.id !== item.id ) {
[355] Fix | Delete
$( child ).before( $widget );
[356] Fix | Delete
}
[357] Fix | Delete
}
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
if ( addNew ) {
[361] Fix | Delete
$widget.find( '.widget-action' ).trigger( 'click' );
[362] Fix | Delete
} else {
[363] Fix | Delete
wpWidgets.saveOrder( $sidebar.attr('id') );
[364] Fix | Delete
}
[365] Fix | Delete
},
[366] Fix | Delete
[367] Fix | Delete
activate: function() {
[368] Fix | Delete
$(this).parent().addClass( 'widget-hover' );
[369] Fix | Delete
},
[370] Fix | Delete
[371] Fix | Delete
deactivate: function() {
[372] Fix | Delete
// Remove all min-height added on "start".
[373] Fix | Delete
$(this).css( 'min-height', '' ).parent().removeClass( 'widget-hover' );
[374] Fix | Delete
},
[375] Fix | Delete
[376] Fix | Delete
receive: function( event, ui ) {
[377] Fix | Delete
var $sender = $( ui.sender );
[378] Fix | Delete
[379] Fix | Delete
// Don't add more widgets to orphaned sidebars.
[380] Fix | Delete
if ( this.id.indexOf('orphaned_widgets') > -1 ) {
[381] Fix | Delete
$sender.sortable('cancel');
[382] Fix | Delete
return;
[383] Fix | Delete
}
[384] Fix | Delete
[385] Fix | Delete
// If the last widget was moved out of an orphaned sidebar, close and remove it.
[386] Fix | Delete
if ( $sender.attr('id').indexOf('orphaned_widgets') > -1 && ! $sender.children('.widget').length ) {
[387] Fix | Delete
$sender.parents('.orphan-sidebar').slideUp( 400, function(){ $(this).remove(); } );
[388] Fix | Delete
}
[389] Fix | Delete
}
[390] Fix | Delete
}).sortable( 'option', 'connectWith', 'div.widgets-sortables' );
[391] Fix | Delete
[392] Fix | Delete
$('#available-widgets').droppable({
[393] Fix | Delete
tolerance: 'pointer',
[394] Fix | Delete
accept: function(o){
[395] Fix | Delete
return $(o).parent().attr('id') !== 'widget-list';
[396] Fix | Delete
},
[397] Fix | Delete
drop: function(e,ui) {
[398] Fix | Delete
ui.draggable.addClass('deleting');
[399] Fix | Delete
$('#removing-widget').hide().children('span').empty();
[400] Fix | Delete
},
[401] Fix | Delete
over: function(e,ui) {
[402] Fix | Delete
ui.draggable.addClass('deleting');
[403] Fix | Delete
$('div.widget-placeholder').hide();
[404] Fix | Delete
[405] Fix | Delete
if ( ui.draggable.hasClass('ui-sortable-helper') ) {
[406] Fix | Delete
$('#removing-widget').show().children('span')
[407] Fix | Delete
.html( ui.draggable.find( 'div.widget-title' ).children( 'h3' ).html() );
[408] Fix | Delete
}
[409] Fix | Delete
},
[410] Fix | Delete
out: function(e,ui) {
[411] Fix | Delete
ui.draggable.removeClass('deleting');
[412] Fix | Delete
$('div.widget-placeholder').show();
[413] Fix | Delete
$('#removing-widget').hide().children('span').empty();
[414] Fix | Delete
}
[415] Fix | Delete
});
[416] Fix | Delete
[417] Fix | Delete
// Area Chooser.
[418] Fix | Delete
$( '#widgets-right .widgets-holder-wrap' ).each( function( index, element ) {
[419] Fix | Delete
var $element = $( element ),
[420] Fix | Delete
name = $element.find( '.sidebar-name h2' ).text() || '',
[421] Fix | Delete
ariaLabel = $element.find( '.sidebar-name' ).data( 'add-to' ),
[422] Fix | Delete
id = $element.find( '.widgets-sortables' ).attr( 'id' ),
[423] Fix | Delete
li = $( '<li>' ),
[424] Fix | Delete
button = $( '<button>', {
[425] Fix | Delete
type: 'button',
[426] Fix | Delete
'aria-pressed': 'false',
[427] Fix | Delete
'class': 'widgets-chooser-button',
[428] Fix | Delete
'aria-label': ariaLabel
[429] Fix | Delete
} ).text( name.toString().trim() );
[430] Fix | Delete
[431] Fix | Delete
li.append( button );
[432] Fix | Delete
[433] Fix | Delete
if ( index === 0 ) {
[434] Fix | Delete
li.addClass( 'widgets-chooser-selected' );
[435] Fix | Delete
button.attr( 'aria-pressed', 'true' );
[436] Fix | Delete
}
[437] Fix | Delete
[438] Fix | Delete
selectSidebar.append( li );
[439] Fix | Delete
li.data( 'sidebarId', id );
[440] Fix | Delete
});
[441] Fix | Delete
[442] Fix | Delete
$( '#available-widgets .widget .widget-top' ).on( 'click.widgets-chooser', function() {
[443] Fix | Delete
var $widget = $( this ).closest( '.widget' ),
[444] Fix | Delete
toggleButton = $( this ).find( '.widget-action' ),
[445] Fix | Delete
chooserButtons = selectSidebar.find( '.widgets-chooser-button' );
[446] Fix | Delete
[447] Fix | Delete
if ( $widget.hasClass( 'widget-in-question' ) || $( '#widgets-left' ).hasClass( 'chooser' ) ) {
[448] Fix | Delete
toggleButton.attr( 'aria-expanded', 'false' );
[449] Fix | Delete
self.closeChooser();
[450] Fix | Delete
} else {
[451] Fix | Delete
// Open the chooser.
[452] Fix | Delete
self.clearWidgetSelection();
[453] Fix | Delete
$( '#widgets-left' ).addClass( 'chooser' );
[454] Fix | Delete
// Add CSS class and insert the chooser after the widget description.
[455] Fix | Delete
$widget.addClass( 'widget-in-question' ).children( '.widget-description' ).after( chooser );
[456] Fix | Delete
// Open the chooser with a slide down animation.
[457] Fix | Delete
chooser.slideDown( 300, function() {
[458] Fix | Delete
// Update the toggle button aria-expanded attribute after previous DOM manipulations.
[459] Fix | Delete
toggleButton.attr( 'aria-expanded', 'true' );
[460] Fix | Delete
});
[461] Fix | Delete
[462] Fix | Delete
chooserButtons.on( 'click.widgets-chooser', function() {
[463] Fix | Delete
selectSidebar.find( '.widgets-chooser-selected' ).removeClass( 'widgets-chooser-selected' );
[464] Fix | Delete
chooserButtons.attr( 'aria-pressed', 'false' );
[465] Fix | Delete
$( this )
[466] Fix | Delete
.attr( 'aria-pressed', 'true' )
[467] Fix | Delete
.closest( 'li' ).addClass( 'widgets-chooser-selected' );
[468] Fix | Delete
} );
[469] Fix | Delete
}
[470] Fix | Delete
});
[471] Fix | Delete
[472] Fix | Delete
// Add event handlers.
[473] Fix | Delete
chooser.on( 'click.widgets-chooser', function( event ) {
[474] Fix | Delete
var $target = $( event.target );
[475] Fix | Delete
[476] Fix | Delete
if ( $target.hasClass('button-primary') ) {
[477] Fix | Delete
self.addWidget( chooser );
[478] Fix | Delete
self.closeChooser();
[479] Fix | Delete
} else if ( $target.hasClass( 'widgets-chooser-cancel' ) ) {
[480] Fix | Delete
self.closeChooser();
[481] Fix | Delete
}
[482] Fix | Delete
}).on( 'keyup.widgets-chooser', function( event ) {
[483] Fix | Delete
if ( event.which === $.ui.keyCode.ESCAPE ) {
[484] Fix | Delete
self.closeChooser();
[485] Fix | Delete
}
[486] Fix | Delete
});
[487] Fix | Delete
},
[488] Fix | Delete
[489] Fix | Delete
saveOrder : function( sidebarId ) {
[490] Fix | Delete
var data = {
[491] Fix | Delete
action: 'widgets-order',
[492] Fix | Delete
savewidgets: $('#_wpnonce_widgets').val(),
[493] Fix | Delete
sidebars: []
[494] Fix | Delete
};
[495] Fix | Delete
[496] Fix | Delete
if ( sidebarId ) {
[497] Fix | Delete
$( '#' + sidebarId ).find( '.spinner:first' ).addClass( 'is-active' );
[498] Fix | Delete
}
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function