2018-06-27 22:30:15 -04:00
|
|
|
/**
|
|
|
|
* @output wp-admin/js/widgets.js
|
|
|
|
*/
|
|
|
|
|
2018-08-19 09:33:24 -04:00
|
|
|
/* global ajaxurl, isRtl, wpWidgets */
|
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
(function($) {
|
2015-05-09 20:32:31 -04:00
|
|
|
var $document = $( document );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2018-08-19 09:33:24 -04:00
|
|
|
window.wpWidgets = {
|
2015-06-30 20:58:24 -04:00
|
|
|
/**
|
|
|
|
* A closed Sidebar that gets a Widget dragged over it.
|
|
|
|
*
|
2017-09-08 15:11:43 -04:00
|
|
|
* @var {element|null}
|
2015-06-30 20:58:24 -04:00
|
|
|
*/
|
|
|
|
hoveredSidebar: null,
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-09-08 15:11:43 -04:00
|
|
|
/**
|
|
|
|
* Lookup of which widgets have had change events triggered.
|
|
|
|
*
|
|
|
|
* @var {object}
|
|
|
|
*/
|
|
|
|
dirtyWidgets: {},
|
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
init : function() {
|
2013-11-08 18:05:10 -05:00
|
|
|
var rem, the_id,
|
|
|
|
self = this,
|
2013-11-24 17:07:10 -05:00
|
|
|
chooser = $('.widgets-chooser'),
|
2013-11-08 18:05:10 -05:00
|
|
|
selectSidebar = chooser.find('.widgets-chooser-sidebars'),
|
|
|
|
sidebars = $('div.widgets-sortables'),
|
2013-11-19 20:35:10 -05:00
|
|
|
isRTL = !! ( 'undefined' !== typeof isRtl && isRtl );
|
2013-11-08 18:05:10 -05:00
|
|
|
|
2017-09-27 12:29:44 -04:00
|
|
|
// Handle the widgets containers in the right column.
|
|
|
|
$( '#widgets-right .sidebar-name' )
|
|
|
|
/*
|
|
|
|
* Toggle the widgets containers when clicked and update the toggle
|
|
|
|
* button `aria-expanded` attribute value.
|
|
|
|
*/
|
2021-01-22 07:32:03 -05:00
|
|
|
.on( 'click', function() {
|
2017-09-27 12:29:44 -04:00
|
|
|
var $this = $( this ),
|
|
|
|
$wrap = $this.closest( '.widgets-holder-wrap '),
|
|
|
|
$toggle = $this.find( '.handlediv' );
|
2013-11-19 23:45:10 -05:00
|
|
|
|
2017-09-27 12:29:44 -04:00
|
|
|
if ( $wrap.hasClass( 'closed' ) ) {
|
|
|
|
$wrap.removeClass( 'closed' );
|
|
|
|
$toggle.attr( 'aria-expanded', 'true' );
|
|
|
|
// Refresh the jQuery UI sortable items.
|
|
|
|
$this.parent().sortable( 'refresh' );
|
|
|
|
} else {
|
|
|
|
$wrap.addClass( 'closed' );
|
|
|
|
$toggle.attr( 'aria-expanded', 'false' );
|
|
|
|
}
|
2015-05-09 20:32:31 -04:00
|
|
|
|
2017-09-27 12:29:44 -04:00
|
|
|
// Update the admin menu "sticky" state.
|
|
|
|
$document.triggerHandler( 'wp-pin-menu' );
|
|
|
|
})
|
|
|
|
/*
|
|
|
|
* Set the initial `aria-expanded` attribute value on the widgets
|
|
|
|
* containers toggle button. The first one is expanded by default.
|
|
|
|
*/
|
|
|
|
.find( '.handlediv' ).each( function( index ) {
|
|
|
|
if ( 0 === index ) {
|
|
|
|
// jQuery equivalent of `continue` within an `each()` loop.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$( this ).attr( 'aria-expanded', 'false' );
|
|
|
|
});
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-09-08 15:11:43 -04:00
|
|
|
// Show AYS dialog when there are unsaved widget changes.
|
|
|
|
$( window ).on( 'beforeunload.widgets', function( event ) {
|
|
|
|
var dirtyWidgetIds = [], unsavedWidgetsElements;
|
|
|
|
$.each( self.dirtyWidgets, function( widgetId, dirty ) {
|
|
|
|
if ( dirty ) {
|
|
|
|
dirtyWidgetIds.push( widgetId );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if ( 0 !== dirtyWidgetIds.length ) {
|
|
|
|
unsavedWidgetsElements = $( '#widgets-right' ).find( '.widget' ).filter( function() {
|
|
|
|
return -1 !== dirtyWidgetIds.indexOf( $( this ).prop( 'id' ).replace( /^widget-\d+_/, '' ) );
|
|
|
|
});
|
|
|
|
unsavedWidgetsElements.each( function() {
|
|
|
|
if ( ! $( this ).hasClass( 'open' ) ) {
|
|
|
|
$( this ).find( '.widget-title-action:first' ).click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Bring the first unsaved widget into view and focus on the first tabbable field.
|
|
|
|
unsavedWidgetsElements.first().each( function() {
|
|
|
|
if ( this.scrollIntoViewIfNeeded ) {
|
|
|
|
this.scrollIntoViewIfNeeded();
|
|
|
|
} else {
|
|
|
|
this.scrollIntoView();
|
|
|
|
}
|
|
|
|
$( this ).find( '.widget-inside :tabbable:first' ).focus();
|
|
|
|
} );
|
|
|
|
|
2020-07-07 13:01:06 -04:00
|
|
|
event.returnValue = wp.i18n.__( 'The changes you made will be lost if you navigate away from this page.' );
|
2017-09-08 15:11:43 -04:00
|
|
|
return event.returnValue;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-09-27 12:29:44 -04:00
|
|
|
// Handle the widgets containers in the left column.
|
2021-01-22 07:32:03 -05:00
|
|
|
$( '#widgets-left .sidebar-name' ).on( 'click', function() {
|
2017-09-27 12:29:44 -04:00
|
|
|
var $wrap = $( this ).closest( '.widgets-holder-wrap' );
|
|
|
|
|
|
|
|
$wrap
|
|
|
|
.toggleClass( 'closed' )
|
|
|
|
.find( '.handlediv' ).attr( 'aria-expanded', ! $wrap.hasClass( 'closed' ) );
|
|
|
|
|
|
|
|
// Update the admin menu "sticky" state.
|
2015-05-09 20:32:31 -04:00
|
|
|
$document.triggerHandler( 'wp-pin-menu' );
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
|
2021-01-22 07:32:03 -05:00
|
|
|
$(document.body).on('click.widgets-toggle', function(e) {
|
2020-02-11 10:26:09 -05:00
|
|
|
var target = $(e.target), css = {},
|
2017-09-08 15:11:43 -04:00
|
|
|
widget, inside, targetWidth, widgetWidth, margin, saveButton, widgetId,
|
2017-04-19 17:14:44 -04:00
|
|
|
toggleBtn = target.closest( '.widget' ).find( '.widget-top button.widget-action' );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
if ( target.parents('.widget-top').length && ! target.parents('#available-widgets').length ) {
|
|
|
|
widget = target.closest('div.widget');
|
|
|
|
inside = widget.children('.widget-inside');
|
2017-09-08 15:11:43 -04:00
|
|
|
targetWidth = parseInt( widget.find('input.widget-width').val(), 10 );
|
2013-11-26 20:30:10 -05:00
|
|
|
widgetWidth = widget.parent().width();
|
2017-09-08 15:11:43 -04:00
|
|
|
widgetId = inside.find( '.widget-id' ).val();
|
|
|
|
|
|
|
|
// Save button is initially disabled, but is enabled when a field is changed.
|
|
|
|
if ( ! widget.data( 'dirty-state-initialized' ) ) {
|
|
|
|
saveButton = inside.find( '.widget-control-save' );
|
2020-07-07 13:01:06 -04:00
|
|
|
saveButton.prop( 'disabled', true ).val( wp.i18n.__( 'Saved' ) );
|
2017-09-08 15:11:43 -04:00
|
|
|
inside.on( 'input change', function() {
|
|
|
|
self.dirtyWidgets[ widgetId ] = true;
|
|
|
|
widget.addClass( 'widget-dirty' );
|
2020-07-07 13:01:06 -04:00
|
|
|
saveButton.prop( 'disabled', false ).val( wp.i18n.__( 'Save' ) );
|
2017-09-08 15:11:43 -04:00
|
|
|
});
|
|
|
|
widget.data( 'dirty-state-initialized', true );
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
if ( inside.is(':hidden') ) {
|
2013-11-19 20:35:10 -05:00
|
|
|
if ( targetWidth > 250 && ( targetWidth + 30 > widgetWidth ) && widget.closest('div.widgets-sortables').length ) {
|
|
|
|
if ( widget.closest('div.widget-liquid-right').length ) {
|
|
|
|
margin = isRTL ? 'margin-right' : 'margin-left';
|
|
|
|
} else {
|
|
|
|
margin = isRTL ? 'margin-left' : 'margin-right';
|
|
|
|
}
|
|
|
|
|
|
|
|
css[ margin ] = widgetWidth - ( targetWidth + 30 ) + 'px';
|
|
|
|
widget.css( css );
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
2017-04-19 17:14:44 -04:00
|
|
|
/*
|
|
|
|
* Don't change the order of attributes changes and animation:
|
|
|
|
* it's important for screen readers, see ticket #31476.
|
|
|
|
*/
|
|
|
|
toggleBtn.attr( 'aria-expanded', 'true' );
|
|
|
|
inside.slideDown( 'fast', function() {
|
|
|
|
widget.addClass( 'open' );
|
|
|
|
});
|
2012-08-22 20:04:18 -04:00
|
|
|
} else {
|
2017-04-19 17:14:44 -04:00
|
|
|
/*
|
|
|
|
* Don't change the order of attributes changes and animation:
|
|
|
|
* it's important for screen readers, see ticket #31476.
|
|
|
|
*/
|
|
|
|
toggleBtn.attr( 'aria-expanded', 'false' );
|
|
|
|
inside.slideUp( 'fast', function() {
|
2013-11-19 20:35:10 -05:00
|
|
|
widget.attr( 'style', '' );
|
2014-05-01 10:09:16 -04:00
|
|
|
widget.removeClass( 'open' );
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if ( target.hasClass('widget-control-save') ) {
|
|
|
|
wpWidgets.save( target.closest('div.widget'), 0, 1, 0 );
|
|
|
|
e.preventDefault();
|
|
|
|
} else if ( target.hasClass('widget-control-remove') ) {
|
|
|
|
wpWidgets.save( target.closest('div.widget'), 1, 1, 0 );
|
|
|
|
} else if ( target.hasClass('widget-control-close') ) {
|
2014-09-10 13:36:15 -04:00
|
|
|
widget = target.closest('div.widget');
|
|
|
|
widget.removeClass( 'open' );
|
2017-04-19 17:14:44 -04:00
|
|
|
toggleBtn.attr( 'aria-expanded', 'false' );
|
2014-09-10 13:36:15 -04:00
|
|
|
wpWidgets.close( widget );
|
2015-10-21 01:23:26 -04:00
|
|
|
} else if ( target.attr( 'id' ) === 'inactive-widgets-control-remove' ) {
|
|
|
|
wpWidgets.removeInactiveWidgets();
|
|
|
|
e.preventDefault();
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-11-26 20:30:10 -05:00
|
|
|
sidebars.children('.widget').each( function() {
|
|
|
|
var $this = $(this);
|
|
|
|
|
|
|
|
wpWidgets.appendTitle( this );
|
|
|
|
|
|
|
|
if ( $this.find( 'p.widget-error' ).length ) {
|
2017-04-19 17:14:44 -04:00
|
|
|
$this.find( '.widget-action' ).trigger( 'click' ).attr( 'aria-expanded', 'true' );
|
2013-11-20 06:12:11 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#widget-list').children('.widget').draggable({
|
|
|
|
connectToSortable: 'div.widgets-sortables',
|
|
|
|
handle: '> .widget-top > .widget-title',
|
|
|
|
distance: 2,
|
|
|
|
helper: 'clone',
|
2020-02-11 10:26:09 -05:00
|
|
|
zIndex: 101,
|
2015-05-09 20:32:31 -04:00
|
|
|
containment: '#wpwrap',
|
2015-06-30 20:58:24 -04:00
|
|
|
refreshPositions: true,
|
2013-11-24 17:07:10 -05:00
|
|
|
start: function( event, ui ) {
|
|
|
|
var chooser = $(this).find('.widgets-chooser');
|
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
ui.helper.find('div.widget-description').hide();
|
|
|
|
the_id = this.id;
|
2013-11-24 17:07:10 -05:00
|
|
|
|
|
|
|
if ( chooser.length ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Hide the chooser and move it out of the widget.
|
2013-11-24 17:07:10 -05:00
|
|
|
$( '#wpbody-content' ).append( chooser.hide() );
|
2020-01-28 19:45:18 -05:00
|
|
|
// Delete the cloned chooser from the drag helper.
|
2013-11-24 17:07:10 -05:00
|
|
|
ui.helper.find('.widgets-chooser').remove();
|
|
|
|
self.clearWidgetSelection();
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
2013-11-08 18:05:10 -05:00
|
|
|
stop: function() {
|
2013-11-20 06:12:11 -05:00
|
|
|
if ( rem ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
$(rem).hide();
|
2013-11-20 06:12:11 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
rem = '';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-06-30 20:58:24 -04:00
|
|
|
/**
|
|
|
|
* Opens and closes previously closed Sidebars when Widgets are dragged over/out of them.
|
|
|
|
*/
|
|
|
|
sidebars.droppable( {
|
2015-07-05 14:20:24 -04:00
|
|
|
tolerance: 'intersect',
|
2015-06-30 20:58:24 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open Sidebar when a Widget gets dragged over it.
|
|
|
|
*
|
2017-12-15 08:42:46 -05:00
|
|
|
* @ignore
|
|
|
|
*
|
2020-07-27 19:35:02 -04:00
|
|
|
* @param {Object} event jQuery event object.
|
2015-06-30 20:58:24 -04:00
|
|
|
*/
|
|
|
|
over: function( event ) {
|
|
|
|
var $wrap = $( event.target ).parent();
|
|
|
|
|
|
|
|
if ( wpWidgets.hoveredSidebar && ! $wrap.is( wpWidgets.hoveredSidebar ) ) {
|
|
|
|
// Close the previous Sidebar as the Widget has been dragged onto another Sidebar.
|
|
|
|
wpWidgets.closeSidebar( event );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $wrap.hasClass( 'closed' ) ) {
|
|
|
|
wpWidgets.hoveredSidebar = $wrap;
|
2017-09-27 12:29:44 -04:00
|
|
|
$wrap
|
|
|
|
.removeClass( 'closed' )
|
|
|
|
.find( '.handlediv' ).attr( 'aria-expanded', 'true' );
|
2015-06-30 20:58:24 -04:00
|
|
|
}
|
2015-07-21 21:25:26 -04:00
|
|
|
|
|
|
|
$( this ).sortable( 'refresh' );
|
2015-06-30 20:58:24 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close Sidebar when the Widget gets dragged out of it.
|
|
|
|
*
|
2017-12-15 08:42:46 -05:00
|
|
|
* @ignore
|
|
|
|
*
|
2020-07-27 19:35:02 -04:00
|
|
|
* @param {Object} event jQuery event object.
|
2015-06-30 20:58:24 -04:00
|
|
|
*/
|
|
|
|
out: function( event ) {
|
|
|
|
if ( wpWidgets.hoveredSidebar ) {
|
|
|
|
wpWidgets.closeSidebar( event );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
sidebars.sortable({
|
|
|
|
placeholder: 'widget-placeholder',
|
|
|
|
items: '> .widget',
|
|
|
|
handle: '> .widget-top > .widget-title',
|
|
|
|
cursor: 'move',
|
|
|
|
distance: 2,
|
2015-05-09 20:32:31 -04:00
|
|
|
containment: '#wpwrap',
|
2015-06-03 18:59:25 -04:00
|
|
|
tolerance: 'pointer',
|
2015-07-05 14:20:24 -04:00
|
|
|
refreshPositions: true,
|
2013-11-26 20:30:10 -05:00
|
|
|
start: function( event, ui ) {
|
2013-11-29 12:58:10 -05:00
|
|
|
var height, $this = $(this),
|
2013-11-26 20:30:10 -05:00
|
|
|
$wrap = $this.parent(),
|
|
|
|
inside = ui.item.children('.widget-inside');
|
|
|
|
|
2013-11-24 17:07:10 -05:00
|
|
|
if ( inside.css('display') === 'block' ) {
|
2015-09-14 23:10:24 -04:00
|
|
|
ui.item.removeClass('open');
|
2017-04-19 17:14:44 -04:00
|
|
|
ui.item.find( '.widget-top button.widget-action' ).attr( 'aria-expanded', 'false' );
|
2013-11-24 17:07:10 -05:00
|
|
|
inside.hide();
|
|
|
|
$(this).sortable('refreshPositions');
|
|
|
|
}
|
2013-11-26 20:30:10 -05:00
|
|
|
|
2013-11-29 12:58:10 -05:00
|
|
|
if ( ! $wrap.hasClass('closed') ) {
|
2013-11-26 20:30:10 -05:00
|
|
|
// Lock all open sidebars min-height when starting to drag.
|
|
|
|
// Prevents jumping when dragging a widget from an open sidebar to a closed sidebar below.
|
2013-11-29 12:58:10 -05:00
|
|
|
height = ui.item.hasClass('ui-draggable') ? $this.height() : 1 + $this.height();
|
|
|
|
$this.css( 'min-height', height + 'px' );
|
2013-11-20 06:12:11 -05:00
|
|
|
}
|
2013-11-26 20:30:10 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
stop: function( event, ui ) {
|
|
|
|
var addNew, widgetNumber, $sidebar, $children, child, item,
|
|
|
|
$widget = ui.item,
|
|
|
|
id = the_id;
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-06-30 20:58:24 -04:00
|
|
|
// Reset the var to hold a previously closed sidebar.
|
|
|
|
wpWidgets.hoveredSidebar = null;
|
|
|
|
|
2013-11-26 20:30:10 -05:00
|
|
|
if ( $widget.hasClass('deleting') ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
wpWidgets.save( $widget, 1, 0, 1 ); // Delete widget.
|
2013-11-26 20:30:10 -05:00
|
|
|
$widget.remove();
|
2012-08-22 20:04:18 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-26 20:30:10 -05:00
|
|
|
addNew = $widget.find('input.add_new').val();
|
|
|
|
widgetNumber = $widget.find('input.multi_number').val();
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2013-11-29 12:58:10 -05:00
|
|
|
$widget.attr( 'style', '' ).removeClass('ui-draggable');
|
2012-08-22 20:04:18 -04:00
|
|
|
the_id = '';
|
|
|
|
|
2013-11-26 20:30:10 -05:00
|
|
|
if ( addNew ) {
|
|
|
|
if ( 'multi' === addNew ) {
|
|
|
|
$widget.html(
|
|
|
|
$widget.html().replace( /<[^<>]+>/g, function( tag ) {
|
2013-11-26 20:42:09 -05:00
|
|
|
return tag.replace( /__i__|%i%/g, widgetNumber );
|
2013-11-26 20:30:10 -05:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
$widget.attr( 'id', id.replace( '__i__', widgetNumber ) );
|
|
|
|
widgetNumber++;
|
|
|
|
|
|
|
|
$( 'div#' + id ).find( 'input.multi_number' ).val( widgetNumber );
|
|
|
|
} else if ( 'single' === addNew ) {
|
|
|
|
$widget.attr( 'id', 'new-' + id );
|
2012-08-22 20:04:18 -04:00
|
|
|
rem = 'div#' + id;
|
|
|
|
}
|
2013-11-26 20:30:10 -05:00
|
|
|
|
|
|
|
wpWidgets.save( $widget, 0, 0, 1 );
|
|
|
|
$widget.find('input.add_new').val('');
|
2015-05-09 20:32:31 -04:00
|
|
|
$document.trigger( 'widget-added', [ $widget ] );
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
2013-11-26 20:30:10 -05:00
|
|
|
|
|
|
|
$sidebar = $widget.parent();
|
|
|
|
|
|
|
|
if ( $sidebar.parent().hasClass('closed') ) {
|
2017-09-27 12:29:44 -04:00
|
|
|
$sidebar.parent()
|
|
|
|
.removeClass( 'closed' )
|
|
|
|
.find( '.handlediv' ).attr( 'aria-expanded', 'true' );
|
|
|
|
|
2013-11-26 20:30:10 -05:00
|
|
|
$children = $sidebar.children('.widget');
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Make sure the dropped widget is at the top.
|
2013-11-26 20:30:10 -05:00
|
|
|
if ( $children.length > 1 ) {
|
|
|
|
child = $children.get(0);
|
|
|
|
item = $widget.get(0);
|
|
|
|
|
|
|
|
if ( child.id && item.id && child.id !== item.id ) {
|
|
|
|
$( child ).before( $widget );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( addNew ) {
|
2017-04-19 17:14:44 -04:00
|
|
|
$widget.find( '.widget-action' ).trigger( 'click' );
|
2013-11-26 20:30:10 -05:00
|
|
|
} else {
|
|
|
|
wpWidgets.saveOrder( $sidebar.attr('id') );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-11-29 12:58:10 -05:00
|
|
|
activate: function() {
|
|
|
|
$(this).parent().addClass( 'widget-hover' );
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
|
|
|
|
2013-11-26 20:42:09 -05:00
|
|
|
deactivate: function() {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Remove all min-height added on "start".
|
2013-11-29 12:58:10 -05:00
|
|
|
$(this).css( 'min-height', '' ).parent().removeClass( 'widget-hover' );
|
2013-11-26 20:30:10 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
receive: function( event, ui ) {
|
|
|
|
var $sender = $( ui.sender );
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Don't add more widgets to orphaned sidebars.
|
2013-11-26 20:30:10 -05:00
|
|
|
if ( this.id.indexOf('orphaned_widgets') > -1 ) {
|
|
|
|
$sender.sortable('cancel');
|
|
|
|
return;
|
2013-11-20 06:12:11 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2013-11-26 20:30:10 -05:00
|
|
|
// If the last widget was moved out of an orphaned sidebar, close and remove it.
|
|
|
|
if ( $sender.attr('id').indexOf('orphaned_widgets') > -1 && ! $sender.children('.widget').length ) {
|
|
|
|
$sender.parents('.orphan-sidebar').slideUp( 400, function(){ $(this).remove(); } );
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
}
|
2013-11-26 20:30:10 -05:00
|
|
|
}).sortable( 'option', 'connectWith', 'div.widgets-sortables' );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
$('#available-widgets').droppable({
|
|
|
|
tolerance: 'pointer',
|
|
|
|
accept: function(o){
|
2013-11-08 18:05:10 -05:00
|
|
|
return $(o).parent().attr('id') !== 'widget-list';
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
|
|
|
drop: function(e,ui) {
|
|
|
|
ui.draggable.addClass('deleting');
|
2015-03-09 15:44:26 -04:00
|
|
|
$('#removing-widget').hide().children('span').empty();
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
|
|
|
over: function(e,ui) {
|
|
|
|
ui.draggable.addClass('deleting');
|
|
|
|
$('div.widget-placeholder').hide();
|
|
|
|
|
2013-11-20 06:12:11 -05:00
|
|
|
if ( ui.draggable.hasClass('ui-sortable-helper') ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
$('#removing-widget').show().children('span')
|
2015-10-10 12:34:25 -04:00
|
|
|
.html( ui.draggable.find( 'div.widget-title' ).children( 'h3' ).html() );
|
2013-11-20 06:12:11 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
|
|
|
out: function(e,ui) {
|
|
|
|
ui.draggable.removeClass('deleting');
|
|
|
|
$('div.widget-placeholder').show();
|
2015-03-09 15:44:26 -04:00
|
|
|
$('#removing-widget').hide().children('span').empty();
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
});
|
2013-11-08 18:05:10 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Area Chooser.
|
2013-11-08 18:05:10 -05:00
|
|
|
$( '#widgets-right .widgets-holder-wrap' ).each( function( index, element ) {
|
|
|
|
var $element = $( element ),
|
2021-01-22 07:32:03 -05:00
|
|
|
name = $element.find( '.sidebar-name h2' ).text() || '',
|
2018-03-07 17:27:31 -05:00
|
|
|
ariaLabel = $element.find( '.sidebar-name' ).data( 'add-to' ),
|
2013-11-08 18:05:10 -05:00
|
|
|
id = $element.find( '.widgets-sortables' ).attr( 'id' ),
|
2018-03-07 17:27:31 -05:00
|
|
|
li = $( '<li>' ),
|
|
|
|
button = $( '<button>', {
|
|
|
|
type: 'button',
|
|
|
|
'aria-pressed': 'false',
|
|
|
|
'class': 'widgets-chooser-button',
|
|
|
|
'aria-label': ariaLabel
|
2021-01-22 07:32:03 -05:00
|
|
|
} ).text( name.toString().trim() );
|
2018-03-07 17:27:31 -05:00
|
|
|
|
|
|
|
li.append( button );
|
2013-11-08 18:05:10 -05:00
|
|
|
|
|
|
|
if ( index === 0 ) {
|
|
|
|
li.addClass( 'widgets-chooser-selected' );
|
2018-03-07 17:27:31 -05:00
|
|
|
button.attr( 'aria-pressed', 'true' );
|
2013-11-08 18:05:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
selectSidebar.append( li );
|
|
|
|
li.data( 'sidebarId', id );
|
|
|
|
});
|
|
|
|
|
2018-03-07 17:27:31 -05:00
|
|
|
$( '#available-widgets .widget .widget-top' ).on( 'click.widgets-chooser', function() {
|
|
|
|
var $widget = $( this ).closest( '.widget' ),
|
|
|
|
toggleButton = $( this ).find( '.widget-action' ),
|
|
|
|
chooserButtons = selectSidebar.find( '.widgets-chooser-button' );
|
2013-11-08 18:05:10 -05:00
|
|
|
|
2013-11-26 20:30:10 -05:00
|
|
|
if ( $widget.hasClass( 'widget-in-question' ) || $( '#widgets-left' ).hasClass( 'chooser' ) ) {
|
2018-03-07 17:27:31 -05:00
|
|
|
toggleButton.attr( 'aria-expanded', 'false' );
|
2013-11-08 18:05:10 -05:00
|
|
|
self.closeChooser();
|
|
|
|
} else {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Open the chooser.
|
2013-11-08 18:05:10 -05:00
|
|
|
self.clearWidgetSelection();
|
|
|
|
$( '#widgets-left' ).addClass( 'chooser' );
|
2018-03-07 17:27:31 -05:00
|
|
|
// Add CSS class and insert the chooser after the widget description.
|
2013-11-26 20:30:10 -05:00
|
|
|
$widget.addClass( 'widget-in-question' ).children( '.widget-description' ).after( chooser );
|
2018-03-07 17:27:31 -05:00
|
|
|
// Open the chooser with a slide down animation.
|
2013-11-19 13:03:09 -05:00
|
|
|
chooser.slideDown( 300, function() {
|
2018-03-07 17:27:31 -05:00
|
|
|
// Update the toggle button aria-expanded attribute after previous DOM manipulations.
|
|
|
|
toggleButton.attr( 'aria-expanded', 'true' );
|
2013-11-08 18:05:10 -05:00
|
|
|
});
|
2013-11-19 13:03:09 -05:00
|
|
|
|
2018-03-07 17:27:31 -05:00
|
|
|
chooserButtons.on( 'click.widgets-chooser', function() {
|
|
|
|
selectSidebar.find( '.widgets-chooser-selected' ).removeClass( 'widgets-chooser-selected' );
|
|
|
|
chooserButtons.attr( 'aria-pressed', 'false' );
|
|
|
|
$( this )
|
|
|
|
.attr( 'aria-pressed', 'true' )
|
|
|
|
.closest( 'li' ).addClass( 'widgets-chooser-selected' );
|
2013-11-20 06:12:11 -05:00
|
|
|
} );
|
2013-11-08 18:05:10 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Add event handlers.
|
2013-11-08 18:05:10 -05:00
|
|
|
chooser.on( 'click.widgets-chooser', function( event ) {
|
|
|
|
var $target = $( event.target );
|
|
|
|
|
|
|
|
if ( $target.hasClass('button-primary') ) {
|
|
|
|
self.addWidget( chooser );
|
|
|
|
self.closeChooser();
|
2016-09-28 15:54:28 -04:00
|
|
|
} else if ( $target.hasClass( 'widgets-chooser-cancel' ) ) {
|
2013-11-08 18:05:10 -05:00
|
|
|
self.closeChooser();
|
2013-11-19 13:03:09 -05:00
|
|
|
}
|
|
|
|
}).on( 'keyup.widgets-chooser', function( event ) {
|
2018-03-07 17:27:31 -05:00
|
|
|
if ( event.which === $.ui.keyCode.ESCAPE ) {
|
2013-11-19 13:03:09 -05:00
|
|
|
self.closeChooser();
|
2013-11-08 18:05:10 -05:00
|
|
|
}
|
|
|
|
});
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
|
|
|
|
2013-11-26 20:30:10 -05:00
|
|
|
saveOrder : function( sidebarId ) {
|
|
|
|
var data = {
|
2012-08-22 20:04:18 -04:00
|
|
|
action: 'widgets-order',
|
|
|
|
savewidgets: $('#_wpnonce_widgets').val(),
|
|
|
|
sidebars: []
|
|
|
|
};
|
|
|
|
|
2013-11-26 20:30:10 -05:00
|
|
|
if ( sidebarId ) {
|
2015-04-03 00:52:27 -04:00
|
|
|
$( '#' + sidebarId ).find( '.spinner:first' ).addClass( 'is-active' );
|
2013-11-26 20:30:10 -05:00
|
|
|
}
|
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
$('div.widgets-sortables').each( function() {
|
2013-11-20 06:12:11 -05:00
|
|
|
if ( $(this).sortable ) {
|
2013-11-26 20:30:10 -05:00
|
|
|
data['sidebars[' + $(this).attr('id') + ']'] = $(this).sortable('toArray').join(',');
|
2013-11-20 06:12:11 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
|
2013-11-26 20:30:10 -05:00
|
|
|
$.post( ajaxurl, data, function() {
|
2015-10-21 01:23:26 -04:00
|
|
|
$( '#inactive-widgets-control-remove' ).prop( 'disabled' , ! $( '#wp_inactive_widgets .widget' ).length );
|
2015-04-03 00:52:27 -04:00
|
|
|
$( '.spinner' ).removeClass( 'is-active' );
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-11-26 20:30:10 -05:00
|
|
|
save : function( widget, del, animate, order ) {
|
2017-09-08 15:11:43 -04:00
|
|
|
var self = this, data, a,
|
|
|
|
sidebarId = widget.closest( 'div.widgets-sortables' ).attr( 'id' ),
|
2018-01-16 20:24:30 -05:00
|
|
|
form = widget.find( 'form' ),
|
|
|
|
isAdd = widget.find( 'input.add_new' ).val();
|
2017-09-08 15:11:43 -04:00
|
|
|
|
2018-01-16 20:24:30 -05:00
|
|
|
if ( ! del && ! isAdd && form.prop( 'checkValidity' ) && ! form[0].checkValidity() ) {
|
2017-09-08 15:11:43 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = form.serialize();
|
2013-11-26 20:42:09 -05:00
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
widget = $(widget);
|
2015-04-03 00:52:27 -04:00
|
|
|
$( '.spinner', widget ).addClass( 'is-active' );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
a = {
|
|
|
|
action: 'save-widget',
|
|
|
|
savewidgets: $('#_wpnonce_widgets').val(),
|
2013-11-26 20:30:10 -05:00
|
|
|
sidebar: sidebarId
|
2012-08-22 20:04:18 -04:00
|
|
|
};
|
|
|
|
|
2013-11-20 06:12:11 -05:00
|
|
|
if ( del ) {
|
2013-11-08 18:05:10 -05:00
|
|
|
a.delete_widget = 1;
|
2013-11-20 06:12:11 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
data += '&' + $.param(a);
|
|
|
|
|
2013-11-26 20:30:10 -05:00
|
|
|
$.post( ajaxurl, data, function(r) {
|
2017-09-08 15:11:43 -04:00
|
|
|
var id = $('input.widget-id', widget).val();
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
if ( del ) {
|
2013-11-20 06:12:11 -05:00
|
|
|
if ( ! $('input.widget_number', widget).val() ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
$('#available-widgets').find('input.widget-id').each(function(){
|
2013-11-20 06:12:11 -05:00
|
|
|
if ( $(this).val() === id ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
$(this).closest('div.widget').show();
|
2013-11-20 06:12:11 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( animate ) {
|
|
|
|
order = 0;
|
2017-10-10 16:39:47 -04:00
|
|
|
widget.slideUp( 'fast', function() {
|
|
|
|
$( this ).remove();
|
2012-08-22 20:04:18 -04:00
|
|
|
wpWidgets.saveOrder();
|
2017-10-10 16:39:47 -04:00
|
|
|
delete self.dirtyWidgets[ id ];
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
widget.remove();
|
2017-10-10 16:39:47 -04:00
|
|
|
delete self.dirtyWidgets[ id ];
|
2015-10-21 01:23:26 -04:00
|
|
|
|
|
|
|
if ( sidebarId === 'wp_inactive_widgets' ) {
|
|
|
|
$( '#inactive-widgets-control-remove' ).prop( 'disabled' , ! $( '#wp_inactive_widgets .widget' ).length );
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
} else {
|
2015-04-03 00:52:27 -04:00
|
|
|
$( '.spinner' ).removeClass( 'is-active' );
|
2012-08-22 20:04:18 -04:00
|
|
|
if ( r && r.length > 2 ) {
|
2014-04-06 15:06:14 -04:00
|
|
|
$( 'div.widget-content', widget ).html( r );
|
2013-11-26 20:30:10 -05:00
|
|
|
wpWidgets.appendTitle( widget );
|
2017-09-08 15:11:43 -04:00
|
|
|
|
|
|
|
// Re-disable the save button.
|
2020-07-07 13:01:06 -04:00
|
|
|
widget.find( '.widget-control-save' ).prop( 'disabled', true ).val( wp.i18n.__( 'Saved' ) );
|
2017-09-08 15:11:43 -04:00
|
|
|
|
|
|
|
widget.removeClass( 'widget-dirty' );
|
|
|
|
|
|
|
|
// Clear the dirty flag from the widget.
|
|
|
|
delete self.dirtyWidgets[ id ];
|
|
|
|
|
2015-05-09 20:32:31 -04:00
|
|
|
$document.trigger( 'widget-updated', [ widget ] );
|
2015-10-21 01:23:26 -04:00
|
|
|
|
|
|
|
if ( sidebarId === 'wp_inactive_widgets' ) {
|
|
|
|
$( '#inactive-widgets-control-remove' ).prop( 'disabled' , ! $( '#wp_inactive_widgets .widget' ).length );
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
}
|
2015-10-21 01:23:26 -04:00
|
|
|
|
2013-11-20 06:12:11 -05:00
|
|
|
if ( order ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
wpWidgets.saveOrder();
|
2013-11-20 06:12:11 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-10-21 01:23:26 -04:00
|
|
|
removeInactiveWidgets : function() {
|
2017-10-10 16:39:47 -04:00
|
|
|
var $element = $( '.remove-inactive-widgets' ), self = this, a, data;
|
2015-10-21 01:23:26 -04:00
|
|
|
|
|
|
|
$( '.spinner', $element ).addClass( 'is-active' );
|
|
|
|
|
|
|
|
a = {
|
|
|
|
action : 'delete-inactive-widgets',
|
|
|
|
removeinactivewidgets : $( '#_wpnonce_remove_inactive_widgets' ).val()
|
|
|
|
};
|
|
|
|
|
|
|
|
data = $.param( a );
|
|
|
|
|
|
|
|
$.post( ajaxurl, data, function() {
|
2017-10-10 16:39:47 -04:00
|
|
|
$( '#wp_inactive_widgets .widget' ).each(function() {
|
|
|
|
var $widget = $( this );
|
|
|
|
delete self.dirtyWidgets[ $widget.find( 'input.widget-id' ).val() ];
|
|
|
|
$widget.remove();
|
|
|
|
});
|
|
|
|
$( '#inactive-widgets-control-remove' ).prop( 'disabled', true );
|
2015-10-21 01:23:26 -04:00
|
|
|
$( '.spinner', $element ).removeClass( 'is-active' );
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
appendTitle : function(widget) {
|
|
|
|
var title = $('input[id*="-title"]', widget).val() || '';
|
|
|
|
|
2013-11-20 06:12:11 -05:00
|
|
|
if ( title ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
title = ': ' + title.replace(/<[^<>]+>/g, '').replace(/</g, '<').replace(/>/g, '>');
|
2013-11-20 06:12:11 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
$(widget).children('.widget-top').children('.widget-title').children()
|
|
|
|
.children('.in-widget-title').html(title);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
close : function(widget) {
|
2013-11-19 20:35:10 -05:00
|
|
|
widget.children('.widget-inside').slideUp('fast', function() {
|
2017-04-19 17:14:44 -04:00
|
|
|
widget.attr( 'style', '' )
|
|
|
|
.find( '.widget-top button.widget-action' )
|
|
|
|
.attr( 'aria-expanded', 'false' )
|
|
|
|
.focus();
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
2013-11-08 18:05:10 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
addWidget: function( chooser ) {
|
2013-12-05 18:14:09 -05:00
|
|
|
var widget, widgetId, add, n, viewportTop, viewportBottom, sidebarBounds,
|
2013-11-08 18:05:10 -05:00
|
|
|
sidebarId = chooser.find( '.widgets-chooser-selected' ).data('sidebarId'),
|
|
|
|
sidebar = $( '#' + sidebarId );
|
|
|
|
|
2013-11-19 13:03:09 -05:00
|
|
|
widget = $('#available-widgets').find('.widget-in-question').clone();
|
|
|
|
widgetId = widget.attr('id');
|
|
|
|
add = widget.find( 'input.add_new' ).val();
|
|
|
|
n = widget.find( 'input.multi_number' ).val();
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Remove the cloned chooser from the widget.
|
2013-12-04 19:02:11 -05:00
|
|
|
widget.find('.widgets-chooser').remove();
|
|
|
|
|
2013-11-08 18:05:10 -05:00
|
|
|
if ( 'multi' === add ) {
|
|
|
|
widget.html(
|
|
|
|
widget.html().replace( /<[^<>]+>/g, function(m) {
|
|
|
|
return m.replace( /__i__|%i%/g, n );
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
widget.attr( 'id', widgetId.replace( '__i__', n ) );
|
|
|
|
n++;
|
|
|
|
$( '#' + widgetId ).find('input.multi_number').val(n);
|
|
|
|
} else if ( 'single' === add ) {
|
|
|
|
widget.attr( 'id', 'new-' + widgetId );
|
|
|
|
$( '#' + widgetId ).hide();
|
|
|
|
}
|
|
|
|
|
2017-09-27 12:29:44 -04:00
|
|
|
// Open the widgets container.
|
|
|
|
sidebar.closest( '.widgets-holder-wrap' )
|
|
|
|
.removeClass( 'closed' )
|
|
|
|
.find( '.handlediv' ).attr( 'aria-expanded', 'true' );
|
2013-11-08 18:05:10 -05:00
|
|
|
|
2013-12-05 17:27:11 -05:00
|
|
|
sidebar.append( widget );
|
2013-11-26 20:30:10 -05:00
|
|
|
sidebar.sortable('refresh');
|
2013-11-08 18:05:10 -05:00
|
|
|
|
|
|
|
wpWidgets.save( widget, 0, 0, 1 );
|
2020-01-28 19:45:18 -05:00
|
|
|
// No longer "new" widget.
|
2013-11-08 18:05:10 -05:00
|
|
|
widget.find( 'input.add_new' ).val('');
|
|
|
|
|
2015-05-09 20:32:31 -04:00
|
|
|
$document.trigger( 'widget-added', [ widget ] );
|
2014-04-06 15:06:14 -04:00
|
|
|
|
2013-12-11 14:49:11 -05:00
|
|
|
/*
|
2013-12-05 17:22:11 -05:00
|
|
|
* Check if any part of the sidebar is visible in the viewport. If it is, don't scroll.
|
|
|
|
* Otherwise, scroll up to so the sidebar is in view.
|
|
|
|
*
|
|
|
|
* We do this by comparing the top and bottom, of the sidebar so see if they are within
|
|
|
|
* the bounds of the viewport.
|
|
|
|
*/
|
2013-12-05 18:14:09 -05:00
|
|
|
viewportTop = $(window).scrollTop();
|
|
|
|
viewportBottom = viewportTop + $(window).height();
|
|
|
|
sidebarBounds = sidebar.offset();
|
2013-12-11 14:49:11 -05:00
|
|
|
|
2013-12-05 18:14:09 -05:00
|
|
|
sidebarBounds.bottom = sidebarBounds.top + sidebar.outerHeight();
|
2013-12-05 17:22:11 -05:00
|
|
|
|
2013-12-05 18:14:09 -05:00
|
|
|
if ( viewportTop > sidebarBounds.bottom || viewportBottom < sidebarBounds.top ) {
|
2013-12-05 17:22:11 -05:00
|
|
|
$( 'html, body' ).animate({
|
2013-12-05 18:14:09 -05:00
|
|
|
scrollTop: sidebarBounds.top - 130
|
2013-12-05 17:22:11 -05:00
|
|
|
}, 200 );
|
|
|
|
}
|
2013-11-08 18:05:10 -05:00
|
|
|
|
|
|
|
window.setTimeout( function() {
|
|
|
|
// Cannot use a callback in the animation above as it fires twice,
|
|
|
|
// have to queue this "by hand".
|
|
|
|
widget.find( '.widget-title' ).trigger('click');
|
2018-03-07 17:27:31 -05:00
|
|
|
// At the end of the animation, announce the widget has been added.
|
2020-07-07 13:01:06 -04:00
|
|
|
window.wp.a11y.speak( wp.i18n.__( 'Widget has been added to the selected sidebar' ), 'assertive' );
|
2013-11-08 18:05:10 -05:00
|
|
|
}, 250 );
|
|
|
|
},
|
|
|
|
|
|
|
|
closeChooser: function() {
|
2018-03-07 17:27:31 -05:00
|
|
|
var self = this,
|
|
|
|
widgetInQuestion = $( '#available-widgets .widget-in-question' );
|
2013-11-08 18:05:10 -05:00
|
|
|
|
2013-11-24 17:07:10 -05:00
|
|
|
$( '.widgets-chooser' ).slideUp( 200, function() {
|
2013-11-21 14:28:10 -05:00
|
|
|
$( '#wpbody-content' ).append( this );
|
2013-11-08 18:05:10 -05:00
|
|
|
self.clearWidgetSelection();
|
2018-03-07 17:27:31 -05:00
|
|
|
// Move focus back to the toggle button.
|
|
|
|
widgetInQuestion.find( '.widget-action' ).attr( 'aria-expanded', 'false' ).focus();
|
2013-11-08 18:05:10 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
clearWidgetSelection: function() {
|
|
|
|
$( '#widgets-left' ).removeClass( 'chooser' );
|
2013-11-19 13:03:09 -05:00
|
|
|
$( '.widget-in-question' ).removeClass( 'widget-in-question' );
|
2015-06-30 20:58:24 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes a Sidebar that was previously closed, but opened by dragging a Widget over it.
|
|
|
|
*
|
|
|
|
* Used when a Widget gets dragged in/out of the Sidebar and never dropped.
|
|
|
|
*
|
2020-07-27 19:35:02 -04:00
|
|
|
* @param {Object} event jQuery event object.
|
2015-06-30 20:58:24 -04:00
|
|
|
*/
|
2017-09-27 12:29:44 -04:00
|
|
|
closeSidebar: function( event ) {
|
|
|
|
this.hoveredSidebar
|
|
|
|
.addClass( 'closed' )
|
|
|
|
.find( '.handlediv' ).attr( 'aria-expanded', 'false' );
|
|
|
|
|
|
|
|
$( event.target ).css( 'min-height', '' );
|
2015-06-30 20:58:24 -04:00
|
|
|
this.hoveredSidebar = null;
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-09 20:32:31 -04:00
|
|
|
$document.ready( function(){ wpWidgets.init(); } );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
})(jQuery);
|
Script Loader: Add backward compatibility for JavaScript i18n globals and properties deprecated in WordPress 5.5.
The recommended approach for any plugins using these globals or properties is to switch to the newer `wp.i18n` functions.
In the meantime, this ensures that accessing any of these globals does not break the rest of the code on the page, and an appropriate warning message is logged to the JavaScript console.
Follow-up to: https://core.trac.wordpress.org/query?summary=~wp.i18n&milestone=5.5
Props omarreiss, peterwilsoncc, kbjohnson90, johnbillion, TimothyBlynJacobs, joostdevalk, ocean90, desrosj, SergeyBiryukov.
Fixes #51123.
Built from https://develop.svn.wordpress.org/trunk@48923
git-svn-id: http://core.svn.wordpress.org/trunk@48685 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-08-31 16:30:03 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removed in 5.5.0, needed for back-compatibility.
|
|
|
|
*
|
|
|
|
* @since 4.9.0
|
|
|
|
* @deprecated 5.5.0
|
|
|
|
*
|
|
|
|
* @type {object}
|
|
|
|
*/
|
|
|
|
wpWidgets.l10n = wpWidgets.l10n || {
|
|
|
|
save: '',
|
|
|
|
saved: '',
|
|
|
|
saveAlert: '',
|
|
|
|
widgetAdded: ''
|
|
|
|
};
|
|
|
|
|
2020-10-14 17:13:08 -04:00
|
|
|
wpWidgets.l10n = window.wp.deprecateL10nObject( 'wpWidgets.l10n', wpWidgets.l10n, '5.5.0' );
|