2018-06-28 04:30:15 +02:00
|
|
|
/**
|
|
|
|
* @output wp-admin/js/customize-widgets.js
|
|
|
|
*/
|
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
/* global _wpCustomizeWidgetsSettings */
|
|
|
|
(function( wp, $ ){
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
if ( ! wp || ! wp.customize ) { return; }
|
|
|
|
|
|
|
|
// Set up our namespace...
|
|
|
|
var api = wp.customize,
|
2014-07-09 22:58:15 +02:00
|
|
|
l10n;
|
2014-04-07 11:04:14 +02:00
|
|
|
|
2017-12-15 14:42:46 +01:00
|
|
|
/**
|
|
|
|
* @namespace wp.customize.Widgets
|
|
|
|
*/
|
2014-04-07 11:04:14 +02:00
|
|
|
api.Widgets = api.Widgets || {};
|
2015-10-06 23:59:25 +02:00
|
|
|
api.Widgets.savedWidgetIds = {};
|
2014-04-07 11:04:14 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Link settings.
|
2014-04-07 11:04:14 +02:00
|
|
|
api.Widgets.data = _wpCustomizeWidgetsSettings || {};
|
|
|
|
l10n = api.Widgets.data.l10n;
|
2014-03-05 21:41:14 +01:00
|
|
|
|
|
|
|
/**
|
2014-04-07 16:10:14 +02:00
|
|
|
* wp.customize.Widgets.WidgetModel
|
|
|
|
*
|
|
|
|
* A single widget model.
|
|
|
|
*
|
2017-12-15 14:42:46 +01:00
|
|
|
* @class wp.customize.Widgets.WidgetModel
|
2014-04-07 16:10:14 +02:00
|
|
|
* @augments Backbone.Model
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2017-12-15 14:42:46 +01:00
|
|
|
api.Widgets.WidgetModel = Backbone.Model.extend(/** @lends wp.customize.Widgets.WidgetModel.prototype */{
|
2014-03-05 21:41:14 +01: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 22:59:29 +01:00
|
|
|
transport: null,
|
2014-03-05 21:41:14 +01:00
|
|
|
params: [],
|
|
|
|
width: null,
|
2014-04-08 10:12:15 +02:00
|
|
|
height: null,
|
|
|
|
search_matched: true
|
2014-04-07 11:04:14 +02:00
|
|
|
});
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2014-04-07 16:10:14 +02:00
|
|
|
/**
|
|
|
|
* wp.customize.Widgets.WidgetCollection
|
|
|
|
*
|
|
|
|
* Collection for widget models.
|
|
|
|
*
|
2017-12-15 14:42:46 +01:00
|
|
|
* @class wp.customize.Widgets.WidgetCollection
|
|
|
|
* @augments Backbone.Collection
|
2014-04-07 16:10:14 +02:00
|
|
|
*/
|
2017-12-15 14:42:46 +01:00
|
|
|
api.Widgets.WidgetCollection = Backbone.Collection.extend(/** @lends wp.customize.Widgets.WidgetCollection.prototype */{
|
2014-04-07 11:04:14 +02:00
|
|
|
model: api.Widgets.WidgetModel,
|
2014-03-21 22:13:15 +01:00
|
|
|
|
|
|
|
// Controls searching on the current widget collection
|
2020-01-29 01:45:18 +01:00
|
|
|
// and triggers an update event.
|
2014-03-21 22:13:15 +01:00
|
|
|
doSearch: function( value ) {
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Don't do anything if we've already done this search.
|
|
|
|
// Useful because the search handler fires multiple times per keystroke.
|
2014-03-21 22:13:15 +01:00
|
|
|
if ( this.terms === value ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Updates terms with the value passed.
|
2014-03-21 22:13:15 +01:00
|
|
|
this.terms = value;
|
|
|
|
|
|
|
|
// If we have terms, run a search...
|
|
|
|
if ( this.terms.length > 0 ) {
|
|
|
|
this.search( this.terms );
|
|
|
|
}
|
|
|
|
|
2016-10-03 18:28:31 +02:00
|
|
|
// If search is blank, set all the widgets as they matched the search to reset the views.
|
2014-03-21 22:13:15 +01:00
|
|
|
if ( this.terms === '' ) {
|
2014-04-08 10:12:15 +02:00
|
|
|
this.each( function ( widget ) {
|
|
|
|
widget.set( 'search_matched', true );
|
|
|
|
} );
|
2014-03-21 22:13:15 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Performs a search within the collection.
|
2014-03-21 22:13:15 +01:00
|
|
|
// @uses RegExp
|
|
|
|
search: function( term ) {
|
2014-04-08 10:12:15 +02:00
|
|
|
var match, haystack;
|
2014-03-21 22:13:15 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Escape the term string for RegExp meta characters.
|
2014-03-21 22:13:15 +01:00
|
|
|
term = term.replace( /[-\/\\^$*+?.()|[\]{}]/g, '\\$&' );
|
|
|
|
|
|
|
|
// Consider spaces as word delimiters and match the whole string
|
2020-01-29 01:45:18 +01:00
|
|
|
// so matching terms can be combined.
|
2014-03-21 22:13:15 +01:00
|
|
|
term = term.replace( / /g, ')(?=.*' );
|
|
|
|
match = new RegExp( '^(?=.*' + term + ').+', 'i' );
|
|
|
|
|
2014-04-08 10:12:15 +02: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 22:13:15 +01:00
|
|
|
}
|
2014-04-07 11:04:14 +02:00
|
|
|
});
|
|
|
|
api.Widgets.availableWidgets = new api.Widgets.WidgetCollection( api.Widgets.data.availableWidgets );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 16:10:14 +02:00
|
|
|
/**
|
|
|
|
* wp.customize.Widgets.SidebarModel
|
|
|
|
*
|
|
|
|
* A single sidebar model.
|
|
|
|
*
|
2017-12-15 14:42:46 +01:00
|
|
|
* @class wp.customize.Widgets.SidebarModel
|
2014-04-07 16:10:14 +02:00
|
|
|
* @augments Backbone.Model
|
|
|
|
*/
|
2017-12-15 14:42:46 +01:00
|
|
|
api.Widgets.SidebarModel = Backbone.Model.extend(/** @lends wp.customize.Widgets.SidebarModel.prototype */{
|
2014-03-05 21:41:14 +01: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 11:04:14 +02:00
|
|
|
});
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2014-04-07 16:10:14 +02:00
|
|
|
/**
|
|
|
|
* wp.customize.Widgets.SidebarCollection
|
|
|
|
*
|
|
|
|
* Collection for sidebar models.
|
|
|
|
*
|
2017-12-15 14:42:46 +01:00
|
|
|
* @class wp.customize.Widgets.SidebarCollection
|
2014-04-07 16:10:14 +02:00
|
|
|
* @augments Backbone.Collection
|
|
|
|
*/
|
2017-12-15 14:42:46 +01:00
|
|
|
api.Widgets.SidebarCollection = Backbone.Collection.extend(/** @lends wp.customize.Widgets.SidebarCollection.prototype */{
|
2014-04-07 11:04:14 +02:00
|
|
|
model: api.Widgets.SidebarModel
|
|
|
|
});
|
|
|
|
api.Widgets.registeredSidebars = new api.Widgets.SidebarCollection( api.Widgets.data.registeredSidebars );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2017-12-15 14:42:46 +01:00
|
|
|
api.Widgets.AvailableWidgetsPanelView = wp.Backbone.View.extend(/** @lends wp.customize.Widgets.AvailableWidgetsPanelView.prototype */{
|
2014-04-07 16:10:14 +02:00
|
|
|
|
|
|
|
el: '#available-widgets',
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'input #widgets-search': 'search',
|
|
|
|
'focus .widget-tpl' : 'focus',
|
|
|
|
'click .widget-tpl' : '_submit',
|
|
|
|
'keypress .widget-tpl' : '_submit',
|
|
|
|
'keydown' : 'keyboardAccessible'
|
|
|
|
},
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Cache current selected widget.
|
2014-04-07 16:10:14 +02:00
|
|
|
selected: null,
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Cache sidebar control which has opened panel.
|
2014-04-07 16:10:14 +02:00
|
|
|
currentSidebarControl: null,
|
|
|
|
$search: null,
|
2016-10-03 18:28:31 +02:00
|
|
|
$clearResults: null,
|
|
|
|
searchMatchesCount: null,
|
2014-04-07 16:10:14 +02:00
|
|
|
|
2017-12-15 14:42:46 +01:00
|
|
|
/**
|
|
|
|
* View class for the available widgets panel.
|
|
|
|
*
|
|
|
|
* @constructs wp.customize.Widgets.AvailableWidgetsPanelView
|
|
|
|
* @augments wp.Backbone.View
|
|
|
|
*/
|
2014-04-07 16:10:14 +02:00
|
|
|
initialize: function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.$search = $( '#widgets-search' );
|
|
|
|
|
2016-10-03 18:28:31 +02:00
|
|
|
this.$clearResults = this.$el.find( '.clear-results' );
|
|
|
|
|
2014-04-07 16:10:14 +02:00
|
|
|
_.bindAll( this, 'close' );
|
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
this.listenTo( this.collection, 'change', this.updateList );
|
2014-04-07 16:10:14 +02:00
|
|
|
|
|
|
|
this.updateList();
|
|
|
|
|
2016-10-03 18:28:31 +02:00
|
|
|
// Set the initial search count to the number of available widgets.
|
|
|
|
this.searchMatchesCount = this.collection.length;
|
|
|
|
|
2020-01-29 01:45:18 +01: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 available widgets panel. Also close on back button click.
|
|
|
|
*/
|
2015-08-09 21:00:24 +02:00
|
|
|
$( '#customize-controls, #available-widgets .customize-section-title' ).on( 'click keydown', function( e ) {
|
2014-04-07 16:10:14 +02:00
|
|
|
var isAddNewBtn = $( e.target ).is( '.add-new-widget, .add-new-widget *' );
|
|
|
|
if ( $( 'body' ).hasClass( 'adding-widget' ) && ! isAddNewBtn ) {
|
|
|
|
self.close();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2020-07-13 22:15:06 +02:00
|
|
|
// Clear the search results and trigger an `input` event to fire a new search.
|
2016-10-03 18:28:31 +02:00
|
|
|
this.$clearResults.on( 'click', function() {
|
2020-07-13 22:15:06 +02:00
|
|
|
self.$search.val( '' ).focus().trigger( 'input' );
|
2016-10-03 18:28:31 +02:00
|
|
|
} );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Close the panel if the URL in the preview changes.
|
2014-07-09 22:58:15 +02:00
|
|
|
api.previewer.bind( 'url', this.close );
|
2014-04-07 16:10:14 +02:00
|
|
|
},
|
|
|
|
|
2017-12-15 14:42:46 +01:00
|
|
|
/**
|
|
|
|
* Performs a search and handles selected widget.
|
|
|
|
*/
|
2019-03-09 13:56:54 +01:00
|
|
|
search: _.debounce( function( event ) {
|
2014-04-07 16:10:14 +02:00
|
|
|
var firstVisible;
|
|
|
|
|
|
|
|
this.collection.doSearch( event.target.value );
|
2016-10-03 18:28:31 +02:00
|
|
|
// Update the search matches count.
|
|
|
|
this.updateSearchMatchesCount();
|
|
|
|
// Announce how many search results.
|
|
|
|
this.announceSearchMatches();
|
2014-04-07 16:10:14 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Remove a widget from being selected if it is no longer visible.
|
2014-04-07 16:10:14 +02:00
|
|
|
if ( this.selected && ! this.selected.is( ':visible' ) ) {
|
|
|
|
this.selected.removeClass( 'selected' );
|
|
|
|
this.selected = null;
|
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// If a widget was selected but the filter value has been cleared out, clear selection.
|
2014-04-07 16:10:14 +02:00
|
|
|
if ( this.selected && ! event.target.value ) {
|
|
|
|
this.selected.removeClass( 'selected' );
|
|
|
|
this.selected = null;
|
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// If a filter has been entered and a widget hasn't been selected, select the first one shown.
|
2014-04-07 16:10:14 +02:00
|
|
|
if ( ! this.selected && event.target.value ) {
|
|
|
|
firstVisible = this.$el.find( '> .widget-tpl:visible:first' );
|
|
|
|
if ( firstVisible.length ) {
|
|
|
|
this.select( firstVisible );
|
|
|
|
}
|
|
|
|
}
|
2016-10-03 18:28:31 +02: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' );
|
|
|
|
}
|
2019-03-09 13:56:54 +01:00
|
|
|
}, 500 ),
|
2016-10-03 18:28:31 +02:00
|
|
|
|
2017-12-15 14:42:46 +01:00
|
|
|
/**
|
|
|
|
* Updates the count of the available widgets that have the `search_matched` attribute.
|
|
|
|
*/
|
2016-10-03 18:28:31 +02:00
|
|
|
updateSearchMatchesCount: function() {
|
|
|
|
this.searchMatchesCount = this.collection.where({ search_matched: true }).length;
|
2014-04-07 16:10:14 +02:00
|
|
|
},
|
|
|
|
|
2017-12-15 14:42:46 +01:00
|
|
|
/**
|
|
|
|
* Sends a message to the aria-live region to announce how many search results.
|
|
|
|
*/
|
2019-03-09 13:56:54 +01:00
|
|
|
announceSearchMatches: function() {
|
2016-10-03 18:28:31 +02:00
|
|
|
var message = l10n.widgetsFound.replace( '%d', this.searchMatchesCount ) ;
|
|
|
|
|
|
|
|
if ( ! this.searchMatchesCount ) {
|
|
|
|
message = l10n.noWidgetsFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
wp.a11y.speak( message );
|
2019-03-09 13:56:54 +01:00
|
|
|
},
|
2016-10-03 18:28:31 +02:00
|
|
|
|
2017-12-15 14:42:46 +01:00
|
|
|
/**
|
|
|
|
* Changes visibility of available widgets.
|
|
|
|
*/
|
2014-04-07 16:10:14 +02:00
|
|
|
updateList: function() {
|
|
|
|
this.collection.each( function( widget ) {
|
|
|
|
var widgetTpl = $( '#widget-tpl-' + widget.id );
|
2014-04-08 10:12:15 +02:00
|
|
|
widgetTpl.toggle( widget.get( 'search_matched' ) && ! widget.get( 'is_disabled' ) );
|
2014-04-07 16:10:14 +02:00
|
|
|
if ( widget.get( 'is_disabled' ) && widgetTpl.is( this.selected ) ) {
|
|
|
|
this.selected = null;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2017-12-15 14:42:46 +01:00
|
|
|
/**
|
|
|
|
* Highlights a widget.
|
|
|
|
*/
|
2014-04-07 16:10:14 +02:00
|
|
|
select: function( widgetTpl ) {
|
|
|
|
this.selected = $( widgetTpl );
|
|
|
|
this.selected.siblings( '.widget-tpl' ).removeClass( 'selected' );
|
|
|
|
this.selected.addClass( 'selected' );
|
|
|
|
},
|
|
|
|
|
2017-12-15 14:42:46 +01:00
|
|
|
/**
|
|
|
|
* Highlights a widget on focus.
|
|
|
|
*/
|
2014-04-07 16:10:14 +02:00
|
|
|
focus: function( event ) {
|
|
|
|
this.select( $( event.currentTarget ) );
|
|
|
|
},
|
|
|
|
|
2017-12-15 14:42:46 +01:00
|
|
|
/**
|
|
|
|
* Handles submit for keypress and click on widget.
|
|
|
|
*/
|
2014-04-07 16:10:14 +02:00
|
|
|
_submit: function( event ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Only proceed with keypress if it is Enter or Spacebar.
|
2014-04-07 16:10:14 +02:00
|
|
|
if ( event.type === 'keypress' && ( event.which !== 13 && event.which !== 32 ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.submit( $( event.currentTarget ) );
|
|
|
|
},
|
|
|
|
|
2017-12-15 14:42:46 +01:00
|
|
|
/**
|
|
|
|
* Adds a selected widget to the sidebar.
|
|
|
|
*/
|
2014-04-07 16:10:14 +02:00
|
|
|
submit: function( widgetTpl ) {
|
2015-02-12 00:32:27 +01:00
|
|
|
var widgetId, widget, widgetFormControl;
|
2014-04-07 16:10:14 +02: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-12 00:32:27 +01:00
|
|
|
widgetFormControl = this.currentSidebarControl.addWidget( widget.get( 'id_base' ) );
|
|
|
|
if ( widgetFormControl ) {
|
|
|
|
widgetFormControl.focus();
|
|
|
|
}
|
2014-04-07 16:10:14 +02:00
|
|
|
|
|
|
|
this.close();
|
|
|
|
},
|
|
|
|
|
2017-12-15 14:42:46 +01:00
|
|
|
/**
|
|
|
|
* Opens the panel.
|
|
|
|
*/
|
2014-04-07 16:10:14 +02:00
|
|
|
open: function( sidebarControl ) {
|
|
|
|
this.currentSidebarControl = sidebarControl;
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Wide widget controls appear over the preview, and so they need to be collapsed when the panel opens.
|
2014-04-07 16:10:14 +02:00
|
|
|
_( this.currentSidebarControl.getWidgetFormControls() ).each( function( control ) {
|
|
|
|
if ( control.params.is_wide ) {
|
|
|
|
control.collapseForm();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2017-10-13 23:21:55 +02:00
|
|
|
if ( api.section.has( 'publish_settings' ) ) {
|
|
|
|
api.section( 'publish_settings' ).collapse();
|
|
|
|
}
|
|
|
|
|
2014-04-07 16:10:14 +02:00
|
|
|
$( 'body' ).addClass( 'adding-widget' );
|
|
|
|
|
|
|
|
this.$el.find( '.selected' ).removeClass( 'selected' );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Reset search.
|
2014-04-07 16:10:14 +02:00
|
|
|
this.collection.doSearch( '' );
|
|
|
|
|
2015-04-21 16:15:26 +02:00
|
|
|
if ( ! api.settings.browser.mobile ) {
|
|
|
|
this.$search.focus();
|
|
|
|
}
|
2014-04-07 16:10:14 +02:00
|
|
|
},
|
|
|
|
|
2017-12-15 14:42:46 +01:00
|
|
|
/**
|
|
|
|
* Closes the panel.
|
|
|
|
*/
|
2014-04-07 16:10:14 +02:00
|
|
|
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' );
|
|
|
|
|
2020-07-13 22:15:06 +02:00
|
|
|
this.$search.val( '' ).trigger( 'input' );
|
2014-04-07 16:10:14 +02:00
|
|
|
},
|
|
|
|
|
2017-12-15 14:42:46 +01:00
|
|
|
/**
|
|
|
|
* Adds keyboard accessiblity to the panel.
|
|
|
|
*/
|
2014-04-07 16:10:14 +02:00
|
|
|
keyboardAccessible: function( event ) {
|
|
|
|
var isEnter = ( event.which === 13 ),
|
|
|
|
isEsc = ( event.which === 27 ),
|
|
|
|
isDown = ( event.which === 40 ),
|
|
|
|
isUp = ( event.which === 38 ),
|
2014-07-19 03:19:14 +02:00
|
|
|
isTab = ( event.which === 9 ),
|
|
|
|
isShift = ( event.shiftKey ),
|
2014-04-07 16:10:14 +02:00
|
|
|
selected = null,
|
|
|
|
firstVisible = this.$el.find( '> .widget-tpl:visible:first' ),
|
|
|
|
lastVisible = this.$el.find( '> .widget-tpl:visible:last' ),
|
2014-07-19 03:19:14 +02:00
|
|
|
isSearchFocused = $( event.target ).is( this.$search ),
|
|
|
|
isLastWidgetFocused = $( event.target ).is( '.widget-tpl:visible:last' );
|
2014-04-07 16:10:14 +02: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;
|
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// If enter pressed but nothing entered, don't do anything.
|
2014-04-07 16:10:14 +02:00
|
|
|
if ( isEnter && ! this.$search.val() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isEnter ) {
|
|
|
|
this.submit();
|
|
|
|
} else if ( isEsc ) {
|
|
|
|
this.close( { returnFocus: true } );
|
|
|
|
}
|
2014-07-19 03:19:14 +02:00
|
|
|
|
2015-05-29 15:57:26 +02:00
|
|
|
if ( this.currentSidebarControl && isTab && ( isShift && isSearchFocused || ! isShift && isLastWidgetFocused ) ) {
|
2014-07-19 03:19:14 +02:00
|
|
|
this.currentSidebarControl.container.find( '.add-new-widget' ).focus();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2014-04-07 16:10:14 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-04-02 20:20:16 +02: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.
|
2017-12-15 14:42:46 +01:00
|
|
|
*
|
|
|
|
* @alias wp.customize.Widgets.formSyncHandlers
|
2014-04-02 20:20:16 +02:00
|
|
|
*/
|
2014-04-07 11:04:14 +02:00
|
|
|
api.Widgets.formSyncHandlers = {
|
2014-04-02 20:20:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {jQuery.Event} e
|
2014-04-07 11:04:14 +02:00
|
|
|
* @param {jQuery} widget
|
2020-07-28 01:35:02 +02:00
|
|
|
* @param {string} newForm
|
2014-04-02 20:20:16 +02:00
|
|
|
*/
|
2014-04-07 16:10:14 +02:00
|
|
|
rss: function( e, widget, newForm ) {
|
2014-04-07 11:04:14 +02: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 20:20:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-15 14:42:46 +01:00
|
|
|
api.Widgets.WidgetControl = api.Control.extend(/** @lends wp.customize.Widgets.WidgetControl.prototype */{
|
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 23:51:22 +01:00
|
|
|
defaultExpandedArguments: {
|
2014-11-11 23:37:22 +01: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 23:51:22 +01:00
|
|
|
},
|
|
|
|
|
2014-12-04 03:04:22 +01:00
|
|
|
/**
|
2017-12-15 14:42:46 +01:00
|
|
|
* wp.customize.Widgets.WidgetControl
|
|
|
|
*
|
|
|
|
* Customizer control for widgets.
|
|
|
|
* Note that 'widget_form' must match the WP_Widget_Form_Customize_Control::$type
|
|
|
|
*
|
2014-12-04 03:04:22 +01:00
|
|
|
* @since 4.1.0
|
2017-12-15 14:42:46 +01:00
|
|
|
*
|
|
|
|
* @constructs wp.customize.Widgets.WidgetControl
|
|
|
|
* @augments wp.customize.Control
|
2014-12-04 03:04:22 +01:00
|
|
|
*/
|
2015-09-25 23:02:27 +02: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 23:51:22 +01:00
|
|
|
var control = this;
|
2015-09-25 23:02:27 +02: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 23:51:22 +01:00
|
|
|
control.expandedArgumentsQueue = [];
|
2015-09-25 23:02:27 +02: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 23:51:22 +01: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 23:10:27 +02:00
|
|
|
control.altNotice = true;
|
2015-09-25 23:02:27 +02: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 23:51:22 +01:00
|
|
|
},
|
|
|
|
|
2014-03-05 21:41:14 +01:00
|
|
|
/**
|
2015-09-25 23:02:27 +02:00
|
|
|
* Set up the control.
|
|
|
|
*
|
|
|
|
* @since 3.9.0
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
|
|
|
ready: function() {
|
2015-09-25 23:02:27 +02: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;
|
|
|
|
|
Customize: Add global notifications area.
* Displays an error notification in the global area when a save attempt is rejected due to invalid settings. An error notification is also displayed when saving fails due to a network error or server error.
* Introduces `wp.customize.Notifications` subclass of `wp.customize.Values` to contain instances of `wp.customize.Notification` and manage their rendering into a container.
* Exposes the global notification area as `wp.customize.notifications` collection instance.
* Updates the `notifications` object on `Control` to use `Notifications` rather than `Values` and to re-use the rendering logic from the former. The old `Control#renderNotifications` method is deprecated.
* Allows notifications to be dismissed by instantiating them with a `dismissible` property.
* Allows `wp.customize.Notification` to be extended with custom templates and `render` functions.
* Triggers a `removed` event on `wp.customize.Values` instances _after_ a value has been removed from the collection.
Props delawski, westonruter, karmatosed, celloexpressions, Fab1en, melchoyce, Kelderic, afercia, adamsilverstein.
See #34893, #39896.
Fixes #35210, #31582, #37727, #37269.
Built from https://develop.svn.wordpress.org/trunk@41374
git-svn-id: http://core.svn.wordpress.org/trunk@41207 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2017-09-12 09:03:46 +02:00
|
|
|
// Update the notification container element now that the widget content has been embedded.
|
|
|
|
control.notifications.container = control.getNotificationsContainerElement();
|
|
|
|
control.notifications.render();
|
|
|
|
|
2015-09-25 23:02:27 +02:00
|
|
|
widgetContent = $( control.params.widget_content );
|
|
|
|
control.container.find( '.widget-content:first' ).append( widgetContent );
|
2014-11-11 23:46:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Trigger widget-added event so that plugins can attach any event
|
|
|
|
* listeners and dynamic UI elements.
|
|
|
|
*/
|
2015-09-25 23:02:27 +02:00
|
|
|
$( document ).trigger( 'widget-added', [ control.container.find( '.widget:first' ) ] );
|
|
|
|
|
2014-03-05 21:41:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 11:04:14 +02:00
|
|
|
* Handle changes to the setting
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
|
|
|
_setupModel: function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
var self = this, rememberSavedWidgetId;
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Remember saved widgets so we know which to trash (move to inactive widgets sidebar).
|
2014-04-07 18:32:15 +02:00
|
|
|
rememberSavedWidgetId = function() {
|
|
|
|
api.Widgets.savedWidgetIds[self.params.widget_id] = true;
|
2014-04-07 11:04:14 +02:00
|
|
|
};
|
2014-04-07 18:32:15 +02:00
|
|
|
api.bind( 'ready', rememberSavedWidgetId );
|
|
|
|
api.bind( 'saved', rememberSavedWidgetId );
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
this._updateCount = 0;
|
|
|
|
this.isWidgetUpdating = false;
|
|
|
|
this.liveUpdateMode = true;
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Update widget whenever model changes.
|
2014-04-07 18:32:15 +02:00
|
|
|
this.setting.bind( function( to, from ) {
|
|
|
|
if ( ! _( from ).isEqual( to ) && ! self.isWidgetUpdating ) {
|
|
|
|
self.updateWidget( { instance: to } );
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
},
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
/**
|
|
|
|
* Add special behaviors for wide widget controls
|
|
|
|
*/
|
|
|
|
_setupWideWidget: function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
var self = this, $widgetInside, $widgetForm, $customizeSidebar,
|
|
|
|
$themeControlsContainer, positionWidget;
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2017-08-13 07:55:43 +02:00
|
|
|
if ( ! this.params.is_wide || $( window ).width() <= 640 /* max-width breakpoint in customize-controls.css */ ) {
|
2014-04-07 11:04:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 18:32:15 +02: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 21:41:14 +01:00
|
|
|
|
2017-08-13 07:42:42 +02:00
|
|
|
this.container.find( '.form:first' ).css( {
|
2014-04-07 18:32:15 +02:00
|
|
|
'max-width': this.params.width,
|
|
|
|
'min-height': this.params.height
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 11:04:14 +02: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 18:32:15 +02:00
|
|
|
positionWidget = function() {
|
|
|
|
var offsetTop = self.container.offset().top,
|
|
|
|
windowHeight = $( window ).height(),
|
|
|
|
formHeight = $widgetForm.outerHeight(),
|
2014-04-07 11:04:14 +02:00
|
|
|
top;
|
2014-04-07 18:32:15 +02:00
|
|
|
$widgetInside.css( 'max-height', windowHeight );
|
2014-04-07 11:04:14 +02:00
|
|
|
top = Math.max(
|
2020-01-29 01:45:18 +01:00
|
|
|
0, // Prevent top from going off screen.
|
2014-04-07 11:04:14 +02:00
|
|
|
Math.min(
|
2020-01-29 01:45:18 +01: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 11:04:14 +02:00
|
|
|
)
|
|
|
|
);
|
2014-04-07 18:32:15 +02:00
|
|
|
$widgetInside.css( 'top', top );
|
2014-04-07 11:04:14 +02:00
|
|
|
};
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 18:32:15 +02: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 21:41:14 +01:00
|
|
|
} );
|
2014-04-07 18:32:15 +02:00
|
|
|
this.container.on( 'collapsed', function() {
|
|
|
|
$customizeSidebar.off( 'scroll', positionWidget );
|
|
|
|
$( window ).off( 'resize', positionWidget );
|
|
|
|
$themeControlsContainer.off( 'expanded collapsed', positionWidget );
|
2014-03-05 21:41:14 +01:00
|
|
|
} );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Reposition whenever a sidebar's widgets are changed.
|
2014-04-07 16:10:14 +02:00
|
|
|
api.each( function( setting ) {
|
2014-04-07 11:04:14 +02:00
|
|
|
if ( 0 === setting.id.indexOf( 'sidebars_widgets[' ) ) {
|
|
|
|
setting.bind( function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
if ( self.container.hasClass( 'expanded' ) ) {
|
|
|
|
positionWidget();
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-03-05 21:41:14 +01:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 11:04:14 +02:00
|
|
|
* Show/hide the control when clicking on the form title, when clicking
|
|
|
|
* the close button
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 11:04:14 +02:00
|
|
|
_setupControlToggle: function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
var self = this, $closeBtn;
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
this.container.find( '.widget-top' ).on( 'click', function( e ) {
|
2014-04-07 11:04:14 +02:00
|
|
|
e.preventDefault();
|
2014-04-07 18:32:15 +02:00
|
|
|
var sidebarWidgetsControl = self.getSidebarWidgetsControl();
|
2014-04-07 22:00:16 +02:00
|
|
|
if ( sidebarWidgetsControl.isReordering ) {
|
2014-04-07 11:04:14 +02:00
|
|
|
return;
|
2014-03-05 21:41:14 +01: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 23:51:22 +01:00
|
|
|
self.expanded( ! self.expanded() );
|
2014-03-05 21:41:14 +01:00
|
|
|
} );
|
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
$closeBtn = this.container.find( '.widget-control-close' );
|
2019-03-09 13:56:54 +01:00
|
|
|
$closeBtn.on( 'click', 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 23:51:22 +01:00
|
|
|
self.collapse();
|
2020-01-29 01:45:18 +01:00
|
|
|
self.container.find( '.widget-top .widget-action:first' ).focus(); // Keyboard accessibility.
|
2014-03-05 21:41:14 +01:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 11:04:14 +02:00
|
|
|
* Update the title of the form if a title field is entered
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 11:04:14 +02:00
|
|
|
_setupWidgetTitle: function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
var self = this, updateTitle;
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
updateTitle = function() {
|
|
|
|
var title = self.setting().title,
|
|
|
|
inWidgetTitle = self.container.find( '.in-widget-title' );
|
2014-04-07 11:04:14 +02:00
|
|
|
|
|
|
|
if ( title ) {
|
2014-04-07 18:32:15 +02:00
|
|
|
inWidgetTitle.text( ': ' + title );
|
2014-04-07 11:04:14 +02:00
|
|
|
} else {
|
2014-04-07 18:32:15 +02:00
|
|
|
inWidgetTitle.text( '' );
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
2014-04-07 11:04:14 +02:00
|
|
|
};
|
2014-04-07 18:32:15 +02:00
|
|
|
this.setting.bind( updateTitle );
|
|
|
|
updateTitle();
|
2014-04-07 11:04:14 +02:00
|
|
|
},
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
/**
|
|
|
|
* Set up the widget-reorder-nav
|
|
|
|
*/
|
|
|
|
_setupReorderUI: function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
var self = this, selectSidebarItem, $moveWidgetArea,
|
2016-02-17 16:22:26 +01:00
|
|
|
$reorderNav, updateAvailableSidebars, template;
|
2014-04-07 11:04:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* select the provided sidebar list item in the move widget area
|
|
|
|
*
|
|
|
|
* @param {jQuery} li
|
|
|
|
*/
|
2014-04-07 18:32:15 +02:00
|
|
|
selectSidebarItem = function( li ) {
|
2014-04-07 11:04:14 +02:00
|
|
|
li.siblings( '.selected' ).removeClass( 'selected' );
|
|
|
|
li.addClass( 'selected' );
|
2014-04-07 18:32:15 +02:00
|
|
|
var isSelfSidebar = ( li.data( 'id' ) === self.params.sidebar_id );
|
|
|
|
self.container.find( '.move-widget-btn' ).prop( 'disabled', isSelfSidebar );
|
2014-04-07 11:04:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the widget reordering elements to the widget control
|
|
|
|
*/
|
2014-04-07 18:32:15 +02:00
|
|
|
this.container.find( '.widget-title-action' ).after( $( api.Widgets.data.tpl.widgetReorderNav ) );
|
2016-02-17 16:22:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
template = _.template( api.Widgets.data.tpl.moveWidgetArea );
|
|
|
|
$moveWidgetArea = $( template( {
|
2014-04-07 11:04:14 +02:00
|
|
|
sidebars: _( api.Widgets.registeredSidebars.toArray() ).pluck( 'attributes' )
|
|
|
|
} )
|
|
|
|
);
|
2014-04-07 18:32:15 +02:00
|
|
|
this.container.find( '.widget-top' ).after( $moveWidgetArea );
|
2014-04-07 11:04:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update available sidebars when their rendered state changes
|
|
|
|
*/
|
2014-04-07 18:32:15 +02:00
|
|
|
updateAvailableSidebars = function() {
|
2015-02-11 21:45:26 +01:00
|
|
|
var $sidebarItems = $moveWidgetArea.find( 'li' ), selfSidebarItem,
|
|
|
|
renderedSidebarCount = 0;
|
2014-04-07 18:32:15 +02:00
|
|
|
|
|
|
|
selfSidebarItem = $sidebarItems.filter( function(){
|
|
|
|
return $( this ).data( 'id' ) === self.params.sidebar_id;
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2014-04-07 18:32:15 +02:00
|
|
|
|
|
|
|
$sidebarItems.each( function() {
|
2014-04-07 11:04:14 +02:00
|
|
|
var li = $( this ),
|
2015-02-11 21:45:26 +01:00
|
|
|
sidebarId, sidebar, sidebarIsRendered;
|
2014-04-07 11:04:14 +02:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
sidebarId = li.data( 'id' );
|
2014-04-07 22:00:16 +02:00
|
|
|
sidebar = api.Widgets.registeredSidebars.get( sidebarId );
|
2015-02-11 21:45:26 +01:00
|
|
|
sidebarIsRendered = sidebar.get( 'is_rendered' );
|
2014-04-07 18:32:15 +02:00
|
|
|
|
2015-02-11 21:45:26 +01:00
|
|
|
li.toggle( sidebarIsRendered );
|
2014-04-07 18:32:15 +02:00
|
|
|
|
2015-02-11 21:45:26 +01:00
|
|
|
if ( sidebarIsRendered ) {
|
|
|
|
renderedSidebarCount += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( li.hasClass( 'selected' ) && ! sidebarIsRendered ) {
|
2014-04-07 18:32:15 +02:00
|
|
|
selectSidebarItem( selfSidebarItem );
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
|
|
|
} );
|
2015-01-20 21:36:21 +01:00
|
|
|
|
2015-02-11 21:45:26 +01:00
|
|
|
if ( renderedSidebarCount > 1 ) {
|
2015-01-20 21:36:21 +01:00
|
|
|
self.container.find( '.move-widget' ).show();
|
2015-02-11 21:45:26 +01:00
|
|
|
} else {
|
|
|
|
self.container.find( '.move-widget' ).hide();
|
2015-01-20 21:36:21 +01:00
|
|
|
}
|
2014-04-07 11:04:14 +02:00
|
|
|
};
|
2014-04-07 18:32:15 +02:00
|
|
|
|
|
|
|
updateAvailableSidebars();
|
|
|
|
api.Widgets.registeredSidebars.on( 'change:is_rendered', updateAvailableSidebars );
|
2014-04-07 11:04:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle clicks for up/down/move on the reorder nav
|
|
|
|
*/
|
2014-04-07 18:32:15 +02:00
|
|
|
$reorderNav = this.container.find( '.widget-reorder-nav' );
|
2014-07-19 03:58:15 +02: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 11:04:14 +02:00
|
|
|
if ( event.type === 'keypress' && ( event.which !== 13 && event.which !== 32 ) ) {
|
2014-03-05 21:41:14 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-04-07 11:04:14 +02:00
|
|
|
$( this ).focus();
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
if ( $( this ).is( '.move-widget' ) ) {
|
2014-04-07 18:32:15 +02:00
|
|
|
self.toggleWidgetMoveArea();
|
2014-03-05 21:41:14 +01:00
|
|
|
} else {
|
2014-04-07 18:32:15 +02:00
|
|
|
var isMoveDown = $( this ).is( '.move-widget-down' ),
|
|
|
|
isMoveUp = $( this ).is( '.move-widget-up' ),
|
|
|
|
i = self.getWidgetSidebarPosition();
|
2014-04-07 11:04:14 +02:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
if ( ( isMoveUp && i === 0 ) || ( isMoveDown && i === self.getSidebarWidgetsControl().setting().length - 1 ) ) {
|
2014-04-07 11:04:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
if ( isMoveUp ) {
|
|
|
|
self.moveUp();
|
2015-03-01 20:11:27 +01:00
|
|
|
wp.a11y.speak( l10n.widgetMovedUp );
|
2014-04-07 11:04:14 +02:00
|
|
|
} else {
|
2014-04-07 18:32:15 +02:00
|
|
|
self.moveDown();
|
2015-03-01 20:11:27 +01:00
|
|
|
wp.a11y.speak( l10n.widgetMovedDown );
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
$( this ).focus(); // Re-focus after the container was moved.
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
/**
|
|
|
|
* Handle selecting a sidebar to move to
|
|
|
|
*/
|
2014-12-23 18:24:24 +01:00
|
|
|
this.container.find( '.widget-area-select' ).on( 'click keypress', 'li', function( event ) {
|
2014-04-07 11:04:14 +02:00
|
|
|
if ( event.type === 'keypress' && ( event.which !== 13 && event.which !== 32 ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-23 18:24:24 +01:00
|
|
|
event.preventDefault();
|
2014-04-07 18:32:15 +02:00
|
|
|
selectSidebarItem( $( this ) );
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
/**
|
|
|
|
* Move widget to another sidebar
|
|
|
|
*/
|
2014-04-07 18:32:15 +02: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 11:04:14 +02:00
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-10-15 19:21:19 +02:00
|
|
|
* Highlight widgets in preview when interacted with in the Customizer
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 11:04:14 +02:00
|
|
|
_setupHighlightEffects: function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
var self = this;
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Highlight whenever hovering or clicking over the form.
|
2014-04-07 18:32:15 +02:00
|
|
|
this.container.on( 'mouseenter click', function() {
|
|
|
|
self.setting.previewer.send( 'highlight-widget', self.params.widget_id );
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Highlight when the setting is updated.
|
2014-04-07 18:32:15 +02:00
|
|
|
this.setting.bind( function() {
|
|
|
|
self.setting.previewer.send( 'highlight-widget', self.params.widget_id );
|
2014-03-05 21:41:14 +01:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 11:04:14 +02:00
|
|
|
* Set up event handlers for widget updating
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 11:04:14 +02:00
|
|
|
_setupUpdateUI: function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
var self = this, $widgetRoot, $widgetContent,
|
|
|
|
$saveBtn, updateWidgetDebounced, formSyncHandler;
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
$widgetRoot = this.container.find( '.widget:first' );
|
|
|
|
$widgetContent = $widgetRoot.find( '.widget-content:first' );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Configure update button.
|
2014-04-07 18:32:15 +02:00
|
|
|
$saveBtn = this.container.find( '.widget-control-save' );
|
|
|
|
$saveBtn.val( l10n.saveBtnLabel );
|
|
|
|
$saveBtn.attr( 'title', l10n.saveBtnTooltip );
|
2016-09-28 21:54:28 +02:00
|
|
|
$saveBtn.removeClass( 'button-primary' );
|
2014-04-07 18:32:15 +02:00
|
|
|
$saveBtn.on( 'click', function( e ) {
|
2014-04-07 11:04:14 +02:00
|
|
|
e.preventDefault();
|
2014-04-07 22:00:16 +02:00
|
|
|
self.updateWidget( { disable_form: true } ); // @todo disable_form is unused?
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
updateWidgetDebounced = _.debounce( function() {
|
|
|
|
self.updateWidget();
|
2014-04-07 11:04:14 +02:00
|
|
|
}, 250 );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Trigger widget form update when hitting Enter within an input.
|
2014-04-16 02:11:35 +02:00
|
|
|
$widgetContent.on( 'keydown', 'input', function( e ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
if ( 13 === e.which ) { // Enter.
|
2014-04-07 11:04:14 +02:00
|
|
|
e.preventDefault();
|
2014-04-07 22:00:16 +02:00
|
|
|
self.updateWidget( { ignoreActiveElement: true } );
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-03-05 21:41:14 +01:00
|
|
|
} );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Handle widgets that support live previews.
|
2014-04-07 18:32:15 +02:00
|
|
|
$widgetContent.on( 'change input propertychange', ':input', function( e ) {
|
2015-07-29 18:03:24 +02:00
|
|
|
if ( ! self.liveUpdateMode ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( e.type === 'change' || ( this.checkValidity && this.checkValidity() ) ) {
|
|
|
|
updateWidgetDebounced();
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Remove loading indicators when the setting is saved and the preview updates.
|
2014-04-07 18:32:15 +02:00
|
|
|
this.setting.previewer.channel.bind( 'synced', function() {
|
|
|
|
self.container.removeClass( 'previewer-loading' );
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2014-04-07 18:32:15 +02:00
|
|
|
|
2014-07-09 22:58:15 +02:00
|
|
|
api.previewer.bind( 'widget-updated', function( updatedWidgetId ) {
|
2014-04-07 18:32:15 +02:00
|
|
|
if ( updatedWidgetId === self.params.widget_id ) {
|
|
|
|
self.container.removeClass( 'previewer-loading' );
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2014-04-07 18:32:15 +02: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 11:04:14 +02:00
|
|
|
}
|
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
2014-04-07 11:04:14 +02:00
|
|
|
},
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-07-10 01:58:16 +02:00
|
|
|
/**
|
|
|
|
* Update widget control to indicate whether it is currently rendered.
|
|
|
|
*
|
|
|
|
* Overrides api.Control.toggle()
|
|
|
|
*
|
2014-12-04 03:04:22 +01:00
|
|
|
* @since 4.1.0
|
|
|
|
*
|
2020-07-28 01:35:02 +02:00
|
|
|
* @param {boolean} active
|
2014-12-04 03:04:22 +01:00
|
|
|
* @param {Object} args
|
2017-12-15 14:42:46 +01:00
|
|
|
* @param {function} args.completeCallback
|
2014-07-10 01:58:16 +02: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 23:51:22 +01:00
|
|
|
onChangeActive: function ( active, args ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Note: there is a second 'args' parameter being passed, merged on top of this.defaultActiveArguments.
|
2014-07-10 01:58:16 +02: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 23:51:22 +01:00
|
|
|
if ( args.completeCallback ) {
|
|
|
|
args.completeCallback();
|
|
|
|
}
|
2014-07-10 01:58:16 +02:00
|
|
|
},
|
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
/**
|
|
|
|
* Set up event handlers for widget removal
|
|
|
|
*/
|
|
|
|
_setupRemoveUI: function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
var self = this, $removeBtn, replaceDeleteWithRemove;
|
2014-04-07 11:04:14 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Configure remove button.
|
2017-04-19 23:14:44 +02:00
|
|
|
$removeBtn = this.container.find( '.widget-control-remove' );
|
2019-03-09 13:56:54 +01:00
|
|
|
$removeBtn.on( 'click', function() {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Find an adjacent element to add focus to when this widget goes away.
|
2014-04-07 18:32:15 +02: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 21:41:14 +01:00
|
|
|
} else {
|
2014-04-07 18:32:15 +02:00
|
|
|
$adjacentFocusTarget = self.container.next( '.customize-control-sidebar_widgets' ).find( '.add-new-widget:first' );
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
2014-04-02 20:20:16 +02:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
self.container.slideUp( function() {
|
2014-04-07 22:00:16 +02:00
|
|
|
var sidebarsWidgetsControl = api.Widgets.getSidebarWidgetControlContainingWidget( self.params.widget_id ),
|
|
|
|
sidebarWidgetIds, i;
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 22:00:16 +02:00
|
|
|
if ( ! sidebarsWidgetsControl ) {
|
2014-04-07 18:32:15 +02:00
|
|
|
return;
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-04-07 22:00:16 +02:00
|
|
|
|
|
|
|
sidebarWidgetIds = sidebarsWidgetsControl.setting().slice();
|
|
|
|
i = _.indexOf( sidebarWidgetIds, self.params.widget_id );
|
2014-04-07 11:04:14 +02:00
|
|
|
if ( -1 === i ) {
|
2014-04-07 18:32:15 +02:00
|
|
|
return;
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-04-07 22:00:16 +02:00
|
|
|
|
|
|
|
sidebarWidgetIds.splice( i, 1 );
|
|
|
|
sidebarsWidgetsControl.setting( sidebarWidgetIds );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
$adjacentFocusTarget.focus(); // Keyboard accessibility.
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
replaceDeleteWithRemove = function() {
|
2020-01-29 01:45:18 +01:00
|
|
|
$removeBtn.text( l10n.removeBtnLabel ); // wp_widget_control() outputs the button as "Delete".
|
2014-04-07 18:32:15 +02:00
|
|
|
$removeBtn.attr( 'title', l10n.removeBtnTooltip );
|
2014-04-07 11:04:14 +02:00
|
|
|
};
|
2014-04-07 18:32:15 +02:00
|
|
|
|
|
|
|
if ( this.params.is_new ) {
|
|
|
|
api.bind( 'saved', replaceDeleteWithRemove );
|
2014-04-07 11:04:14 +02:00
|
|
|
} else {
|
2014-04-07 18:32:15 +02:00
|
|
|
replaceDeleteWithRemove();
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
|
|
|
},
|
2014-03-05 21:41:14 +01:00
|
|
|
|
|
|
|
/**
|
2014-04-07 11:04:14 +02: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 22:23:25 +01:00
|
|
|
* over when copying sanitized values over to the form loaded.
|
2014-04-07 11:04:14 +02:00
|
|
|
*
|
|
|
|
* @param {jQuery} container element in which to look for inputs
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {jQuery} inputs
|
2014-04-07 11:04:14 +02:00
|
|
|
* @private
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 16:10:14 +02:00
|
|
|
_getInputs: function( container ) {
|
2014-04-07 11:04:14 +02:00
|
|
|
return $( container ).find( ':input[name]' );
|
2014-03-05 21:41:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 11:04:14 +02: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
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {string}
|
2014-04-07 11:04:14 +02:00
|
|
|
* @private
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 16:10:14 +02:00
|
|
|
_getInputsSignature: function( inputs ) {
|
2014-04-07 18:32:15 +02: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 11:04:14 +02:00
|
|
|
} else {
|
2014-04-07 18:32:15 +02:00
|
|
|
signatureParts = [ $input.attr( 'id' ), $input.attr( 'name' ) ];
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
2014-04-07 18:32:15 +02:00
|
|
|
|
|
|
|
return signatureParts.join( ',' );
|
2014-03-05 21:41:14 +01:00
|
|
|
} );
|
2014-04-07 18:32:15 +02:00
|
|
|
|
|
|
|
return inputsSignatures.join( ';' );
|
2014-03-05 21:41:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-04-04 18:34:26 +02:00
|
|
|
* Get the state for an input depending on its type.
|
2014-04-07 11:04:14 +02:00
|
|
|
*
|
2015-04-04 18:34:26 +02:00
|
|
|
* @param {jQuery|Element} input
|
2020-07-28 01:35:02 +02:00
|
|
|
* @return {string|boolean|Array|*}
|
2014-04-07 11:04:14 +02:00
|
|
|
* @private
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2015-04-04 18:34:26 +02: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 18:32:15 +02:00
|
|
|
|
2015-04-04 18:34:26 +02:00
|
|
|
/**
|
|
|
|
* Update an input's state based on its type.
|
|
|
|
*
|
|
|
|
* @param {jQuery|Element} input
|
2020-07-28 01:35:02 +02:00
|
|
|
* @param {string|boolean|Array|*} state
|
2015-04-04 18:34:26 +02:00
|
|
|
* @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 {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Make sure all state items are strings since the DOM value is a string.
|
2015-04-04 18:34:26 +02:00
|
|
|
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 11:04:14 +02:00
|
|
|
} else {
|
2015-04-04 18:34:26 +02:00
|
|
|
input.val( state );
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
2014-04-07 11:04:14 +02:00
|
|
|
},
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* Begin public API methods
|
|
|
|
**********************************************************************/
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
/**
|
|
|
|
* @return {wp.customize.controlConstructor.sidebar_widgets[]}
|
|
|
|
*/
|
|
|
|
getSidebarWidgetsControl: function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
var settingId, sidebarWidgetsControl;
|
|
|
|
|
|
|
|
settingId = 'sidebars_widgets[' + this.params.sidebar_id + ']';
|
|
|
|
sidebarWidgetsControl = api.control( settingId );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
if ( ! sidebarWidgetsControl ) {
|
|
|
|
return;
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-04-07 18:32:15 +02:00
|
|
|
|
|
|
|
return sidebarWidgetsControl;
|
2014-03-05 21:41:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 11:04:14 +02:00
|
|
|
* Submit the widget form via Ajax and get back the updated instance,
|
|
|
|
* along with the new widget control form to render.
|
|
|
|
*
|
2020-07-28 01:35:02 +02:00
|
|
|
* @param {Object} [args]
|
2014-04-07 11:04:14 +02:00
|
|
|
* @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.
|
2020-07-28 01:35:02 +02: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 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 16:10:14 +02:00
|
|
|
updateWidget: function( args ) {
|
2014-04-07 18:32:15 +02:00
|
|
|
var self = this, instanceOverride, completeCallback, $widgetRoot, $widgetContent,
|
|
|
|
updateNumber, params, data, $inputs, processing, jqxhr, isChanged;
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2015-09-25 23:02:27 +02:00
|
|
|
// The updateWidget logic requires that the form fields to be fully present.
|
|
|
|
self.embedWidgetContent();
|
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
args = $.extend( {
|
|
|
|
instance: null,
|
|
|
|
complete: null,
|
2014-04-07 22:00:16 +02:00
|
|
|
ignoreActiveElement: false
|
2014-04-07 11:04:14 +02:00
|
|
|
}, args );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
instanceOverride = args.instance;
|
|
|
|
completeCallback = args.complete;
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
this._updateCount += 1;
|
|
|
|
updateNumber = this._updateCount;
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
$widgetRoot = this.container.find( '.widget:first' );
|
|
|
|
$widgetContent = $widgetRoot.find( '.widget-content:first' );
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Remove a previous error message.
|
2014-04-07 18:32:15 +02:00
|
|
|
$widgetContent.find( '.widget-error' ).remove();
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
this.container.addClass( 'widget-form-loading' );
|
|
|
|
this.container.addClass( 'previewer-loading' );
|
2014-04-07 11:04:14 +02:00
|
|
|
processing = api.state( 'processing' );
|
|
|
|
processing( processing() + 1 );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
if ( ! this.liveUpdateMode ) {
|
|
|
|
this.container.addClass( 'widget-form-disabled' );
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
params = {};
|
|
|
|
params.action = 'update-widget';
|
|
|
|
params.wp_customize = 'on';
|
2016-01-27 18:55:26 +01:00
|
|
|
params.nonce = api.settings.nonce['update-widget'];
|
Customize: Implement customized state persistence with changesets.
Includes infrastructure developed in the Customize Snapshots feature plugin.
See https://make.wordpress.org/core/2016/10/12/customize-changesets-technical-design-decisions/
Props westonruter, valendesigns, utkarshpatel, stubgo, lgedeon, ocean90, ryankienstra, mihai2u, dlh, aaroncampbell, jonathanbardo, jorbin.
See #28721.
See #31089.
Fixes #30937.
Fixes #31517.
Fixes #30028.
Fixes #23225.
Fixes #34142.
Fixes #36485.
Built from https://develop.svn.wordpress.org/trunk@38810
git-svn-id: http://core.svn.wordpress.org/trunk@38753 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-10-18 22:05:31 +02:00
|
|
|
params.customize_theme = api.settings.theme.stylesheet;
|
2015-07-29 18:03:24 +02:00
|
|
|
params.customized = wp.customize.previewer.query().customized;
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
data = $.param( params );
|
2014-04-07 18:32:15 +02:00
|
|
|
$inputs = this._getInputs( $widgetContent );
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2020-01-29 01:45:18 +01: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 18:32:15 +02:00
|
|
|
$inputs.each( function() {
|
2015-04-04 18:34:26 +02:00
|
|
|
$( this ).data( 'state' + updateNumber, self._getInputState( this ) );
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
if ( instanceOverride ) {
|
|
|
|
data += '&' + $.param( { 'sanitized_widget_setting': JSON.stringify( instanceOverride ) } );
|
2014-04-07 11:04:14 +02:00
|
|
|
} else {
|
2014-04-07 18:32:15 +02:00
|
|
|
data += '&' + $inputs.serialize();
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-04-07 18:32:15 +02:00
|
|
|
data += '&' + $widgetContent.find( '~ :input' ).serialize();
|
|
|
|
|
2015-03-10 23:45:27 +01:00
|
|
|
if ( this._previousUpdateRequest ) {
|
|
|
|
this._previousUpdateRequest.abort();
|
|
|
|
}
|
2014-04-07 18:32:15 +02:00
|
|
|
jqxhr = $.post( wp.ajax.settings.url, data );
|
2015-03-10 23:45:27 +01:00
|
|
|
this._previousUpdateRequest = jqxhr;
|
2014-04-07 11:04:14 +02:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
jqxhr.done( function( r ) {
|
|
|
|
var message, sanitizedForm, $sanitizedInputs, hasSameInputsInResponse,
|
|
|
|
isLiveUpdateAborted = false;
|
2014-04-07 11:04:14 +02:00
|
|
|
|
|
|
|
// Check if the user is logged out.
|
|
|
|
if ( '0' === r ) {
|
2014-07-09 22:58:15 +02:00
|
|
|
api.previewer.preview.iframe.hide();
|
|
|
|
api.previewer.login().done( function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
self.updateWidget( args );
|
2014-07-09 22:58:15 +02:00
|
|
|
api.previewer.preview.iframe.show();
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
// Check for cheaters.
|
|
|
|
if ( '-1' === r ) {
|
2014-07-09 22:58:15 +02:00
|
|
|
api.previewer.cheatin();
|
2014-04-07 11:04:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
if ( r.success ) {
|
2014-04-07 18:32:15 +02:00
|
|
|
sanitizedForm = $( '<div>' + r.data.form + '</div>' );
|
|
|
|
$sanitizedInputs = self._getInputs( sanitizedForm );
|
|
|
|
hasSameInputsInResponse = self._getInputsSignature( $inputs ) === self._getInputsSignature( $sanitizedInputs );
|
2014-04-07 11:04:14 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Restore live update mode if sanitized fields are now aligned with the existing fields.
|
2014-04-07 18:32:15 +02:00
|
|
|
if ( hasSameInputsInResponse && ! self.liveUpdateMode ) {
|
|
|
|
self.liveUpdateMode = true;
|
|
|
|
self.container.removeClass( 'widget-form-disabled' );
|
|
|
|
self.container.find( 'input[name="savewidget"]' ).hide();
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Sync sanitized field states to existing fields if they are aligned.
|
2014-04-07 18:32:15 +02: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 18:34:26 +02:00
|
|
|
sanitizedState = self._getInputState( $sanitizedInput );
|
2014-04-07 18:32:15 +02:00
|
|
|
$input.data( 'sanitized', sanitizedState );
|
|
|
|
|
2015-04-04 18:34:26 +02:00
|
|
|
canUpdateState = ( ! _.isEqual( submittedState, sanitizedState ) && ( args.ignoreActiveElement || ! $input.is( document.activeElement ) ) );
|
2014-04-07 18:32:15 +02:00
|
|
|
if ( canUpdateState ) {
|
2015-04-04 18:34:26 +02:00
|
|
|
self._setInputState( $input, sanitizedState );
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
|
|
|
} );
|
2014-04-07 18:32:15 +02:00
|
|
|
|
|
|
|
$( document ).trigger( 'widget-synced', [ $widgetRoot, r.data.form ] );
|
2014-04-07 11:04:14 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Otherwise, if sanitized fields are not aligned with existing fields, disable live update mode if enabled.
|
2014-04-07 18:32:15 +02:00
|
|
|
} else if ( self.liveUpdateMode ) {
|
|
|
|
self.liveUpdateMode = false;
|
|
|
|
self.container.find( 'input[name="savewidget"]' ).show();
|
|
|
|
isLiveUpdateAborted = true;
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Otherwise, replace existing form with the sanitized form.
|
2014-03-05 21:41:14 +01:00
|
|
|
} else {
|
2014-04-07 18:32:15 +02:00
|
|
|
$widgetContent.html( r.data.form );
|
|
|
|
|
|
|
|
self.container.removeClass( 'widget-form-disabled' );
|
|
|
|
|
|
|
|
$( document ).trigger( 'widget-updated', [ $widgetRoot ] );
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
|
|
|
|
2014-04-07 11:04:14 +02: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 18:32:15 +02:00
|
|
|
isChanged = ! isLiveUpdateAborted && ! _( self.setting() ).isEqual( r.data.instance );
|
|
|
|
if ( isChanged ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
self.isWidgetUpdating = true; // Suppress triggering another updateWidget.
|
2014-04-07 18:32:15 +02:00
|
|
|
self.setting( r.data.instance );
|
|
|
|
self.isWidgetUpdating = false;
|
2014-04-07 11:04:14 +02:00
|
|
|
} else {
|
2020-01-29 01:45:18 +01:00
|
|
|
// No change was made, so stop the spinner now instead of when the preview would updates.
|
2014-04-07 18:32:15 +02:00
|
|
|
self.container.removeClass( 'previewer-loading' );
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
if ( completeCallback ) {
|
2014-04-07 22:00:16 +02:00
|
|
|
completeCallback.call( self, null, { noChange: ! isChanged, ajaxFinished: true } );
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
|
|
|
} else {
|
2020-01-29 01:45:18 +01:00
|
|
|
// General error message.
|
2014-04-07 11:04:14 +02:00
|
|
|
message = l10n.error;
|
2014-04-07 18:32:15 +02:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
if ( r.data && r.data.message ) {
|
|
|
|
message = r.data.message;
|
|
|
|
}
|
2014-04-07 18:32:15 +02:00
|
|
|
|
|
|
|
if ( completeCallback ) {
|
|
|
|
completeCallback.call( self, message );
|
2014-04-07 11:04:14 +02:00
|
|
|
} else {
|
2014-04-07 18:32:15 +02:00
|
|
|
$widgetContent.prepend( '<p class="widget-error"><strong>' + message + '</strong></p>' );
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
|
|
|
} );
|
2014-04-07 18:32:15 +02:00
|
|
|
|
2014-04-07 16:10:14 +02:00
|
|
|
jqxhr.fail( function( jqXHR, textStatus ) {
|
2014-04-07 18:32:15 +02:00
|
|
|
if ( completeCallback ) {
|
|
|
|
completeCallback.call( self, textStatus );
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
|
|
|
} );
|
2014-04-07 18:32:15 +02:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
jqxhr.always( function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
self.container.removeClass( 'widget-form-loading' );
|
|
|
|
|
|
|
|
$inputs.each( function() {
|
|
|
|
$( this ).removeData( 'state' + updateNumber );
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
processing( processing() - 1 );
|
2014-03-05 21:41:14 +01:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 11:04:14 +02:00
|
|
|
* Expand the accordion section containing a control
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 11:04:14 +02: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 23:51:22 +01:00
|
|
|
api.Control.prototype.expand.call( this );
|
2014-04-07 11:04:14 +02:00
|
|
|
},
|
2014-03-05 21:41:14 +01: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 23:51:22 +01:00
|
|
|
/**
|
2014-12-04 03:04:22 +01: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 23:51:22 +01:00
|
|
|
* @param {Boolean} expanded
|
|
|
|
* @param {Object} [params]
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {Boolean} False if state already applied.
|
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 23:51:22 +01:00
|
|
|
*/
|
|
|
|
_toggleExpanded: api.Section.prototype._toggleExpanded,
|
|
|
|
|
|
|
|
/**
|
2014-12-04 03:04:22 +01: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 23:51:22 +01:00
|
|
|
* @param {Object} [params]
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {Boolean} False if already 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 23:51:22 +01:00
|
|
|
*/
|
|
|
|
expand: api.Section.prototype.expand,
|
|
|
|
|
2014-04-07 11:04:14 +02: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 23:51:22 +01:00
|
|
|
*
|
2014-12-04 03:04:22 +01:00
|
|
|
* @deprecated 4.1.0 Use this.expand() instead.
|
2014-04-07 11:04:14 +02: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 23:51:22 +01:00
|
|
|
this.expand();
|
2014-04-07 11:04:14 +02:00
|
|
|
},
|
2014-03-05 21:41:14 +01: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 23:51:22 +01:00
|
|
|
/**
|
2014-12-04 03:04:22 +01: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 23:51:22 +01:00
|
|
|
* @param {Object} [params]
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {Boolean} False if already collapsed.
|
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 23:51:22 +01:00
|
|
|
*/
|
|
|
|
collapse: api.Section.prototype.collapse,
|
|
|
|
|
2014-04-07 11:04:14 +02: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 23:51:22 +01:00
|
|
|
*
|
2014-12-04 03:04:22 +01:00
|
|
|
* @deprecated 4.1.0 Use this.collapse() instead.
|
2014-04-07 11:04:14 +02: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 23:51:22 +01:00
|
|
|
this.collapse();
|
2014-03-05 21:41:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 11:04:14 +02: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 23:51:22 +01:00
|
|
|
* @deprecated this is poor naming, and it is better to directly set control.expanded( showOrHide )
|
|
|
|
*
|
2014-04-07 18:32:15 +02:00
|
|
|
* @param {boolean|undefined} [showOrHide] If not supplied, will be inverse of current visibility
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 18:32:15 +02: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 23:51:22 +01:00
|
|
|
showOrHide = ! this.expanded();
|
2014-04-07 11:04:14 +02: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 23:51:22 +01:00
|
|
|
this.expanded( showOrHide );
|
|
|
|
},
|
2014-03-05 21:41:14 +01: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 23:51:22 +01:00
|
|
|
/**
|
|
|
|
* Respond to change in the expanded state.
|
|
|
|
*
|
2020-07-28 01:35:02 +02:00
|
|
|
* @param {boolean} 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 23:51:22 +01:00
|
|
|
* @param {Object} args merged on top of this.defaultActiveArguments
|
|
|
|
*/
|
|
|
|
onChangeExpanded: function ( expanded, args ) {
|
2017-04-19 23:14:44 +02:00
|
|
|
var self = this, $widget, $inside, complete, prevComplete, expandControl, $toggleBtn;
|
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 23:51:22 +01:00
|
|
|
|
2015-09-25 23:02:27 +02: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();
|
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// If the expanded state is unchanged only manipulate container expanded states.
|
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 23:51:22 +01:00
|
|
|
if ( args.unchanged ) {
|
|
|
|
if ( expanded ) {
|
|
|
|
api.Control.prototype.expand.call( self, {
|
|
|
|
completeCallback: args.completeCallback
|
|
|
|
});
|
|
|
|
}
|
2014-04-07 11:04:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-03-05 21:41:14 +01: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 23:51:22 +01:00
|
|
|
$widget = this.container.find( 'div.widget:first' );
|
|
|
|
$inside = $widget.find( '.widget-inside:first' );
|
2017-04-19 23:14:44 +02:00
|
|
|
$toggleBtn = this.container.find( '.widget-top button.widget-action' );
|
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 23:51:22 +01:00
|
|
|
|
2016-09-28 06:20:29 +02: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 23:51:22 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Close all other widget controls before expanding this one.
|
2014-04-07 18:32:15 +02: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 23:51:22 +01:00
|
|
|
otherControl.collapse();
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
complete = function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
self.container.removeClass( 'expanding' );
|
|
|
|
self.container.addClass( 'expanded' );
|
2017-08-13 08:25:43 +02:00
|
|
|
$widget.addClass( 'open' );
|
2017-04-19 23:14:44 +02:00
|
|
|
$toggleBtn.attr( 'aria-expanded', 'true' );
|
2014-04-07 18:32:15 +02:00
|
|
|
self.container.trigger( 'expanded' );
|
2014-04-07 11:04:14 +02: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 23:51:22 +01:00
|
|
|
if ( args.completeCallback ) {
|
|
|
|
prevComplete = complete;
|
|
|
|
complete = function () {
|
|
|
|
prevComplete();
|
|
|
|
args.completeCallback();
|
|
|
|
};
|
|
|
|
}
|
2014-04-07 18:32:15 +02: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 23:51:22 +01:00
|
|
|
$inside.fadeIn( args.duration, complete );
|
2014-04-07 11:04:14 +02: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 23:51:22 +01:00
|
|
|
$inside.slideDown( args.duration, complete );
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
2014-04-07 18:32:15 +02:00
|
|
|
|
|
|
|
self.container.trigger( 'expand' );
|
|
|
|
self.container.addClass( 'expanding' );
|
2016-09-28 06:20:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if ( expanded ) {
|
|
|
|
if ( api.section.has( self.section() ) ) {
|
|
|
|
api.section( self.section() ).expand( {
|
|
|
|
completeCallback: expandControl
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
expandControl();
|
|
|
|
}
|
2014-04-07 11:04:14 +02:00
|
|
|
} else {
|
|
|
|
complete = function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
self.container.removeClass( 'collapsing' );
|
|
|
|
self.container.removeClass( 'expanded' );
|
2017-08-13 08:25:43 +02:00
|
|
|
$widget.removeClass( 'open' );
|
2017-04-19 23:14:44 +02:00
|
|
|
$toggleBtn.attr( 'aria-expanded', 'false' );
|
2014-04-07 18:32:15 +02:00
|
|
|
self.container.trigger( 'collapsed' );
|
2014-04-07 11:04:14 +02: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 23:51:22 +01:00
|
|
|
if ( args.completeCallback ) {
|
|
|
|
prevComplete = complete;
|
|
|
|
complete = function () {
|
|
|
|
prevComplete();
|
|
|
|
args.completeCallback();
|
|
|
|
};
|
|
|
|
}
|
2014-04-07 18:32:15 +02: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 23:51:22 +01:00
|
|
|
$inside.fadeOut( args.duration, complete );
|
2014-04-07 11:04:14 +02: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 23:51:22 +01:00
|
|
|
$inside.slideUp( args.duration, function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
$widget.css( { width:'', margin:'' } );
|
2014-04-07 11:04:14 +02:00
|
|
|
complete();
|
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
|
|
|
},
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
/**
|
|
|
|
* Get the position (index) of the widget in the containing sidebar
|
|
|
|
*
|
2020-07-28 01:35:02 +02:00
|
|
|
* @return {number}
|
2014-04-07 11:04:14 +02:00
|
|
|
*/
|
|
|
|
getWidgetSidebarPosition: function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
var sidebarWidgetIds, position;
|
|
|
|
|
|
|
|
sidebarWidgetIds = this.getSidebarWidgetsControl().setting();
|
|
|
|
position = _.indexOf( sidebarWidgetIds, this.params.widget_id );
|
2014-04-02 20:20:16 +02:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
if ( position === -1 ) {
|
2014-04-07 18:32:15 +02:00
|
|
|
return;
|
2014-04-02 20:20:16 +02:00
|
|
|
}
|
2014-04-07 18:32:15 +02:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
return position;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move widget up one in the sidebar
|
|
|
|
*/
|
|
|
|
moveUp: function() {
|
|
|
|
this._moveWidgetByOne( -1 );
|
2014-03-05 21:41:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 11:04:14 +02:00
|
|
|
* Move widget up one in the sidebar
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 11:04:14 +02:00
|
|
|
moveDown: function() {
|
|
|
|
this._moveWidgetByOne( 1 );
|
|
|
|
},
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*
|
2020-07-28 01:35:02 +02:00
|
|
|
* @param {number} offset 1|-1
|
2014-04-07 11:04:14 +02:00
|
|
|
*/
|
2014-04-07 16:10:14 +02:00
|
|
|
_moveWidgetByOne: function( offset ) {
|
2014-04-07 18:32:15 +02:00
|
|
|
var i, sidebarWidgetsSetting, sidebarWidgetIds, adjacentWidgetId;
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
i = this.getWidgetSidebarPosition();
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
sidebarWidgetsSetting = this.getSidebarWidgetsControl().setting;
|
2020-01-29 01:45:18 +01:00
|
|
|
sidebarWidgetIds = Array.prototype.slice.call( sidebarWidgetsSetting() ); // Clone.
|
2014-04-07 18:32:15 +02:00
|
|
|
adjacentWidgetId = sidebarWidgetIds[i + offset];
|
|
|
|
sidebarWidgetIds[i + offset] = this.params.widget_id;
|
|
|
|
sidebarWidgetIds[i] = adjacentWidgetId;
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
sidebarWidgetsSetting( sidebarWidgetIds );
|
2014-03-05 21:41:14 +01:00
|
|
|
},
|
|
|
|
|
2014-04-02 20:20:16 +02:00
|
|
|
/**
|
2014-04-07 11:04:14 +02:00
|
|
|
* Toggle visibility of the widget move area
|
2014-04-02 20:20:16 +02:00
|
|
|
*
|
2020-07-28 01:35:02 +02:00
|
|
|
* @param {boolean} [showOrHide]
|
2014-04-02 20:20:16 +02:00
|
|
|
*/
|
2014-04-07 18:32:15 +02: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 11:04:14 +02:00
|
|
|
}
|
2014-04-07 18:32:15 +02:00
|
|
|
|
|
|
|
if ( showOrHide ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Reset the selected sidebar.
|
2014-04-07 18:32:15 +02:00
|
|
|
$moveWidgetArea.find( '.selected' ).removeClass( 'selected' );
|
|
|
|
|
|
|
|
$moveWidgetArea.find( 'li' ).filter( function() {
|
|
|
|
return $( this ).data( 'id' ) === self.params.sidebar_id;
|
2014-04-07 11:04:14 +02:00
|
|
|
} ).addClass( 'selected' );
|
2014-04-07 18:32:15 +02:00
|
|
|
|
|
|
|
this.container.find( '.move-widget-btn' ).prop( 'disabled', true );
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-04-02 20:20:16 +02:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
$moveWidgetArea.toggleClass( 'active', showOrHide );
|
2014-03-05 21:41:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 11:04:14 +02:00
|
|
|
* Highlight the widget control and section
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 11:04:14 +02:00
|
|
|
highlightSectionAndControl: function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
var $target;
|
2014-04-07 11:04:14 +02:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
if ( this.container.is( ':hidden' ) ) {
|
|
|
|
$target = this.container.closest( '.control-section' );
|
2014-03-05 21:41:14 +01:00
|
|
|
} else {
|
2014-04-07 18:32:15 +02:00
|
|
|
$target = this.container;
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
$( '.highlighted' ).removeClass( 'highlighted' );
|
|
|
|
$target.addClass( 'highlighted' );
|
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
setTimeout( function() {
|
2014-04-07 18:32:15 +02:00
|
|
|
$target.removeClass( 'highlighted' );
|
2014-04-07 11:04:14 +02:00
|
|
|
}, 500 );
|
|
|
|
}
|
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2015-10-17 01:48:25 +02:00
|
|
|
/**
|
|
|
|
* wp.customize.Widgets.WidgetsPanel
|
|
|
|
*
|
|
|
|
* Customizer panel containing the widget area sections.
|
|
|
|
*
|
|
|
|
* @since 4.4.0
|
2017-12-15 14:42:46 +01:00
|
|
|
*
|
|
|
|
* @class wp.customize.Widgets.WidgetsPanel
|
|
|
|
* @augments wp.customize.Panel
|
2015-10-17 01:48:25 +02:00
|
|
|
*/
|
2017-12-15 14:42:46 +01:00
|
|
|
api.Widgets.WidgetsPanel = api.Panel.extend(/** @lends wp.customize.Widgets.WigetsPanel.prototype */{
|
2015-10-17 01:48:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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() {
|
2017-03-22 20:03:45 +01:00
|
|
|
var panelMetaContainer, noticeContainer, updateNotice, getActiveSectionCount, shouldShowNotice;
|
2015-10-17 01:48:25 +02:00
|
|
|
panelMetaContainer = panel.container.find( '.panel-meta' );
|
2017-03-22 20:03:45 +01:00
|
|
|
|
|
|
|
// @todo This should use the Notifications API introduced to panels. See <https://core.trac.wordpress.org/ticket/38794>.
|
|
|
|
noticeContainer = $( '<div></div>', {
|
2015-10-17 01:48:25 +02:00
|
|
|
'class': 'no-widget-areas-rendered-notice'
|
|
|
|
});
|
2017-03-22 20:03:45 +01:00
|
|
|
panelMetaContainer.append( noticeContainer );
|
2015-10-17 01:48:25 +02:00
|
|
|
|
2017-03-22 20:03:45 +01:00
|
|
|
/**
|
|
|
|
* Get the number of active sections in the panel.
|
|
|
|
*
|
|
|
|
* @return {number} Number of active sidebar sections.
|
|
|
|
*/
|
|
|
|
getActiveSectionCount = function() {
|
|
|
|
return _.filter( panel.sections(), function( section ) {
|
2018-08-28 21:55:25 +02:00
|
|
|
return 'sidebar' === section.params.type && section.active();
|
2017-03-22 20:03:45 +01:00
|
|
|
} ).length;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether or not the notice should be displayed.
|
|
|
|
*
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
shouldShowNotice = function() {
|
|
|
|
var activeSectionCount = getActiveSectionCount();
|
|
|
|
if ( 0 === activeSectionCount ) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return activeSectionCount !== api.Widgets.data.registeredSidebars.length;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the notice.
|
|
|
|
*
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {void}
|
2017-03-22 20:03:45 +01:00
|
|
|
*/
|
|
|
|
updateNotice = function() {
|
2017-03-24 23:03:42 +01:00
|
|
|
var activeSectionCount = getActiveSectionCount(), someRenderedMessage, nonRenderedAreaCount, registeredAreaCount;
|
2017-03-22 20:03:45 +01:00
|
|
|
noticeContainer.empty();
|
|
|
|
|
|
|
|
registeredAreaCount = api.Widgets.data.registeredSidebars.length;
|
|
|
|
if ( activeSectionCount !== registeredAreaCount ) {
|
|
|
|
|
|
|
|
if ( 0 !== activeSectionCount ) {
|
|
|
|
nonRenderedAreaCount = registeredAreaCount - activeSectionCount;
|
2017-03-24 23:03:42 +01:00
|
|
|
someRenderedMessage = l10n.someAreasShown[ nonRenderedAreaCount ];
|
2017-03-22 20:03:45 +01:00
|
|
|
} else {
|
2017-03-24 23:03:42 +01:00
|
|
|
someRenderedMessage = l10n.noAreasShown;
|
|
|
|
}
|
|
|
|
if ( someRenderedMessage ) {
|
|
|
|
noticeContainer.append( $( '<p></p>', {
|
|
|
|
text: someRenderedMessage
|
|
|
|
} ) );
|
2017-03-22 20:03:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
noticeContainer.append( $( '<p></p>', {
|
|
|
|
text: l10n.navigatePreview
|
|
|
|
} ) );
|
|
|
|
}
|
2015-10-17 01:48:25 +02:00
|
|
|
};
|
2017-03-22 20:03:45 +01:00
|
|
|
updateNotice();
|
2015-10-17 01:48:25 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the initial visibility state for rendered notice.
|
|
|
|
* Update the visibility of the notice whenever a reflow happens.
|
|
|
|
*/
|
2017-03-22 20:03:45 +01:00
|
|
|
noticeContainer.toggle( shouldShowNotice() );
|
2015-10-17 01:48:25 +02:00
|
|
|
api.previewer.deferred.active.done( function () {
|
2017-03-22 20:03:45 +01:00
|
|
|
noticeContainer.toggle( shouldShowNotice() );
|
2015-10-17 01:48:25 +02:00
|
|
|
});
|
|
|
|
api.bind( 'pane-contents-reflowed', function() {
|
|
|
|
var duration = ( 'resolved' === api.previewer.deferred.active.state() ) ? 'fast' : 0;
|
2017-03-22 20:03:45 +01:00
|
|
|
updateNotice();
|
2015-10-17 01:48:25 +02:00
|
|
|
if ( shouldShowNotice() ) {
|
2017-03-22 20:03:45 +01:00
|
|
|
noticeContainer.slideDown( duration );
|
2015-10-17 01:48:25 +02:00
|
|
|
} else {
|
2017-03-22 20:03:45 +01:00
|
|
|
noticeContainer.slideUp( duration );
|
2015-10-17 01:48:25 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {boolean}
|
2015-10-17 01:48:25 +02:00
|
|
|
*/
|
|
|
|
isContextuallyActive: function() {
|
|
|
|
var panel = this;
|
|
|
|
return panel.active();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-11-13 13:19:23 +01:00
|
|
|
/**
|
|
|
|
* wp.customize.Widgets.SidebarSection
|
|
|
|
*
|
|
|
|
* Customizer section representing a widget area widget
|
|
|
|
*
|
|
|
|
* @since 4.1.0
|
2017-12-15 14:42:46 +01:00
|
|
|
*
|
|
|
|
* @class wp.customize.Widgets.SidebarSection
|
|
|
|
* @augments wp.customize.Section
|
2014-11-13 13:19:23 +01:00
|
|
|
*/
|
2017-12-15 14:42:46 +01:00
|
|
|
api.Widgets.SidebarSection = api.Section.extend(/** @lends wp.customize.Widgets.SidebarSection.prototype */{
|
2014-11-13 13:19:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sync the section's active state back to the Backbone model's is_rendered attribute
|
2014-12-04 03:04:22 +01:00
|
|
|
*
|
|
|
|
* @since 4.1.0
|
2014-11-13 13:19:23 +01: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 11:04:14 +02:00
|
|
|
/**
|
2014-04-07 16:10:14 +02:00
|
|
|
* wp.customize.Widgets.SidebarControl
|
|
|
|
*
|
|
|
|
* Customizer control for widgets.
|
2014-04-07 11:04:14 +02:00
|
|
|
* Note that 'sidebar_widgets' must match the WP_Widget_Area_Customize_Control::$type
|
2014-04-07 16:10:14 +02:00
|
|
|
*
|
2014-11-13 13:19:23 +01:00
|
|
|
* @since 3.9.0
|
|
|
|
*
|
2017-12-15 14:42:46 +01:00
|
|
|
* @class wp.customize.Widgets.SidebarControl
|
2014-04-07 16:10:14 +02:00
|
|
|
* @augments wp.customize.Control
|
2014-04-07 11:04:14 +02:00
|
|
|
*/
|
2017-12-15 14:42:46 +01:00
|
|
|
api.Widgets.SidebarControl = api.Control.extend(/** @lends wp.customize.Widgets.SidebarControl.prototype */{
|
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 23:51:22 +01:00
|
|
|
|
2014-03-05 21:41:14 +01:00
|
|
|
/**
|
2014-04-07 11:04:14 +02:00
|
|
|
* Set up the control
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 11:04:14 +02:00
|
|
|
ready: function() {
|
2014-04-07 22:00:16 +02: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 21:41:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 11:04:14 +02:00
|
|
|
* Update ordering of widget control forms when the setting is updated
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 11:04:14 +02:00
|
|
|
_setupModel: function() {
|
2014-11-13 13:19:23 +01:00
|
|
|
var self = this;
|
2014-04-07 22:00:16 +02: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 23:51:22 +01:00
|
|
|
var widgetFormControls, removedWidgetIds, priority;
|
2014-04-07 22:00:16 +02:00
|
|
|
|
|
|
|
removedWidgetIds = _( oldWidgetIds ).difference( newWidgetIds );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Filter out any persistent widget IDs for widgets which have been deactivated.
|
2014-04-07 22:00:16 +02:00
|
|
|
newWidgetIds = _( newWidgetIds ).filter( function( newWidgetId ) {
|
|
|
|
var parsedWidgetId = parseWidgetId( newWidgetId );
|
|
|
|
|
|
|
|
return !! api.Widgets.availableWidgets.findWhere( { id_base: parsedWidgetId.id_base } );
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 22:00:16 +02:00
|
|
|
widgetFormControls = _( newWidgetIds ).map( function( widgetId ) {
|
|
|
|
var widgetFormControl = api.Widgets.getWidgetFormControlForWidget( widgetId );
|
|
|
|
|
|
|
|
if ( ! widgetFormControl ) {
|
|
|
|
widgetFormControl = self.addWidget( widgetId );
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-04-07 22:00:16 +02:00
|
|
|
|
|
|
|
return widgetFormControl;
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Sort widget controls to their new positions.
|
2014-04-07 22:00:16 +02: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 23:51:22 +01:00
|
|
|
return aIndex - bIndex;
|
|
|
|
});
|
2014-04-07 22:00:16 +02: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 23:51:22 +01:00
|
|
|
priority = 0;
|
|
|
|
_( widgetFormControls ).each( function ( control ) {
|
|
|
|
control.priority( priority );
|
|
|
|
control.section( self.section() );
|
|
|
|
priority += 1;
|
|
|
|
});
|
2020-01-29 01:45:18 +01:00
|
|
|
self.priority( priority ); // Make sure sidebar control remains at end.
|
2014-04-07 22:00:16 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Re-sort widget form controls (including widgets form other sidebars newly moved here).
|
2014-04-07 22:00:16 +02:00
|
|
|
self._applyCardinalOrderClassNames();
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// If the widget was dragged into the sidebar, make sure the sidebar_id param is updated.
|
2014-04-07 22:00:16 +02:00
|
|
|
_( widgetFormControls ).each( function( widgetFormControl ) {
|
|
|
|
widgetFormControl.params.sidebar_id = self.params.sidebar_id;
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Cleanup after widget removal.
|
2014-04-07 22:00:16 +02:00
|
|
|
_( removedWidgetIds ).each( function( removedWidgetId ) {
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Using setTimeout so that when moving a widget to another sidebar,
|
|
|
|
// the other sidebars_widgets settings get a chance to update.
|
2014-04-07 11:04:14 +02:00
|
|
|
setTimeout( function() {
|
2014-04-07 22:00:16 +02:00
|
|
|
var removedControl, wasDraggedToAnotherSidebar, inactiveWidgets, removedIdBase,
|
|
|
|
widget, isPresentInAnotherSidebar = false;
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Check if the widget is in another sidebar.
|
2014-04-07 22:00:16 +02:00
|
|
|
api.each( function( otherSetting ) {
|
2014-04-08 06:03:14 +02:00
|
|
|
if ( otherSetting.id === self.setting.id || 0 !== otherSetting.id.indexOf( 'sidebars_widgets[' ) || otherSetting.id === 'sidebars_widgets[wp_inactive_widgets]' ) {
|
2014-04-07 11:04:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2014-04-07 22:00:16 +02:00
|
|
|
var otherSidebarWidgets = otherSetting(), i;
|
|
|
|
|
|
|
|
i = _.indexOf( otherSidebarWidgets, removedWidgetId );
|
2014-04-07 11:04:14 +02:00
|
|
|
if ( -1 !== i ) {
|
2014-04-07 22:00:16 +02:00
|
|
|
isPresentInAnotherSidebar = true;
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
|
|
|
} );
|
2014-03-22 21:55:18 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
// If the widget is present in another sidebar, abort!
|
2014-04-07 22:00:16 +02:00
|
|
|
if ( isPresentInAnotherSidebar ) {
|
2014-04-07 11:04:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-03-22 21:55:18 +01:00
|
|
|
|
2014-04-07 22:00:16 +02:00
|
|
|
removedControl = api.Widgets.getWidgetFormControlForWidget( removedWidgetId );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Detect if widget control was dragged to another sidebar.
|
2014-04-07 22:00:16 +02:00
|
|
|
wasDraggedToAnotherSidebar = removedControl && $.contains( document, removedControl.container[0] ) && ! $.contains( self.$sectionContent[0], removedControl.container[0] );
|
2014-04-02 20:20:16 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Delete any widget form controls for removed widgets.
|
2014-04-07 22:00:16 +02:00
|
|
|
if ( removedControl && ! wasDraggedToAnotherSidebar ) {
|
|
|
|
api.control.remove( removedControl.id );
|
|
|
|
removedControl.container.remove();
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2020-02-10 05:12:07 +01:00
|
|
|
// Move widget to inactive widgets sidebar (move it to Trash) if has been previously saved.
|
2020-01-29 01:45:18 +01:00
|
|
|
// This prevents the inactive widgets sidebar from overflowing with throwaway widgets.
|
2014-04-07 22:00:16 +02:00
|
|
|
if ( api.Widgets.savedWidgetIds[removedWidgetId] ) {
|
2014-04-08 06:03:14 +02:00
|
|
|
inactiveWidgets = api.value( 'sidebars_widgets[wp_inactive_widgets]' )().slice();
|
2014-04-07 22:00:16 +02:00
|
|
|
inactiveWidgets.push( removedWidgetId );
|
2014-04-08 06:03:14 +02:00
|
|
|
api.value( 'sidebars_widgets[wp_inactive_widgets]' )( _( inactiveWidgets ).unique() );
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Make old single widget available for adding again.
|
2014-04-07 22:00:16 +02:00
|
|
|
removedIdBase = parseWidgetId( removedWidgetId ).id_base;
|
|
|
|
widget = api.Widgets.availableWidgets.findWhere( { id_base: removedIdBase } );
|
2014-04-07 11:04:14 +02:00
|
|
|
if ( widget && ! widget.get( 'is_multi' ) ) {
|
|
|
|
widget.set( 'is_disabled', false );
|
|
|
|
}
|
|
|
|
} );
|
2014-04-02 20:20:16 +02:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 11:04:14 +02:00
|
|
|
* Allow widgets in sidebar to be re-ordered, and for the order to be previewed
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 11:04:14 +02:00
|
|
|
_setupSortable: function() {
|
2014-04-07 22:00:16 +02:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.isReordering = false;
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
/**
|
|
|
|
* Update widget order setting when controls are re-ordered
|
|
|
|
*/
|
2014-04-07 22:00:16 +02:00
|
|
|
this.$sectionContent.sortable( {
|
2014-04-07 11:04:14 +02:00
|
|
|
items: '> .customize-control-widget_form',
|
|
|
|
handle: '.widget-top',
|
|
|
|
axis: 'y',
|
2015-06-04 00:59:25 +02:00
|
|
|
tolerance: 'pointer',
|
2014-04-07 11:04:14 +02:00
|
|
|
connectWith: '.accordion-section-content:has(.customize-control-sidebar_widgets)',
|
|
|
|
update: function() {
|
2014-04-07 22:00:16 +02:00
|
|
|
var widgetContainerIds = self.$sectionContent.sortable( 'toArray' ), widgetIds;
|
|
|
|
|
|
|
|
widgetIds = $.map( widgetContainerIds, function( widgetContainerId ) {
|
|
|
|
return $( '#' + widgetContainerId ).find( ':input[name=widget-id]' ).val();
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2014-04-07 22:00:16 +02:00
|
|
|
|
|
|
|
self.setting( widgetIds );
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
/**
|
2014-10-15 19:21:19 +02:00
|
|
|
* Expand other Customizer sidebar section when dragging a control widget over it,
|
2014-04-07 11:04:14 +02:00
|
|
|
* allowing the control to be dropped into another section
|
|
|
|
*/
|
2014-04-07 22:00:16 +02:00
|
|
|
this.$controlSection.find( '.accordion-section-title' ).droppable({
|
2014-04-07 11:04:14 +02: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 23:51:22 +01:00
|
|
|
var section = api.section( self.section.get() );
|
|
|
|
section.expand({
|
2020-01-29 01:45:18 +01:00
|
|
|
allowMultiple: true, // Prevent the section being dragged from to be collapsed.
|
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 23:51:22 +01:00
|
|
|
completeCallback: function () {
|
2020-01-29 01:45:18 +01:00
|
|
|
// @todo It is not clear when refreshPositions should be called on which sections, or if it is even needed.
|
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 23:51:22 +01:00
|
|
|
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 11:04:14 +02:00
|
|
|
}
|
2014-04-07 22:00:16 +02:00
|
|
|
});
|
2014-04-07 11:04:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Keyboard-accessible reordering
|
|
|
|
*/
|
2015-10-20 22:15:26 +02:00
|
|
|
this.container.find( '.reorder-toggle' ).on( 'click', function() {
|
2014-04-07 22:00:16 +02:00
|
|
|
self.toggleReordering( ! self.isReordering );
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 11:04:14 +02:00
|
|
|
* Set up UI for adding a new widget
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 11:04:14 +02:00
|
|
|
_setupAddition: function() {
|
2014-04-07 22:00:16 +02:00
|
|
|
var self = this;
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2015-10-20 22:15:26 +02:00
|
|
|
this.container.find( '.add-new-widget' ).on( 'click', function() {
|
|
|
|
var addNewWidgetBtn = $( this );
|
2014-04-07 11:04:14 +02:00
|
|
|
|
2014-04-07 22:00:16 +02:00
|
|
|
if ( self.$sectionContent.hasClass( 'reordering' ) ) {
|
2014-04-07 11:04:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $( 'body' ).hasClass( 'adding-widget' ) ) {
|
2015-10-20 22:15:26 +02:00
|
|
|
addNewWidgetBtn.attr( 'aria-expanded', 'true' );
|
2014-04-07 22:00:16 +02:00
|
|
|
api.Widgets.availableWidgetsPanel.open( self );
|
2014-03-05 21:41:14 +01:00
|
|
|
} else {
|
2015-10-20 22:15:26 +02:00
|
|
|
addNewWidgetBtn.attr( 'aria-expanded', 'false' );
|
2014-04-07 11:04:14 +02:00
|
|
|
api.Widgets.availableWidgetsPanel.close();
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2014-03-05 21:41:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-04-07 11:04:14 +02:00
|
|
|
* Add classes to the widget_form controls to assist with styling
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 11:04:14 +02: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 23:51:22 +01:00
|
|
|
var widgetControls = [];
|
|
|
|
_.each( this.setting(), function ( widgetId ) {
|
|
|
|
var widgetControl = api.Widgets.getWidgetFormControlForWidget( widgetId );
|
|
|
|
if ( widgetControl ) {
|
|
|
|
widgetControls.push( widgetControl );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-02-13 00:52:27 +01:00
|
|
|
if ( 0 === widgetControls.length || ( 1 === api.Widgets.registeredSidebars.length && widgetControls.length <= 1 ) ) {
|
2015-01-20 23:45:22 +01: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 23:51:22 +01:00
|
|
|
return;
|
2015-01-20 23:45:22 +01: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 23:51:22 +01:00
|
|
|
}
|
2014-04-07 11:04:14 +02: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 23:51:22 +01: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 11:04:14 +02:00
|
|
|
.addClass( 'first-widget' )
|
|
|
|
.find( '.move-widget-up' ).prop( 'tabIndex', -1 );
|
2014-04-07 22:00:16 +02: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 23:51:22 +01:00
|
|
|
_.last( widgetControls ).container
|
2014-04-07 11:04:14 +02:00
|
|
|
.addClass( 'last-widget' )
|
|
|
|
.find( '.move-widget-down' ).prop( 'tabIndex', -1 );
|
2014-03-05 21:41:14 +01:00
|
|
|
},
|
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Begin public API methods
|
|
|
|
**********************************************************************/
|
|
|
|
|
2014-03-05 21:41:14 +01:00
|
|
|
/**
|
2014-04-07 11:04:14 +02:00
|
|
|
* Enable/disable the reordering UI
|
2014-03-05 21:41:14 +01:00
|
|
|
*
|
2020-07-28 01:35:02 +02: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 23:51:22 +01:00
|
|
|
*
|
|
|
|
* @todo We should have a reordering state instead and rename this to onChangeReordering
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 22:00:16 +02:00
|
|
|
toggleReordering: function( showOrHide ) {
|
2015-10-20 22:15:26 +02:00
|
|
|
var addNewWidgetBtn = this.$sectionContent.find( '.add-new-widget' ),
|
|
|
|
reorderBtn = this.container.find( '.reorder-toggle' ),
|
|
|
|
widgetsTitle = this.$sectionContent.find( '.widget-title' );
|
|
|
|
|
2014-04-07 22:00:16 +02:00
|
|
|
showOrHide = Boolean( showOrHide );
|
|
|
|
|
|
|
|
if ( showOrHide === this.$sectionContent.hasClass( 'reordering' ) ) {
|
2014-04-07 11:04:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2014-04-07 22:00:16 +02:00
|
|
|
this.isReordering = showOrHide;
|
|
|
|
this.$sectionContent.toggleClass( 'reordering', showOrHide );
|
2014-04-07 11:04:14 +02:00
|
|
|
|
2014-04-07 22:00:16 +02: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 23:51:22 +01:00
|
|
|
formControl.collapse();
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2014-07-19 05:24:15 +02:00
|
|
|
|
2015-10-20 22:15:26 +02: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-19 05:32:17 +02:00
|
|
|
} else {
|
2015-10-20 22:15:26 +02: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 21:41:14 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-02-27 11:35:24 +01:00
|
|
|
* Get the widget_form Customize controls associated with the current sidebar.
|
|
|
|
*
|
2016-07-07 01:49:30 +02:00
|
|
|
* @since 3.9.0
|
2014-04-07 11:04:14 +02:00
|
|
|
* @return {wp.customize.controlConstructor.widget_form[]}
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 11:04:14 +02:00
|
|
|
getWidgetFormControls: function() {
|
2015-02-27 11:35:24 +01:00
|
|
|
var formControls = [];
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2015-02-27 11:35:24 +01:00
|
|
|
_( this.setting() ).each( function( widgetId ) {
|
2014-04-07 22:00:16 +02:00
|
|
|
var settingId = widgetIdToSettingId( widgetId ),
|
|
|
|
formControl = api.control( settingId );
|
2015-02-27 11:35:24 +01:00
|
|
|
if ( formControl ) {
|
|
|
|
formControls.push( formControl );
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
|
|
|
} );
|
2014-04-07 22:00:16 +02:00
|
|
|
|
|
|
|
return formControls;
|
2014-03-05 21:41:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2019-11-29 17:56:02 +01:00
|
|
|
* @param {string} widgetId or an id_base for adding a previously non-existing widget.
|
2020-07-28 01:35:02 +02:00
|
|
|
* @return {Object|false} widget_form control instance, or false on error.
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 22:00:16 +02: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 23:51:22 +01:00
|
|
|
var self = this, controlHtml, $widget, controlType = 'widget_form', controlContainer, controlConstructor,
|
2014-04-07 22:00:16 +02:00
|
|
|
parsedWidgetId = parseWidgetId( widgetId ),
|
|
|
|
widgetNumber = parsedWidgetId.number,
|
|
|
|
widgetIdBase = parsedWidgetId.id_base,
|
|
|
|
widget = api.Widgets.availableWidgets.findWhere( {id_base: widgetIdBase} ),
|
2014-10-29 23:57:23 +01:00
|
|
|
settingId, isExistingWidget, widgetFormControl, sidebarWidgets, settingArgs, setting;
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
if ( ! widget ) {
|
2014-04-08 10:12:15 +02:00
|
|
|
return false;
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-04-07 22:00:16 +02:00
|
|
|
|
|
|
|
if ( widgetNumber && ! widget.get( 'is_multi' ) ) {
|
2014-04-08 10:12:15 +02:00
|
|
|
return false;
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Set up new multi widget.
|
2014-04-07 22:00:16 +02:00
|
|
|
if ( widget.get( 'is_multi' ) && ! widgetNumber ) {
|
2014-04-07 11:04:14 +02:00
|
|
|
widget.set( 'multi_number', widget.get( 'multi_number' ) + 1 );
|
2014-04-07 22:00:16 +02:00
|
|
|
widgetNumber = widget.get( 'multi_number' );
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-15 00:46:16 +02:00
|
|
|
controlHtml = $.trim( $( '#widget-tpl-' + widget.get( 'id' ) ).html() );
|
2014-04-07 11:04:14 +02:00
|
|
|
if ( widget.get( 'is_multi' ) ) {
|
2014-04-07 22:00:16 +02:00
|
|
|
controlHtml = controlHtml.replace( /<[^<>]+>/g, function( m ) {
|
|
|
|
return m.replace( /__i__|%i%/g, widgetNumber );
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
|
|
|
} else {
|
2020-01-29 01:45:18 +01:00
|
|
|
widget.set( 'is_disabled', true ); // Prevent single widget from being added again now.
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2014-04-07 22:00:16 +02: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 23:51:22 +01:00
|
|
|
controlContainer = $( '<li/>' )
|
2014-04-07 22:00:16 +02:00
|
|
|
.addClass( 'customize-control' )
|
|
|
|
.addClass( 'customize-control-' + controlType )
|
|
|
|
.append( $widget );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// 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 23:51:22 +01:00
|
|
|
controlContainer.find( '> .widget-icon' ).remove();
|
2014-04-07 22:00:16 +02:00
|
|
|
|
2014-04-07 11:04:14 +02: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 23:51:22 +01:00
|
|
|
controlContainer.find( 'input[name="widget_number"]' ).val( widgetNumber );
|
|
|
|
controlContainer.find( 'input[name="multi_number"]' ).val( widgetNumber );
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
2014-04-07 11:04:14 +02: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 23:51:22 +01:00
|
|
|
widgetId = controlContainer.find( '[name="widget-id"]' ).val();
|
2014-04-07 22:00:16 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
controlContainer.hide(); // To be slid-down below.
|
2014-04-07 22:00:16 +02:00
|
|
|
|
|
|
|
settingId = 'widget_' + widget.get( 'id_base' );
|
2014-04-07 11:04:14 +02:00
|
|
|
if ( widget.get( 'is_multi' ) ) {
|
2014-04-07 22:00:16 +02:00
|
|
|
settingId += '[' + widgetNumber + ']';
|
2014-03-05 21:41:14 +01: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 23:51:22 +01:00
|
|
|
controlContainer.attr( 'id', 'customize-control-' + settingId.replace( /\]/g, '' ).replace( /\[/g, '-' ) );
|
2014-03-05 21:41:14 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Only create setting if it doesn't already exist (if we're adding a pre-existing inactive widget).
|
2014-04-07 22:00:16 +02:00
|
|
|
isExistingWidget = api.has( settingId );
|
|
|
|
if ( ! isExistingWidget ) {
|
|
|
|
settingArgs = {
|
2016-03-21 22:59:29 +01:00
|
|
|
transport: api.Widgets.data.selectiveRefreshableWidgets[ widget.get( 'id_base' ) ] ? 'postMessage' : 'refresh',
|
2014-04-07 22:00:16 +02:00
|
|
|
previewer: this.setting.previewer
|
2014-04-07 11:04:14 +02:00
|
|
|
};
|
2014-10-29 23:57:23 +01:00
|
|
|
setting = api.create( settingId, settingId, '', settingArgs );
|
2020-01-29 01:45:18 +01:00
|
|
|
setting.set( {} ); // Mark dirty, changing from '' to {}.
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2014-04-07 22:00:16 +02:00
|
|
|
controlConstructor = api.controlConstructor[controlType];
|
|
|
|
widgetFormControl = new controlConstructor( settingId, {
|
2017-10-04 08:48:46 +02:00
|
|
|
settings: {
|
|
|
|
'default': settingId
|
2014-04-07 11:04:14 +02:00
|
|
|
},
|
2017-10-04 08:48:46 +02:00
|
|
|
content: controlContainer,
|
|
|
|
sidebar_id: self.params.sidebar_id,
|
|
|
|
widget_id: widgetId,
|
|
|
|
widget_id_base: widget.get( 'id_base' ),
|
|
|
|
type: controlType,
|
|
|
|
is_new: ! isExistingWidget,
|
|
|
|
width: widget.get( 'width' ),
|
|
|
|
height: widget.get( 'height' ),
|
|
|
|
is_wide: widget.get( 'is_wide' )
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
2017-10-04 08:48:46 +02:00
|
|
|
api.control.add( widgetFormControl );
|
2014-04-07 11:04:14 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Make sure widget is removed from the other sidebars.
|
2014-04-07 22:00:16 +02:00
|
|
|
api.each( function( otherSetting ) {
|
|
|
|
if ( otherSetting.id === self.setting.id ) {
|
2014-04-07 11:04:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-04-07 22:00:16 +02:00
|
|
|
|
|
|
|
if ( 0 !== otherSetting.id.indexOf( 'sidebars_widgets[' ) ) {
|
2014-04-07 11:04:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-04-07 22:00:16 +02:00
|
|
|
|
|
|
|
var otherSidebarWidgets = otherSetting().slice(),
|
|
|
|
i = _.indexOf( otherSidebarWidgets, widgetId );
|
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
if ( -1 !== i ) {
|
2014-04-07 22:00:16 +02:00
|
|
|
otherSidebarWidgets.splice( i );
|
|
|
|
otherSetting( otherSidebarWidgets );
|
2014-04-07 11:04:14 +02:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Add widget to this sidebar.
|
2014-04-07 22:00:16 +02:00
|
|
|
sidebarWidgets = this.setting().slice();
|
|
|
|
if ( -1 === _.indexOf( sidebarWidgets, widgetId ) ) {
|
|
|
|
sidebarWidgets.push( widgetId );
|
|
|
|
this.setting( sidebarWidgets );
|
2014-03-05 21:41:14 +01: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 23:51:22 +01:00
|
|
|
controlContainer.slideDown( function() {
|
2014-04-07 22:00:16 +02:00
|
|
|
if ( isExistingWidget ) {
|
|
|
|
widgetFormControl.updateWidget( {
|
2015-03-18 20:29:27 +01:00
|
|
|
instance: widgetFormControl.setting()
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2014-04-07 22:00:16 +02:00
|
|
|
return widgetFormControl;
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Register models for custom panel, section, and control types.
|
2015-10-17 01:48:25 +02:00
|
|
|
$.extend( api.panelConstructor, {
|
|
|
|
widgets: api.Widgets.WidgetsPanel
|
|
|
|
});
|
2014-11-13 13:19:23 +01:00
|
|
|
$.extend( api.sectionConstructor, {
|
|
|
|
sidebar: api.Widgets.SidebarSection
|
|
|
|
});
|
2014-04-07 11:04:14 +02:00
|
|
|
$.extend( api.controlConstructor, {
|
|
|
|
widget_form: api.Widgets.WidgetControl,
|
|
|
|
sidebar_widgets: api.Widgets.SidebarControl
|
|
|
|
});
|
|
|
|
|
2014-04-07 22:00:16 +02:00
|
|
|
/**
|
|
|
|
* Init Customizer for widgets.
|
|
|
|
*/
|
2014-04-07 11:04:14 +02:00
|
|
|
api.bind( 'ready', function() {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Set up the widgets panel.
|
2014-04-07 16:10:14 +02:00
|
|
|
api.Widgets.availableWidgetsPanel = new api.Widgets.AvailableWidgetsPanelView({
|
|
|
|
collection: api.Widgets.availableWidgets
|
|
|
|
});
|
2014-04-07 11:04:14 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Highlight widget control.
|
2014-07-09 22:58:15 +02:00
|
|
|
api.previewer.bind( 'highlight-widget-control', api.Widgets.highlightWidgetFormControl );
|
2014-04-07 11:04:14 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Open and focus widget control.
|
2014-07-09 22:58:15 +02:00
|
|
|
api.previewer.bind( 'focus-widget-control', api.Widgets.focusWidgetFormControl );
|
2014-04-07 11:04:14 +02:00
|
|
|
} );
|
|
|
|
|
2014-04-01 17:26:15 +02:00
|
|
|
/**
|
|
|
|
* Highlight a widget control.
|
|
|
|
*
|
|
|
|
* @param {string} widgetId
|
|
|
|
*/
|
2014-04-07 11:04:14 +02:00
|
|
|
api.Widgets.highlightWidgetFormControl = function( widgetId ) {
|
|
|
|
var control = api.Widgets.getWidgetFormControlForWidget( widgetId );
|
2014-04-01 17:26:15 +02:00
|
|
|
|
|
|
|
if ( control ) {
|
|
|
|
control.highlightSectionAndControl();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Focus a widget control.
|
|
|
|
*
|
|
|
|
* @param {string} widgetId
|
|
|
|
*/
|
2014-04-07 11:04:14 +02:00
|
|
|
api.Widgets.focusWidgetFormControl = function( widgetId ) {
|
|
|
|
var control = api.Widgets.getWidgetFormControlForWidget( widgetId );
|
2014-04-01 17:26:15 +02:00
|
|
|
|
|
|
|
if ( control ) {
|
|
|
|
control.focus();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-03-05 21:41:14 +01:00
|
|
|
/**
|
|
|
|
* Given a widget control, find the sidebar widgets control that contains it.
|
2014-04-07 22:00:16 +02:00
|
|
|
* @param {string} widgetId
|
2020-07-28 01:35:02 +02:00
|
|
|
* @return {Object|null}
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 22:00:16 +02:00
|
|
|
api.Widgets.getSidebarWidgetControlContainingWidget = function( widgetId ) {
|
|
|
|
var foundControl = null;
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// @todo This can use widgetIdToSettingId(), then pass into wp.customize.control( x ).getSidebarWidgetsControl().
|
2014-04-07 16:10:14 +02:00
|
|
|
api.control.each( function( control ) {
|
2014-04-07 22:00:16 +02:00
|
|
|
if ( control.params.type === 'sidebar_widgets' && -1 !== _.indexOf( control.setting(), widgetId ) ) {
|
|
|
|
foundControl = control;
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
|
|
|
} );
|
2014-04-07 11:04:14 +02:00
|
|
|
|
2014-04-07 22:00:16 +02:00
|
|
|
return foundControl;
|
2014-03-05 21:41:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-04-07 22:00:16 +02:00
|
|
|
* Given a widget ID for a widget appearing in the preview, get the widget form control associated with it.
|
|
|
|
*
|
|
|
|
* @param {string} widgetId
|
2020-07-28 01:35:02 +02:00
|
|
|
* @return {Object|null}
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 22:00:16 +02:00
|
|
|
api.Widgets.getWidgetFormControlForWidget = function( widgetId ) {
|
|
|
|
var foundControl = null;
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// @todo We can just use widgetIdToSettingId() here.
|
2014-04-07 16:10:14 +02:00
|
|
|
api.control.each( function( control ) {
|
2014-04-07 22:00:16 +02:00
|
|
|
if ( control.params.type === 'widget_form' && control.params.widget_id === widgetId ) {
|
|
|
|
foundControl = control;
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2014-04-07 22:00:16 +02:00
|
|
|
return foundControl;
|
2014-03-05 21:41:14 +01:00
|
|
|
};
|
|
|
|
|
2016-05-16 09:22:30 +02: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 21:41:14 +01:00
|
|
|
/**
|
2020-07-28 01:35:02 +02:00
|
|
|
* @param {string} widgetId
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {Object}
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 22:00:16 +02:00
|
|
|
function parseWidgetId( widgetId ) {
|
2014-03-06 17:45:15 +01:00
|
|
|
var matches, parsed = {
|
2014-03-05 21:41:14 +01:00
|
|
|
number: null,
|
|
|
|
id_base: null
|
|
|
|
};
|
2014-04-07 22:00:16 +02:00
|
|
|
|
|
|
|
matches = widgetId.match( /^(.+)-(\d+)$/ );
|
2014-03-05 21:41:14 +01:00
|
|
|
if ( matches ) {
|
|
|
|
parsed.id_base = matches[1];
|
|
|
|
parsed.number = parseInt( matches[2], 10 );
|
|
|
|
} else {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Likely an old single widget.
|
2014-04-07 22:00:16 +02:00
|
|
|
parsed.id_base = widgetId;
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
2014-04-07 22:00:16 +02:00
|
|
|
|
2014-03-05 21:41:14 +01:00
|
|
|
return parsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-28 01:35:02 +02:00
|
|
|
* @param {string} widgetId
|
|
|
|
* @return {string} settingId
|
2014-03-05 21:41:14 +01:00
|
|
|
*/
|
2014-04-07 22:00:16 +02:00
|
|
|
function widgetIdToSettingId( widgetId ) {
|
|
|
|
var parsed = parseWidgetId( widgetId ), settingId;
|
2014-03-06 17:45:15 +01:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
settingId = 'widget_' + parsed.id_base;
|
2014-03-05 21:41:14 +01:00
|
|
|
if ( parsed.number ) {
|
2014-04-07 18:32:15 +02:00
|
|
|
settingId += '[' + parsed.number + ']';
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
2014-04-07 22:00:16 +02:00
|
|
|
|
2014-04-07 18:32:15 +02:00
|
|
|
return settingId;
|
2014-03-05 21:41:14 +01:00
|
|
|
}
|
|
|
|
|
2014-04-07 11:04:14 +02:00
|
|
|
})( window.wp, jQuery );
|