diff --git a/wp-admin/js/customize-widgets.js b/wp-admin/js/customize-widgets.js
index 290142d481..fc6028b65f 100644
--- a/wp-admin/js/customize-widgets.js
+++ b/wp-admin/js/customize-widgets.js
@@ -3,8 +3,12 @@
var WidgetCustomizer = ( function ($) {
'use strict';
- var customize = wp.customize;
- var self = {
+ var Widget,
+ WidgetCollection,
+ Sidebar,
+ SidebarCollection,
+ OldPreviewer,
+ customize = wp.customize, self = {
update_widget_ajax_action: null,
update_widget_nonce_value: null,
update_widget_nonce_post_key: null,
@@ -39,7 +43,7 @@ var WidgetCustomizer = ( function ($) {
/**
* Set up model
*/
- var Widget = self.Widget = Backbone.Model.extend( {
+ Widget = self.Widget = Backbone.Model.extend( {
id: null,
temp_id: null,
classname: null,
@@ -55,12 +59,13 @@ var WidgetCustomizer = ( function ($) {
width: null,
height: null
} );
- var WidgetCollection = self.WidgetCollection = Backbone.Collection.extend( {
+
+ WidgetCollection = self.WidgetCollection = Backbone.Collection.extend( {
model: Widget
} );
self.available_widgets = new WidgetCollection( self.available_widgets );
- var Sidebar = self.Sidebar = Backbone.Model.extend( {
+ Sidebar = self.Sidebar = Backbone.Model.extend( {
after_title: null,
after_widget: null,
before_title: null,
@@ -71,7 +76,8 @@ var WidgetCustomizer = ( function ($) {
name: null,
is_rendered: false
} );
- var SidebarCollection = self.SidebarCollection = Backbone.Collection.extend( {
+
+ SidebarCollection = self.SidebarCollection = Backbone.Collection.extend( {
model: Sidebar
} );
self.registered_sidebars = new SidebarCollection( self.registered_sidebars );
@@ -99,13 +105,13 @@ var WidgetCustomizer = ( function ($) {
var show_first_visible_sidebar = function () {
self.registered_sidebars.off( 'change:is_rendered', show_first_visible_sidebar );
- var first_rendered_sidebar = self.registered_sidebars.find( function ( sidebar ) {
+ var section, first_rendered_sidebar = self.registered_sidebars.find( function ( sidebar ) {
return sidebar.get( 'is_rendered' );
} );
if ( ! first_rendered_sidebar ) {
return;
}
- var section = $( '#accordion-section-sidebar-widgets-' + first_rendered_sidebar.get( 'id' ) );
+ section = $( '#accordion-section-sidebar-widgets-' + first_rendered_sidebar.get( 'id' ) );
if ( ! section.hasClass( 'open' ) ) {
section.find( '.accordion-section-title' ).trigger( 'click' );
}
@@ -138,11 +144,14 @@ var WidgetCustomizer = ( function ($) {
* Update ordering of widget control forms when the setting is updated
*/
_setupModel: function() {
- var control = this;
- var registered_sidebar = self.registered_sidebars.get( control.params.sidebar_id );
+ var control = this,
+ registered_sidebar = self.registered_sidebars.get( control.params.sidebar_id );
control.setting.bind( function( new_widget_ids, old_widget_ids ) {
- var removed_widget_ids = _( old_widget_ids ).difference( new_widget_ids );
+ var widget_form_controls,
+ sidebar_widgets_add_control,
+ final_control_containers,
+ removed_widget_ids = _( old_widget_ids ).difference( new_widget_ids );
// Filter out any persistent widget_ids for widgets which have been deactivated
new_widget_ids = _( new_widget_ids ).filter( function ( new_widget_id ) {
@@ -150,7 +159,7 @@ var WidgetCustomizer = ( function ($) {
return !! self.available_widgets.findWhere( { id_base: parsed_widget_id.id_base } );
} );
- var widget_form_controls = _( new_widget_ids ).map( function ( widget_id ) {
+ widget_form_controls = _( new_widget_ids ).map( function ( widget_id ) {
var widget_form_control = self.getWidgetFormControlForWidget( widget_id );
if ( ! widget_form_control ) {
widget_form_control = control.addWidget( widget_id );
@@ -160,18 +169,18 @@ var WidgetCustomizer = ( function ($) {
// Sort widget controls to their new positions
widget_form_controls.sort( function ( a, b ) {
- var a_index = new_widget_ids.indexOf( a.params.widget_id );
- var b_index = new_widget_ids.indexOf( b.params.widget_id );
+ var a_index = new_widget_ids.indexOf( a.params.widget_id ),
+ b_index = new_widget_ids.indexOf( b.params.widget_id );
if ( a_index === b_index ) {
return 0;
}
return a_index < b_index ? -1 : 1;
} );
- var sidebar_widgets_add_control = control.section_content.find( '.customize-control-sidebar_widgets' );
+ sidebar_widgets_add_control = control.section_content.find( '.customize-control-sidebar_widgets' );
// Append the controls to put them in the right order
- var final_control_containers = _( widget_form_controls ).map( function( widget_form_controls ) {
+ final_control_containers = _( widget_form_controls ).map( function( widget_form_controls ) {
return widget_form_controls.container[0];
} );
@@ -189,15 +198,21 @@ var WidgetCustomizer = ( function ($) {
// Using setTimeout so that when moving a widget to another sidebar, the other sidebars_widgets settings get a chance to update
setTimeout( function () {
- var is_present_in_another_sidebar = false;
+ var is_present_in_another_sidebar = false,
+ removed_control,
+ was_dragged_to_another_sidebar,
+ inactive_widgets,
+ removed_id_base,
+ widget;
// Check if the widget is in another sidebar
wp.customize.each( function ( other_setting ) {
if ( other_setting.id === control.setting.id || 0 !== other_setting.id.indexOf( 'sidebars_widgets[' ) || other_setting.id === 'sidebars_widgets[wp_inactive_widgets]' ) {
return;
}
- var other_sidebar_widgets = other_setting();
- var i = other_sidebar_widgets.indexOf( removed_widget_id );
+ var other_sidebar_widgets = other_setting(), i;
+
+ i = other_sidebar_widgets.indexOf( removed_widget_id );
if ( -1 !== i ) {
is_present_in_another_sidebar = true;
}
@@ -208,10 +223,10 @@ var WidgetCustomizer = ( function ($) {
return;
}
- var removed_control = self.getWidgetFormControlForWidget( removed_widget_id );
+ removed_control = self.getWidgetFormControlForWidget( removed_widget_id );
// Detect if widget control was dragged to another sidebar
- var was_dragged_to_another_sidebar = (
+ was_dragged_to_another_sidebar = (
removed_control &&
$.contains( document, removed_control.container[0] ) &&
! $.contains( control.section_content[0], removed_control.container[0] )
@@ -226,14 +241,14 @@ var WidgetCustomizer = ( function ($) {
// Move widget to inactive widgets sidebar (move it to trash) if has been previously saved
// This prevents the inactive widgets sidebar from overflowing with throwaway widgets
if ( self.saved_widget_ids[removed_widget_id] ) {
- var inactive_widgets = wp.customize.value( 'sidebars_widgets[wp_inactive_widgets]' )().slice();
+ inactive_widgets = wp.customize.value( 'sidebars_widgets[wp_inactive_widgets]' )().slice();
inactive_widgets.push( removed_widget_id );
wp.customize.value( 'sidebars_widgets[wp_inactive_widgets]' )( _( inactive_widgets ).unique() );
}
// Make old single widget available for adding again
- var removed_id_base = parse_widget_id( removed_widget_id ).id_base;
- var widget = self.available_widgets.findWhere( { id_base: removed_id_base } );
+ removed_id_base = parse_widget_id( removed_widget_id ).id_base;
+ widget = self.available_widgets.findWhere( { id_base: removed_id_base } );
if ( widget && ! widget.get( 'is_multi' ) ) {
widget.set( 'is_disabled', false );
}
@@ -250,8 +265,8 @@ var WidgetCustomizer = ( function ($) {
// Show the sidebar section when it becomes visible
registered_sidebar.on( 'change:is_rendered', function ( ) {
- var section_selector = '#accordion-section-sidebar-widgets-' + this.get( 'id' );
- var section = $( section_selector );
+ var section_selector = '#accordion-section-sidebar-widgets-' + this.get( 'id' ), section;
+ section = $( section_selector );
if ( this.get( 'is_rendered' ) ) {
section.stop().slideDown( function () {
$( this ).css( 'height', 'auto' ); // so that the .accordion-section-content won't overflow
@@ -283,8 +298,8 @@ var WidgetCustomizer = ( function ($) {
axis: 'y',
connectWith: '.accordion-section-content:has(.customize-control-sidebar_widgets)',
update: function () {
- var widget_container_ids = control.section_content.sortable( 'toArray' );
- var widget_ids = $.map( widget_container_ids, function ( widget_container_id ) {
+ var widget_container_ids = control.section_content.sortable( 'toArray' ), widget_ids;
+ widget_ids = $.map( widget_container_ids, function ( widget_container_id ) {
return $( '#' + widget_container_id ).find( ':input[name=widget-id]' ).val();
} );
control.setting( widget_ids );
@@ -392,10 +407,12 @@ var WidgetCustomizer = ( function ($) {
* @return {wp.customize.controlConstructor.widget_form[]}
*/
getWidgetFormControls: function () {
- var control = this;
- var form_controls = _( control.setting() ).map( function ( widget_id ) {
- var setting_id = widget_id_to_setting_id( widget_id );
- var form_control = customize.control( setting_id );
+ var control = this, form_controls;
+
+ form_controls = _( control.setting() ).map( function ( widget_id ) {
+ var setting_id = widget_id_to_setting_id( widget_id ),
+ form_control = customize.control( setting_id );
+
if ( ! form_control ) {
throw new Error( 'Unable to find widget_form control for ' + widget_id );
}
@@ -409,11 +426,21 @@ var WidgetCustomizer = ( function ($) {
* @returns {object} widget_form control instance
*/
addWidget: function ( widget_id ) {
- var control = this;
- var parsed_widget_id = parse_widget_id( widget_id );
- var widget_number = parsed_widget_id.number;
- var widget_id_base = parsed_widget_id.id_base;
- var widget = self.available_widgets.findWhere( {id_base: widget_id_base} );
+ var control = this,
+ control_html,
+ customize_control_type = 'widget_form',
+ customize_control,
+ parsed_widget_id = parse_widget_id( widget_id ),
+ widget_number = parsed_widget_id.number,
+ widget_id_base = parsed_widget_id.id_base,
+ widget = self.available_widgets.findWhere( {id_base: widget_id_base} ),
+ setting_id,
+ is_existing_widget,
+ Constructor,
+ widget_form_control,
+ sidebar_widgets,
+ setting_args;
+
if ( ! widget ) {
throw new Error( 'Widget unexpectedly not found.' );
}
@@ -427,7 +454,7 @@ var WidgetCustomizer = ( function ($) {
widget_number = widget.get( 'multi_number' );
}
- var control_html = $( '#widget-tpl-' + widget.get( 'id' ) ).html();
+ control_html = $( '#widget-tpl-' + widget.get( 'id' ) ).html();
if ( widget.get( 'is_multi' ) ) {
control_html = control_html.replace( /<[^<>]+>/g, function ( m ) {
return m.replace( /__i__|%i%/g, widget_number );
@@ -436,8 +463,7 @@ var WidgetCustomizer = ( function ($) {
widget.set( 'is_disabled', true ); // Prevent single widget from being added again now
}
- var customize_control_type = 'widget_form';
- var customize_control = $( '
' );
+ customize_control = $( '' );
customize_control.addClass( 'customize-control' );
customize_control.addClass( 'customize-control-' + customize_control_type );
customize_control.append( $( control_html ) );
@@ -449,7 +475,7 @@ var WidgetCustomizer = ( function ($) {
widget_id = customize_control.find( '[name="widget-id"]' ).val();
customize_control.hide(); // to be slid-down below
- var setting_id = 'widget_' + widget.get( 'id_base' );
+ setting_id = 'widget_' + widget.get( 'id_base' );
if ( widget.get( 'is_multi' ) ) {
setting_id += '[' + widget_number + ']';
}
@@ -458,17 +484,17 @@ var WidgetCustomizer = ( function ($) {
control.container.after( customize_control );
// Only create setting if it doesn't already exist (if we're adding a pre-existing inactive widget)
- var is_existing_widget = wp.customize.has( setting_id );
+ is_existing_widget = wp.customize.has( setting_id );
if ( ! is_existing_widget ) {
- var setting_args = {
+ setting_args = {
transport: 'refresh',
previewer: control.setting.previewer
};
wp.customize.create( setting_id, setting_id, {}, setting_args );
}
- var Constructor = wp.customize.controlConstructor[customize_control_type];
- var widget_form_control = new Constructor( setting_id, {
+ Constructor = wp.customize.controlConstructor[customize_control_type];
+ widget_form_control = new Constructor( setting_id, {
params: {
settings: {
'default': setting_id
@@ -494,8 +520,8 @@ var WidgetCustomizer = ( function ($) {
if ( 0 !== other_setting.id.indexOf( 'sidebars_widgets[' ) ) {
return;
}
- var other_sidebar_widgets = other_setting().slice();
- var i = other_sidebar_widgets.indexOf( widget_id );
+ var other_sidebar_widgets = other_setting().slice(), i;
+ i = other_sidebar_widgets.indexOf( widget_id );
if ( -1 !== i ) {
other_sidebar_widgets.splice( i );
other_setting( other_sidebar_widgets );
@@ -503,7 +529,7 @@ var WidgetCustomizer = ( function ($) {
} );
// Add widget to this sidebar
- var sidebar_widgets = control.setting().slice();
+ sidebar_widgets = control.setting().slice();
if ( -1 === sidebar_widgets.indexOf( widget_id ) ) {
sidebar_widgets.push( widget_id );
control.setting( sidebar_widgets );
@@ -560,9 +586,10 @@ var WidgetCustomizer = ( function ($) {
_default: {},
rss: {
formUpdated: function ( serialized_form ) {
- var control = this;
- var old_widget_error = control.container.find( '.widget-error:first' );
- var new_widget_error = serialized_form.find( '.widget-error:first' );
+ var control = this,
+ old_widget_error = control.container.find( '.widget-error:first' ),
+ new_widget_error = serialized_form.find( '.widget-error:first' );
+
if ( old_widget_error.length && new_widget_error.length ) {
old_widget_error.replaceWith( new_widget_error );
} else if ( old_widget_error.length ) {
@@ -580,8 +607,8 @@ var WidgetCustomizer = ( function ($) {
* @param name
*/
hook: function ( name ) {
- var args = Array.prototype.slice.call( arguments, 1 );
- var handler;
+ var args = Array.prototype.slice.call( arguments, 1 ), handler;
+
if ( this.hooks[this.params.widget_id_base] && this.hooks[this.params.widget_id_base][name] ) {
handler = this.hooks[this.params.widget_id_base][name];
} else if ( this.hooks._default[name] ) {
@@ -596,10 +623,10 @@ var WidgetCustomizer = ( function ($) {
* Handle changes to the setting
*/
_setupModel: function () {
- var control = this;
+ var control = this, remember_saved_widget_id;
// Remember saved widgets so we know which to trash (move to inactive widgets sidebar)
- var remember_saved_widget_id = function () {
+ remember_saved_widget_id = function () {
self.saved_widget_ids[control.params.widget_id] = true;
};
wp.customize.bind( 'ready', remember_saved_widget_id );
@@ -620,12 +647,18 @@ var WidgetCustomizer = ( function ($) {
* Add special behaviors for wide widget controls
*/
_setupWideWidget: function () {
- var control = this;
+ var control = this,
+ widget_inside,
+ customize_sidebar,
+ position_widget,
+ theme_controls_container;
+
if ( ! control.params.is_wide ) {
return;
}
- var widget_inside = control.container.find( '.widget-inside' );
- var customize_sidebar = $( '.wp-full-overlay-sidebar-content:first' );
+
+ widget_inside = control.container.find( '.widget-inside' );
+ customize_sidebar = $( '.wp-full-overlay-sidebar-content:first' );
control.container.addClass( 'wide-widget-control' );
control.container.find( '.widget-content:first' ).css( {
@@ -639,16 +672,20 @@ var WidgetCustomizer = ( function ($) {
* widget-top is scrolled out of view, keep the widget-top in view;
* likewise, don't allow the widget to drop off the bottom of the window.
*/
- var position_widget = function () {
- var offset_top = control.container.offset().top;
- var height = widget_inside.outerHeight();
- var top = Math.max( offset_top, 0 );
- var max_top = $( window ).height() - height;
+ position_widget = function () {
+ var offset_top = control.container.offset().top,
+ height,
+ top,
+ max_top;
+
+ height = widget_inside.outerHeight();
+ top = Math.max( offset_top, 0 );
+ max_top = $( window ).height() - height;
top = Math.min( top, max_top );
widget_inside.css( 'top', top );
};
- var theme_controls_container = $( '#customize-theme-controls' );
+ theme_controls_container = $( '#customize-theme-controls' );
control.container.on( 'expand', function () {
customize_sidebar.on( 'scroll', position_widget );
$( window ).on( 'resize', position_widget );
@@ -678,7 +715,8 @@ var WidgetCustomizer = ( function ($) {
* the close button
*/
_setupControlToggle: function() {
- var control = this;
+ var control = this, close_btn;
+
control.container.find( '.widget-top' ).on( 'click', function ( e ) {
e.preventDefault();
var sidebar_widgets_control = control.getSidebarWidgetsControl();
@@ -688,7 +726,7 @@ var WidgetCustomizer = ( function ($) {
control.toggleForm();
} );
- var close_btn = control.container.find( '.widget-control-close' );
+ close_btn = control.container.find( '.widget-control-close' );
// @todo Hitting Enter on this link does nothing; will be resolved in core with
close_btn.on( 'click', function ( e ) {
e.preventDefault();
@@ -701,10 +739,12 @@ var WidgetCustomizer = ( function ($) {
* Update the title of the form if a title field is entered
*/
_setupWidgetTitle: function () {
- var control = this;
- var update_title = function () {
- var title = control.setting().title;
- var in_widget_title = control.container.find( '.in-widget-title' );
+ var control = this, update_title;
+
+ update_title = function () {
+ var title = control.setting().title,
+ in_widget_title = control.container.find( '.in-widget-title' );
+
if ( title ) {
in_widget_title.text( ': ' + title );
} else {
@@ -719,14 +759,18 @@ var WidgetCustomizer = ( function ($) {
* Set up the widget-reorder-nav
*/
_setupReorderUI: function () {
- var control = this;
+ var control = this,
+ select_sidebar_item,
+ move_widget_area,
+ reorder_nav,
+ update_available_sidebars;
/**
* select the provided sidebar list item in the move widget area
*
* @param {jQuery} li
*/
- var select_sidebar_item = function ( li ) {
+ select_sidebar_item = function ( li ) {
li.siblings( '.selected' ).removeClass( 'selected' );
li.addClass( 'selected' );
var is_self_sidebar = ( li.data( 'id' ) === control.params.sidebar_id );
@@ -737,7 +781,7 @@ var WidgetCustomizer = ( function ($) {
* Add the widget reordering elements to the widget control
*/
control.container.find( '.widget-title-action' ).after( $( self.tpl.widget_reorder_nav ) );
- var move_widget_area = $(
+ move_widget_area = $(
_.template( self.tpl.move_widget_area, {
sidebars: _( self.registered_sidebars.toArray() ).pluck( 'attributes' )
} )
@@ -747,15 +791,18 @@ var WidgetCustomizer = ( function ($) {
/**
* Update available sidebars when their rendered state changes
*/
- var update_available_sidebars = function () {
- var sidebar_items = move_widget_area.find( 'li' );
- var self_sidebar_item = sidebar_items.filter( function(){
+ update_available_sidebars = function () {
+ var sidebar_items = move_widget_area.find( 'li' ), self_sidebar_item;
+ self_sidebar_item = sidebar_items.filter( function(){
return $( this ).data( 'id' ) === control.params.sidebar_id;
} );
sidebar_items.each( function () {
- var li = $( this );
- var sidebar_id = li.data( 'id' );
- var sidebar_model = self.registered_sidebars.get( sidebar_id );
+ var li = $( this ),
+ sidebar_id,
+ sidebar_model;
+
+ sidebar_id = li.data( 'id' );
+ sidebar_model = self.registered_sidebars.get( sidebar_id );
li.toggle( sidebar_model.get( 'is_rendered' ) );
if ( li.hasClass( 'selected' ) && ! sidebar_model.get( 'is_rendered' ) ) {
select_sidebar_item( self_sidebar_item );
@@ -768,7 +815,7 @@ var WidgetCustomizer = ( function ($) {
/**
* Handle clicks for up/down/move on the reorder nav
*/
- var reorder_nav = control.container.find( '.widget-reorder-nav' );
+ reorder_nav = control.container.find( '.widget-reorder-nav' );
reorder_nav.find( '.move-widget, .move-widget-down, .move-widget-up' ).on( 'click keypress', function ( event ) {
if ( event.type === 'keypress' && ( event.which !== 13 && event.which !== 32 ) ) {
return;
@@ -778,9 +825,10 @@ var WidgetCustomizer = ( function ($) {
if ( $( this ).is( '.move-widget' ) ) {
control.toggleWidgetMoveArea();
} else {
- var is_move_down = $( this ).is( '.move-widget-down' );
- var is_move_up = $( this ).is( '.move-widget-up' );
- var i = control.getWidgetSidebarPosition();
+ var is_move_down = $( this ).is( '.move-widget-down' ),
+ is_move_up = $( this ).is( '.move-widget-up' ),
+ i = control.getWidgetSidebarPosition();
+
if ( ( is_move_up && i === 0 ) || ( is_move_down && i === control.getSidebarWidgetsControl().setting().length - 1 ) ) {
return;
}
@@ -812,14 +860,20 @@ var WidgetCustomizer = ( function ($) {
control.container.find( '.move-widget-btn' ).click( function () {
control.getSidebarWidgetsControl().toggleReordering( false );
- var old_sidebar_id = control.params.sidebar_id;
- var new_sidebar_id = control.container.find( '.widget-area-select li.selected' ).data( 'id' );
- var old_sidebar_widgets_setting = customize( 'sidebars_widgets[' + old_sidebar_id + ']' );
- var new_sidebar_widgets_setting = customize( 'sidebars_widgets[' + new_sidebar_id + ']' );
- var old_sidebar_widget_ids = Array.prototype.slice.call( old_sidebar_widgets_setting() );
- var new_sidebar_widget_ids = Array.prototype.slice.call( new_sidebar_widgets_setting() );
+ var old_sidebar_id = control.params.sidebar_id,
+ new_sidebar_id = control.container.find( '.widget-area-select li.selected' ).data( 'id' ),
+ old_sidebar_widgets_setting,
+ new_sidebar_widgets_setting,
+ old_sidebar_widget_ids,
+ new_sidebar_widget_ids,
+ i;
- var i = control.getWidgetSidebarPosition();
+ old_sidebar_widgets_setting = customize( 'sidebars_widgets[' + old_sidebar_id + ']' );
+ new_sidebar_widgets_setting = customize( 'sidebars_widgets[' + new_sidebar_id + ']' );
+ old_sidebar_widget_ids = Array.prototype.slice.call( old_sidebar_widgets_setting() );
+ new_sidebar_widget_ids = Array.prototype.slice.call( new_sidebar_widgets_setting() );
+
+ i = control.getWidgetSidebarPosition();
old_sidebar_widget_ids.splice( i, 1 );
new_sidebar_widget_ids.push( control.params.widget_id );
@@ -857,12 +911,15 @@ var WidgetCustomizer = ( function ($) {
* Set up event handlers for widget updating
*/
_setupUpdateUI: function () {
- var control = this;
+ var control = this,
+ widget_content,
+ save_btn,
+ trigger_save;
- var widget_content = control.container.find( '.widget-content' );
+ widget_content = control.container.find( '.widget-content' );
// Configure update button
- var save_btn = control.container.find( '.widget-control-save' );
+ save_btn = control.container.find( '.widget-control-save' );
save_btn.val( self.i18n.save_btn_label );
save_btn.attr( 'title', self.i18n.save_btn_tooltip );
save_btn.removeClass( 'button-primary' ).addClass( 'button-secondary' );
@@ -871,7 +928,7 @@ var WidgetCustomizer = ( function ($) {
control.updateWidget();
} );
- var trigger_save = _.debounce( function () {
+ trigger_save = _.debounce( function () {
// @todo For compatibility with other plugins, should we trigger a click event? What about form submit event?
control.updateWidget();
}, 250 );
@@ -912,10 +969,12 @@ var WidgetCustomizer = ( function ($) {
* Set up event handlers for widget removal
*/
_setupRemoveUI: function () {
- var control = this;
+ var control = this,
+ remove_btn,
+ replace_delete_with_remove;
// Configure remove button
- var remove_btn = control.container.find( 'a.widget-control-remove' );
+ remove_btn = control.container.find( 'a.widget-control-remove' );
// @todo Hitting Enter on this link does nothing; will be resolved in core with
remove_btn.on( 'click', function ( e ) {
e.preventDefault();
@@ -931,12 +990,15 @@ var WidgetCustomizer = ( function ($) {
}
control.container.slideUp( function() {
- var sidebars_widgets_control = self.getSidebarWidgetControlContainingWidget( control.params.widget_id );
+ var sidebars_widgets_control = self.getSidebarWidgetControlContainingWidget( control.params.widget_id ),
+ sidebar_widget_ids,
+ i;
+
if ( ! sidebars_widgets_control ) {
throw new Error( 'Unable to find sidebars_widgets_control' );
}
- var sidebar_widget_ids = sidebars_widgets_control.setting().slice();
- var i = sidebar_widget_ids.indexOf( control.params.widget_id );
+ sidebar_widget_ids = sidebars_widgets_control.setting().slice();
+ i = sidebar_widget_ids.indexOf( control.params.widget_id );
if ( -1 === i ) {
throw new Error( 'Widget is not in sidebar' );
}
@@ -946,7 +1008,7 @@ var WidgetCustomizer = ( function ($) {
} );
} );
- var replace_delete_with_remove = function () {
+ replace_delete_with_remove = function () {
remove_btn.text( self.i18n.remove_btn_label ); // wp_widget_control() outputs the link as "Delete"
remove_btn.attr( 'title', self.i18n.remove_btn_tooltip );
};
@@ -1007,9 +1069,10 @@ var WidgetCustomizer = ( function ($) {
* @return {wp.customize.controlConstructor.sidebar_widgets[]}
*/
getSidebarWidgetsControl: function () {
- var control = this;
- var setting_id = 'sidebars_widgets[' + control.params.sidebar_id + ']';
- var sidebar_widgets_control = customize.control( setting_id );
+ var control = this, setting_id, sidebar_widgets_control;
+
+ setting_id = 'sidebars_widgets[' + control.params.sidebar_id + ']';
+ sidebar_widgets_control = customize.control( setting_id );
if ( ! sidebar_widgets_control ) {
throw new Error( 'Unable to locate sidebar_widgets control for ' + control.params.sidebar_id );
}
@@ -1026,23 +1089,33 @@ var WidgetCustomizer = ( function ($) {
* @param {Boolean} [args.ignore_active_element=false] Whether or not updating a field will be deferred if focus is still on the element.
*/
updateWidget: function ( args ) {
- var control = this;
+ var control = this,
+ instance_override,
+ complete_callback,
+ update_number,
+ widget_content,
+ element_id_to_refocus = null,
+ active_input_selection_start = null,
+ active_input_selection_end = null,
+ params = {},
+ data,
+ inputs,
+ jqxhr;
+
args = $.extend( {
instance: null,
complete: null,
ignore_active_element: false
}, args );
- var instance_override = args.instance;
- var complete_callback = args.complete;
+
+ instance_override = args.instance;
+ complete_callback = args.complete;
control._update_count += 1;
- var update_number = control._update_count;
+ update_number = control._update_count;
- var widget_content = control.container.find( '.widget-content' );
+ widget_content = control.container.find( '.widget-content' );
- var element_id_to_refocus = null;
- var active_input_selection_start = null;
- var active_input_selection_end = null;
// @todo Support more selectors than IDs?
if ( $.contains( control.container[0], document.activeElement ) && $( document.activeElement ).is( '[id]' ) ) {
element_id_to_refocus = $( document.activeElement ).prop( 'id' );
@@ -1057,19 +1130,19 @@ var WidgetCustomizer = ( function ($) {
control.container.addClass( 'widget-form-loading' );
control.container.addClass( 'previewer-loading' );
- var params = {};
+ params = {};
params.action = self.update_widget_ajax_action;
params[self.update_widget_nonce_post_key] = self.update_widget_nonce_value;
- var data = $.param( params );
- var inputs = widget_content.find( ':input, option' );
+ data = $.param( params );
+ inputs = widget_content.find( ':input, option' );
// Store the value we're submitting in data so that when the response comes back,
// we know if it got sanitized; if there is no difference in the sanitized value,
// then we do not need to touch the UI and mess up the user's ongoing editing.
inputs.each( function () {
- var input = $( this );
- var property = control._getInputStatePropertyName( this );
+ var input = $( this ),
+ property = control._getInputStatePropertyName( this );
input.data( 'state' + update_number, input.prop( property ) );
} );
@@ -1080,22 +1153,32 @@ var WidgetCustomizer = ( function ($) {
}
data += '&' + widget_content.find( '~ :input' ).serialize();
- console.log( wp.ajax.settings.url, data );
- var jqxhr = $.post( wp.ajax.settings.url, data, function ( r ) {
+ window.console && window.console.log( wp.ajax.settings.url, data );
+ jqxhr = $.post( wp.ajax.settings.url, data, function ( r ) {
+ var message,
+ sanitized_form,
+ sanitized_inputs,
+ has_same_inputs_in_response,
+ is_instance_identical;
+
if ( r.success ) {
- var sanitized_form = $( '' + r.data.form + '
' );
+ sanitized_form = $( '' + r.data.form + '
' );
+
control.hook( 'formUpdate', sanitized_form );
- var sanitized_inputs = sanitized_form.find( ':input, option' );
- var has_same_inputs_in_response = control._getInputsSignature( inputs ) === control._getInputsSignature( sanitized_inputs );
+ sanitized_inputs = sanitized_form.find( ':input, option' );
+ has_same_inputs_in_response = control._getInputsSignature( inputs ) === control._getInputsSignature( sanitized_inputs );
if ( has_same_inputs_in_response ) {
inputs.each( function ( i ) {
- var input = $( this );
- var sanitized_input = $( sanitized_inputs[i] );
- var property = control._getInputStatePropertyName( this );
- var state = input.data( 'state' + update_number );
- var sanitized_state = sanitized_input.prop( property );
+ var input = $( this ),
+ sanitized_input = $( sanitized_inputs[i] ),
+ property = control._getInputStatePropertyName( this ),
+ state,
+ sanitized_state;
+
+ state = input.data( 'state' + update_number );
+ sanitized_state = sanitized_input.prop( property );
input.data( 'sanitized', sanitized_state );
if ( state !== sanitized_state ) {
@@ -1132,7 +1215,7 @@ var WidgetCustomizer = ( function ($) {
* needing to be rendered, and so we can preempt the event for the
* preview finishing loading.
*/
- var is_instance_identical = _( control.setting() ).isEqual( r.data.instance );
+ is_instance_identical = _( control.setting() ).isEqual( r.data.instance );
if ( is_instance_identical ) {
control.container.removeClass( 'previewer-loading' );
} else {
@@ -1145,8 +1228,8 @@ var WidgetCustomizer = ( function ($) {
complete_callback.call( control, null, { no_change: is_instance_identical, ajax_finished: true } );
}
} else {
- console.log( r );
- var message = 'FAIL';
+ window.console && window.console.log( r );
+ message = 'FAIL';
if ( r.data && r.data.message ) {
message = r.data.message;
}
@@ -1203,9 +1286,10 @@ var WidgetCustomizer = ( function ($) {
* @param {boolean|undefined} [do_expand] If not supplied, will be inverse of current visibility
*/
toggleForm: function ( do_expand ) {
- var control = this;
- var widget = control.container.find( 'div.widget:first' );
- var inside = widget.find( '.widget-inside:first' );
+ var control = this, widget, inside, complete;
+
+ widget = control.container.find( 'div.widget:first' );
+ inside = widget.find( '.widget-inside:first' );
if ( typeof do_expand === 'undefined' ) {
do_expand = ! inside.is( ':visible' );
}
@@ -1215,7 +1299,7 @@ var WidgetCustomizer = ( function ($) {
return;
}
- var complete;
+ complete;
if ( do_expand ) {
// Close all other widget controls before expanding this one
wp.customize.control.each( function ( other_control ) {
@@ -1273,9 +1357,12 @@ var WidgetCustomizer = ( function ($) {
* @returns {Number}
*/
getWidgetSidebarPosition: function () {
- var control = this;
- var sidebar_widget_ids = control.getSidebarWidgetsControl().setting();
- var position = sidebar_widget_ids.indexOf( control.params.widget_id );
+ var control = this,
+ sidebar_widget_ids,
+ position;
+
+ sidebar_widget_ids = control.getSidebarWidgetsControl().setting();
+ position = sidebar_widget_ids.indexOf( control.params.widget_id );
if ( position === -1 ) {
throw new Error( 'Widget was unexpectedly not present in the sidebar.' );
}
@@ -1302,12 +1389,17 @@ var WidgetCustomizer = ( function ($) {
* @param {Number} offset 1|-1
*/
_moveWidgetByOne: function ( offset ) {
- var control = this;
- var i = control.getWidgetSidebarPosition();
+ var control = this,
+ i,
+ sidebar_widgets_setting,
+ sidebar_widget_ids,
+ adjacent_widget_id;
- var sidebar_widgets_setting = control.getSidebarWidgetsControl().setting;
- var sidebar_widget_ids = Array.prototype.slice.call( sidebar_widgets_setting() ); // clone
- var adjacent_widget_id = sidebar_widget_ids[i + offset];
+ i = control.getWidgetSidebarPosition();
+
+ sidebar_widgets_setting = control.getSidebarWidgetsControl().setting;
+ sidebar_widget_ids = Array.prototype.slice.call( sidebar_widgets_setting() ); // clone
+ adjacent_widget_id = sidebar_widget_ids[i + offset];
sidebar_widget_ids[i + offset] = control.params.widget_id;
sidebar_widget_ids[i] = adjacent_widget_id;
@@ -1320,8 +1412,8 @@ var WidgetCustomizer = ( function ($) {
* @param {Boolean} [toggle]
*/
toggleWidgetMoveArea: function ( toggle ) {
- var control = this;
- var move_widget_area = control.container.find( '.move-widget-area' );
+ var control = this, move_widget_area;
+ move_widget_area = control.container.find( '.move-widget-area' );
if ( typeof toggle === 'undefined' ) {
toggle = ! move_widget_area.hasClass( 'active' );
}
@@ -1341,8 +1433,8 @@ var WidgetCustomizer = ( function ($) {
* @return {jQuery}
*/
getPreviewWidgetElement: function () {
- var control = this;
- var widget_customizer_preview = self.getPreviewWindow().WidgetCustomizerPreview;
+ var control = this,
+ widget_customizer_preview = self.getPreviewWindow().WidgetCustomizerPreview;
return widget_customizer_preview.getSidebarWidgetElement( control.params.sidebar_id, control.params.widget_id );
},
@@ -1357,8 +1449,8 @@ var WidgetCustomizer = ( function ($) {
* Highlight the widget control and section
*/
highlightSectionAndControl: function() {
- var control = this;
- var target_element;
+ var control = this, target_element;
+
if ( control.container.is( ':hidden' ) ) {
target_element = control.container.closest( '.control-section' );
} else {
@@ -1376,9 +1468,10 @@ var WidgetCustomizer = ( function ($) {
* Add the widget-customizer-highlighted-widget class to the widget for 500ms
*/
highlightPreviewWidget: function () {
- var control = this;
- var widget_el = control.getPreviewWidgetElement();
- var root_el = widget_el.closest( 'html' );
+ var control = this, widget_el, root_el;
+
+ widget_el = control.getPreviewWidgetElement();
+ root_el = widget_el.closest( 'html' );
root_el.find( '.widget-customizer-highlighted-widget' ).removeClass( 'widget-customizer-highlighted-widget' );
widget_el.addClass( 'widget-customizer-highlighted-widget' );
setTimeout( function () {
@@ -1391,7 +1484,7 @@ var WidgetCustomizer = ( function ($) {
/**
* Capture the instance of the Previewer since it is private
*/
- var OldPreviewer = wp.customize.Previewer;
+ OldPreviewer = wp.customize.Previewer;
wp.customize.Previewer = OldPreviewer.extend( {
initialize: function( params, options ) {
self.previewer = this;
@@ -1452,11 +1545,12 @@ var WidgetCustomizer = ( function ($) {
* Set up event listeners
*/
setup: function () {
- var panel = this;
+ var panel = this, update_available_widgets_list;
+
panel.container = $( '#available-widgets' );
panel.filter_input = $( '#available-widgets-filter' ).find( 'input' );
- var update_available_widgets_list = function () {
+ update_available_widgets_list = function () {
self.available_widgets.each( function ( widget ) {
var widget_tpl = $( '#widget-tpl-' + widget.id );
widget_tpl.toggle( ! widget.get( 'is_disabled' ) );
@@ -1501,7 +1595,8 @@ var WidgetCustomizer = ( function ($) {
{
filterChildSelector: '.widget-title h4',
after: function () {
- var filter_val = panel.filter_input.val();
+ var filter_val = panel.filter_input.val(),
+ first_visible_widget;
// Remove a widget from being selected if it is no longer visible
if ( panel.selected_widget_tpl && ! panel.selected_widget_tpl.is( ':visible' ) ) {
@@ -1517,7 +1612,7 @@ var WidgetCustomizer = ( function ($) {
// If a filter has been entered and a widget hasn't been selected, select the first one shown
if ( ! panel.selected_widget_tpl && filter_val ) {
- var first_visible_widget = panel.container.find( '> .widget-tpl:visible:first' );
+ first_visible_widget = panel.container.find( '> .widget-tpl:visible:first' );
if ( first_visible_widget.length ) {
panel.select( first_visible_widget );
}
@@ -1533,14 +1628,14 @@ var WidgetCustomizer = ( function ($) {
} );
panel.container.on( 'keydown', function ( event ) {
- var is_enter = ( event.which === 13 );
- var is_esc = ( event.which === 27 );
- var is_down = ( event.which === 40 );
- var is_up = ( event.which === 38 );
- var selected_widget_tpl = null;
- var first_visible_widget = panel.container.find( '> .widget-tpl:visible:first' );
- var last_visible_widget = panel.container.find( '> .widget-tpl:visible:last' );
- var is_input_focused = $( event.target ).is( panel.filter_input );
+ var is_enter = ( event.which === 13 ),
+ is_esc = ( event.which === 27 ),
+ is_down = ( event.which === 40 ),
+ is_up = ( event.which === 38 ),
+ selected_widget_tpl = null,
+ first_visible_widget = panel.container.find( '> .widget-tpl:visible:first' ),
+ last_visible_widget = panel.container.find( '> .widget-tpl:visible:last' ),
+ is_input_focused = $( event.target ).is( panel.filter_input );
if ( is_down || is_up ) {
if ( is_down ) {
@@ -1589,7 +1684,7 @@ var WidgetCustomizer = ( function ($) {
},
submit: function ( widget_tpl ) {
- var panel = this;
+ var panel = this, widget_id, widget;
if ( ! widget_tpl ) {
widget_tpl = panel.selected_widget_tpl;
}
@@ -1598,8 +1693,8 @@ var WidgetCustomizer = ( function ($) {
}
panel.select( widget_tpl );
- var widget_id = $( panel.selected_widget_tpl ).data( 'widget-id' );
- var widget = self.available_widgets.findWhere( {id: widget_id} );
+ widget_id = $( panel.selected_widget_tpl ).data( 'widget-id' );
+ widget = self.available_widgets.findWhere( {id: widget_id} );
if ( ! widget ) {
throw new Error( 'Widget unexpectedly not found.' );
}
@@ -1647,11 +1742,11 @@ var WidgetCustomizer = ( function ($) {
* @returns {Object}
*/
function parse_widget_id( widget_id ) {
- var parsed = {
+ var matches, parsed = {
number: null,
id_base: null
};
- var matches = widget_id.match( /^(.+)-(\d+)$/ );
+ matches = widget_id.match( /^(.+)-(\d+)$/ );
if ( matches ) {
parsed.id_base = matches[1];
parsed.number = parseInt( matches[2], 10 );
@@ -1667,8 +1762,9 @@ var WidgetCustomizer = ( function ($) {
* @returns {String} setting_id
*/
function widget_id_to_setting_id( widget_id ) {
- var parsed = parse_widget_id( widget_id );
- var setting_id = 'widget_' + parsed.id_base;
+ var parsed = parse_widget_id( widget_id ), setting_id;
+
+ setting_id = 'widget_' + parsed.id_base;
if ( parsed.number ) {
setting_id += '[' + parsed.number + ']';
}
@@ -1690,7 +1786,7 @@ var WidgetCustomizer = ( function ($) {
(function($){
$.fn.liveFilter = function(inputEl, filterEl, options){
- var defaults = {
+ var el, filter, defaults = {
filterChildSelector: null,
filter: function(el, val){
return $(el).text().toUpperCase().indexOf(val.toUpperCase()) >= 0;
@@ -1700,18 +1796,19 @@ var WidgetCustomizer = ( function ($) {
};
options = $.extend(defaults, options);
- var el = $(this).find(filterEl);
+ el = $(this).find(filterEl);
if (options.filterChildSelector) {
el = el.find(options.filterChildSelector);
}
- var filter = options.filter;
+ filter = options.filter;
$(inputEl).keyup(function(){
- var val = $(this).val();
- var contains = el.filter(function(){
+ var val = $(this).val(), contains, containsNot;
+
+ contains = el.filter(function(){
return filter(this, val);
});
- var containsNot = el.not(contains);
+ containsNot = el.not(contains);
if (options.filterChildSelector){
contains = contains.parents(filterEl);
containsNot = containsNot.parents(filterEl).hide();
diff --git a/wp-admin/js/customize-widgets.min.js b/wp-admin/js/customize-widgets.min.js
index ac73463aa3..f3125924f9 100644
--- a/wp-admin/js/customize-widgets.min.js
+++ b/wp-admin/js/customize-widgets.min.js
@@ -1 +1 @@
-var WidgetCustomizer=function(a){"use strict";function b(a){var b={number:null,id_base:null},c=a.match(/^(.+)-(\d+)$/);return c?(b.id_base=c[1],b.number=parseInt(c[2],10)):b.id_base=a,b}function c(a){var c=b(a),d="widget_"+c.id_base;return c.number&&(d+="["+c.number+"]"),d}var d=wp.customize,e={update_widget_ajax_action:null,update_widget_nonce_value:null,update_widget_nonce_post_key:null,i18n:{save_btn_label:"",save_btn_tooltip:"",remove_btn_label:"",remove_btn_tooltip:""},available_widgets:[],registered_widgets:[],active_sidebar_control:null,previewer:null,saved_widget_ids:{},registered_sidebars:[],tpl:{move_widget_area:"",widget_reorder_nav:""}};a.extend(e,WidgetCustomizer_exports),"undefined"==typeof window.ajaxurl&&(window.ajaxurl=wp.ajax.settings.url),a("#customize-theme-controls").closest("div:not([id])").attr("id","widgets-right");var f=e.Widget=Backbone.Model.extend({id:null,temp_id:null,classname:null,control_tpl:null,description:null,is_disabled:null,is_multi:null,multi_number:null,name:null,id_base:null,transport:"refresh",params:[],width:null,height:null}),g=e.WidgetCollection=Backbone.Collection.extend({model:f});e.available_widgets=new g(e.available_widgets);var h=e.Sidebar=Backbone.Model.extend({after_title:null,after_widget:null,before_title:null,before_widget:null,"class":null,description:null,id:null,name:null,is_rendered:!1}),i=e.SidebarCollection=Backbone.Collection.extend({model:h});e.registered_sidebars=new i(e.registered_sidebars),e.init=function(){this.showFirstSidebarIfRequested(),this.availableWidgetsPanel.setup()},wp.customize.bind("ready",function(){e.init()}),e.showFirstSidebarIfRequested=function(){if(/widget-customizer=open/.test(location.search)){var b=function(){e.registered_sidebars.off("change:is_rendered",b);var c=e.registered_sidebars.find(function(a){return a.get("is_rendered")});if(c){var d=a("#accordion-section-sidebar-widgets-"+c.get("id"));d.hasClass("open")||d.find(".accordion-section-title").trigger("click"),d[0].scrollIntoView()}};b=_.debounce(b,100),e.registered_sidebars.on("change:is_rendered",b)}},d.controlConstructor.sidebar_widgets=d.Control.extend({ready:function(){var a=this;a.control_section=a.container.closest(".control-section"),a.section_content=a.container.closest(".accordion-section-content"),a._setupModel(),a._setupSortable(),a._setupAddition(),a._applyCardinalOrderClassNames()},_setupModel:function(){var c=this,d=e.registered_sidebars.get(c.params.sidebar_id);c.setting.bind(function(d,f){var g=_(f).difference(d);d=_(d).filter(function(a){var c=b(a);return!!e.available_widgets.findWhere({id_base:c.id_base})});var h=_(d).map(function(a){var b=e.getWidgetFormControlForWidget(a);return b||(b=c.addWidget(a)),b});h.sort(function(a,b){var c=d.indexOf(a.params.widget_id),e=d.indexOf(b.params.widget_id);return c===e?0:e>c?-1:1});var i=c.section_content.find(".customize-control-sidebar_widgets"),j=_(h).map(function(a){return a.container[0]});i.before(j),c._applyCardinalOrderClassNames(),_(h).each(function(a){a.params.sidebar_id=c.params.sidebar_id}),_(g).each(function(d){setTimeout(function(){var f=!1;if(wp.customize.each(function(a){if(a.id!==c.setting.id&&0===a.id.indexOf("sidebars_widgets[")&&"sidebars_widgets[wp_inactive_widgets]"!==a.id){var b=a(),e=b.indexOf(d);-1!==e&&(f=!0)}}),!f){var g=e.getWidgetFormControlForWidget(d),h=g&&a.contains(document,g.container[0])&&!a.contains(c.section_content[0],g.container[0]);if(g&&!h&&(wp.customize.control.remove(g.id),g.container.remove()),e.saved_widget_ids[d]){var i=wp.customize.value("sidebars_widgets[wp_inactive_widgets]")().slice();i.push(d),wp.customize.value("sidebars_widgets[wp_inactive_widgets]")(_(i).unique())}var j=b(d).id_base,k=e.available_widgets.findWhere({id_base:j});k&&!k.get("is_multi")&&k.set("is_disabled",!1)}})})}),e.previewer.bind("rendered-sidebars",function(a){var b=!!a[c.params.sidebar_id];d.set("is_rendered",b)}),d.on("change:is_rendered",function(){var b="#accordion-section-sidebar-widgets-"+this.get("id"),c=a(b);this.get("is_rendered")?c.stop().slideDown(function(){a(this).css("height","auto")}):(c.hasClass("open")&&c.find(".accordion-section-title").trigger("click"),c.stop().slideUp())})},_setupSortable:function(){var b=this;b.is_reordering=!1,b.section_content.sortable({items:"> .customize-control-widget_form",handle:".widget-top",axis:"y",connectWith:".accordion-section-content:has(.customize-control-sidebar_widgets)",update:function(){var c=b.section_content.sortable("toArray"),d=a.map(c,function(b){return a("#"+b).find(":input[name=widget-id]").val()});b.setting(d)}}),b.control_section.find(".accordion-section-title").droppable({accept:".customize-control-widget_form",over:function(){b.control_section.hasClass("open")||(b.control_section.addClass("open"),b.section_content.toggle(!1).slideToggle(150,function(){b.section_content.sortable("refreshPositions")}))}}),b.container.find(".reorder-toggle").on("click keydown",function(a){("keydown"!==a.type||13===a.which||32===a.which)&&b.toggleReordering(!b.is_reordering)})},_setupAddition:function(){var b=this;b.container.find(".add-new-widget").on("click keydown",function(c){("keydown"!==c.type||13===c.which||32===c.which)&&(b.section_content.hasClass("reordering")||(a("body").hasClass("adding-widget")?e.availableWidgetsPanel.close():e.availableWidgetsPanel.open(b)))})},_applyCardinalOrderClassNames:function(){var a=this;a.section_content.find(".customize-control-widget_form").removeClass("first-widget").removeClass("last-widget").find(".move-widget-down, .move-widget-up").prop("tabIndex",0),a.section_content.find(".customize-control-widget_form:first").addClass("first-widget").find(".move-widget-up").prop("tabIndex",-1),a.section_content.find(".customize-control-widget_form:last").addClass("last-widget").find(".move-widget-down").prop("tabIndex",-1)},toggleReordering:function(a){var b=this;a=Boolean(a),a!==b.section_content.hasClass("reordering")&&(b.is_reordering=a,b.section_content.toggleClass("reordering",a),a&&_(b.getWidgetFormControls()).each(function(a){a.collapseForm()}))},getWidgetFormControls:function(){var a=this,b=_(a.setting()).map(function(a){var b=c(a),e=d.control(b);if(!e)throw new Error("Unable to find widget_form control for "+a);return e});return b},addWidget:function(c){var d=this,f=b(c),g=f.number,h=f.id_base,i=e.available_widgets.findWhere({id_base:h});if(!i)throw new Error("Widget unexpectedly not found.");if(g&&!i.get("is_multi"))throw new Error("Did not expect a widget number to be supplied for a non-multi widget");i.get("is_multi")&&!g&&(i.set("multi_number",i.get("multi_number")+1),g=i.get("multi_number"));var j=a("#widget-tpl-"+i.get("id")).html();i.get("is_multi")?j=j.replace(/<[^<>]+>/g,function(a){return a.replace(/__i__|%i%/g,g)}):i.set("is_disabled",!0);var k="widget_form",l=a("");l.addClass("customize-control"),l.addClass("customize-control-"+k),l.append(a(j)),l.find("> .widget-icon").remove(),i.get("is_multi")&&(l.find('input[name="widget_number"]').val(g),l.find('input[name="multi_number"]').val(g)),c=l.find('[name="widget-id"]').val(),l.hide();var m="widget_"+i.get("id_base");i.get("is_multi")&&(m+="["+g+"]"),l.attr("id","customize-control-"+m.replace(/\]/g,"").replace(/\[/g,"-")),d.container.after(l);var n=wp.customize.has(m);if(!n){var o={transport:"refresh",previewer:d.setting.previewer};wp.customize.create(m,m,{},o)}var p=wp.customize.controlConstructor[k],q=new p(m,{params:{settings:{"default":m},sidebar_id:d.params.sidebar_id,widget_id:c,widget_id_base:i.get("id_base"),type:k,is_new:!n,width:i.get("width"),height:i.get("height"),is_wide:i.get("is_wide")},previewer:d.setting.previewer});wp.customize.control.add(m,q),wp.customize.each(function(a){if(a.id!==d.setting.id&&0===a.id.indexOf("sidebars_widgets[")){var b=a().slice(),e=b.indexOf(c);-1!==e&&(b.splice(e),a(b))}});var r=d.setting().slice();return-1===r.indexOf(c)&&(r.push(c),d.setting(r)),l.slideDown(function(){n?(q.expandForm(),q.updateWidget({instance:q.setting(),complete:function(a){if(a)throw a;q.focus()}})):q.focus()}),q}}),d.controlConstructor.widget_form=d.Control.extend({ready:function(){var a=this;a._setupModel(),a._setupWideWidget(),a._setupControlToggle(),a._setupWidgetTitle(),a._setupReorderUI(),a._setupHighlightEffects(),a._setupUpdateUI(),a._setupRemoveUI(),a.hook("init")},hooks:{_default:{},rss:{formUpdated:function(a){var b=this,c=b.container.find(".widget-error:first"),d=a.find(".widget-error:first");c.length&&d.length?c.replaceWith(d):c.length?c.remove():d.length&&b.container.find(".widget-content").prepend(d)}}},hook:function(a){var b,c=Array.prototype.slice.call(arguments,1);this.hooks[this.params.widget_id_base]&&this.hooks[this.params.widget_id_base][a]?b=this.hooks[this.params.widget_id_base][a]:this.hooks._default[a]&&(b=this.hooks._default[a]),b&&b.apply(this,c)},_setupModel:function(){var a=this,b=function(){e.saved_widget_ids[a.params.widget_id]=!0};wp.customize.bind("ready",b),wp.customize.bind("saved",b),a._update_count=0,a.is_widget_updating=!1,a.setting.bind(function(b,c){_(c).isEqual(b)||a.is_widget_updating||a.updateWidget({instance:b})})},_setupWideWidget:function(){var b=this;if(b.params.is_wide){var c=b.container.find(".widget-inside"),d=a(".wp-full-overlay-sidebar-content:first");b.container.addClass("wide-widget-control"),b.container.find(".widget-content:first").css({"min-width":b.params.width,"min-height":b.params.height});var e=function(){var d=b.container.offset().top,e=c.outerHeight(),f=Math.max(d,0),g=a(window).height()-e;f=Math.min(f,g),c.css("top",f)},f=a("#customize-theme-controls");b.container.on("expand",function(){d.on("scroll",e),a(window).on("resize",e),f.on("expanded collapsed",e),e()}),b.container.on("collapsed",function(){d.off("scroll",e),f.off("expanded collapsed",e),a(window).off("resize",e)}),wp.customize.each(function(a){0===a.id.indexOf("sidebars_widgets[")&&a.bind(function(){b.container.hasClass("expanded")&&e()})})}},_setupControlToggle:function(){var a=this;a.container.find(".widget-top").on("click",function(b){b.preventDefault();var c=a.getSidebarWidgetsControl();c.is_reordering||a.toggleForm()});var b=a.container.find(".widget-control-close");b.on("click",function(b){b.preventDefault(),a.collapseForm(),a.container.find(".widget-top .widget-action:first").focus()})},_setupWidgetTitle:function(){var a=this,b=function(){var b=a.setting().title,c=a.container.find(".in-widget-title");c.text(b?": "+b:"")};a.setting.bind(b),b()},_setupReorderUI:function(){var b=this,c=function(a){a.siblings(".selected").removeClass("selected"),a.addClass("selected");var c=a.data("id")===b.params.sidebar_id;b.container.find(".move-widget-btn").prop("disabled",c)};b.container.find(".widget-title-action").after(a(e.tpl.widget_reorder_nav));var f=a(_.template(e.tpl.move_widget_area,{sidebars:_(e.registered_sidebars.toArray()).pluck("attributes")}));b.container.find(".widget-top").after(f);var g=function(){var d=f.find("li"),g=d.filter(function(){return a(this).data("id")===b.params.sidebar_id});d.each(function(){var b=a(this),d=b.data("id"),f=e.registered_sidebars.get(d);b.toggle(f.get("is_rendered")),b.hasClass("selected")&&!f.get("is_rendered")&&c(g)})};g(),e.registered_sidebars.on("change:is_rendered",g);var h=b.container.find(".widget-reorder-nav");h.find(".move-widget, .move-widget-down, .move-widget-up").on("click keypress",function(c){if("keypress"!==c.type||13===c.which||32===c.which)if(a(this).focus(),a(this).is(".move-widget"))b.toggleWidgetMoveArea();else{var d=a(this).is(".move-widget-down"),e=a(this).is(".move-widget-up"),f=b.getWidgetSidebarPosition();if(e&&0===f||d&&f===b.getSidebarWidgetsControl().setting().length-1)return;e?b.moveUp():b.moveDown(),a(this).focus()}}),b.container.find(".widget-area-select").on("click keypress","li",function(b){("keypress"!==event.type||13===event.which||32===event.which)&&(b.preventDefault(),c(a(this)))}),b.container.find(".move-widget-btn").click(function(){b.getSidebarWidgetsControl().toggleReordering(!1);var a=b.params.sidebar_id,c=b.container.find(".widget-area-select li.selected").data("id"),e=d("sidebars_widgets["+a+"]"),f=d("sidebars_widgets["+c+"]"),g=Array.prototype.slice.call(e()),h=Array.prototype.slice.call(f()),i=b.getWidgetSidebarPosition();g.splice(i,1),h.push(b.params.widget_id),e(g),f(h),b.focus()})},_setupHighlightEffects:function(){var a=this;a.container.on("mouseenter click",function(){a.highlightPreviewWidget()}),a.setting.bind(function(){a.scrollPreviewWidgetIntoView(),a.highlightPreviewWidget()}),a.container.on("expand",function(){a.scrollPreviewWidgetIntoView()})},_setupUpdateUI:function(){var a=this,b=a.container.find(".widget-content"),c=a.container.find(".widget-control-save");c.val(e.i18n.save_btn_label),c.attr("title",e.i18n.save_btn_tooltip),c.removeClass("button-primary").addClass("button-secondary"),c.on("click",function(b){b.preventDefault(),a.updateWidget()});var d=_.debounce(function(){a.updateWidget()},250);a.container.find(".widget-content").on("keydown","input",function(b){13===b.which&&(b.preventDefault(),a.updateWidget({ignore_active_element:!0}))}),b.on("change input propertychange",":input",function(a){("change"===a.type||this.checkValidity&&this.checkValidity())&&d()}),a.setting.previewer.channel.bind("synced",function(){a.container.removeClass("previewer-loading")}),e.previewer.bind("widget-updated",function(b){b===a.params.widget_id&&a.container.removeClass("previewer-loading")}),e.previewer.bind("rendered-widgets",function(b){var c=!!b[a.params.widget_id];a.container.toggleClass("widget-rendered",c)})},_setupRemoveUI:function(){var a=this,b=a.container.find("a.widget-control-remove");b.on("click",function(b){b.preventDefault();var c;c=a.container.next().is(".customize-control-widget_form")?a.container.next().find(".widget-action:first"):a.container.prev().is(".customize-control-widget_form")?a.container.prev().find(".widget-action:first"):a.container.next(".customize-control-sidebar_widgets").find(".add-new-widget:first"),a.container.slideUp(function(){var b=e.getSidebarWidgetControlContainingWidget(a.params.widget_id);if(!b)throw new Error("Unable to find sidebars_widgets_control");var d=b.setting().slice(),f=d.indexOf(a.params.widget_id);if(-1===f)throw new Error("Widget is not in sidebar");d.splice(f,1),b.setting(d),c.focus()})});var c=function(){b.text(e.i18n.remove_btn_label),b.attr("title",e.i18n.remove_btn_tooltip)};a.params.is_new?wp.customize.bind("saved",c):c()},_getInputsSignature:function(b){var c=_(b).map(function(b){b=a(b);var c;return c=b.is("option")?[b.prop("nodeName"),b.prop("value")]:b.is(":checkbox, :radio")?[b.prop("type"),b.attr("id"),b.attr("name"),b.prop("value")]:[b.prop("nodeName"),b.attr("id"),b.attr("name"),b.attr("type")],c.join(",")});return c.join(";")},_getInputStatePropertyName:function(b){return b=a(b),b.is(":radio, :checkbox")?"checked":b.is("option")?"selected":"value"},getSidebarWidgetsControl:function(){var a=this,b="sidebars_widgets["+a.params.sidebar_id+"]",c=d.control(b);if(!c)throw new Error("Unable to locate sidebar_widgets control for "+a.params.sidebar_id);return c},updateWidget:function(b){var c=this;b=a.extend({instance:null,complete:null,ignore_active_element:!1},b);var d=b.instance,f=b.complete;c._update_count+=1;var g=c._update_count,h=c.container.find(".widget-content"),i=null,j=null,k=null;if(a.contains(c.container[0],document.activeElement)&&a(document.activeElement).is("[id]")){i=a(document.activeElement).prop("id");try{j=document.activeElement.selectionStart,k=document.activeElement.selectionEnd}catch(l){}}c.container.addClass("widget-form-loading"),c.container.addClass("previewer-loading");var m={};m.action=e.update_widget_ajax_action,m[e.update_widget_nonce_post_key]=e.update_widget_nonce_value;var n=a.param(m),o=h.find(":input, option");o.each(function(){var b=a(this),d=c._getInputStatePropertyName(this);b.data("state"+g,b.prop(d))}),n+=d?"&"+a.param({sanitized_widget_setting:JSON.stringify(d)}):"&"+o.serialize(),n+="&"+h.find("~ :input").serialize(),console.log(wp.ajax.settings.url,n);var p=a.post(wp.ajax.settings.url,n,function(d){if(d.success){var e=a(""+d.data.form+"
");c.hook("formUpdate",e);var l=e.find(":input, option"),m=c._getInputsSignature(o)===c._getInputsSignature(l);m?(o.each(function(d){var e=a(this),f=a(l[d]),h=c._getInputStatePropertyName(this),i=e.data("state"+g),j=f.prop(h);e.data("sanitized",j),i!==j?((b.ignore_active_element||!e.is(document.activeElement))&&e.prop(h,j),c.hook("unsanitaryField",e,j,i)):c.hook("sanitaryField",e,i)}),c.hook("formUpdated",e)):(h.html(e.html()),i&&a(document.getElementById(i)).prop({selectionStart:j,selectionEnd:k}).focus(),c.hook("formRefreshed"));var n=_(c.setting()).isEqual(d.data.instance);n?c.container.removeClass("previewer-loading"):(c.is_widget_updating=!0,c.setting(d.data.instance),c.is_widget_updating=!1),f&&f.call(c,null,{no_change:n,ajax_finished:!0})}else{console.log(d);var p="FAIL";if(d.data&&d.data.message&&(p=d.data.message),!f)throw new Error(p);f.call(c,p)}});p.fail(function(a,b){if(!f)throw new Error(b);f.call(c,b)}),p.always(function(){c.container.removeClass("widget-form-loading"),o.each(function(){a(this).removeData("state"+g)})})},expandControlSection:function(){var a=this.container.closest(".accordion-section");a.hasClass("open")||a.find(".accordion-section-title:first").trigger("click")},expandForm:function(){this.toggleForm(!0)},collapseForm:function(){this.toggleForm(!1)},toggleForm:function(a){var b=this,c=b.container.find("div.widget:first"),d=c.find(".widget-inside:first");if("undefined"==typeof a&&(a=!d.is(":visible")),d.is(":visible")!==a){var e;a?(wp.customize.control.each(function(a){b.params.type===a.params.type&&b!==a&&a.collapseForm()}),b.container.trigger("expand"),b.container.addClass("expanding"),e=function(){b.container.removeClass("expanding"),b.container.addClass("expanded"),b.container.trigger("expanded")},b.params.is_wide?d.animate({width:"show"},"fast",e):d.slideDown("fast",e)):(b.container.trigger("collapse"),b.container.addClass("collapsing"),e=function(){b.container.removeClass("collapsing"),b.container.removeClass("expanded"),b.container.trigger("collapsed")},b.params.is_wide?d.animate({width:"hide"},"fast",e):d.slideUp("fast",function(){c.css({width:"",margin:""}),e()}))}},focus:function(){var a=this;a.expandControlSection(),a.expandForm(),a.container.find(":focusable:first").focus().trigger("click")},getWidgetSidebarPosition:function(){var a=this,b=a.getSidebarWidgetsControl().setting(),c=b.indexOf(a.params.widget_id);if(-1===c)throw new Error("Widget was unexpectedly not present in the sidebar.");return c},moveUp:function(){this._moveWidgetByOne(-1)},moveDown:function(){this._moveWidgetByOne(1)},_moveWidgetByOne:function(a){var b=this,c=b.getWidgetSidebarPosition(),d=b.getSidebarWidgetsControl().setting,e=Array.prototype.slice.call(d()),f=e[c+a];e[c+a]=b.params.widget_id,e[c]=f,d(e)},toggleWidgetMoveArea:function(b){var c=this,d=c.container.find(".move-widget-area");"undefined"==typeof b&&(b=!d.hasClass("active")),b&&(d.find(".selected").removeClass("selected"),d.find("li").filter(function(){return a(this).data("id")===c.params.sidebar_id}).addClass("selected"),c.container.find(".move-widget-btn").prop("disabled",!0)),d.toggleClass("active",b)},getPreviewWidgetElement:function(){var a=this,b=e.getPreviewWindow().WidgetCustomizerPreview;return b.getSidebarWidgetElement(a.params.sidebar_id,a.params.widget_id)},scrollPreviewWidgetIntoView:function(){},highlightSectionAndControl:function(){var b,c=this;b=c.container.is(":hidden")?c.container.closest(".control-section"):c.container,a(".widget-customizer-highlighted").removeClass("widget-customizer-highlighted"),b.addClass("widget-customizer-highlighted"),setTimeout(function(){b.removeClass("widget-customizer-highlighted")},500)},highlightPreviewWidget:function(){var a=this,b=a.getPreviewWidgetElement(),c=b.closest("html");c.find(".widget-customizer-highlighted-widget").removeClass("widget-customizer-highlighted-widget"),b.addClass("widget-customizer-highlighted-widget"),setTimeout(function(){b.removeClass("widget-customizer-highlighted-widget")},500)}});var j=wp.customize.Previewer;return wp.customize.Previewer=j.extend({initialize:function(a,b){e.previewer=this,j.prototype.initialize.call(this,a,b),this.bind("refresh",this.refresh)}}),e.getSidebarWidgetControlContainingWidget=function(a){var b=null;return wp.customize.control.each(function(c){"sidebar_widgets"===c.params.type&&-1!==c.setting().indexOf(a)&&(b=c)}),b},e.getWidgetFormControlForWidget=function(a){var b=null;return wp.customize.control.each(function(c){"widget_form"===c.params.type&&c.params.widget_id===a&&(b=c)}),b},e.getPreviewWindow=function(){return a("#customize-preview").find("iframe").prop("contentWindow")},e.availableWidgetsPanel={active_sidebar_widgets_control:null,selected_widget_tpl:null,container:null,filter_input:null,setup:function(){var b=this;b.container=a("#available-widgets"),b.filter_input=a("#available-widgets-filter").find("input");var c=function(){e.available_widgets.each(function(c){var d=a("#widget-tpl-"+c.id);d.toggle(!c.get("is_disabled")),c.get("is_disabled")&&d.is(b.selected_widget_tpl)&&(b.selected_widget_tpl=null)})};e.available_widgets.on("change",c),c(),a("#customize-controls").on("click keydown",function(c){var d=a(c.target).is(".add-new-widget, .add-new-widget *");a("body").hasClass("adding-widget")&&!d&&b.close()}),e.previewer.bind("url",function(){b.close()}),b.container.find(".widget-tpl").on("click keypress",function(a){("keypress"!==a.type||13===a.which||32===a.which)&&b.submit(this)}),b.container.liveFilter("#available-widgets-filter input",".widget-tpl",{filterChildSelector:".widget-title h4",after:function(){var a=b.filter_input.val();if(b.selected_widget_tpl&&!b.selected_widget_tpl.is(":visible")&&(b.selected_widget_tpl.removeClass("selected"),b.selected_widget_tpl=null),b.selected_widget_tpl&&!a&&(b.selected_widget_tpl.removeClass("selected"),b.selected_widget_tpl=null),!b.selected_widget_tpl&&a){var c=b.container.find("> .widget-tpl:visible:first");c.length&&b.select(c)}}}),b.container.find(" > .widget-tpl").on("focus",function(){b.select(this)}),b.container.on("keydown",function(c){var d=13===c.which,e=27===c.which,f=40===c.which,g=38===c.which,h=null,i=b.container.find("> .widget-tpl:visible:first"),j=b.container.find("> .widget-tpl:visible:last"),k=a(c.target).is(b.filter_input);return f||g?(f?k?h=i:b.selected_widget_tpl&&0!==b.selected_widget_tpl.nextAll(".widget-tpl:visible").length&&(h=b.selected_widget_tpl.nextAll(".widget-tpl:visible:first")):g&&(k?h=j:b.selected_widget_tpl&&0!==b.selected_widget_tpl.prevAll(".widget-tpl:visible").length&&(h=b.selected_widget_tpl.prevAll(".widget-tpl:visible:first"))),b.select(h),void(h?h.focus():b.filter_input.focus())):void((!d||b.filter_input.val())&&(d?b.submit():e&&b.close({return_focus:!0})))})},select:function(b){var c=this;c.selected_widget_tpl=a(b),c.selected_widget_tpl.siblings(".widget-tpl").removeClass("selected"),c.selected_widget_tpl.addClass("selected")},submit:function(b){var c=this;if(b||(b=c.selected_widget_tpl),b&&c.active_sidebar_widgets_control){c.select(b);var d=a(c.selected_widget_tpl).data("widget-id"),f=e.available_widgets.findWhere({id:d});if(!f)throw new Error("Widget unexpectedly not found.");c.active_sidebar_widgets_control.addWidget(f.get("id_base")),c.close()}},open:function(b){var c=this;c.active_sidebar_widgets_control=b,_(b.getWidgetFormControls()).each(function(a){a.params.is_wide&&a.collapseForm()}),a("body").addClass("adding-widget"),c.container.find(".widget-tpl").removeClass("selected"),c.filter_input.focus()},close:function(b){var c=this;b=b||{},b.return_focus&&c.active_sidebar_widgets_control&&c.active_sidebar_widgets_control.container.find(".add-new-widget").focus(),c.active_sidebar_widgets_control=null,c.selected_widget_tpl=null,a("body").removeClass("adding-widget"),c.filter_input.val("")}},e}(jQuery);!function(a){a.fn.liveFilter=function(b,c,d){var e={filterChildSelector:null,filter:function(b,c){return a(b).text().toUpperCase().indexOf(c.toUpperCase())>=0},before:function(){},after:function(){}};d=a.extend(e,d);var f=a(this).find(c);d.filterChildSelector&&(f=f.find(d.filterChildSelector));var g=d.filter;a(b).keyup(function(){var b=a(this).val(),e=f.filter(function(){return g(this,b)}),h=f.not(e);d.filterChildSelector&&(e=e.parents(c),h=h.parents(c).hide()),d.before.call(this,e,h),e.show(),h.hide(),""===b&&(e.show(),h.show()),d.after.call(this,e,h)})}}(jQuery);
\ No newline at end of file
+var WidgetCustomizer=function(a){"use strict";function b(a){var b,c={number:null,id_base:null};return b=a.match(/^(.+)-(\d+)$/),b?(c.id_base=b[1],c.number=parseInt(b[2],10)):c.id_base=a,c}function c(a){var c,d=b(a);return c="widget_"+d.id_base,d.number&&(c+="["+d.number+"]"),c}var d,e,f,g,h,i=wp.customize,j={update_widget_ajax_action:null,update_widget_nonce_value:null,update_widget_nonce_post_key:null,i18n:{save_btn_label:"",save_btn_tooltip:"",remove_btn_label:"",remove_btn_tooltip:""},available_widgets:[],registered_widgets:[],active_sidebar_control:null,previewer:null,saved_widget_ids:{},registered_sidebars:[],tpl:{move_widget_area:"",widget_reorder_nav:""}};return a.extend(j,WidgetCustomizer_exports),"undefined"==typeof window.ajaxurl&&(window.ajaxurl=wp.ajax.settings.url),a("#customize-theme-controls").closest("div:not([id])").attr("id","widgets-right"),d=j.Widget=Backbone.Model.extend({id:null,temp_id:null,classname:null,control_tpl:null,description:null,is_disabled:null,is_multi:null,multi_number:null,name:null,id_base:null,transport:"refresh",params:[],width:null,height:null}),e=j.WidgetCollection=Backbone.Collection.extend({model:d}),j.available_widgets=new e(j.available_widgets),f=j.Sidebar=Backbone.Model.extend({after_title:null,after_widget:null,before_title:null,before_widget:null,"class":null,description:null,id:null,name:null,is_rendered:!1}),g=j.SidebarCollection=Backbone.Collection.extend({model:f}),j.registered_sidebars=new g(j.registered_sidebars),j.init=function(){this.showFirstSidebarIfRequested(),this.availableWidgetsPanel.setup()},wp.customize.bind("ready",function(){j.init()}),j.showFirstSidebarIfRequested=function(){if(/widget-customizer=open/.test(location.search)){var b=function(){j.registered_sidebars.off("change:is_rendered",b);var c,d=j.registered_sidebars.find(function(a){return a.get("is_rendered")});d&&(c=a("#accordion-section-sidebar-widgets-"+d.get("id")),c.hasClass("open")||c.find(".accordion-section-title").trigger("click"),c[0].scrollIntoView())};b=_.debounce(b,100),j.registered_sidebars.on("change:is_rendered",b)}},i.controlConstructor.sidebar_widgets=i.Control.extend({ready:function(){var a=this;a.control_section=a.container.closest(".control-section"),a.section_content=a.container.closest(".accordion-section-content"),a._setupModel(),a._setupSortable(),a._setupAddition(),a._applyCardinalOrderClassNames()},_setupModel:function(){var c=this,d=j.registered_sidebars.get(c.params.sidebar_id);c.setting.bind(function(d,e){var f,g,h,i=_(e).difference(d);d=_(d).filter(function(a){var c=b(a);return!!j.available_widgets.findWhere({id_base:c.id_base})}),f=_(d).map(function(a){var b=j.getWidgetFormControlForWidget(a);return b||(b=c.addWidget(a)),b}),f.sort(function(a,b){var c=d.indexOf(a.params.widget_id),e=d.indexOf(b.params.widget_id);return c===e?0:e>c?-1:1}),g=c.section_content.find(".customize-control-sidebar_widgets"),h=_(f).map(function(a){return a.container[0]}),g.before(h),c._applyCardinalOrderClassNames(),_(f).each(function(a){a.params.sidebar_id=c.params.sidebar_id}),_(i).each(function(d){setTimeout(function(){var e,f,g,h,i,k=!1;wp.customize.each(function(a){if(a.id!==c.setting.id&&0===a.id.indexOf("sidebars_widgets[")&&"sidebars_widgets[wp_inactive_widgets]"!==a.id){var b,e=a();b=e.indexOf(d),-1!==b&&(k=!0)}}),k||(e=j.getWidgetFormControlForWidget(d),f=e&&a.contains(document,e.container[0])&&!a.contains(c.section_content[0],e.container[0]),e&&!f&&(wp.customize.control.remove(e.id),e.container.remove()),j.saved_widget_ids[d]&&(g=wp.customize.value("sidebars_widgets[wp_inactive_widgets]")().slice(),g.push(d),wp.customize.value("sidebars_widgets[wp_inactive_widgets]")(_(g).unique())),h=b(d).id_base,i=j.available_widgets.findWhere({id_base:h}),i&&!i.get("is_multi")&&i.set("is_disabled",!1))})})}),j.previewer.bind("rendered-sidebars",function(a){var b=!!a[c.params.sidebar_id];d.set("is_rendered",b)}),d.on("change:is_rendered",function(){var b,c="#accordion-section-sidebar-widgets-"+this.get("id");b=a(c),this.get("is_rendered")?b.stop().slideDown(function(){a(this).css("height","auto")}):(b.hasClass("open")&&b.find(".accordion-section-title").trigger("click"),b.stop().slideUp())})},_setupSortable:function(){var b=this;b.is_reordering=!1,b.section_content.sortable({items:"> .customize-control-widget_form",handle:".widget-top",axis:"y",connectWith:".accordion-section-content:has(.customize-control-sidebar_widgets)",update:function(){var c,d=b.section_content.sortable("toArray");c=a.map(d,function(b){return a("#"+b).find(":input[name=widget-id]").val()}),b.setting(c)}}),b.control_section.find(".accordion-section-title").droppable({accept:".customize-control-widget_form",over:function(){b.control_section.hasClass("open")||(b.control_section.addClass("open"),b.section_content.toggle(!1).slideToggle(150,function(){b.section_content.sortable("refreshPositions")}))}}),b.container.find(".reorder-toggle").on("click keydown",function(a){("keydown"!==a.type||13===a.which||32===a.which)&&b.toggleReordering(!b.is_reordering)})},_setupAddition:function(){var b=this;b.container.find(".add-new-widget").on("click keydown",function(c){("keydown"!==c.type||13===c.which||32===c.which)&&(b.section_content.hasClass("reordering")||(a("body").hasClass("adding-widget")?j.availableWidgetsPanel.close():j.availableWidgetsPanel.open(b)))})},_applyCardinalOrderClassNames:function(){var a=this;a.section_content.find(".customize-control-widget_form").removeClass("first-widget").removeClass("last-widget").find(".move-widget-down, .move-widget-up").prop("tabIndex",0),a.section_content.find(".customize-control-widget_form:first").addClass("first-widget").find(".move-widget-up").prop("tabIndex",-1),a.section_content.find(".customize-control-widget_form:last").addClass("last-widget").find(".move-widget-down").prop("tabIndex",-1)},toggleReordering:function(a){var b=this;a=Boolean(a),a!==b.section_content.hasClass("reordering")&&(b.is_reordering=a,b.section_content.toggleClass("reordering",a),a&&_(b.getWidgetFormControls()).each(function(a){a.collapseForm()}))},getWidgetFormControls:function(){var a,b=this;return a=_(b.setting()).map(function(a){var b=c(a),d=i.control(b);if(!d)throw new Error("Unable to find widget_form control for "+a);return d})},addWidget:function(c){var d,e,f,g,h,i,k,l,m=this,n="widget_form",o=b(c),p=o.number,q=o.id_base,r=j.available_widgets.findWhere({id_base:q});if(!r)throw new Error("Widget unexpectedly not found.");if(p&&!r.get("is_multi"))throw new Error("Did not expect a widget number to be supplied for a non-multi widget");return r.get("is_multi")&&!p&&(r.set("multi_number",r.get("multi_number")+1),p=r.get("multi_number")),d=a("#widget-tpl-"+r.get("id")).html(),r.get("is_multi")?d=d.replace(/<[^<>]+>/g,function(a){return a.replace(/__i__|%i%/g,p)}):r.set("is_disabled",!0),e=a(""),e.addClass("customize-control"),e.addClass("customize-control-"+n),e.append(a(d)),e.find("> .widget-icon").remove(),r.get("is_multi")&&(e.find('input[name="widget_number"]').val(p),e.find('input[name="multi_number"]').val(p)),c=e.find('[name="widget-id"]').val(),e.hide(),f="widget_"+r.get("id_base"),r.get("is_multi")&&(f+="["+p+"]"),e.attr("id","customize-control-"+f.replace(/\]/g,"").replace(/\[/g,"-")),m.container.after(e),g=wp.customize.has(f),g||(l={transport:"refresh",previewer:m.setting.previewer},wp.customize.create(f,f,{},l)),h=wp.customize.controlConstructor[n],i=new h(f,{params:{settings:{"default":f},sidebar_id:m.params.sidebar_id,widget_id:c,widget_id_base:r.get("id_base"),type:n,is_new:!g,width:r.get("width"),height:r.get("height"),is_wide:r.get("is_wide")},previewer:m.setting.previewer}),wp.customize.control.add(f,i),wp.customize.each(function(a){if(a.id!==m.setting.id&&0===a.id.indexOf("sidebars_widgets[")){var b,d=a().slice();b=d.indexOf(c),-1!==b&&(d.splice(b),a(d))}}),k=m.setting().slice(),-1===k.indexOf(c)&&(k.push(c),m.setting(k)),e.slideDown(function(){g?(i.expandForm(),i.updateWidget({instance:i.setting(),complete:function(a){if(a)throw a;i.focus()}})):i.focus()}),i}}),i.controlConstructor.widget_form=i.Control.extend({ready:function(){var a=this;a._setupModel(),a._setupWideWidget(),a._setupControlToggle(),a._setupWidgetTitle(),a._setupReorderUI(),a._setupHighlightEffects(),a._setupUpdateUI(),a._setupRemoveUI(),a.hook("init")},hooks:{_default:{},rss:{formUpdated:function(a){var b=this,c=b.container.find(".widget-error:first"),d=a.find(".widget-error:first");c.length&&d.length?c.replaceWith(d):c.length?c.remove():d.length&&b.container.find(".widget-content").prepend(d)}}},hook:function(a){var b,c=Array.prototype.slice.call(arguments,1);this.hooks[this.params.widget_id_base]&&this.hooks[this.params.widget_id_base][a]?b=this.hooks[this.params.widget_id_base][a]:this.hooks._default[a]&&(b=this.hooks._default[a]),b&&b.apply(this,c)},_setupModel:function(){var a,b=this;a=function(){j.saved_widget_ids[b.params.widget_id]=!0},wp.customize.bind("ready",a),wp.customize.bind("saved",a),b._update_count=0,b.is_widget_updating=!1,b.setting.bind(function(a,c){_(c).isEqual(a)||b.is_widget_updating||b.updateWidget({instance:a})})},_setupWideWidget:function(){var b,c,d,e,f=this;f.params.is_wide&&(b=f.container.find(".widget-inside"),c=a(".wp-full-overlay-sidebar-content:first"),f.container.addClass("wide-widget-control"),f.container.find(".widget-content:first").css({"min-width":f.params.width,"min-height":f.params.height}),d=function(){var c,d,e,g=f.container.offset().top;c=b.outerHeight(),d=Math.max(g,0),e=a(window).height()-c,d=Math.min(d,e),b.css("top",d)},e=a("#customize-theme-controls"),f.container.on("expand",function(){c.on("scroll",d),a(window).on("resize",d),e.on("expanded collapsed",d),d()}),f.container.on("collapsed",function(){c.off("scroll",d),e.off("expanded collapsed",d),a(window).off("resize",d)}),wp.customize.each(function(a){0===a.id.indexOf("sidebars_widgets[")&&a.bind(function(){f.container.hasClass("expanded")&&d()})}))},_setupControlToggle:function(){var a,b=this;b.container.find(".widget-top").on("click",function(a){a.preventDefault();var c=b.getSidebarWidgetsControl();c.is_reordering||b.toggleForm()}),a=b.container.find(".widget-control-close"),a.on("click",function(a){a.preventDefault(),b.collapseForm(),b.container.find(".widget-top .widget-action:first").focus()})},_setupWidgetTitle:function(){var a,b=this;a=function(){var a=b.setting().title,c=b.container.find(".in-widget-title");c.text(a?": "+a:"")},b.setting.bind(a),a()},_setupReorderUI:function(){var b,c,d,e,f=this;b=function(a){a.siblings(".selected").removeClass("selected"),a.addClass("selected");var b=a.data("id")===f.params.sidebar_id;f.container.find(".move-widget-btn").prop("disabled",b)},f.container.find(".widget-title-action").after(a(j.tpl.widget_reorder_nav)),c=a(_.template(j.tpl.move_widget_area,{sidebars:_(j.registered_sidebars.toArray()).pluck("attributes")})),f.container.find(".widget-top").after(c),e=function(){var d,e=c.find("li");d=e.filter(function(){return a(this).data("id")===f.params.sidebar_id}),e.each(function(){var c,e,f=a(this);c=f.data("id"),e=j.registered_sidebars.get(c),f.toggle(e.get("is_rendered")),f.hasClass("selected")&&!e.get("is_rendered")&&b(d)})},e(),j.registered_sidebars.on("change:is_rendered",e),d=f.container.find(".widget-reorder-nav"),d.find(".move-widget, .move-widget-down, .move-widget-up").on("click keypress",function(b){if("keypress"!==b.type||13===b.which||32===b.which)if(a(this).focus(),a(this).is(".move-widget"))f.toggleWidgetMoveArea();else{var c=a(this).is(".move-widget-down"),d=a(this).is(".move-widget-up"),e=f.getWidgetSidebarPosition();if(d&&0===e||c&&e===f.getSidebarWidgetsControl().setting().length-1)return;d?f.moveUp():f.moveDown(),a(this).focus()}}),f.container.find(".widget-area-select").on("click keypress","li",function(c){("keypress"!==event.type||13===event.which||32===event.which)&&(c.preventDefault(),b(a(this)))}),f.container.find(".move-widget-btn").click(function(){f.getSidebarWidgetsControl().toggleReordering(!1);var a,b,c,d,e,g=f.params.sidebar_id,h=f.container.find(".widget-area-select li.selected").data("id");a=i("sidebars_widgets["+g+"]"),b=i("sidebars_widgets["+h+"]"),c=Array.prototype.slice.call(a()),d=Array.prototype.slice.call(b()),e=f.getWidgetSidebarPosition(),c.splice(e,1),d.push(f.params.widget_id),a(c),b(d),f.focus()})},_setupHighlightEffects:function(){var a=this;a.container.on("mouseenter click",function(){a.highlightPreviewWidget()}),a.setting.bind(function(){a.scrollPreviewWidgetIntoView(),a.highlightPreviewWidget()}),a.container.on("expand",function(){a.scrollPreviewWidgetIntoView()})},_setupUpdateUI:function(){var a,b,c,d=this;a=d.container.find(".widget-content"),b=d.container.find(".widget-control-save"),b.val(j.i18n.save_btn_label),b.attr("title",j.i18n.save_btn_tooltip),b.removeClass("button-primary").addClass("button-secondary"),b.on("click",function(a){a.preventDefault(),d.updateWidget()}),c=_.debounce(function(){d.updateWidget()},250),d.container.find(".widget-content").on("keydown","input",function(a){13===a.which&&(a.preventDefault(),d.updateWidget({ignore_active_element:!0}))}),a.on("change input propertychange",":input",function(a){("change"===a.type||this.checkValidity&&this.checkValidity())&&c()}),d.setting.previewer.channel.bind("synced",function(){d.container.removeClass("previewer-loading")}),j.previewer.bind("widget-updated",function(a){a===d.params.widget_id&&d.container.removeClass("previewer-loading")}),j.previewer.bind("rendered-widgets",function(a){var b=!!a[d.params.widget_id];d.container.toggleClass("widget-rendered",b)})},_setupRemoveUI:function(){var a,b,c=this;a=c.container.find("a.widget-control-remove"),a.on("click",function(a){a.preventDefault();var b;b=c.container.next().is(".customize-control-widget_form")?c.container.next().find(".widget-action:first"):c.container.prev().is(".customize-control-widget_form")?c.container.prev().find(".widget-action:first"):c.container.next(".customize-control-sidebar_widgets").find(".add-new-widget:first"),c.container.slideUp(function(){var a,d,e=j.getSidebarWidgetControlContainingWidget(c.params.widget_id);if(!e)throw new Error("Unable to find sidebars_widgets_control");if(a=e.setting().slice(),d=a.indexOf(c.params.widget_id),-1===d)throw new Error("Widget is not in sidebar");a.splice(d,1),e.setting(a),b.focus()})}),b=function(){a.text(j.i18n.remove_btn_label),a.attr("title",j.i18n.remove_btn_tooltip)},c.params.is_new?wp.customize.bind("saved",b):b()},_getInputsSignature:function(b){var c=_(b).map(function(b){b=a(b);var c;return c=b.is("option")?[b.prop("nodeName"),b.prop("value")]:b.is(":checkbox, :radio")?[b.prop("type"),b.attr("id"),b.attr("name"),b.prop("value")]:[b.prop("nodeName"),b.attr("id"),b.attr("name"),b.attr("type")],c.join(",")});return c.join(";")},_getInputStatePropertyName:function(b){return b=a(b),b.is(":radio, :checkbox")?"checked":b.is("option")?"selected":"value"},getSidebarWidgetsControl:function(){var a,b,c=this;if(a="sidebars_widgets["+c.params.sidebar_id+"]",b=i.control(a),!b)throw new Error("Unable to locate sidebar_widgets control for "+c.params.sidebar_id);return b},updateWidget:function(b){var c,d,e,f,g,h,i,k=this,l=null,m=null,n=null,o={};if(b=a.extend({instance:null,complete:null,ignore_active_element:!1},b),c=b.instance,d=b.complete,k._update_count+=1,e=k._update_count,f=k.container.find(".widget-content"),a.contains(k.container[0],document.activeElement)&&a(document.activeElement).is("[id]")){l=a(document.activeElement).prop("id");try{m=document.activeElement.selectionStart,n=document.activeElement.selectionEnd}catch(p){}}k.container.addClass("widget-form-loading"),k.container.addClass("previewer-loading"),o={},o.action=j.update_widget_ajax_action,o[j.update_widget_nonce_post_key]=j.update_widget_nonce_value,g=a.param(o),h=f.find(":input, option"),h.each(function(){var b=a(this),c=k._getInputStatePropertyName(this);b.data("state"+e,b.prop(c))}),g+=c?"&"+a.param({sanitized_widget_setting:JSON.stringify(c)}):"&"+h.serialize(),g+="&"+f.find("~ :input").serialize(),window.console&&window.console.log(wp.ajax.settings.url,g),i=a.post(wp.ajax.settings.url,g,function(c){var g,i,j,o,p;if(c.success)i=a(""+c.data.form+"
"),k.hook("formUpdate",i),j=i.find(":input, option"),o=k._getInputsSignature(h)===k._getInputsSignature(j),o?(h.each(function(c){var d,f,g=a(this),h=a(j[c]),i=k._getInputStatePropertyName(this);d=g.data("state"+e),f=h.prop(i),g.data("sanitized",f),d!==f?((b.ignore_active_element||!g.is(document.activeElement))&&g.prop(i,f),k.hook("unsanitaryField",g,f,d)):k.hook("sanitaryField",g,d)}),k.hook("formUpdated",i)):(f.html(i.html()),l&&a(document.getElementById(l)).prop({selectionStart:m,selectionEnd:n}).focus(),k.hook("formRefreshed")),p=_(k.setting()).isEqual(c.data.instance),p?k.container.removeClass("previewer-loading"):(k.is_widget_updating=!0,k.setting(c.data.instance),k.is_widget_updating=!1),d&&d.call(k,null,{no_change:p,ajax_finished:!0});else{if(window.console&&window.console.log(c),g="FAIL",c.data&&c.data.message&&(g=c.data.message),!d)throw new Error(g);d.call(k,g)}}),i.fail(function(a,b){if(!d)throw new Error(b);d.call(k,b)}),i.always(function(){k.container.removeClass("widget-form-loading"),h.each(function(){a(this).removeData("state"+e)})})},expandControlSection:function(){var a=this.container.closest(".accordion-section");a.hasClass("open")||a.find(".accordion-section-title:first").trigger("click")},expandForm:function(){this.toggleForm(!0)},collapseForm:function(){this.toggleForm(!1)},toggleForm:function(a){var b,c,d,e=this;b=e.container.find("div.widget:first"),c=b.find(".widget-inside:first"),"undefined"==typeof a&&(a=!c.is(":visible")),c.is(":visible")!==a&&(a?(wp.customize.control.each(function(a){e.params.type===a.params.type&&e!==a&&a.collapseForm()}),e.container.trigger("expand"),e.container.addClass("expanding"),d=function(){e.container.removeClass("expanding"),e.container.addClass("expanded"),e.container.trigger("expanded")},e.params.is_wide?c.animate({width:"show"},"fast",d):c.slideDown("fast",d)):(e.container.trigger("collapse"),e.container.addClass("collapsing"),d=function(){e.container.removeClass("collapsing"),e.container.removeClass("expanded"),e.container.trigger("collapsed")},e.params.is_wide?c.animate({width:"hide"},"fast",d):c.slideUp("fast",function(){b.css({width:"",margin:""}),d()})))},focus:function(){var a=this;a.expandControlSection(),a.expandForm(),a.container.find(":focusable:first").focus().trigger("click")},getWidgetSidebarPosition:function(){var a,b,c=this;if(a=c.getSidebarWidgetsControl().setting(),b=a.indexOf(c.params.widget_id),-1===b)throw new Error("Widget was unexpectedly not present in the sidebar.");return b},moveUp:function(){this._moveWidgetByOne(-1)},moveDown:function(){this._moveWidgetByOne(1)},_moveWidgetByOne:function(a){var b,c,d,e,f=this;b=f.getWidgetSidebarPosition(),c=f.getSidebarWidgetsControl().setting,d=Array.prototype.slice.call(c()),e=d[b+a],d[b+a]=f.params.widget_id,d[b]=e,c(d)},toggleWidgetMoveArea:function(b){var c,d=this;c=d.container.find(".move-widget-area"),"undefined"==typeof b&&(b=!c.hasClass("active")),b&&(c.find(".selected").removeClass("selected"),c.find("li").filter(function(){return a(this).data("id")===d.params.sidebar_id}).addClass("selected"),d.container.find(".move-widget-btn").prop("disabled",!0)),c.toggleClass("active",b)},getPreviewWidgetElement:function(){var a=this,b=j.getPreviewWindow().WidgetCustomizerPreview;return b.getSidebarWidgetElement(a.params.sidebar_id,a.params.widget_id)},scrollPreviewWidgetIntoView:function(){},highlightSectionAndControl:function(){var b,c=this;b=c.container.is(":hidden")?c.container.closest(".control-section"):c.container,a(".widget-customizer-highlighted").removeClass("widget-customizer-highlighted"),b.addClass("widget-customizer-highlighted"),setTimeout(function(){b.removeClass("widget-customizer-highlighted")},500)},highlightPreviewWidget:function(){var a,b,c=this;a=c.getPreviewWidgetElement(),b=a.closest("html"),b.find(".widget-customizer-highlighted-widget").removeClass("widget-customizer-highlighted-widget"),a.addClass("widget-customizer-highlighted-widget"),setTimeout(function(){a.removeClass("widget-customizer-highlighted-widget")},500)}}),h=wp.customize.Previewer,wp.customize.Previewer=h.extend({initialize:function(a,b){j.previewer=this,h.prototype.initialize.call(this,a,b),this.bind("refresh",this.refresh)}}),j.getSidebarWidgetControlContainingWidget=function(a){var b=null;return wp.customize.control.each(function(c){"sidebar_widgets"===c.params.type&&-1!==c.setting().indexOf(a)&&(b=c)}),b},j.getWidgetFormControlForWidget=function(a){var b=null;return wp.customize.control.each(function(c){"widget_form"===c.params.type&&c.params.widget_id===a&&(b=c)}),b},j.getPreviewWindow=function(){return a("#customize-preview").find("iframe").prop("contentWindow")},j.availableWidgetsPanel={active_sidebar_widgets_control:null,selected_widget_tpl:null,container:null,filter_input:null,setup:function(){var b,c=this;c.container=a("#available-widgets"),c.filter_input=a("#available-widgets-filter").find("input"),b=function(){j.available_widgets.each(function(b){var d=a("#widget-tpl-"+b.id);d.toggle(!b.get("is_disabled")),b.get("is_disabled")&&d.is(c.selected_widget_tpl)&&(c.selected_widget_tpl=null)})},j.available_widgets.on("change",b),b(),a("#customize-controls").on("click keydown",function(b){var d=a(b.target).is(".add-new-widget, .add-new-widget *");a("body").hasClass("adding-widget")&&!d&&c.close()}),j.previewer.bind("url",function(){c.close()}),c.container.find(".widget-tpl").on("click keypress",function(a){("keypress"!==a.type||13===a.which||32===a.which)&&c.submit(this)}),c.container.liveFilter("#available-widgets-filter input",".widget-tpl",{filterChildSelector:".widget-title h4",after:function(){var a,b=c.filter_input.val();c.selected_widget_tpl&&!c.selected_widget_tpl.is(":visible")&&(c.selected_widget_tpl.removeClass("selected"),c.selected_widget_tpl=null),c.selected_widget_tpl&&!b&&(c.selected_widget_tpl.removeClass("selected"),c.selected_widget_tpl=null),!c.selected_widget_tpl&&b&&(a=c.container.find("> .widget-tpl:visible:first"),a.length&&c.select(a))}}),c.container.find(" > .widget-tpl").on("focus",function(){c.select(this)}),c.container.on("keydown",function(b){var d=13===b.which,e=27===b.which,f=40===b.which,g=38===b.which,h=null,i=c.container.find("> .widget-tpl:visible:first"),j=c.container.find("> .widget-tpl:visible:last"),k=a(b.target).is(c.filter_input);return f||g?(f?k?h=i:c.selected_widget_tpl&&0!==c.selected_widget_tpl.nextAll(".widget-tpl:visible").length&&(h=c.selected_widget_tpl.nextAll(".widget-tpl:visible:first")):g&&(k?h=j:c.selected_widget_tpl&&0!==c.selected_widget_tpl.prevAll(".widget-tpl:visible").length&&(h=c.selected_widget_tpl.prevAll(".widget-tpl:visible:first"))),c.select(h),void(h?h.focus():c.filter_input.focus())):void((!d||c.filter_input.val())&&(d?c.submit():e&&c.close({return_focus:!0})))})},select:function(b){var c=this;c.selected_widget_tpl=a(b),c.selected_widget_tpl.siblings(".widget-tpl").removeClass("selected"),c.selected_widget_tpl.addClass("selected")},submit:function(b){var c,d,e=this;if(b||(b=e.selected_widget_tpl),b&&e.active_sidebar_widgets_control){if(e.select(b),c=a(e.selected_widget_tpl).data("widget-id"),d=j.available_widgets.findWhere({id:c}),!d)throw new Error("Widget unexpectedly not found.");e.active_sidebar_widgets_control.addWidget(d.get("id_base")),e.close()}},open:function(b){var c=this;c.active_sidebar_widgets_control=b,_(b.getWidgetFormControls()).each(function(a){a.params.is_wide&&a.collapseForm()}),a("body").addClass("adding-widget"),c.container.find(".widget-tpl").removeClass("selected"),c.filter_input.focus()},close:function(b){var c=this;b=b||{},b.return_focus&&c.active_sidebar_widgets_control&&c.active_sidebar_widgets_control.container.find(".add-new-widget").focus(),c.active_sidebar_widgets_control=null,c.selected_widget_tpl=null,a("body").removeClass("adding-widget"),c.filter_input.val("")}},j}(jQuery);!function(a){a.fn.liveFilter=function(b,c,d){var e,f,g={filterChildSelector:null,filter:function(b,c){return a(b).text().toUpperCase().indexOf(c.toUpperCase())>=0},before:function(){},after:function(){}};d=a.extend(g,d),e=a(this).find(c),d.filterChildSelector&&(e=e.find(d.filterChildSelector)),f=d.filter,a(b).keyup(function(){var b,g,h=a(this).val();b=e.filter(function(){return f(this,h)}),g=e.not(b),d.filterChildSelector&&(b=b.parents(c),g=g.parents(c).hide()),d.before.call(this,b,g),b.show(),g.hide(),""===h&&(b.show(),g.show()),d.after.call(this,b,g)})}}(jQuery);
\ No newline at end of file
diff --git a/wp-includes/js/customize-preview-widgets.js b/wp-includes/js/customize-preview-widgets.js
index 4a99f6510f..67b5ed7411 100644
--- a/wp-includes/js/customize-preview-widgets.js
+++ b/wp-includes/js/customize-preview-widgets.js
@@ -3,7 +3,7 @@
var WidgetCustomizerPreview = (function ($) {
'use strict';
- var self = {
+ var OldPreview, self = {
rendered_sidebars: {}, // @todo Make rendered a property of the Backbone model
rendered_widgets: {}, // @todo Make rendered a property of the Backbone model
registered_sidebars: [], // @todo Make a Backbone collection
@@ -31,14 +31,19 @@ var WidgetCustomizerPreview = (function ($) {
buildWidgetSelectors: function () {
$.each( self.registered_sidebars, function ( i, sidebar ) {
var widget_tpl = [
- sidebar.before_widget.replace('%1$s', '').replace('%2$s', ''),
- sidebar.before_title,
- sidebar.after_title,
- sidebar.after_widget
- ].join('');
- var empty_widget = $(widget_tpl);
- var widget_selector = empty_widget.prop('tagName');
- var widget_classes = empty_widget.prop('className').replace(/^\s+|\s+$/g, '');
+ sidebar.before_widget.replace('%1$s', '').replace('%2$s', ''),
+ sidebar.before_title,
+ sidebar.after_title,
+ sidebar.after_widget
+ ].join(''),
+ empty_widget,
+ widget_selector,
+ widget_classes;
+
+ empty_widget = $(widget_tpl);
+ widget_selector = empty_widget.prop('tagName');
+ widget_classes = empty_widget.prop('className').replace(/^\s+|\s+$/g, '');
+
if ( widget_classes ) {
widget_selector += '.' + widget_classes.split(/\s+/).join('.');
}
@@ -98,7 +103,7 @@ var WidgetCustomizerPreview = (function ($) {
/**
* Capture the instance of the Preview since it is private
*/
- var OldPreview = wp.customize.Preview;
+ OldPreview = wp.customize.Preview;
wp.customize.Preview = OldPreview.extend( {
initialize: function( params, options ) {
self.preview = this;
diff --git a/wp-includes/js/customize-preview-widgets.min.js b/wp-includes/js/customize-preview-widgets.min.js
index ea0e77d3fd..eec064cd35 100644
--- a/wp-includes/js/customize-preview-widgets.min.js
+++ b/wp-includes/js/customize-preview-widgets.min.js
@@ -1 +1 @@
-var WidgetCustomizerPreview=function(a){"use strict";var b={rendered_sidebars:{},rendered_widgets:{},registered_sidebars:[],registered_widgets:{},widget_selectors:[],render_widget_ajax_action:null,render_widget_nonce_value:null,render_widget_nonce_post_key:null,preview:null,i18n:{},init:function(){this.buildWidgetSelectors(),this.highlightControls(),b.preview.bind("active",function(){b.preview.send("rendered-sidebars",b.rendered_sidebars),b.preview.send("rendered-widgets",b.rendered_widgets)})},buildWidgetSelectors:function(){a.each(b.registered_sidebars,function(c,d){var e=[d.before_widget.replace("%1$s","").replace("%2$s",""),d.before_title,d.after_title,d.after_widget].join(""),f=a(e),g=f.prop("tagName"),h=f.prop("className").replace(/^\s+|\s+$/g,"");h&&(g+="."+h.split(/\s+/).join(".")),b.widget_selectors.push(g)})},getSidebarWidgetElement:function(b,c){return a("[id="+c+"]").filter(function(){return a(this).data("widget_customizer_sidebar_id")===b})},highlightControls:function(){var c=this.widget_selectors.join(",");a(c).attr("title",b.i18n.widget_tooltip),a(document).on("mouseenter",c,function(){var b=parent.WidgetCustomizer.getWidgetFormControlForWidget(a(this).prop("id"));b&&b.highlightSectionAndControl()}),a(document).on("click",c,function(b){if(b.shiftKey){b.preventDefault();var c=parent.WidgetCustomizer.getWidgetFormControlForWidget(a(this).prop("id"));c&&c.focus()}})}};a.extend(b,WidgetCustomizerPreview_exports);var c=wp.customize.Preview;return wp.customize.Preview=c.extend({initialize:function(a,d){b.preview=this,c.prototype.initialize.call(this,a,d)}}),a(function(){b.init()}),b}(jQuery);
\ No newline at end of file
+var WidgetCustomizerPreview=function(a){"use strict";var b,c={rendered_sidebars:{},rendered_widgets:{},registered_sidebars:[],registered_widgets:{},widget_selectors:[],render_widget_ajax_action:null,render_widget_nonce_value:null,render_widget_nonce_post_key:null,preview:null,i18n:{},init:function(){this.buildWidgetSelectors(),this.highlightControls(),c.preview.bind("active",function(){c.preview.send("rendered-sidebars",c.rendered_sidebars),c.preview.send("rendered-widgets",c.rendered_widgets)})},buildWidgetSelectors:function(){a.each(c.registered_sidebars,function(b,d){var e,f,g,h=[d.before_widget.replace("%1$s","").replace("%2$s",""),d.before_title,d.after_title,d.after_widget].join("");e=a(h),f=e.prop("tagName"),g=e.prop("className").replace(/^\s+|\s+$/g,""),g&&(f+="."+g.split(/\s+/).join(".")),c.widget_selectors.push(f)})},getSidebarWidgetElement:function(b,c){return a("[id="+c+"]").filter(function(){return a(this).data("widget_customizer_sidebar_id")===b})},highlightControls:function(){var b=this.widget_selectors.join(",");a(b).attr("title",c.i18n.widget_tooltip),a(document).on("mouseenter",b,function(){var b=parent.WidgetCustomizer.getWidgetFormControlForWidget(a(this).prop("id"));b&&b.highlightSectionAndControl()}),a(document).on("click",b,function(b){if(b.shiftKey){b.preventDefault();var c=parent.WidgetCustomizer.getWidgetFormControlForWidget(a(this).prop("id"));c&&c.focus()}})}};return a.extend(c,WidgetCustomizerPreview_exports),b=wp.customize.Preview,wp.customize.Preview=b.extend({initialize:function(a,d){c.preview=this,b.prototype.initialize.call(this,a,d)}}),a(function(){c.init()}),c}(jQuery);
\ No newline at end of file