2014-04-07 05:04:14 -04:00
|
|
|
/* global _wpCustomizeWidgetsSettings */
|
|
|
|
(function( wp, $ ){
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( ! wp || ! wp.customize ) { return; }
|
|
|
|
|
|
|
|
// Set up our namespace...
|
|
|
|
var api = wp.customize,
|
2014-07-09 16:58:15 -04:00
|
|
|
l10n;
|
2014-04-07 05:04:14 -04:00
|
|
|
|
|
|
|
api.Widgets = api.Widgets || {};
|
2015-10-06 17:59:25 -04:00
|
|
|
api.Widgets.savedWidgetIds = {};
|
2014-04-07 05:04:14 -04:00
|
|
|
|
|
|
|
// Link settings
|
|
|
|
api.Widgets.data = _wpCustomizeWidgetsSettings || {};
|
|
|
|
l10n = api.Widgets.data.l10n;
|
|
|
|
delete api.Widgets.data.l10n;
|
2014-03-05 15:41:14 -05:00
|
|
|
|
|
|
|
/**
|
2014-04-07 10:10:14 -04:00
|
|
|
* wp.customize.Widgets.WidgetModel
|
|
|
|
*
|
|
|
|
* A single widget model.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @augments Backbone.Model
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
api.Widgets.WidgetModel = Backbone.Model.extend({
|
2014-03-05 15:41:14 -05:00
|
|
|
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,
|
2016-03-21 17:59:29 -04:00
|
|
|
transport: null,
|
2014-03-05 15:41:14 -05:00
|
|
|
params: [],
|
|
|
|
width: null,
|
2014-04-08 04:12:15 -04:00
|
|
|
height: null,
|
|
|
|
search_matched: true
|
2014-04-07 05:04:14 -04:00
|
|
|
});
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 10:10:14 -04:00
|
|
|
/**
|
|
|
|
* wp.customize.Widgets.WidgetCollection
|
|
|
|
*
|
|
|
|
* Collection for widget models.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @augments Backbone.Model
|
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
api.Widgets.WidgetCollection = Backbone.Collection.extend({
|
|
|
|
model: api.Widgets.WidgetModel,
|
2014-03-21 17:13:15 -04:00
|
|
|
|
|
|
|
// Controls searching on the current widget collection
|
|
|
|
// and triggers an update event
|
|
|
|
doSearch: function( value ) {
|
|
|
|
|
|
|
|
// Don't do anything if we've already done this search
|
|
|
|
// Useful because the search handler fires multiple times per keystroke
|
|
|
|
if ( this.terms === value ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Updates terms with the value passed
|
|
|
|
this.terms = value;
|
|
|
|
|
|
|
|
// If we have terms, run a search...
|
|
|
|
if ( this.terms.length > 0 ) {
|
|
|
|
this.search( this.terms );
|
|
|
|
}
|
|
|
|
|
2016-10-03 12:28:31 -04:00
|
|
|
// If search is blank, set all the widgets as they matched the search to reset the views.
|
2014-03-21 17:13:15 -04:00
|
|
|
if ( this.terms === '' ) {
|
2014-04-08 04:12:15 -04:00
|
|
|
this.each( function ( widget ) {
|
|
|
|
widget.set( 'search_matched', true );
|
|
|
|
} );
|
2014-03-21 17:13:15 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Performs a search within the collection
|
|
|
|
// @uses RegExp
|
|
|
|
search: function( term ) {
|
2014-04-08 04:12:15 -04:00
|
|
|
var match, haystack;
|
2014-03-21 17:13:15 -04:00
|
|
|
|
|
|
|
// Escape the term string for RegExp meta characters
|
|
|
|
term = term.replace( /[-\/\\^$*+?.()|[\]{}]/g, '\\$&' );
|
|
|
|
|
|
|
|
// Consider spaces as word delimiters and match the whole string
|
|
|
|
// so matching terms can be combined
|
|
|
|
term = term.replace( / /g, ')(?=.*' );
|
|
|
|
match = new RegExp( '^(?=.*' + term + ').+', 'i' );
|
|
|
|
|
2014-04-08 04:12:15 -04:00
|
|
|
this.each( function ( data ) {
|
|
|
|
haystack = [ data.get( 'name' ), data.get( 'id' ), data.get( 'description' ) ].join( ' ' );
|
|
|
|
data.set( 'search_matched', match.test( haystack ) );
|
|
|
|
} );
|
2014-03-21 17:13:15 -04:00
|
|
|
}
|
2014-04-07 05:04:14 -04:00
|
|
|
});
|
|
|
|
api.Widgets.availableWidgets = new api.Widgets.WidgetCollection( api.Widgets.data.availableWidgets );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 10:10:14 -04:00
|
|
|
/**
|
|
|
|
* wp.customize.Widgets.SidebarModel
|
|
|
|
*
|
|
|
|
* A single sidebar model.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @augments Backbone.Model
|
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
api.Widgets.SidebarModel = Backbone.Model.extend({
|
2014-03-05 15:41:14 -05:00
|
|
|
after_title: null,
|
|
|
|
after_widget: null,
|
|
|
|
before_title: null,
|
|
|
|
before_widget: null,
|
|
|
|
'class': null,
|
|
|
|
description: null,
|
|
|
|
id: null,
|
|
|
|
name: null,
|
|
|
|
is_rendered: false
|
2014-04-07 05:04:14 -04:00
|
|
|
});
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 10:10:14 -04:00
|
|
|
/**
|
|
|
|
* wp.customize.Widgets.SidebarCollection
|
|
|
|
*
|
|
|
|
* Collection for sidebar models.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @augments Backbone.Collection
|
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
api.Widgets.SidebarCollection = Backbone.Collection.extend({
|
|
|
|
model: api.Widgets.SidebarModel
|
|
|
|
});
|
|
|
|
api.Widgets.registeredSidebars = new api.Widgets.SidebarCollection( api.Widgets.data.registeredSidebars );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 10:10:14 -04:00
|
|
|
/**
|
|
|
|
* wp.customize.Widgets.AvailableWidgetsPanelView
|
|
|
|
*
|
|
|
|
* View class for the available widgets panel.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @augments wp.Backbone.View
|
|
|
|
* @augments Backbone.View
|
|
|
|
*/
|
|
|
|
api.Widgets.AvailableWidgetsPanelView = wp.Backbone.View.extend({
|
|
|
|
|
|
|
|
el: '#available-widgets',
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'input #widgets-search': 'search',
|
|
|
|
'keyup #widgets-search': 'search',
|
|
|
|
'focus .widget-tpl' : 'focus',
|
|
|
|
'click .widget-tpl' : '_submit',
|
|
|
|
'keypress .widget-tpl' : '_submit',
|
|
|
|
'keydown' : 'keyboardAccessible'
|
|
|
|
},
|
|
|
|
|
|
|
|
// Cache current selected widget
|
|
|
|
selected: null,
|
|
|
|
|
|
|
|
// Cache sidebar control which has opened panel
|
|
|
|
currentSidebarControl: null,
|
|
|
|
$search: null,
|
2016-10-03 12:28:31 -04:00
|
|
|
$clearResults: null,
|
|
|
|
searchMatchesCount: null,
|
2014-04-07 10:10:14 -04:00
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.$search = $( '#widgets-search' );
|
|
|
|
|
2016-10-03 12:28:31 -04:00
|
|
|
this.$clearResults = this.$el.find( '.clear-results' );
|
|
|
|
|
2014-04-07 10:10:14 -04:00
|
|
|
_.bindAll( this, 'close' );
|
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
this.listenTo( this.collection, 'change', this.updateList );
|
2014-04-07 10:10:14 -04:00
|
|
|
|
|
|
|
this.updateList();
|
|
|
|
|
2016-10-03 12:28:31 -04:00
|
|
|
// Set the initial search count to the number of available widgets.
|
|
|
|
this.searchMatchesCount = this.collection.length;
|
|
|
|
|
2014-04-07 10:10:14 -04:00
|
|
|
// If the available widgets panel is open and the customize controls are
|
|
|
|
// interacted with (i.e. available widgets panel is blurred) then close the
|
2015-05-29 09:57:26 -04:00
|
|
|
// available widgets panel. Also close on back button click.
|
2015-08-09 15:00:24 -04:00
|
|
|
$( '#customize-controls, #available-widgets .customize-section-title' ).on( 'click keydown', function( e ) {
|
2014-04-07 10:10:14 -04:00
|
|
|
var isAddNewBtn = $( e.target ).is( '.add-new-widget, .add-new-widget *' );
|
|
|
|
if ( $( 'body' ).hasClass( 'adding-widget' ) && ! isAddNewBtn ) {
|
|
|
|
self.close();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2016-10-03 12:28:31 -04:00
|
|
|
// Clear the search results and trigger a `keyup` event to fire a new search.
|
|
|
|
this.$clearResults.on( 'click', function() {
|
|
|
|
self.$search.val( '' ).focus().trigger( 'keyup' );
|
|
|
|
} );
|
|
|
|
|
2014-04-07 10:10:14 -04:00
|
|
|
// Close the panel if the URL in the preview changes
|
2014-07-09 16:58:15 -04:00
|
|
|
api.previewer.bind( 'url', this.close );
|
2014-04-07 10:10:14 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
// Performs a search and handles selected widget
|
|
|
|
search: function( event ) {
|
|
|
|
var firstVisible;
|
|
|
|
|
|
|
|
this.collection.doSearch( event.target.value );
|
2016-10-03 12:28:31 -04:00
|
|
|
// Update the search matches count.
|
|
|
|
this.updateSearchMatchesCount();
|
|
|
|
// Announce how many search results.
|
|
|
|
this.announceSearchMatches();
|
2014-04-07 10:10:14 -04:00
|
|
|
|
|
|
|
// Remove a widget from being selected if it is no longer visible
|
|
|
|
if ( this.selected && ! this.selected.is( ':visible' ) ) {
|
|
|
|
this.selected.removeClass( 'selected' );
|
|
|
|
this.selected = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a widget was selected but the filter value has been cleared out, clear selection
|
|
|
|
if ( this.selected && ! event.target.value ) {
|
|
|
|
this.selected.removeClass( 'selected' );
|
|
|
|
this.selected = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a filter has been entered and a widget hasn't been selected, select the first one shown
|
|
|
|
if ( ! this.selected && event.target.value ) {
|
|
|
|
firstVisible = this.$el.find( '> .widget-tpl:visible:first' );
|
|
|
|
if ( firstVisible.length ) {
|
|
|
|
this.select( firstVisible );
|
|
|
|
}
|
|
|
|
}
|
2016-10-03 12:28:31 -04:00
|
|
|
|
|
|
|
// Toggle the clear search results button.
|
|
|
|
if ( '' !== event.target.value ) {
|
|
|
|
this.$clearResults.addClass( 'is-visible' );
|
|
|
|
} else if ( '' === event.target.value ) {
|
|
|
|
this.$clearResults.removeClass( 'is-visible' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set a CSS class on the search container when there are no search results.
|
|
|
|
if ( ! this.searchMatchesCount ) {
|
|
|
|
this.$el.addClass( 'no-widgets-found' );
|
|
|
|
} else {
|
|
|
|
this.$el.removeClass( 'no-widgets-found' );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Update the count of the available widgets that have the `search_matched` attribute.
|
|
|
|
updateSearchMatchesCount: function() {
|
|
|
|
this.searchMatchesCount = this.collection.where({ search_matched: true }).length;
|
2014-04-07 10:10:14 -04:00
|
|
|
},
|
|
|
|
|
2016-10-03 12:28:31 -04:00
|
|
|
// Send a message to the aria-live region to announce how many search results.
|
|
|
|
announceSearchMatches: _.debounce( function() {
|
|
|
|
var message = l10n.widgetsFound.replace( '%d', this.searchMatchesCount ) ;
|
|
|
|
|
|
|
|
if ( ! this.searchMatchesCount ) {
|
|
|
|
message = l10n.noWidgetsFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
wp.a11y.speak( message );
|
|
|
|
}, 500 ),
|
|
|
|
|
2014-04-08 04:12:15 -04:00
|
|
|
// Changes visibility of available widgets
|
2014-04-07 10:10:14 -04:00
|
|
|
updateList: function() {
|
|
|
|
this.collection.each( function( widget ) {
|
|
|
|
var widgetTpl = $( '#widget-tpl-' + widget.id );
|
2014-04-08 04:12:15 -04:00
|
|
|
widgetTpl.toggle( widget.get( 'search_matched' ) && ! widget.get( 'is_disabled' ) );
|
2014-04-07 10:10:14 -04:00
|
|
|
if ( widget.get( 'is_disabled' ) && widgetTpl.is( this.selected ) ) {
|
|
|
|
this.selected = null;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2014-04-08 04:12:15 -04:00
|
|
|
// Highlights a widget
|
2014-04-07 10:10:14 -04:00
|
|
|
select: function( widgetTpl ) {
|
|
|
|
this.selected = $( widgetTpl );
|
|
|
|
this.selected.siblings( '.widget-tpl' ).removeClass( 'selected' );
|
|
|
|
this.selected.addClass( 'selected' );
|
|
|
|
},
|
|
|
|
|
2014-04-08 04:12:15 -04:00
|
|
|
// Highlights a widget on focus
|
2014-04-07 10:10:14 -04:00
|
|
|
focus: function( event ) {
|
|
|
|
this.select( $( event.currentTarget ) );
|
|
|
|
},
|
|
|
|
|
|
|
|
// Submit handler for keypress and click on widget
|
|
|
|
_submit: function( event ) {
|
|
|
|
// Only proceed with keypress if it is Enter or Spacebar
|
|
|
|
if ( event.type === 'keypress' && ( event.which !== 13 && event.which !== 32 ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.submit( $( event.currentTarget ) );
|
|
|
|
},
|
|
|
|
|
|
|
|
// Adds a selected widget to the sidebar
|
|
|
|
submit: function( widgetTpl ) {
|
2015-02-11 18:32:27 -05:00
|
|
|
var widgetId, widget, widgetFormControl;
|
2014-04-07 10:10:14 -04:00
|
|
|
|
|
|
|
if ( ! widgetTpl ) {
|
|
|
|
widgetTpl = this.selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! widgetTpl || ! this.currentSidebarControl ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.select( widgetTpl );
|
|
|
|
|
|
|
|
widgetId = $( this.selected ).data( 'widget-id' );
|
|
|
|
widget = this.collection.findWhere( { id: widgetId } );
|
|
|
|
if ( ! widget ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-11 18:32:27 -05:00
|
|
|
widgetFormControl = this.currentSidebarControl.addWidget( widget.get( 'id_base' ) );
|
|
|
|
if ( widgetFormControl ) {
|
|
|
|
widgetFormControl.focus();
|
|
|
|
}
|
2014-04-07 10:10:14 -04:00
|
|
|
|
|
|
|
this.close();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Opens the panel
|
|
|
|
open: function( sidebarControl ) {
|
|
|
|
this.currentSidebarControl = sidebarControl;
|
|
|
|
|
|
|
|
// Wide widget controls appear over the preview, and so they need to be collapsed when the panel opens
|
|
|
|
_( this.currentSidebarControl.getWidgetFormControls() ).each( function( control ) {
|
|
|
|
if ( control.params.is_wide ) {
|
|
|
|
control.collapseForm();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( 'body' ).addClass( 'adding-widget' );
|
|
|
|
|
|
|
|
this.$el.find( '.selected' ).removeClass( 'selected' );
|
|
|
|
|
|
|
|
// Reset search
|
|
|
|
this.collection.doSearch( '' );
|
|
|
|
|
2015-04-21 10:15:26 -04:00
|
|
|
if ( ! api.settings.browser.mobile ) {
|
|
|
|
this.$search.focus();
|
|
|
|
}
|
2014-04-07 10:10:14 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
// Closes the panel
|
|
|
|
close: function( options ) {
|
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
if ( options.returnFocus && this.currentSidebarControl ) {
|
|
|
|
this.currentSidebarControl.container.find( '.add-new-widget' ).focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.currentSidebarControl = null;
|
|
|
|
this.selected = null;
|
|
|
|
|
|
|
|
$( 'body' ).removeClass( 'adding-widget' );
|
|
|
|
|
|
|
|
this.$search.val( '' );
|
|
|
|
},
|
|
|
|
|
|
|
|
// Add keyboard accessiblity to the panel
|
|
|
|
keyboardAccessible: function( event ) {
|
|
|
|
var isEnter = ( event.which === 13 ),
|
|
|
|
isEsc = ( event.which === 27 ),
|
|
|
|
isDown = ( event.which === 40 ),
|
|
|
|
isUp = ( event.which === 38 ),
|
2014-07-18 21:19:14 -04:00
|
|
|
isTab = ( event.which === 9 ),
|
|
|
|
isShift = ( event.shiftKey ),
|
2014-04-07 10:10:14 -04:00
|
|
|
selected = null,
|
|
|
|
firstVisible = this.$el.find( '> .widget-tpl:visible:first' ),
|
|
|
|
lastVisible = this.$el.find( '> .widget-tpl:visible:last' ),
|
2014-07-18 21:19:14 -04:00
|
|
|
isSearchFocused = $( event.target ).is( this.$search ),
|
|
|
|
isLastWidgetFocused = $( event.target ).is( '.widget-tpl:visible:last' );
|
2014-04-07 10:10:14 -04:00
|
|
|
|
|
|
|
if ( isDown || isUp ) {
|
|
|
|
if ( isDown ) {
|
|
|
|
if ( isSearchFocused ) {
|
|
|
|
selected = firstVisible;
|
|
|
|
} else if ( this.selected && this.selected.nextAll( '.widget-tpl:visible' ).length !== 0 ) {
|
|
|
|
selected = this.selected.nextAll( '.widget-tpl:visible:first' );
|
|
|
|
}
|
|
|
|
} else if ( isUp ) {
|
|
|
|
if ( isSearchFocused ) {
|
|
|
|
selected = lastVisible;
|
|
|
|
} else if ( this.selected && this.selected.prevAll( '.widget-tpl:visible' ).length !== 0 ) {
|
|
|
|
selected = this.selected.prevAll( '.widget-tpl:visible:first' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.select( selected );
|
|
|
|
|
|
|
|
if ( selected ) {
|
|
|
|
selected.focus();
|
|
|
|
} else {
|
|
|
|
this.$search.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If enter pressed but nothing entered, don't do anything
|
|
|
|
if ( isEnter && ! this.$search.val() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isEnter ) {
|
|
|
|
this.submit();
|
|
|
|
} else if ( isEsc ) {
|
|
|
|
this.close( { returnFocus: true } );
|
|
|
|
}
|
2014-07-18 21:19:14 -04:00
|
|
|
|
2015-05-29 09:57:26 -04:00
|
|
|
if ( this.currentSidebarControl && isTab && ( isShift && isSearchFocused || ! isShift && isLastWidgetFocused ) ) {
|
2014-07-18 21:19:14 -04:00
|
|
|
this.currentSidebarControl.container.find( '.add-new-widget' ).focus();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2014-04-07 10:10:14 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-04-02 14:20:16 -04:00
|
|
|
/**
|
|
|
|
* Handlers for the widget-synced event, organized by widget ID base.
|
|
|
|
* Other widgets may provide their own update handlers by adding
|
|
|
|
* listeners for the widget-synced event.
|
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
api.Widgets.formSyncHandlers = {
|
2014-04-02 14:20:16 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {jQuery.Event} e
|
2014-04-07 05:04:14 -04:00
|
|
|
* @param {jQuery} widget
|
|
|
|
* @param {String} newForm
|
2014-04-02 14:20:16 -04:00
|
|
|
*/
|
2014-04-07 10:10:14 -04:00
|
|
|
rss: function( e, widget, newForm ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
var oldWidgetError = widget.find( '.widget-error:first' ),
|
|
|
|
newWidgetError = $( '<div>' + newForm + '</div>' ).find( '.widget-error:first' );
|
|
|
|
|
|
|
|
if ( oldWidgetError.length && newWidgetError.length ) {
|
|
|
|
oldWidgetError.replaceWith( newWidgetError );
|
|
|
|
} else if ( oldWidgetError.length ) {
|
|
|
|
oldWidgetError.remove();
|
|
|
|
} else if ( newWidgetError.length ) {
|
|
|
|
widget.find( '.widget-content:first' ).prepend( newWidgetError );
|
2014-04-02 14:20:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-05 15:41:14 -05:00
|
|
|
/**
|
2014-04-07 10:10:14 -04:00
|
|
|
* wp.customize.Widgets.WidgetControl
|
|
|
|
*
|
|
|
|
* Customizer control for widgets.
|
2014-04-07 05:04:14 -04:00
|
|
|
* Note that 'widget_form' must match the WP_Widget_Form_Customize_Control::$type
|
2014-04-07 10:10:14 -04:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @augments wp.customize.Control
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
api.Widgets.WidgetControl = api.Control.extend({
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
defaultExpandedArguments: {
|
2014-11-11 17:37:22 -05:00
|
|
|
duration: 'fast',
|
|
|
|
completeCallback: $.noop
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
},
|
|
|
|
|
2014-12-03 21:04:22 -05:00
|
|
|
/**
|
|
|
|
* @since 4.1.0
|
|
|
|
*/
|
2015-09-25 17:02:27 -04:00
|
|
|
initialize: function( id, options ) {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
var control = this;
|
2015-09-25 17:02:27 -04:00
|
|
|
|
|
|
|
control.widgetControlEmbedded = false;
|
|
|
|
control.widgetContentEmbedded = false;
|
|
|
|
control.expanded = new api.Value( false );
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
control.expandedArgumentsQueue = [];
|
2015-09-25 17:02:27 -04:00
|
|
|
control.expanded.bind( function( expanded ) {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
var args = control.expandedArgumentsQueue.shift();
|
|
|
|
args = $.extend( {}, control.defaultExpandedArguments, args );
|
|
|
|
control.onChangeExpanded( expanded, args );
|
|
|
|
});
|
Customize: Add setting validation model and control notifications to augment setting sanitization.
When a setting is invalid, not only will it be blocked from being saved but all other settings will be blocked as well. This ensures that Customizer saves aren't partial but are more transactional. User will be displayed the error in a notification so that they can fix and re-attempt saving.
PHP changes:
* Introduces `WP_Customize_Setting::validate()`, `WP_Customize_Setting::$validate_callback`, and the `customize_validate_{$setting_id}` filter.
* Introduces `WP_Customize_Manager::validate_setting_values()` to do validation (and sanitization) for the setting values supplied, returning a list of `WP_Error` instances for invalid settings.
* Attempting to save settings that are invalid will result in the save being blocked entirely, with the errors being sent in the `customize_save_response`. Modifies `WP_Customize_Manager::save()` to check all settings for validity issues prior to calling their `save` methods.
* Introduces `WP_Customize_Setting::json()` for parity with the other Customizer classes. This includes exporting of the `type`.
* Modifies `WP_Customize_Manager::post_value()` to apply `validate` after `sanitize`, and if validation fails, to return the `$default`.
* Introduces `customize_save_validation_before` action which fires right before the validation checks are made prior to saving.
JS changes:
* Introduces `wp.customize.Notification` in JS which to represent `WP_Error` instances returned from the server when setting validation fails.
* Introduces `wp.customize.Setting.prototype.notifications`.
* Introduces `wp.customize.Control.prototype.notifications`, which are synced with a control's settings' notifications.
* Introduces `wp.customize.Control.prototype.renderNotifications()` to re-render a control's notifications in its notification area. This is called automatically when the notifications collection changes.
* Introduces `wp.customize.settingConstructor`, allowing custom setting types to be used in the same way that custom controls, panels, and sections can be made.
* Injects a notification area into existing controls which is populated in response to the control's `notifications` collection changing. A custom control can customize the placement of the notification area by overriding the new `getNotificationsContainerElement` method.
* When a save fails due to setting invalidity, the invalidity errors will be added to the settings to then populate in the controls' notification areas, and the first such invalid control will be focused.
Props westonruter, celloexpressions, mrahmadawais.
See #35210.
See #30937.
Fixes #34893.
Built from https://develop.svn.wordpress.org/trunk@37476
git-svn-id: http://core.svn.wordpress.org/trunk@37444 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-05-20 17:10:27 -04:00
|
|
|
control.altNotice = true;
|
2015-09-25 17:02:27 -04:00
|
|
|
|
|
|
|
api.Control.prototype.initialize.call( control, id, options );
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
},
|
|
|
|
|
2014-03-05 15:41:14 -05:00
|
|
|
/**
|
2015-09-25 17:02:27 -04:00
|
|
|
* Set up the control.
|
|
|
|
*
|
|
|
|
* @since 3.9.0
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
|
|
|
ready: function() {
|
2015-09-25 17:02:27 -04:00
|
|
|
var control = this;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Embed a placeholder once the section is expanded. The full widget
|
|
|
|
* form content will be embedded once the control itself is expanded,
|
|
|
|
* and at this point the widget-added event will be triggered.
|
|
|
|
*/
|
|
|
|
if ( ! control.section() ) {
|
|
|
|
control.embedWidgetControl();
|
|
|
|
} else {
|
|
|
|
api.section( control.section(), function( section ) {
|
|
|
|
var onExpanded = function( isExpanded ) {
|
|
|
|
if ( isExpanded ) {
|
|
|
|
control.embedWidgetControl();
|
|
|
|
section.expanded.unbind( onExpanded );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if ( section.expanded() ) {
|
|
|
|
onExpanded( true );
|
|
|
|
} else {
|
|
|
|
section.expanded.bind( onExpanded );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Embed the .widget element inside the li container.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*/
|
|
|
|
embedWidgetControl: function() {
|
|
|
|
var control = this, widgetControl;
|
|
|
|
|
|
|
|
if ( control.widgetControlEmbedded ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
control.widgetControlEmbedded = true;
|
|
|
|
|
|
|
|
widgetControl = $( control.params.widget_control );
|
|
|
|
control.container.append( widgetControl );
|
|
|
|
|
|
|
|
control._setupModel();
|
|
|
|
control._setupWideWidget();
|
|
|
|
control._setupControlToggle();
|
|
|
|
|
|
|
|
control._setupWidgetTitle();
|
|
|
|
control._setupReorderUI();
|
|
|
|
control._setupHighlightEffects();
|
|
|
|
control._setupUpdateUI();
|
|
|
|
control._setupRemoveUI();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Embed the actual widget form inside of .widget-content and finally trigger the widget-added event.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*/
|
|
|
|
embedWidgetContent: function() {
|
|
|
|
var control = this, widgetContent;
|
|
|
|
|
|
|
|
control.embedWidgetControl();
|
|
|
|
if ( control.widgetContentEmbedded ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
control.widgetContentEmbedded = true;
|
|
|
|
|
|
|
|
widgetContent = $( control.params.widget_content );
|
|
|
|
control.container.find( '.widget-content:first' ).append( widgetContent );
|
2014-11-11 17:46:23 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Trigger widget-added event so that plugins can attach any event
|
|
|
|
* listeners and dynamic UI elements.
|
|
|
|
*/
|
2015-09-25 17:02:27 -04:00
|
|
|
$( document ).trigger( 'widget-added', [ control.container.find( '.widget:first' ) ] );
|
|
|
|
|
2014-03-05 15:41:14 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Handle changes to the setting
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
|
|
|
_setupModel: function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
var self = this, rememberSavedWidgetId;
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Remember saved widgets so we know which to trash (move to inactive widgets sidebar)
|
2014-04-07 12:32:15 -04:00
|
|
|
rememberSavedWidgetId = function() {
|
|
|
|
api.Widgets.savedWidgetIds[self.params.widget_id] = true;
|
2014-04-07 05:04:14 -04:00
|
|
|
};
|
2014-04-07 12:32:15 -04:00
|
|
|
api.bind( 'ready', rememberSavedWidgetId );
|
|
|
|
api.bind( 'saved', rememberSavedWidgetId );
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
this._updateCount = 0;
|
|
|
|
this.isWidgetUpdating = false;
|
|
|
|
this.liveUpdateMode = true;
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Update widget whenever model changes
|
2014-04-07 12:32:15 -04:00
|
|
|
this.setting.bind( function( to, from ) {
|
|
|
|
if ( ! _( from ).isEqual( to ) && ! self.isWidgetUpdating ) {
|
|
|
|
self.updateWidget( { instance: to } );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
},
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
/**
|
|
|
|
* Add special behaviors for wide widget controls
|
|
|
|
*/
|
|
|
|
_setupWideWidget: function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
var self = this, $widgetInside, $widgetForm, $customizeSidebar,
|
|
|
|
$themeControlsContainer, positionWidget;
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
if ( ! this.params.is_wide ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
$widgetInside = this.container.find( '.widget-inside' );
|
|
|
|
$widgetForm = $widgetInside.find( '> .form' );
|
|
|
|
$customizeSidebar = $( '.wp-full-overlay-sidebar-content:first' );
|
|
|
|
this.container.addClass( 'wide-widget-control' );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
this.container.find( '.widget-content:first' ).css( {
|
|
|
|
'max-width': this.params.width,
|
|
|
|
'min-height': this.params.height
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
/**
|
|
|
|
* Keep the widget-inside positioned so the top of fixed-positioned
|
|
|
|
* element is at the same top position as the widget-top. When the
|
|
|
|
* 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.
|
|
|
|
* If a widget is too tall to fit in the window, don't let the height
|
|
|
|
* exceed the window height so that the contents of the widget control
|
|
|
|
* will become scrollable (overflow:auto).
|
|
|
|
*/
|
2014-04-07 12:32:15 -04:00
|
|
|
positionWidget = function() {
|
|
|
|
var offsetTop = self.container.offset().top,
|
|
|
|
windowHeight = $( window ).height(),
|
|
|
|
formHeight = $widgetForm.outerHeight(),
|
2014-04-07 05:04:14 -04:00
|
|
|
top;
|
2014-04-07 12:32:15 -04:00
|
|
|
$widgetInside.css( 'max-height', windowHeight );
|
2014-04-07 05:04:14 -04:00
|
|
|
top = Math.max(
|
|
|
|
0, // prevent top from going off screen
|
|
|
|
Math.min(
|
2014-04-07 12:32:15 -04:00
|
|
|
Math.max( offsetTop, 0 ), // distance widget in panel is from top of screen
|
|
|
|
windowHeight - formHeight // flush up against bottom of screen
|
2014-04-07 05:04:14 -04:00
|
|
|
)
|
|
|
|
);
|
2014-04-07 12:32:15 -04:00
|
|
|
$widgetInside.css( 'top', top );
|
2014-04-07 05:04:14 -04:00
|
|
|
};
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
$themeControlsContainer = $( '#customize-theme-controls' );
|
|
|
|
this.container.on( 'expand', function() {
|
|
|
|
positionWidget();
|
|
|
|
$customizeSidebar.on( 'scroll', positionWidget );
|
|
|
|
$( window ).on( 'resize', positionWidget );
|
|
|
|
$themeControlsContainer.on( 'expanded collapsed', positionWidget );
|
2014-03-05 15:41:14 -05:00
|
|
|
} );
|
2014-04-07 12:32:15 -04:00
|
|
|
this.container.on( 'collapsed', function() {
|
|
|
|
$customizeSidebar.off( 'scroll', positionWidget );
|
|
|
|
$( window ).off( 'resize', positionWidget );
|
|
|
|
$themeControlsContainer.off( 'expanded collapsed', positionWidget );
|
2014-03-05 15:41:14 -05:00
|
|
|
} );
|
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Reposition whenever a sidebar's widgets are changed
|
2014-04-07 10:10:14 -04:00
|
|
|
api.each( function( setting ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( 0 === setting.id.indexOf( 'sidebars_widgets[' ) ) {
|
|
|
|
setting.bind( function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
if ( self.container.hasClass( 'expanded' ) ) {
|
|
|
|
positionWidget();
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-03-05 15:41:14 -05:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Show/hide the control when clicking on the form title, when clicking
|
|
|
|
* the close button
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
_setupControlToggle: function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
var self = this, $closeBtn;
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
this.container.find( '.widget-top' ).on( 'click', function( e ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
e.preventDefault();
|
2014-04-07 12:32:15 -04:00
|
|
|
var sidebarWidgetsControl = self.getSidebarWidgetsControl();
|
2014-04-07 16:00:16 -04:00
|
|
|
if ( sidebarWidgetsControl.isReordering ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
return;
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
self.expanded( ! self.expanded() );
|
2014-03-05 15:41:14 -05:00
|
|
|
} );
|
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
$closeBtn = this.container.find( '.widget-control-close' );
|
|
|
|
$closeBtn.on( 'click', function( e ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
e.preventDefault();
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
self.collapse();
|
2014-04-07 12:32:15 -04:00
|
|
|
self.container.find( '.widget-top .widget-action:first' ).focus(); // keyboard accessibility
|
2014-03-05 15:41:14 -05:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Update the title of the form if a title field is entered
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
_setupWidgetTitle: function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
var self = this, updateTitle;
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
updateTitle = function() {
|
|
|
|
var title = self.setting().title,
|
|
|
|
inWidgetTitle = self.container.find( '.in-widget-title' );
|
2014-04-07 05:04:14 -04:00
|
|
|
|
|
|
|
if ( title ) {
|
2014-04-07 12:32:15 -04:00
|
|
|
inWidgetTitle.text( ': ' + title );
|
2014-04-07 05:04:14 -04:00
|
|
|
} else {
|
2014-04-07 12:32:15 -04:00
|
|
|
inWidgetTitle.text( '' );
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
2014-04-07 05:04:14 -04:00
|
|
|
};
|
2014-04-07 12:32:15 -04:00
|
|
|
this.setting.bind( updateTitle );
|
|
|
|
updateTitle();
|
2014-04-07 05:04:14 -04:00
|
|
|
},
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
/**
|
|
|
|
* Set up the widget-reorder-nav
|
|
|
|
*/
|
|
|
|
_setupReorderUI: function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
var self = this, selectSidebarItem, $moveWidgetArea,
|
2016-02-17 10:22:26 -05:00
|
|
|
$reorderNav, updateAvailableSidebars, template;
|
2014-04-07 05:04:14 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* select the provided sidebar list item in the move widget area
|
|
|
|
*
|
|
|
|
* @param {jQuery} li
|
|
|
|
*/
|
2014-04-07 12:32:15 -04:00
|
|
|
selectSidebarItem = function( li ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
li.siblings( '.selected' ).removeClass( 'selected' );
|
|
|
|
li.addClass( 'selected' );
|
2014-04-07 12:32:15 -04:00
|
|
|
var isSelfSidebar = ( li.data( 'id' ) === self.params.sidebar_id );
|
|
|
|
self.container.find( '.move-widget-btn' ).prop( 'disabled', isSelfSidebar );
|
2014-04-07 05:04:14 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the widget reordering elements to the widget control
|
|
|
|
*/
|
2014-04-07 12:32:15 -04:00
|
|
|
this.container.find( '.widget-title-action' ).after( $( api.Widgets.data.tpl.widgetReorderNav ) );
|
2016-02-17 10:22:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
template = _.template( api.Widgets.data.tpl.moveWidgetArea );
|
|
|
|
$moveWidgetArea = $( template( {
|
2014-04-07 05:04:14 -04:00
|
|
|
sidebars: _( api.Widgets.registeredSidebars.toArray() ).pluck( 'attributes' )
|
|
|
|
} )
|
|
|
|
);
|
2014-04-07 12:32:15 -04:00
|
|
|
this.container.find( '.widget-top' ).after( $moveWidgetArea );
|
2014-04-07 05:04:14 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update available sidebars when their rendered state changes
|
|
|
|
*/
|
2014-04-07 12:32:15 -04:00
|
|
|
updateAvailableSidebars = function() {
|
2015-02-11 15:45:26 -05:00
|
|
|
var $sidebarItems = $moveWidgetArea.find( 'li' ), selfSidebarItem,
|
|
|
|
renderedSidebarCount = 0;
|
2014-04-07 12:32:15 -04:00
|
|
|
|
|
|
|
selfSidebarItem = $sidebarItems.filter( function(){
|
|
|
|
return $( this ).data( 'id' ) === self.params.sidebar_id;
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-04-07 12:32:15 -04:00
|
|
|
|
|
|
|
$sidebarItems.each( function() {
|
2014-04-07 05:04:14 -04:00
|
|
|
var li = $( this ),
|
2015-02-11 15:45:26 -05:00
|
|
|
sidebarId, sidebar, sidebarIsRendered;
|
2014-04-07 05:04:14 -04:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
sidebarId = li.data( 'id' );
|
2014-04-07 16:00:16 -04:00
|
|
|
sidebar = api.Widgets.registeredSidebars.get( sidebarId );
|
2015-02-11 15:45:26 -05:00
|
|
|
sidebarIsRendered = sidebar.get( 'is_rendered' );
|
2014-04-07 12:32:15 -04:00
|
|
|
|
2015-02-11 15:45:26 -05:00
|
|
|
li.toggle( sidebarIsRendered );
|
2014-04-07 12:32:15 -04:00
|
|
|
|
2015-02-11 15:45:26 -05:00
|
|
|
if ( sidebarIsRendered ) {
|
|
|
|
renderedSidebarCount += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( li.hasClass( 'selected' ) && ! sidebarIsRendered ) {
|
2014-04-07 12:32:15 -04:00
|
|
|
selectSidebarItem( selfSidebarItem );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
|
|
|
} );
|
2015-01-20 15:36:21 -05:00
|
|
|
|
2015-02-11 15:45:26 -05:00
|
|
|
if ( renderedSidebarCount > 1 ) {
|
2015-01-20 15:36:21 -05:00
|
|
|
self.container.find( '.move-widget' ).show();
|
2015-02-11 15:45:26 -05:00
|
|
|
} else {
|
|
|
|
self.container.find( '.move-widget' ).hide();
|
2015-01-20 15:36:21 -05:00
|
|
|
}
|
2014-04-07 05:04:14 -04:00
|
|
|
};
|
2014-04-07 12:32:15 -04:00
|
|
|
|
|
|
|
updateAvailableSidebars();
|
|
|
|
api.Widgets.registeredSidebars.on( 'change:is_rendered', updateAvailableSidebars );
|
2014-04-07 05:04:14 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle clicks for up/down/move on the reorder nav
|
|
|
|
*/
|
2014-04-07 12:32:15 -04:00
|
|
|
$reorderNav = this.container.find( '.widget-reorder-nav' );
|
2014-07-18 21:58:15 -04:00
|
|
|
$reorderNav.find( '.move-widget, .move-widget-down, .move-widget-up' ).each( function() {
|
|
|
|
$( this ).prepend( self.container.find( '.widget-title' ).text() + ': ' );
|
|
|
|
} ).on( 'click keypress', function( event ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( event.type === 'keypress' && ( event.which !== 13 && event.which !== 32 ) ) {
|
2014-03-05 15:41:14 -05:00
|
|
|
return;
|
|
|
|
}
|
2014-04-07 05:04:14 -04:00
|
|
|
$( this ).focus();
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( $( this ).is( '.move-widget' ) ) {
|
2014-04-07 12:32:15 -04:00
|
|
|
self.toggleWidgetMoveArea();
|
2014-03-05 15:41:14 -05:00
|
|
|
} else {
|
2014-04-07 12:32:15 -04:00
|
|
|
var isMoveDown = $( this ).is( '.move-widget-down' ),
|
|
|
|
isMoveUp = $( this ).is( '.move-widget-up' ),
|
|
|
|
i = self.getWidgetSidebarPosition();
|
2014-04-07 05:04:14 -04:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
if ( ( isMoveUp && i === 0 ) || ( isMoveDown && i === self.getSidebarWidgetsControl().setting().length - 1 ) ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
if ( isMoveUp ) {
|
|
|
|
self.moveUp();
|
2015-03-01 14:11:27 -05:00
|
|
|
wp.a11y.speak( l10n.widgetMovedUp );
|
2014-04-07 05:04:14 -04:00
|
|
|
} else {
|
2014-04-07 12:32:15 -04:00
|
|
|
self.moveDown();
|
2015-03-01 14:11:27 -05:00
|
|
|
wp.a11y.speak( l10n.widgetMovedDown );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$( this ).focus(); // re-focus after the container was moved
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
/**
|
|
|
|
* Handle selecting a sidebar to move to
|
|
|
|
*/
|
2014-12-23 12:24:24 -05:00
|
|
|
this.container.find( '.widget-area-select' ).on( 'click keypress', 'li', function( event ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( event.type === 'keypress' && ( event.which !== 13 && event.which !== 32 ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-23 12:24:24 -05:00
|
|
|
event.preventDefault();
|
2014-04-07 12:32:15 -04:00
|
|
|
selectSidebarItem( $( this ) );
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
/**
|
|
|
|
* Move widget to another sidebar
|
|
|
|
*/
|
2014-04-07 12:32:15 -04:00
|
|
|
this.container.find( '.move-widget-btn' ).click( function() {
|
|
|
|
self.getSidebarWidgetsControl().toggleReordering( false );
|
|
|
|
|
|
|
|
var oldSidebarId = self.params.sidebar_id,
|
|
|
|
newSidebarId = self.container.find( '.widget-area-select li.selected' ).data( 'id' ),
|
|
|
|
oldSidebarWidgetsSetting, newSidebarWidgetsSetting,
|
|
|
|
oldSidebarWidgetIds, newSidebarWidgetIds, i;
|
|
|
|
|
|
|
|
oldSidebarWidgetsSetting = api( 'sidebars_widgets[' + oldSidebarId + ']' );
|
|
|
|
newSidebarWidgetsSetting = api( 'sidebars_widgets[' + newSidebarId + ']' );
|
|
|
|
oldSidebarWidgetIds = Array.prototype.slice.call( oldSidebarWidgetsSetting() );
|
|
|
|
newSidebarWidgetIds = Array.prototype.slice.call( newSidebarWidgetsSetting() );
|
|
|
|
|
|
|
|
i = self.getWidgetSidebarPosition();
|
|
|
|
oldSidebarWidgetIds.splice( i, 1 );
|
|
|
|
newSidebarWidgetIds.push( self.params.widget_id );
|
|
|
|
|
|
|
|
oldSidebarWidgetsSetting( oldSidebarWidgetIds );
|
|
|
|
newSidebarWidgetsSetting( newSidebarWidgetIds );
|
|
|
|
|
|
|
|
self.focus();
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-10-15 13:21:19 -04:00
|
|
|
* Highlight widgets in preview when interacted with in the Customizer
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
_setupHighlightEffects: function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
var self = this;
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Highlight whenever hovering or clicking over the form
|
2014-04-07 12:32:15 -04:00
|
|
|
this.container.on( 'mouseenter click', function() {
|
|
|
|
self.setting.previewer.send( 'highlight-widget', self.params.widget_id );
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Highlight when the setting is updated
|
2014-04-07 12:32:15 -04:00
|
|
|
this.setting.bind( function() {
|
|
|
|
self.setting.previewer.send( 'highlight-widget', self.params.widget_id );
|
2014-03-05 15:41:14 -05:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Set up event handlers for widget updating
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
_setupUpdateUI: function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
var self = this, $widgetRoot, $widgetContent,
|
|
|
|
$saveBtn, updateWidgetDebounced, formSyncHandler;
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
$widgetRoot = this.container.find( '.widget:first' );
|
|
|
|
$widgetContent = $widgetRoot.find( '.widget-content:first' );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Configure update button
|
2014-04-07 12:32:15 -04:00
|
|
|
$saveBtn = this.container.find( '.widget-control-save' );
|
|
|
|
$saveBtn.val( l10n.saveBtnLabel );
|
|
|
|
$saveBtn.attr( 'title', l10n.saveBtnTooltip );
|
2016-09-28 15:54:28 -04:00
|
|
|
$saveBtn.removeClass( 'button-primary' );
|
2014-04-07 12:32:15 -04:00
|
|
|
$saveBtn.on( 'click', function( e ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
e.preventDefault();
|
2014-04-07 16:00:16 -04:00
|
|
|
self.updateWidget( { disable_form: true } ); // @todo disable_form is unused?
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
updateWidgetDebounced = _.debounce( function() {
|
|
|
|
self.updateWidget();
|
2014-04-07 05:04:14 -04:00
|
|
|
}, 250 );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Trigger widget form update when hitting Enter within an input
|
2014-04-15 20:11:35 -04:00
|
|
|
$widgetContent.on( 'keydown', 'input', function( e ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( 13 === e.which ) { // Enter
|
|
|
|
e.preventDefault();
|
2014-04-07 16:00:16 -04:00
|
|
|
self.updateWidget( { ignoreActiveElement: true } );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-03-05 15:41:14 -05:00
|
|
|
} );
|
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Handle widgets that support live previews
|
2014-04-07 12:32:15 -04:00
|
|
|
$widgetContent.on( 'change input propertychange', ':input', function( e ) {
|
2015-07-29 12:03:24 -04:00
|
|
|
if ( ! self.liveUpdateMode ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( e.type === 'change' || ( this.checkValidity && this.checkValidity() ) ) {
|
|
|
|
updateWidgetDebounced();
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Remove loading indicators when the setting is saved and the preview updates
|
2014-04-07 12:32:15 -04:00
|
|
|
this.setting.previewer.channel.bind( 'synced', function() {
|
|
|
|
self.container.removeClass( 'previewer-loading' );
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-04-07 12:32:15 -04:00
|
|
|
|
2014-07-09 16:58:15 -04:00
|
|
|
api.previewer.bind( 'widget-updated', function( updatedWidgetId ) {
|
2014-04-07 12:32:15 -04:00
|
|
|
if ( updatedWidgetId === self.params.widget_id ) {
|
|
|
|
self.container.removeClass( 'previewer-loading' );
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
formSyncHandler = api.Widgets.formSyncHandlers[ this.params.widget_id_base ];
|
|
|
|
if ( formSyncHandler ) {
|
|
|
|
$( document ).on( 'widget-synced', function( e, widget ) {
|
|
|
|
if ( $widgetRoot.is( widget ) ) {
|
|
|
|
formSyncHandler.apply( document, arguments );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
2014-04-07 05:04:14 -04:00
|
|
|
},
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-07-09 19:58:16 -04:00
|
|
|
/**
|
|
|
|
* Update widget control to indicate whether it is currently rendered.
|
|
|
|
*
|
|
|
|
* Overrides api.Control.toggle()
|
|
|
|
*
|
2014-12-03 21:04:22 -05:00
|
|
|
* @since 4.1.0
|
|
|
|
*
|
|
|
|
* @param {Boolean} active
|
|
|
|
* @param {Object} args
|
|
|
|
* @param {Callback} args.completeCallback
|
2014-07-09 19:58:16 -04:00
|
|
|
*/
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
onChangeActive: function ( active, args ) {
|
|
|
|
// Note: there is a second 'args' parameter being passed, merged on top of this.defaultActiveArguments
|
2014-07-09 19:58:16 -04:00
|
|
|
this.container.toggleClass( 'widget-rendered', active );
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
if ( args.completeCallback ) {
|
|
|
|
args.completeCallback();
|
|
|
|
}
|
2014-07-09 19:58:16 -04:00
|
|
|
},
|
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
/**
|
|
|
|
* Set up event handlers for widget removal
|
|
|
|
*/
|
|
|
|
_setupRemoveUI: function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
var self = this, $removeBtn, replaceDeleteWithRemove;
|
2014-04-07 05:04:14 -04:00
|
|
|
|
|
|
|
// Configure remove button
|
2014-04-07 12:32:15 -04:00
|
|
|
$removeBtn = this.container.find( 'a.widget-control-remove' );
|
|
|
|
$removeBtn.on( 'click', function( e ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
// Find an adjacent element to add focus to when this widget goes away
|
2014-04-07 12:32:15 -04:00
|
|
|
var $adjacentFocusTarget;
|
|
|
|
if ( self.container.next().is( '.customize-control-widget_form' ) ) {
|
|
|
|
$adjacentFocusTarget = self.container.next().find( '.widget-action:first' );
|
|
|
|
} else if ( self.container.prev().is( '.customize-control-widget_form' ) ) {
|
|
|
|
$adjacentFocusTarget = self.container.prev().find( '.widget-action:first' );
|
2014-03-05 15:41:14 -05:00
|
|
|
} else {
|
2014-04-07 12:32:15 -04:00
|
|
|
$adjacentFocusTarget = self.container.next( '.customize-control-sidebar_widgets' ).find( '.add-new-widget:first' );
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
2014-04-02 14:20:16 -04:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
self.container.slideUp( function() {
|
2014-04-07 16:00:16 -04:00
|
|
|
var sidebarsWidgetsControl = api.Widgets.getSidebarWidgetControlContainingWidget( self.params.widget_id ),
|
|
|
|
sidebarWidgetIds, i;
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 16:00:16 -04:00
|
|
|
if ( ! sidebarsWidgetsControl ) {
|
2014-04-07 12:32:15 -04:00
|
|
|
return;
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-04-07 16:00:16 -04:00
|
|
|
|
|
|
|
sidebarWidgetIds = sidebarsWidgetsControl.setting().slice();
|
|
|
|
i = _.indexOf( sidebarWidgetIds, self.params.widget_id );
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( -1 === i ) {
|
2014-04-07 12:32:15 -04:00
|
|
|
return;
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-04-07 16:00:16 -04:00
|
|
|
|
|
|
|
sidebarWidgetIds.splice( i, 1 );
|
|
|
|
sidebarsWidgetsControl.setting( sidebarWidgetIds );
|
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
$adjacentFocusTarget.focus(); // keyboard accessibility
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
replaceDeleteWithRemove = function() {
|
|
|
|
$removeBtn.text( l10n.removeBtnLabel ); // wp_widget_control() outputs the link as "Delete"
|
|
|
|
$removeBtn.attr( 'title', l10n.removeBtnTooltip );
|
2014-04-07 05:04:14 -04:00
|
|
|
};
|
2014-04-07 12:32:15 -04:00
|
|
|
|
|
|
|
if ( this.params.is_new ) {
|
|
|
|
api.bind( 'saved', replaceDeleteWithRemove );
|
2014-04-07 05:04:14 -04:00
|
|
|
} else {
|
2014-04-07 12:32:15 -04:00
|
|
|
replaceDeleteWithRemove();
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
|
|
|
},
|
2014-03-05 15:41:14 -05:00
|
|
|
|
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Find all inputs in a widget container that should be considered when
|
|
|
|
* comparing the loaded form with the sanitized form, whose fields will
|
|
|
|
* be aligned to copy the sanitized over. The elements returned by this
|
|
|
|
* are passed into this._getInputsSignature(), and they are iterated
|
2015-12-06 16:23:25 -05:00
|
|
|
* over when copying sanitized values over to the form loaded.
|
2014-04-07 05:04:14 -04:00
|
|
|
*
|
|
|
|
* @param {jQuery} container element in which to look for inputs
|
|
|
|
* @returns {jQuery} inputs
|
|
|
|
* @private
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 10:10:14 -04:00
|
|
|
_getInputs: function( container ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
return $( container ).find( ':input[name]' );
|
2014-03-05 15:41:14 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Iterate over supplied inputs and create a signature string for all of them together.
|
|
|
|
* This string can be used to compare whether or not the form has all of the same fields.
|
|
|
|
*
|
|
|
|
* @param {jQuery} inputs
|
|
|
|
* @returns {string}
|
|
|
|
* @private
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 10:10:14 -04:00
|
|
|
_getInputsSignature: function( inputs ) {
|
2014-04-07 12:32:15 -04:00
|
|
|
var inputsSignatures = _( inputs ).map( function( input ) {
|
|
|
|
var $input = $( input ), signatureParts;
|
|
|
|
|
|
|
|
if ( $input.is( ':checkbox, :radio' ) ) {
|
|
|
|
signatureParts = [ $input.attr( 'id' ), $input.attr( 'name' ), $input.prop( 'value' ) ];
|
2014-04-07 05:04:14 -04:00
|
|
|
} else {
|
2014-04-07 12:32:15 -04:00
|
|
|
signatureParts = [ $input.attr( 'id' ), $input.attr( 'name' ) ];
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
2014-04-07 12:32:15 -04:00
|
|
|
|
|
|
|
return signatureParts.join( ',' );
|
2014-03-05 15:41:14 -05:00
|
|
|
} );
|
2014-04-07 12:32:15 -04:00
|
|
|
|
|
|
|
return inputsSignatures.join( ';' );
|
2014-03-05 15:41:14 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-04-04 12:34:26 -04:00
|
|
|
* Get the state for an input depending on its type.
|
2014-04-07 05:04:14 -04:00
|
|
|
*
|
2015-04-04 12:34:26 -04:00
|
|
|
* @param {jQuery|Element} input
|
|
|
|
* @returns {string|boolean|array|*}
|
2014-04-07 05:04:14 -04:00
|
|
|
* @private
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2015-04-04 12:34:26 -04:00
|
|
|
_getInputState: function( input ) {
|
|
|
|
input = $( input );
|
|
|
|
if ( input.is( ':radio, :checkbox' ) ) {
|
|
|
|
return input.prop( 'checked' );
|
|
|
|
} else if ( input.is( 'select[multiple]' ) ) {
|
|
|
|
return input.find( 'option:selected' ).map( function () {
|
|
|
|
return $( this ).val();
|
|
|
|
} ).get();
|
|
|
|
} else {
|
|
|
|
return input.val();
|
|
|
|
}
|
|
|
|
},
|
2014-04-07 12:32:15 -04:00
|
|
|
|
2015-04-04 12:34:26 -04:00
|
|
|
/**
|
|
|
|
* Update an input's state based on its type.
|
|
|
|
*
|
|
|
|
* @param {jQuery|Element} input
|
|
|
|
* @param {string|boolean|array|*} state
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_setInputState: function ( input, state ) {
|
|
|
|
input = $( input );
|
|
|
|
if ( input.is( ':radio, :checkbox' ) ) {
|
|
|
|
input.prop( 'checked', state );
|
|
|
|
} else if ( input.is( 'select[multiple]' ) ) {
|
|
|
|
if ( ! $.isArray( state ) ) {
|
|
|
|
state = [];
|
|
|
|
} else {
|
|
|
|
// Make sure all state items are strings since the DOM value is a string
|
|
|
|
state = _.map( state, function ( value ) {
|
|
|
|
return String( value );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
input.find( 'option' ).each( function () {
|
|
|
|
$( this ).prop( 'selected', -1 !== _.indexOf( state, String( this.value ) ) );
|
|
|
|
} );
|
2014-04-07 05:04:14 -04:00
|
|
|
} else {
|
2015-04-04 12:34:26 -04:00
|
|
|
input.val( state );
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
2014-04-07 05:04:14 -04:00
|
|
|
},
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
/***********************************************************************
|
|
|
|
* Begin public API methods
|
|
|
|
**********************************************************************/
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
/**
|
|
|
|
* @return {wp.customize.controlConstructor.sidebar_widgets[]}
|
|
|
|
*/
|
|
|
|
getSidebarWidgetsControl: function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
var settingId, sidebarWidgetsControl;
|
|
|
|
|
|
|
|
settingId = 'sidebars_widgets[' + this.params.sidebar_id + ']';
|
|
|
|
sidebarWidgetsControl = api.control( settingId );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
if ( ! sidebarWidgetsControl ) {
|
|
|
|
return;
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-04-07 12:32:15 -04:00
|
|
|
|
|
|
|
return sidebarWidgetsControl;
|
2014-03-05 15:41:14 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Submit the widget form via Ajax and get back the updated instance,
|
|
|
|
* along with the new widget control form to render.
|
|
|
|
*
|
|
|
|
* @param {object} [args]
|
|
|
|
* @param {Object|null} [args.instance=null] When the model changes, the instance is sent here; otherwise, the inputs from the form are used
|
|
|
|
* @param {Function|null} [args.complete=null] Function which is called when the request finishes. Context is bound to the control. First argument is any error. Following arguments are for success.
|
2014-04-07 16:00:16 -04:00
|
|
|
* @param {Boolean} [args.ignoreActiveElement=false] Whether or not updating a field will be deferred if focus is still on the element.
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 10:10:14 -04:00
|
|
|
updateWidget: function( args ) {
|
2014-04-07 12:32:15 -04:00
|
|
|
var self = this, instanceOverride, completeCallback, $widgetRoot, $widgetContent,
|
|
|
|
updateNumber, params, data, $inputs, processing, jqxhr, isChanged;
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2015-09-25 17:02:27 -04:00
|
|
|
// The updateWidget logic requires that the form fields to be fully present.
|
|
|
|
self.embedWidgetContent();
|
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
args = $.extend( {
|
|
|
|
instance: null,
|
|
|
|
complete: null,
|
2014-04-07 16:00:16 -04:00
|
|
|
ignoreActiveElement: false
|
2014-04-07 05:04:14 -04:00
|
|
|
}, args );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
instanceOverride = args.instance;
|
|
|
|
completeCallback = args.complete;
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
this._updateCount += 1;
|
|
|
|
updateNumber = this._updateCount;
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
$widgetRoot = this.container.find( '.widget:first' );
|
|
|
|
$widgetContent = $widgetRoot.find( '.widget-content:first' );
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Remove a previous error message
|
2014-04-07 12:32:15 -04:00
|
|
|
$widgetContent.find( '.widget-error' ).remove();
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
this.container.addClass( 'widget-form-loading' );
|
|
|
|
this.container.addClass( 'previewer-loading' );
|
2014-04-07 05:04:14 -04:00
|
|
|
processing = api.state( 'processing' );
|
|
|
|
processing( processing() + 1 );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
if ( ! this.liveUpdateMode ) {
|
|
|
|
this.container.addClass( 'widget-form-disabled' );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
params = {};
|
|
|
|
params.action = 'update-widget';
|
|
|
|
params.wp_customize = 'on';
|
2016-01-27 12:55:26 -05:00
|
|
|
params.nonce = api.settings.nonce['update-widget'];
|
2014-04-14 18:46:16 -04:00
|
|
|
params.theme = api.settings.theme.stylesheet;
|
2015-07-29 12:03:24 -04:00
|
|
|
params.customized = wp.customize.previewer.query().customized;
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
data = $.param( params );
|
2014-04-07 12:32:15 -04:00
|
|
|
$inputs = this._getInputs( $widgetContent );
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// 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.
|
2014-04-07 12:32:15 -04:00
|
|
|
$inputs.each( function() {
|
2015-04-04 12:34:26 -04:00
|
|
|
$( this ).data( 'state' + updateNumber, self._getInputState( this ) );
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
if ( instanceOverride ) {
|
|
|
|
data += '&' + $.param( { 'sanitized_widget_setting': JSON.stringify( instanceOverride ) } );
|
2014-04-07 05:04:14 -04:00
|
|
|
} else {
|
2014-04-07 12:32:15 -04:00
|
|
|
data += '&' + $inputs.serialize();
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-04-07 12:32:15 -04:00
|
|
|
data += '&' + $widgetContent.find( '~ :input' ).serialize();
|
|
|
|
|
2015-03-10 18:45:27 -04:00
|
|
|
if ( this._previousUpdateRequest ) {
|
|
|
|
this._previousUpdateRequest.abort();
|
|
|
|
}
|
2014-04-07 12:32:15 -04:00
|
|
|
jqxhr = $.post( wp.ajax.settings.url, data );
|
2015-03-10 18:45:27 -04:00
|
|
|
this._previousUpdateRequest = jqxhr;
|
2014-04-07 05:04:14 -04:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
jqxhr.done( function( r ) {
|
|
|
|
var message, sanitizedForm, $sanitizedInputs, hasSameInputsInResponse,
|
|
|
|
isLiveUpdateAborted = false;
|
2014-04-07 05:04:14 -04:00
|
|
|
|
|
|
|
// Check if the user is logged out.
|
|
|
|
if ( '0' === r ) {
|
2014-07-09 16:58:15 -04:00
|
|
|
api.previewer.preview.iframe.hide();
|
|
|
|
api.previewer.login().done( function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
self.updateWidget( args );
|
2014-07-09 16:58:15 -04:00
|
|
|
api.previewer.preview.iframe.show();
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Check for cheaters.
|
|
|
|
if ( '-1' === r ) {
|
2014-07-09 16:58:15 -04:00
|
|
|
api.previewer.cheatin();
|
2014-04-07 05:04:14 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( r.success ) {
|
2014-04-07 12:32:15 -04:00
|
|
|
sanitizedForm = $( '<div>' + r.data.form + '</div>' );
|
|
|
|
$sanitizedInputs = self._getInputs( sanitizedForm );
|
|
|
|
hasSameInputsInResponse = self._getInputsSignature( $inputs ) === self._getInputsSignature( $sanitizedInputs );
|
2014-04-07 05:04:14 -04:00
|
|
|
|
|
|
|
// Restore live update mode if sanitized fields are now aligned with the existing fields
|
2014-04-07 12:32:15 -04:00
|
|
|
if ( hasSameInputsInResponse && ! self.liveUpdateMode ) {
|
|
|
|
self.liveUpdateMode = true;
|
|
|
|
self.container.removeClass( 'widget-form-disabled' );
|
|
|
|
self.container.find( 'input[name="savewidget"]' ).hide();
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Sync sanitized field states to existing fields if they are aligned
|
2014-04-07 12:32:15 -04:00
|
|
|
if ( hasSameInputsInResponse && self.liveUpdateMode ) {
|
|
|
|
$inputs.each( function( i ) {
|
|
|
|
var $input = $( this ),
|
|
|
|
$sanitizedInput = $( $sanitizedInputs[i] ),
|
|
|
|
submittedState, sanitizedState, canUpdateState;
|
|
|
|
|
|
|
|
submittedState = $input.data( 'state' + updateNumber );
|
2015-04-04 12:34:26 -04:00
|
|
|
sanitizedState = self._getInputState( $sanitizedInput );
|
2014-04-07 12:32:15 -04:00
|
|
|
$input.data( 'sanitized', sanitizedState );
|
|
|
|
|
2015-04-04 12:34:26 -04:00
|
|
|
canUpdateState = ( ! _.isEqual( submittedState, sanitizedState ) && ( args.ignoreActiveElement || ! $input.is( document.activeElement ) ) );
|
2014-04-07 12:32:15 -04:00
|
|
|
if ( canUpdateState ) {
|
2015-04-04 12:34:26 -04:00
|
|
|
self._setInputState( $input, sanitizedState );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
|
|
|
} );
|
2014-04-07 12:32:15 -04:00
|
|
|
|
|
|
|
$( document ).trigger( 'widget-synced', [ $widgetRoot, r.data.form ] );
|
2014-04-07 05:04:14 -04:00
|
|
|
|
|
|
|
// Otherwise, if sanitized fields are not aligned with existing fields, disable live update mode if enabled
|
2014-04-07 12:32:15 -04:00
|
|
|
} else if ( self.liveUpdateMode ) {
|
|
|
|
self.liveUpdateMode = false;
|
|
|
|
self.container.find( 'input[name="savewidget"]' ).show();
|
|
|
|
isLiveUpdateAborted = true;
|
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Otherwise, replace existing form with the sanitized form
|
2014-03-05 15:41:14 -05:00
|
|
|
} else {
|
2014-04-07 12:32:15 -04:00
|
|
|
$widgetContent.html( r.data.form );
|
|
|
|
|
|
|
|
self.container.removeClass( 'widget-form-disabled' );
|
|
|
|
|
|
|
|
$( document ).trigger( 'widget-updated', [ $widgetRoot ] );
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
/**
|
|
|
|
* If the old instance is identical to the new one, there is nothing new
|
|
|
|
* needing to be rendered, and so we can preempt the event for the
|
|
|
|
* preview finishing loading.
|
|
|
|
*/
|
2014-04-07 12:32:15 -04:00
|
|
|
isChanged = ! isLiveUpdateAborted && ! _( self.setting() ).isEqual( r.data.instance );
|
|
|
|
if ( isChanged ) {
|
|
|
|
self.isWidgetUpdating = true; // suppress triggering another updateWidget
|
|
|
|
self.setting( r.data.instance );
|
|
|
|
self.isWidgetUpdating = false;
|
2014-04-07 05:04:14 -04:00
|
|
|
} else {
|
|
|
|
// no change was made, so stop the spinner now instead of when the preview would updates
|
2014-04-07 12:32:15 -04:00
|
|
|
self.container.removeClass( 'previewer-loading' );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
if ( completeCallback ) {
|
2014-04-07 16:00:16 -04:00
|
|
|
completeCallback.call( self, null, { noChange: ! isChanged, ajaxFinished: true } );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
|
|
|
} else {
|
2014-04-07 12:32:15 -04:00
|
|
|
// General error message
|
2014-04-07 05:04:14 -04:00
|
|
|
message = l10n.error;
|
2014-04-07 12:32:15 -04:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( r.data && r.data.message ) {
|
|
|
|
message = r.data.message;
|
|
|
|
}
|
2014-04-07 12:32:15 -04:00
|
|
|
|
|
|
|
if ( completeCallback ) {
|
|
|
|
completeCallback.call( self, message );
|
2014-04-07 05:04:14 -04:00
|
|
|
} else {
|
2014-04-07 12:32:15 -04:00
|
|
|
$widgetContent.prepend( '<p class="widget-error"><strong>' + message + '</strong></p>' );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
|
|
|
} );
|
2014-04-07 12:32:15 -04:00
|
|
|
|
2014-04-07 10:10:14 -04:00
|
|
|
jqxhr.fail( function( jqXHR, textStatus ) {
|
2014-04-07 12:32:15 -04:00
|
|
|
if ( completeCallback ) {
|
|
|
|
completeCallback.call( self, textStatus );
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
|
|
|
} );
|
2014-04-07 12:32:15 -04:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
jqxhr.always( function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
self.container.removeClass( 'widget-form-loading' );
|
|
|
|
|
|
|
|
$inputs.each( function() {
|
|
|
|
$( this ).removeData( 'state' + updateNumber );
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
processing( processing() - 1 );
|
2014-03-05 15:41:14 -05:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Expand the accordion section containing a control
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
expandControlSection: function() {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
api.Control.prototype.expand.call( this );
|
2014-04-07 05:04:14 -04:00
|
|
|
},
|
2014-03-05 15:41:14 -05:00
|
|
|
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
/**
|
2014-12-03 21:04:22 -05:00
|
|
|
* @since 4.1.0
|
|
|
|
*
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
* @param {Boolean} expanded
|
|
|
|
* @param {Object} [params]
|
|
|
|
* @returns {Boolean} false if state already applied
|
|
|
|
*/
|
|
|
|
_toggleExpanded: api.Section.prototype._toggleExpanded,
|
|
|
|
|
|
|
|
/**
|
2014-12-03 21:04:22 -05:00
|
|
|
* @since 4.1.0
|
|
|
|
*
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
* @param {Object} [params]
|
|
|
|
* @returns {Boolean} false if already expanded
|
|
|
|
*/
|
|
|
|
expand: api.Section.prototype.expand,
|
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
/**
|
|
|
|
* Expand the widget form control
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
*
|
2014-12-03 21:04:22 -05:00
|
|
|
* @deprecated 4.1.0 Use this.expand() instead.
|
2014-04-07 05:04:14 -04:00
|
|
|
*/
|
|
|
|
expandForm: function() {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
this.expand();
|
2014-04-07 05:04:14 -04:00
|
|
|
},
|
2014-03-05 15:41:14 -05:00
|
|
|
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
/**
|
2014-12-03 21:04:22 -05:00
|
|
|
* @since 4.1.0
|
|
|
|
*
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
* @param {Object} [params]
|
|
|
|
* @returns {Boolean} false if already collapsed
|
|
|
|
*/
|
|
|
|
collapse: api.Section.prototype.collapse,
|
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
/**
|
|
|
|
* Collapse the widget form control
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
*
|
2014-12-03 21:04:22 -05:00
|
|
|
* @deprecated 4.1.0 Use this.collapse() instead.
|
2014-04-07 05:04:14 -04:00
|
|
|
*/
|
|
|
|
collapseForm: function() {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
this.collapse();
|
2014-03-05 15:41:14 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Expand or collapse the widget control
|
|
|
|
*
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
* @deprecated this is poor naming, and it is better to directly set control.expanded( showOrHide )
|
|
|
|
*
|
2014-04-07 12:32:15 -04:00
|
|
|
* @param {boolean|undefined} [showOrHide] If not supplied, will be inverse of current visibility
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 12:32:15 -04:00
|
|
|
toggleForm: function( showOrHide ) {
|
|
|
|
if ( typeof showOrHide === 'undefined' ) {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
showOrHide = ! this.expanded();
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
this.expanded( showOrHide );
|
|
|
|
},
|
2014-03-05 15:41:14 -05:00
|
|
|
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
/**
|
|
|
|
* Respond to change in the expanded state.
|
|
|
|
*
|
|
|
|
* @param {Boolean} expanded
|
|
|
|
* @param {Object} args merged on top of this.defaultActiveArguments
|
|
|
|
*/
|
|
|
|
onChangeExpanded: function ( expanded, args ) {
|
2016-09-28 00:20:29 -04:00
|
|
|
var self = this, $widget, $inside, complete, prevComplete, expandControl;
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
|
2015-09-25 17:02:27 -04:00
|
|
|
self.embedWidgetControl(); // Make sure the outer form is embedded so that the expanded state can be set in the UI.
|
|
|
|
if ( expanded ) {
|
|
|
|
self.embedWidgetContent();
|
|
|
|
}
|
|
|
|
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
// If the expanded state is unchanged only manipulate container expanded states
|
|
|
|
if ( args.unchanged ) {
|
|
|
|
if ( expanded ) {
|
|
|
|
api.Control.prototype.expand.call( self, {
|
|
|
|
completeCallback: args.completeCallback
|
|
|
|
});
|
|
|
|
}
|
2014-04-07 05:04:14 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-03-05 15:41:14 -05:00
|
|
|
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
$widget = this.container.find( 'div.widget:first' );
|
|
|
|
$inside = $widget.find( '.widget-inside:first' );
|
|
|
|
|
2016-09-28 00:20:29 -04:00
|
|
|
expandControl = function() {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Close all other widget controls before expanding this one
|
2014-04-07 12:32:15 -04:00
|
|
|
api.control.each( function( otherControl ) {
|
|
|
|
if ( self.params.type === otherControl.params.type && self !== otherControl ) {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
otherControl.collapse();
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
complete = function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
self.container.removeClass( 'expanding' );
|
|
|
|
self.container.addClass( 'expanded' );
|
|
|
|
self.container.trigger( 'expanded' );
|
2014-04-07 05:04:14 -04:00
|
|
|
};
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
if ( args.completeCallback ) {
|
|
|
|
prevComplete = complete;
|
|
|
|
complete = function () {
|
|
|
|
prevComplete();
|
|
|
|
args.completeCallback();
|
|
|
|
};
|
|
|
|
}
|
2014-04-07 12:32:15 -04:00
|
|
|
|
|
|
|
if ( self.params.is_wide ) {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
$inside.fadeIn( args.duration, complete );
|
2014-04-07 05:04:14 -04:00
|
|
|
} else {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
$inside.slideDown( args.duration, complete );
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
2014-04-07 12:32:15 -04:00
|
|
|
|
|
|
|
self.container.trigger( 'expand' );
|
|
|
|
self.container.addClass( 'expanding' );
|
2016-09-28 00:20:29 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
if ( expanded ) {
|
|
|
|
if ( api.section.has( self.section() ) ) {
|
|
|
|
api.section( self.section() ).expand( {
|
|
|
|
completeCallback: expandControl
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
expandControl();
|
|
|
|
}
|
2014-04-07 05:04:14 -04:00
|
|
|
} else {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
complete = function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
self.container.removeClass( 'collapsing' );
|
|
|
|
self.container.removeClass( 'expanded' );
|
|
|
|
self.container.trigger( 'collapsed' );
|
2014-04-07 05:04:14 -04:00
|
|
|
};
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
if ( args.completeCallback ) {
|
|
|
|
prevComplete = complete;
|
|
|
|
complete = function () {
|
|
|
|
prevComplete();
|
|
|
|
args.completeCallback();
|
|
|
|
};
|
|
|
|
}
|
2014-04-07 12:32:15 -04:00
|
|
|
|
|
|
|
self.container.trigger( 'collapse' );
|
|
|
|
self.container.addClass( 'collapsing' );
|
|
|
|
|
|
|
|
if ( self.params.is_wide ) {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
$inside.fadeOut( args.duration, complete );
|
2014-04-07 05:04:14 -04:00
|
|
|
} else {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
$inside.slideUp( args.duration, function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
$widget.css( { width:'', margin:'' } );
|
2014-04-07 05:04:14 -04:00
|
|
|
complete();
|
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
|
|
|
},
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
/**
|
|
|
|
* Get the position (index) of the widget in the containing sidebar
|
|
|
|
*
|
|
|
|
* @returns {Number}
|
|
|
|
*/
|
|
|
|
getWidgetSidebarPosition: function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
var sidebarWidgetIds, position;
|
|
|
|
|
|
|
|
sidebarWidgetIds = this.getSidebarWidgetsControl().setting();
|
|
|
|
position = _.indexOf( sidebarWidgetIds, this.params.widget_id );
|
2014-04-02 14:20:16 -04:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( position === -1 ) {
|
2014-04-07 12:32:15 -04:00
|
|
|
return;
|
2014-04-02 14:20:16 -04:00
|
|
|
}
|
2014-04-07 12:32:15 -04:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
return position;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move widget up one in the sidebar
|
|
|
|
*/
|
|
|
|
moveUp: function() {
|
|
|
|
this._moveWidgetByOne( -1 );
|
2014-03-05 15:41:14 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Move widget up one in the sidebar
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
moveDown: function() {
|
|
|
|
this._moveWidgetByOne( 1 );
|
|
|
|
},
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*
|
|
|
|
* @param {Number} offset 1|-1
|
|
|
|
*/
|
2014-04-07 10:10:14 -04:00
|
|
|
_moveWidgetByOne: function( offset ) {
|
2014-04-07 12:32:15 -04:00
|
|
|
var i, sidebarWidgetsSetting, sidebarWidgetIds, adjacentWidgetId;
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
i = this.getWidgetSidebarPosition();
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
sidebarWidgetsSetting = this.getSidebarWidgetsControl().setting;
|
|
|
|
sidebarWidgetIds = Array.prototype.slice.call( sidebarWidgetsSetting() ); // clone
|
|
|
|
adjacentWidgetId = sidebarWidgetIds[i + offset];
|
|
|
|
sidebarWidgetIds[i + offset] = this.params.widget_id;
|
|
|
|
sidebarWidgetIds[i] = adjacentWidgetId;
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
sidebarWidgetsSetting( sidebarWidgetIds );
|
2014-03-05 15:41:14 -05:00
|
|
|
},
|
|
|
|
|
2014-04-02 14:20:16 -04:00
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Toggle visibility of the widget move area
|
2014-04-02 14:20:16 -04:00
|
|
|
*
|
2014-04-07 12:32:15 -04:00
|
|
|
* @param {Boolean} [showOrHide]
|
2014-04-02 14:20:16 -04:00
|
|
|
*/
|
2014-04-07 12:32:15 -04:00
|
|
|
toggleWidgetMoveArea: function( showOrHide ) {
|
|
|
|
var self = this, $moveWidgetArea;
|
|
|
|
|
|
|
|
$moveWidgetArea = this.container.find( '.move-widget-area' );
|
|
|
|
|
|
|
|
if ( typeof showOrHide === 'undefined' ) {
|
|
|
|
showOrHide = ! $moveWidgetArea.hasClass( 'active' );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-04-07 12:32:15 -04:00
|
|
|
|
|
|
|
if ( showOrHide ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
// reset the selected sidebar
|
2014-04-07 12:32:15 -04:00
|
|
|
$moveWidgetArea.find( '.selected' ).removeClass( 'selected' );
|
|
|
|
|
|
|
|
$moveWidgetArea.find( 'li' ).filter( function() {
|
|
|
|
return $( this ).data( 'id' ) === self.params.sidebar_id;
|
2014-04-07 05:04:14 -04:00
|
|
|
} ).addClass( 'selected' );
|
2014-04-07 12:32:15 -04:00
|
|
|
|
|
|
|
this.container.find( '.move-widget-btn' ).prop( 'disabled', true );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-04-02 14:20:16 -04:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
$moveWidgetArea.toggleClass( 'active', showOrHide );
|
2014-03-05 15:41:14 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Highlight the widget control and section
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
highlightSectionAndControl: function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
var $target;
|
2014-04-07 05:04:14 -04:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
if ( this.container.is( ':hidden' ) ) {
|
|
|
|
$target = this.container.closest( '.control-section' );
|
2014-03-05 15:41:14 -05:00
|
|
|
} else {
|
2014-04-07 12:32:15 -04:00
|
|
|
$target = this.container;
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
$( '.highlighted' ).removeClass( 'highlighted' );
|
|
|
|
$target.addClass( 'highlighted' );
|
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
setTimeout( function() {
|
2014-04-07 12:32:15 -04:00
|
|
|
$target.removeClass( 'highlighted' );
|
2014-04-07 05:04:14 -04:00
|
|
|
}, 500 );
|
|
|
|
}
|
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2015-10-16 19:48:25 -04:00
|
|
|
/**
|
|
|
|
* wp.customize.Widgets.WidgetsPanel
|
|
|
|
*
|
|
|
|
* Customizer panel containing the widget area sections.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*/
|
|
|
|
api.Widgets.WidgetsPanel = api.Panel.extend({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add and manage the display of the no-rendered-areas notice.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*/
|
|
|
|
ready: function () {
|
|
|
|
var panel = this;
|
|
|
|
|
|
|
|
api.Panel.prototype.ready.call( panel );
|
|
|
|
|
|
|
|
panel.deferred.embedded.done(function() {
|
|
|
|
var panelMetaContainer, noRenderedAreasNotice, shouldShowNotice;
|
|
|
|
panelMetaContainer = panel.container.find( '.panel-meta' );
|
|
|
|
noRenderedAreasNotice = $( '<div></div>', {
|
|
|
|
'class': 'no-widget-areas-rendered-notice'
|
|
|
|
});
|
|
|
|
noRenderedAreasNotice.append( $( '<em></em>', {
|
|
|
|
text: l10n.noAreasRendered
|
|
|
|
} ) );
|
|
|
|
panelMetaContainer.append( noRenderedAreasNotice );
|
|
|
|
|
|
|
|
shouldShowNotice = function() {
|
|
|
|
return ( 0 === _.filter( panel.sections(), function( section ) {
|
|
|
|
return section.active();
|
|
|
|
} ).length );
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the initial visibility state for rendered notice.
|
|
|
|
* Update the visibility of the notice whenever a reflow happens.
|
|
|
|
*/
|
|
|
|
noRenderedAreasNotice.toggle( shouldShowNotice() );
|
|
|
|
api.previewer.deferred.active.done( function () {
|
|
|
|
noRenderedAreasNotice.toggle( shouldShowNotice() );
|
|
|
|
});
|
|
|
|
api.bind( 'pane-contents-reflowed', function() {
|
|
|
|
var duration = ( 'resolved' === api.previewer.deferred.active.state() ) ? 'fast' : 0;
|
|
|
|
if ( shouldShowNotice() ) {
|
|
|
|
noRenderedAreasNotice.slideDown( duration );
|
|
|
|
} else {
|
|
|
|
noRenderedAreasNotice.slideUp( duration );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allow an active widgets panel to be contextually active even when it has no active sections (widget areas).
|
|
|
|
*
|
|
|
|
* This ensures that the widgets panel appears even when there are no
|
|
|
|
* sidebars displayed on the URL currently being previewed.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
isContextuallyActive: function() {
|
|
|
|
var panel = this;
|
|
|
|
return panel.active();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-11-13 07:19:23 -05:00
|
|
|
/**
|
|
|
|
* wp.customize.Widgets.SidebarSection
|
|
|
|
*
|
|
|
|
* Customizer section representing a widget area widget
|
|
|
|
*
|
|
|
|
* @since 4.1.0
|
|
|
|
*/
|
|
|
|
api.Widgets.SidebarSection = api.Section.extend({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sync the section's active state back to the Backbone model's is_rendered attribute
|
2014-12-03 21:04:22 -05:00
|
|
|
*
|
|
|
|
* @since 4.1.0
|
2014-11-13 07:19:23 -05:00
|
|
|
*/
|
|
|
|
ready: function () {
|
|
|
|
var section = this, registeredSidebar;
|
|
|
|
api.Section.prototype.ready.call( this );
|
|
|
|
registeredSidebar = api.Widgets.registeredSidebars.get( section.params.sidebarId );
|
|
|
|
section.active.bind( function ( active ) {
|
|
|
|
registeredSidebar.set( 'is_rendered', active );
|
|
|
|
});
|
|
|
|
registeredSidebar.set( 'is_rendered', section.active() );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
/**
|
2014-04-07 10:10:14 -04:00
|
|
|
* wp.customize.Widgets.SidebarControl
|
|
|
|
*
|
|
|
|
* Customizer control for widgets.
|
2014-04-07 05:04:14 -04:00
|
|
|
* Note that 'sidebar_widgets' must match the WP_Widget_Area_Customize_Control::$type
|
2014-04-07 10:10:14 -04:00
|
|
|
*
|
2014-11-13 07:19:23 -05:00
|
|
|
* @since 3.9.0
|
|
|
|
*
|
2014-04-07 10:10:14 -04:00
|
|
|
* @constructor
|
|
|
|
* @augments wp.customize.Control
|
2014-04-07 05:04:14 -04:00
|
|
|
*/
|
|
|
|
api.Widgets.SidebarControl = api.Control.extend({
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
|
2014-03-05 15:41:14 -05:00
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Set up the control
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
ready: function() {
|
2014-04-07 16:00:16 -04:00
|
|
|
this.$controlSection = this.container.closest( '.control-section' );
|
|
|
|
this.$sectionContent = this.container.closest( '.accordion-section-content' );
|
|
|
|
|
|
|
|
this._setupModel();
|
|
|
|
this._setupSortable();
|
|
|
|
this._setupAddition();
|
|
|
|
this._applyCardinalOrderClassNames();
|
2014-03-05 15:41:14 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Update ordering of widget control forms when the setting is updated
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
_setupModel: function() {
|
2014-11-13 07:19:23 -05:00
|
|
|
var self = this;
|
2014-04-07 16:00:16 -04:00
|
|
|
|
|
|
|
this.setting.bind( function( newWidgetIds, oldWidgetIds ) {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
var widgetFormControls, removedWidgetIds, priority;
|
2014-04-07 16:00:16 -04:00
|
|
|
|
|
|
|
removedWidgetIds = _( oldWidgetIds ).difference( newWidgetIds );
|
|
|
|
|
|
|
|
// Filter out any persistent widget IDs for widgets which have been deactivated
|
|
|
|
newWidgetIds = _( newWidgetIds ).filter( function( newWidgetId ) {
|
|
|
|
var parsedWidgetId = parseWidgetId( newWidgetId );
|
|
|
|
|
|
|
|
return !! api.Widgets.availableWidgets.findWhere( { id_base: parsedWidgetId.id_base } );
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 16:00:16 -04:00
|
|
|
widgetFormControls = _( newWidgetIds ).map( function( widgetId ) {
|
|
|
|
var widgetFormControl = api.Widgets.getWidgetFormControlForWidget( widgetId );
|
|
|
|
|
|
|
|
if ( ! widgetFormControl ) {
|
|
|
|
widgetFormControl = self.addWidget( widgetId );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-04-07 16:00:16 -04:00
|
|
|
|
|
|
|
return widgetFormControl;
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Sort widget controls to their new positions
|
2014-04-07 16:00:16 -04:00
|
|
|
widgetFormControls.sort( function( a, b ) {
|
|
|
|
var aIndex = _.indexOf( newWidgetIds, a.params.widget_id ),
|
|
|
|
bIndex = _.indexOf( newWidgetIds, b.params.widget_id );
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
return aIndex - bIndex;
|
|
|
|
});
|
2014-04-07 16:00:16 -04:00
|
|
|
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
priority = 0;
|
|
|
|
_( widgetFormControls ).each( function ( control ) {
|
|
|
|
control.priority( priority );
|
|
|
|
control.section( self.section() );
|
|
|
|
priority += 1;
|
|
|
|
});
|
|
|
|
self.priority( priority ); // Make sure sidebar control remains at end
|
2014-04-07 16:00:16 -04:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Re-sort widget form controls (including widgets form other sidebars newly moved here)
|
2014-04-07 16:00:16 -04:00
|
|
|
self._applyCardinalOrderClassNames();
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// If the widget was dragged into the sidebar, make sure the sidebar_id param is updated
|
2014-04-07 16:00:16 -04:00
|
|
|
_( widgetFormControls ).each( function( widgetFormControl ) {
|
|
|
|
widgetFormControl.params.sidebar_id = self.params.sidebar_id;
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Cleanup after widget removal
|
2014-04-07 16:00:16 -04:00
|
|
|
_( removedWidgetIds ).each( function( removedWidgetId ) {
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Using setTimeout so that when moving a widget to another sidebar, the other sidebars_widgets settings get a chance to update
|
|
|
|
setTimeout( function() {
|
2014-04-07 16:00:16 -04:00
|
|
|
var removedControl, wasDraggedToAnotherSidebar, inactiveWidgets, removedIdBase,
|
|
|
|
widget, isPresentInAnotherSidebar = false;
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Check if the widget is in another sidebar
|
2014-04-07 16:00:16 -04:00
|
|
|
api.each( function( otherSetting ) {
|
2014-04-08 00:03:14 -04:00
|
|
|
if ( otherSetting.id === self.setting.id || 0 !== otherSetting.id.indexOf( 'sidebars_widgets[' ) || otherSetting.id === 'sidebars_widgets[wp_inactive_widgets]' ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 16:00:16 -04:00
|
|
|
var otherSidebarWidgets = otherSetting(), i;
|
|
|
|
|
|
|
|
i = _.indexOf( otherSidebarWidgets, removedWidgetId );
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( -1 !== i ) {
|
2014-04-07 16:00:16 -04:00
|
|
|
isPresentInAnotherSidebar = true;
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
|
|
|
} );
|
2014-03-22 16:55:18 -04:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// If the widget is present in another sidebar, abort!
|
2014-04-07 16:00:16 -04:00
|
|
|
if ( isPresentInAnotherSidebar ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-03-22 16:55:18 -04:00
|
|
|
|
2014-04-07 16:00:16 -04:00
|
|
|
removedControl = api.Widgets.getWidgetFormControlForWidget( removedWidgetId );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Detect if widget control was dragged to another sidebar
|
2014-04-07 16:00:16 -04:00
|
|
|
wasDraggedToAnotherSidebar = removedControl && $.contains( document, removedControl.container[0] ) && ! $.contains( self.$sectionContent[0], removedControl.container[0] );
|
2014-04-02 14:20:16 -04:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Delete any widget form controls for removed widgets
|
2014-04-07 16:00:16 -04:00
|
|
|
if ( removedControl && ! wasDraggedToAnotherSidebar ) {
|
|
|
|
api.control.remove( removedControl.id );
|
|
|
|
removedControl.container.remove();
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// 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
|
2014-04-07 16:00:16 -04:00
|
|
|
if ( api.Widgets.savedWidgetIds[removedWidgetId] ) {
|
2014-04-08 00:03:14 -04:00
|
|
|
inactiveWidgets = api.value( 'sidebars_widgets[wp_inactive_widgets]' )().slice();
|
2014-04-07 16:00:16 -04:00
|
|
|
inactiveWidgets.push( removedWidgetId );
|
2014-04-08 00:03:14 -04:00
|
|
|
api.value( 'sidebars_widgets[wp_inactive_widgets]' )( _( inactiveWidgets ).unique() );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Make old single widget available for adding again
|
2014-04-07 16:00:16 -04:00
|
|
|
removedIdBase = parseWidgetId( removedWidgetId ).id_base;
|
|
|
|
widget = api.Widgets.availableWidgets.findWhere( { id_base: removedIdBase } );
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( widget && ! widget.get( 'is_multi' ) ) {
|
|
|
|
widget.set( 'is_disabled', false );
|
|
|
|
}
|
|
|
|
} );
|
2014-04-02 14:20:16 -04:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Allow widgets in sidebar to be re-ordered, and for the order to be previewed
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
_setupSortable: function() {
|
2014-04-07 16:00:16 -04:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.isReordering = false;
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
/**
|
|
|
|
* Update widget order setting when controls are re-ordered
|
|
|
|
*/
|
2014-04-07 16:00:16 -04:00
|
|
|
this.$sectionContent.sortable( {
|
2014-04-07 05:04:14 -04:00
|
|
|
items: '> .customize-control-widget_form',
|
|
|
|
handle: '.widget-top',
|
|
|
|
axis: 'y',
|
2015-06-03 18:59:25 -04:00
|
|
|
tolerance: 'pointer',
|
2014-04-07 05:04:14 -04:00
|
|
|
connectWith: '.accordion-section-content:has(.customize-control-sidebar_widgets)',
|
|
|
|
update: function() {
|
2014-04-07 16:00:16 -04:00
|
|
|
var widgetContainerIds = self.$sectionContent.sortable( 'toArray' ), widgetIds;
|
|
|
|
|
|
|
|
widgetIds = $.map( widgetContainerIds, function( widgetContainerId ) {
|
|
|
|
return $( '#' + widgetContainerId ).find( ':input[name=widget-id]' ).val();
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-04-07 16:00:16 -04:00
|
|
|
|
|
|
|
self.setting( widgetIds );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
/**
|
2014-10-15 13:21:19 -04:00
|
|
|
* Expand other Customizer sidebar section when dragging a control widget over it,
|
2014-04-07 05:04:14 -04:00
|
|
|
* allowing the control to be dropped into another section
|
|
|
|
*/
|
2014-04-07 16:00:16 -04:00
|
|
|
this.$controlSection.find( '.accordion-section-title' ).droppable({
|
2014-04-07 05:04:14 -04:00
|
|
|
accept: '.customize-control-widget_form',
|
|
|
|
over: function() {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
var section = api.section( self.section.get() );
|
|
|
|
section.expand({
|
|
|
|
allowMultiple: true, // Prevent the section being dragged from to be collapsed
|
|
|
|
completeCallback: function () {
|
|
|
|
// @todo It is not clear when refreshPositions should be called on which sections, or if it is even needed
|
|
|
|
api.section.each( function ( otherSection ) {
|
|
|
|
if ( otherSection.container.find( '.customize-control-sidebar_widgets' ).length ) {
|
|
|
|
otherSection.container.find( '.accordion-section-content:first' ).sortable( 'refreshPositions' );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
});
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-04-07 16:00:16 -04:00
|
|
|
});
|
2014-04-07 05:04:14 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Keyboard-accessible reordering
|
|
|
|
*/
|
2015-10-20 16:15:26 -04:00
|
|
|
this.container.find( '.reorder-toggle' ).on( 'click', function() {
|
2014-04-07 16:00:16 -04:00
|
|
|
self.toggleReordering( ! self.isReordering );
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Set up UI for adding a new widget
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
_setupAddition: function() {
|
2014-04-07 16:00:16 -04:00
|
|
|
var self = this;
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2015-10-20 16:15:26 -04:00
|
|
|
this.container.find( '.add-new-widget' ).on( 'click', function() {
|
|
|
|
var addNewWidgetBtn = $( this );
|
2014-04-07 05:04:14 -04:00
|
|
|
|
2014-04-07 16:00:16 -04:00
|
|
|
if ( self.$sectionContent.hasClass( 'reordering' ) ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $( 'body' ).hasClass( 'adding-widget' ) ) {
|
2015-10-20 16:15:26 -04:00
|
|
|
addNewWidgetBtn.attr( 'aria-expanded', 'true' );
|
2014-04-07 16:00:16 -04:00
|
|
|
api.Widgets.availableWidgetsPanel.open( self );
|
2014-03-05 15:41:14 -05:00
|
|
|
} else {
|
2015-10-20 16:15:26 -04:00
|
|
|
addNewWidgetBtn.attr( 'aria-expanded', 'false' );
|
2014-04-07 05:04:14 -04:00
|
|
|
api.Widgets.availableWidgetsPanel.close();
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-03-05 15:41:14 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Add classes to the widget_form controls to assist with styling
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
_applyCardinalOrderClassNames: function() {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
var widgetControls = [];
|
|
|
|
_.each( this.setting(), function ( widgetId ) {
|
|
|
|
var widgetControl = api.Widgets.getWidgetFormControlForWidget( widgetId );
|
|
|
|
if ( widgetControl ) {
|
|
|
|
widgetControls.push( widgetControl );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-02-12 18:52:27 -05:00
|
|
|
if ( 0 === widgetControls.length || ( 1 === api.Widgets.registeredSidebars.length && widgetControls.length <= 1 ) ) {
|
2015-01-20 17:45:22 -05:00
|
|
|
this.container.find( '.reorder-toggle' ).hide();
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
return;
|
2015-01-20 17:45:22 -05:00
|
|
|
} else {
|
|
|
|
this.container.find( '.reorder-toggle' ).show();
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
}
|
2014-04-07 05:04:14 -04:00
|
|
|
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
$( widgetControls ).each( function () {
|
|
|
|
$( this.container )
|
|
|
|
.removeClass( 'first-widget' )
|
|
|
|
.removeClass( 'last-widget' )
|
|
|
|
.find( '.move-widget-down, .move-widget-up' ).prop( 'tabIndex', 0 );
|
|
|
|
});
|
|
|
|
|
|
|
|
_.first( widgetControls ).container
|
2014-04-07 05:04:14 -04:00
|
|
|
.addClass( 'first-widget' )
|
|
|
|
.find( '.move-widget-up' ).prop( 'tabIndex', -1 );
|
2014-04-07 16:00:16 -04:00
|
|
|
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
_.last( widgetControls ).container
|
2014-04-07 05:04:14 -04:00
|
|
|
.addClass( 'last-widget' )
|
|
|
|
.find( '.move-widget-down' ).prop( 'tabIndex', -1 );
|
2014-03-05 15:41:14 -05:00
|
|
|
},
|
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Begin public API methods
|
|
|
|
**********************************************************************/
|
|
|
|
|
2014-03-05 15:41:14 -05:00
|
|
|
/**
|
2014-04-07 05:04:14 -04:00
|
|
|
* Enable/disable the reordering UI
|
2014-03-05 15:41:14 -05:00
|
|
|
*
|
2014-04-07 16:00:16 -04:00
|
|
|
* @param {Boolean} showOrHide to enable/disable reordering
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
*
|
|
|
|
* @todo We should have a reordering state instead and rename this to onChangeReordering
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 16:00:16 -04:00
|
|
|
toggleReordering: function( showOrHide ) {
|
2015-10-20 16:15:26 -04:00
|
|
|
var addNewWidgetBtn = this.$sectionContent.find( '.add-new-widget' ),
|
|
|
|
reorderBtn = this.container.find( '.reorder-toggle' ),
|
|
|
|
widgetsTitle = this.$sectionContent.find( '.widget-title' );
|
|
|
|
|
2014-04-07 16:00:16 -04:00
|
|
|
showOrHide = Boolean( showOrHide );
|
|
|
|
|
|
|
|
if ( showOrHide === this.$sectionContent.hasClass( 'reordering' ) ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 16:00:16 -04:00
|
|
|
this.isReordering = showOrHide;
|
|
|
|
this.$sectionContent.toggleClass( 'reordering', showOrHide );
|
2014-04-07 05:04:14 -04:00
|
|
|
|
2014-04-07 16:00:16 -04:00
|
|
|
if ( showOrHide ) {
|
|
|
|
_( this.getWidgetFormControls() ).each( function( formControl ) {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
formControl.collapse();
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-07-18 23:24:15 -04:00
|
|
|
|
2015-10-20 16:15:26 -04:00
|
|
|
addNewWidgetBtn.attr({ 'tabindex': '-1', 'aria-hidden': 'true' });
|
|
|
|
reorderBtn.attr( 'aria-label', l10n.reorderLabelOff );
|
|
|
|
wp.a11y.speak( l10n.reorderModeOn );
|
|
|
|
// Hide widget titles while reordering: title is already in the reorder controls.
|
|
|
|
widgetsTitle.attr( 'aria-hidden', 'true' );
|
2014-07-18 23:32:17 -04:00
|
|
|
} else {
|
2015-10-20 16:15:26 -04:00
|
|
|
addNewWidgetBtn.removeAttr( 'tabindex aria-hidden' );
|
|
|
|
reorderBtn.attr( 'aria-label', l10n.reorderLabelOn );
|
|
|
|
wp.a11y.speak( l10n.reorderModeOff );
|
|
|
|
widgetsTitle.attr( 'aria-hidden', 'false' );
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-02-27 05:35:24 -05:00
|
|
|
* Get the widget_form Customize controls associated with the current sidebar.
|
|
|
|
*
|
2016-07-06 19:49:30 -04:00
|
|
|
* @since 3.9.0
|
2014-04-07 05:04:14 -04:00
|
|
|
* @return {wp.customize.controlConstructor.widget_form[]}
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
getWidgetFormControls: function() {
|
2015-02-27 05:35:24 -05:00
|
|
|
var formControls = [];
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2015-02-27 05:35:24 -05:00
|
|
|
_( this.setting() ).each( function( widgetId ) {
|
2014-04-07 16:00:16 -04:00
|
|
|
var settingId = widgetIdToSettingId( widgetId ),
|
|
|
|
formControl = api.control( settingId );
|
2015-02-27 05:35:24 -05:00
|
|
|
if ( formControl ) {
|
|
|
|
formControls.push( formControl );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
|
|
|
} );
|
2014-04-07 16:00:16 -04:00
|
|
|
|
|
|
|
return formControls;
|
2014-03-05 15:41:14 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 16:00:16 -04:00
|
|
|
* @param {string} widgetId or an id_base for adding a previously non-existing widget
|
2014-04-08 04:12:15 -04:00
|
|
|
* @returns {object|false} widget_form control instance, or false on error
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 16:00:16 -04:00
|
|
|
addWidget: function( widgetId ) {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
var self = this, controlHtml, $widget, controlType = 'widget_form', controlContainer, controlConstructor,
|
2014-04-07 16:00:16 -04:00
|
|
|
parsedWidgetId = parseWidgetId( widgetId ),
|
|
|
|
widgetNumber = parsedWidgetId.number,
|
|
|
|
widgetIdBase = parsedWidgetId.id_base,
|
|
|
|
widget = api.Widgets.availableWidgets.findWhere( {id_base: widgetIdBase} ),
|
2014-10-29 18:57:23 -04:00
|
|
|
settingId, isExistingWidget, widgetFormControl, sidebarWidgets, settingArgs, setting;
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( ! widget ) {
|
2014-04-08 04:12:15 -04:00
|
|
|
return false;
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-04-07 16:00:16 -04:00
|
|
|
|
|
|
|
if ( widgetNumber && ! widget.get( 'is_multi' ) ) {
|
2014-04-08 04:12:15 -04:00
|
|
|
return false;
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Set up new multi widget
|
2014-04-07 16:00:16 -04:00
|
|
|
if ( widget.get( 'is_multi' ) && ! widgetNumber ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
widget.set( 'multi_number', widget.get( 'multi_number' ) + 1 );
|
2014-04-07 16:00:16 -04:00
|
|
|
widgetNumber = widget.get( 'multi_number' );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-14 18:46:16 -04:00
|
|
|
controlHtml = $.trim( $( '#widget-tpl-' + widget.get( 'id' ) ).html() );
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( widget.get( 'is_multi' ) ) {
|
2014-04-07 16:00:16 -04:00
|
|
|
controlHtml = controlHtml.replace( /<[^<>]+>/g, function( m ) {
|
|
|
|
return m.replace( /__i__|%i%/g, widgetNumber );
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
widget.set( 'is_disabled', true ); // Prevent single widget from being added again now
|
|
|
|
}
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 16:00:16 -04:00
|
|
|
$widget = $( controlHtml );
|
|
|
|
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
controlContainer = $( '<li/>' )
|
2014-04-07 16:00:16 -04:00
|
|
|
.addClass( 'customize-control' )
|
|
|
|
.addClass( 'customize-control-' + controlType )
|
|
|
|
.append( $widget );
|
|
|
|
|
|
|
|
// Remove icon which is visible inside the panel
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
controlContainer.find( '> .widget-icon' ).remove();
|
2014-04-07 16:00:16 -04:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( widget.get( 'is_multi' ) ) {
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
controlContainer.find( 'input[name="widget_number"]' ).val( widgetNumber );
|
|
|
|
controlContainer.find( 'input[name="multi_number"]' ).val( widgetNumber );
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
2014-04-07 05:04:14 -04:00
|
|
|
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
widgetId = controlContainer.find( '[name="widget-id"]' ).val();
|
2014-04-07 16:00:16 -04:00
|
|
|
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
controlContainer.hide(); // to be slid-down below
|
2014-04-07 16:00:16 -04:00
|
|
|
|
|
|
|
settingId = 'widget_' + widget.get( 'id_base' );
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( widget.get( 'is_multi' ) ) {
|
2014-04-07 16:00:16 -04:00
|
|
|
settingId += '[' + widgetNumber + ']';
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
controlContainer.attr( 'id', 'customize-control-' + settingId.replace( /\]/g, '' ).replace( /\[/g, '-' ) );
|
2014-03-05 15:41:14 -05:00
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
// Only create setting if it doesn't already exist (if we're adding a pre-existing inactive widget)
|
2014-04-07 16:00:16 -04:00
|
|
|
isExistingWidget = api.has( settingId );
|
|
|
|
if ( ! isExistingWidget ) {
|
|
|
|
settingArgs = {
|
2016-03-21 17:59:29 -04:00
|
|
|
transport: api.Widgets.data.selectiveRefreshableWidgets[ widget.get( 'id_base' ) ] ? 'postMessage' : 'refresh',
|
2014-04-07 16:00:16 -04:00
|
|
|
previewer: this.setting.previewer
|
2014-04-07 05:04:14 -04:00
|
|
|
};
|
2014-10-29 18:57:23 -04:00
|
|
|
setting = api.create( settingId, settingId, '', settingArgs );
|
|
|
|
setting.set( {} ); // mark dirty, changing from '' to {}
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 16:00:16 -04:00
|
|
|
controlConstructor = api.controlConstructor[controlType];
|
|
|
|
widgetFormControl = new controlConstructor( settingId, {
|
2014-04-07 05:04:14 -04:00
|
|
|
params: {
|
|
|
|
settings: {
|
2014-04-07 16:00:16 -04:00
|
|
|
'default': settingId
|
2014-04-07 05:04:14 -04:00
|
|
|
},
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
content: controlContainer,
|
2014-04-07 16:00:16 -04:00
|
|
|
sidebar_id: self.params.sidebar_id,
|
|
|
|
widget_id: widgetId,
|
2014-04-07 05:04:14 -04:00
|
|
|
widget_id_base: widget.get( 'id_base' ),
|
2014-04-07 16:00:16 -04:00
|
|
|
type: controlType,
|
|
|
|
is_new: ! isExistingWidget,
|
2014-04-07 05:04:14 -04:00
|
|
|
width: widget.get( 'width' ),
|
|
|
|
height: widget.get( 'height' ),
|
2015-11-01 17:27:26 -05:00
|
|
|
is_wide: widget.get( 'is_wide' ),
|
|
|
|
active: true
|
2014-04-07 05:04:14 -04:00
|
|
|
},
|
2014-04-07 16:00:16 -04:00
|
|
|
previewer: self.setting.previewer
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
2014-04-07 16:00:16 -04:00
|
|
|
api.control.add( settingId, widgetFormControl );
|
2014-04-07 05:04:14 -04:00
|
|
|
|
|
|
|
// Make sure widget is removed from the other sidebars
|
2014-04-07 16:00:16 -04:00
|
|
|
api.each( function( otherSetting ) {
|
|
|
|
if ( otherSetting.id === self.setting.id ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-04-07 16:00:16 -04:00
|
|
|
|
|
|
|
if ( 0 !== otherSetting.id.indexOf( 'sidebars_widgets[' ) ) {
|
2014-04-07 05:04:14 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-04-07 16:00:16 -04:00
|
|
|
|
|
|
|
var otherSidebarWidgets = otherSetting().slice(),
|
|
|
|
i = _.indexOf( otherSidebarWidgets, widgetId );
|
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
if ( -1 !== i ) {
|
2014-04-07 16:00:16 -04:00
|
|
|
otherSidebarWidgets.splice( i );
|
|
|
|
otherSetting( otherSidebarWidgets );
|
2014-04-07 05:04:14 -04:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Add widget to this sidebar
|
2014-04-07 16:00:16 -04:00
|
|
|
sidebarWidgets = this.setting().slice();
|
|
|
|
if ( -1 === _.indexOf( sidebarWidgets, widgetId ) ) {
|
|
|
|
sidebarWidgets.push( widgetId );
|
|
|
|
this.setting( sidebarWidgets );
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
|
|
|
|
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
|
|
|
controlContainer.slideDown( function() {
|
2014-04-07 16:00:16 -04:00
|
|
|
if ( isExistingWidget ) {
|
|
|
|
widgetFormControl.updateWidget( {
|
2015-03-18 15:29:27 -04:00
|
|
|
instance: widgetFormControl.setting()
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2014-04-07 16:00:16 -04:00
|
|
|
return widgetFormControl;
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2015-10-16 19:48:25 -04:00
|
|
|
// Register models for custom panel, section, and control types
|
|
|
|
$.extend( api.panelConstructor, {
|
|
|
|
widgets: api.Widgets.WidgetsPanel
|
|
|
|
});
|
2014-11-13 07:19:23 -05:00
|
|
|
$.extend( api.sectionConstructor, {
|
|
|
|
sidebar: api.Widgets.SidebarSection
|
|
|
|
});
|
2014-04-07 05:04:14 -04:00
|
|
|
$.extend( api.controlConstructor, {
|
|
|
|
widget_form: api.Widgets.WidgetControl,
|
|
|
|
sidebar_widgets: api.Widgets.SidebarControl
|
|
|
|
});
|
|
|
|
|
2014-04-07 16:00:16 -04:00
|
|
|
/**
|
|
|
|
* Init Customizer for widgets.
|
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
api.bind( 'ready', function() {
|
|
|
|
// Set up the widgets panel
|
2014-04-07 10:10:14 -04:00
|
|
|
api.Widgets.availableWidgetsPanel = new api.Widgets.AvailableWidgetsPanelView({
|
|
|
|
collection: api.Widgets.availableWidgets
|
|
|
|
});
|
2014-04-07 05:04:14 -04:00
|
|
|
|
|
|
|
// Highlight widget control
|
2014-07-09 16:58:15 -04:00
|
|
|
api.previewer.bind( 'highlight-widget-control', api.Widgets.highlightWidgetFormControl );
|
2014-04-07 05:04:14 -04:00
|
|
|
|
|
|
|
// Open and focus widget control
|
2014-07-09 16:58:15 -04:00
|
|
|
api.previewer.bind( 'focus-widget-control', api.Widgets.focusWidgetFormControl );
|
2014-04-07 05:04:14 -04:00
|
|
|
} );
|
|
|
|
|
2014-04-01 11:26:15 -04:00
|
|
|
/**
|
|
|
|
* Highlight a widget control.
|
|
|
|
*
|
|
|
|
* @param {string} widgetId
|
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
api.Widgets.highlightWidgetFormControl = function( widgetId ) {
|
|
|
|
var control = api.Widgets.getWidgetFormControlForWidget( widgetId );
|
2014-04-01 11:26:15 -04:00
|
|
|
|
|
|
|
if ( control ) {
|
|
|
|
control.highlightSectionAndControl();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Focus a widget control.
|
|
|
|
*
|
|
|
|
* @param {string} widgetId
|
|
|
|
*/
|
2014-04-07 05:04:14 -04:00
|
|
|
api.Widgets.focusWidgetFormControl = function( widgetId ) {
|
|
|
|
var control = api.Widgets.getWidgetFormControlForWidget( widgetId );
|
2014-04-01 11:26:15 -04:00
|
|
|
|
|
|
|
if ( control ) {
|
|
|
|
control.focus();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-03-05 15:41:14 -05:00
|
|
|
/**
|
|
|
|
* Given a widget control, find the sidebar widgets control that contains it.
|
2014-04-07 16:00:16 -04:00
|
|
|
* @param {string} widgetId
|
2014-03-05 15:41:14 -05:00
|
|
|
* @return {object|null}
|
|
|
|
*/
|
2014-04-07 16:00:16 -04:00
|
|
|
api.Widgets.getSidebarWidgetControlContainingWidget = function( widgetId ) {
|
|
|
|
var foundControl = null;
|
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
// @todo this can use widgetIdToSettingId(), then pass into wp.customize.control( x ).getSidebarWidgetsControl()
|
2014-04-07 10:10:14 -04:00
|
|
|
api.control.each( function( control ) {
|
2014-04-07 16:00:16 -04:00
|
|
|
if ( control.params.type === 'sidebar_widgets' && -1 !== _.indexOf( control.setting(), widgetId ) ) {
|
|
|
|
foundControl = control;
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
|
|
|
} );
|
2014-04-07 05:04:14 -04:00
|
|
|
|
2014-04-07 16:00:16 -04:00
|
|
|
return foundControl;
|
2014-03-05 15:41:14 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-04-07 16:00:16 -04:00
|
|
|
* Given a widget ID for a widget appearing in the preview, get the widget form control associated with it.
|
|
|
|
*
|
|
|
|
* @param {string} widgetId
|
2014-03-05 15:41:14 -05:00
|
|
|
* @return {object|null}
|
|
|
|
*/
|
2014-04-07 16:00:16 -04:00
|
|
|
api.Widgets.getWidgetFormControlForWidget = function( widgetId ) {
|
|
|
|
var foundControl = null;
|
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
// @todo We can just use widgetIdToSettingId() here
|
2014-04-07 10:10:14 -04:00
|
|
|
api.control.each( function( control ) {
|
2014-04-07 16:00:16 -04:00
|
|
|
if ( control.params.type === 'widget_form' && control.params.widget_id === widgetId ) {
|
|
|
|
foundControl = control;
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2014-04-07 16:00:16 -04:00
|
|
|
return foundControl;
|
2014-03-05 15:41:14 -05:00
|
|
|
};
|
|
|
|
|
2016-05-16 03:22:30 -04:00
|
|
|
/**
|
|
|
|
* Initialize Edit Menu button in Nav Menu widget.
|
|
|
|
*/
|
|
|
|
$( document ).on( 'widget-added', function( event, widgetContainer ) {
|
|
|
|
var parsedWidgetId, widgetControl, navMenuSelect, editMenuButton;
|
|
|
|
parsedWidgetId = parseWidgetId( widgetContainer.find( '> .widget-inside > .form > .widget-id' ).val() );
|
|
|
|
if ( 'nav_menu' !== parsedWidgetId.id_base ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
widgetControl = api.control( 'widget_nav_menu[' + String( parsedWidgetId.number ) + ']' );
|
|
|
|
if ( ! widgetControl ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
navMenuSelect = widgetContainer.find( 'select[name*="nav_menu"]' );
|
|
|
|
editMenuButton = widgetContainer.find( '.edit-selected-nav-menu > button' );
|
|
|
|
if ( 0 === navMenuSelect.length || 0 === editMenuButton.length ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
navMenuSelect.on( 'change', function() {
|
|
|
|
if ( api.section.has( 'nav_menu[' + navMenuSelect.val() + ']' ) ) {
|
|
|
|
editMenuButton.parent().show();
|
|
|
|
} else {
|
|
|
|
editMenuButton.parent().hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
editMenuButton.on( 'click', function() {
|
|
|
|
var section = api.section( 'nav_menu[' + navMenuSelect.val() + ']' );
|
|
|
|
if ( section ) {
|
|
|
|
focusConstructWithBreadcrumb( section, widgetControl );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Focus (expand) one construct and then focus on another construct after the first is collapsed.
|
|
|
|
*
|
|
|
|
* This overrides the back button to serve the purpose of breadcrumb navigation.
|
|
|
|
*
|
|
|
|
* @param {wp.customize.Section|wp.customize.Panel|wp.customize.Control} focusConstruct - The object to initially focus.
|
|
|
|
* @param {wp.customize.Section|wp.customize.Panel|wp.customize.Control} returnConstruct - The object to return focus.
|
|
|
|
*/
|
|
|
|
function focusConstructWithBreadcrumb( focusConstruct, returnConstruct ) {
|
|
|
|
focusConstruct.focus();
|
|
|
|
function onceCollapsed( isExpanded ) {
|
|
|
|
if ( ! isExpanded ) {
|
|
|
|
focusConstruct.expanded.unbind( onceCollapsed );
|
|
|
|
returnConstruct.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
focusConstruct.expanded.bind( onceCollapsed );
|
|
|
|
}
|
|
|
|
|
2014-03-05 15:41:14 -05:00
|
|
|
/**
|
2014-04-07 16:00:16 -04:00
|
|
|
* @param {String} widgetId
|
2014-03-05 15:41:14 -05:00
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2014-04-07 16:00:16 -04:00
|
|
|
function parseWidgetId( widgetId ) {
|
2014-03-06 11:45:15 -05:00
|
|
|
var matches, parsed = {
|
2014-03-05 15:41:14 -05:00
|
|
|
number: null,
|
|
|
|
id_base: null
|
|
|
|
};
|
2014-04-07 16:00:16 -04:00
|
|
|
|
|
|
|
matches = widgetId.match( /^(.+)-(\d+)$/ );
|
2014-03-05 15:41:14 -05:00
|
|
|
if ( matches ) {
|
|
|
|
parsed.id_base = matches[1];
|
|
|
|
parsed.number = parseInt( matches[2], 10 );
|
|
|
|
} else {
|
|
|
|
// likely an old single widget
|
2014-04-07 16:00:16 -04:00
|
|
|
parsed.id_base = widgetId;
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
2014-04-07 16:00:16 -04:00
|
|
|
|
2014-03-05 15:41:14 -05:00
|
|
|
return parsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-07 16:00:16 -04:00
|
|
|
* @param {String} widgetId
|
2014-04-07 12:32:15 -04:00
|
|
|
* @returns {String} settingId
|
2014-03-05 15:41:14 -05:00
|
|
|
*/
|
2014-04-07 16:00:16 -04:00
|
|
|
function widgetIdToSettingId( widgetId ) {
|
|
|
|
var parsed = parseWidgetId( widgetId ), settingId;
|
2014-03-06 11:45:15 -05:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
settingId = 'widget_' + parsed.id_base;
|
2014-03-05 15:41:14 -05:00
|
|
|
if ( parsed.number ) {
|
2014-04-07 12:32:15 -04:00
|
|
|
settingId += '[' + parsed.number + ']';
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
2014-04-07 16:00:16 -04:00
|
|
|
|
2014-04-07 12:32:15 -04:00
|
|
|
return settingId;
|
2014-03-05 15:41:14 -05:00
|
|
|
}
|
|
|
|
|
2014-04-07 05:04:14 -04:00
|
|
|
})( window.wp, jQuery );
|