diff --git a/wp-admin/js/customize-controls.js b/wp-admin/js/customize-controls.js index 764d787857..3dfef9aa35 100644 --- a/wp-admin/js/customize-controls.js +++ b/wp-admin/js/customize-controls.js @@ -3401,6 +3401,12 @@ api.Control = api.Class.extend({ defaultActiveArguments: { duration: 'fast', completeCallback: $.noop }, + /** + * Default params. + * + * @since 4.9.0 + * @var {object} + */ defaults: { label: '', description: '', diff --git a/wp-includes/js/customize-selective-refresh.js b/wp-includes/js/customize-selective-refresh.js index 9f78161511..b1169eb277 100644 --- a/wp-includes/js/customize-selective-refresh.js +++ b/wp-includes/js/customize-selective-refresh.js @@ -32,28 +32,37 @@ wp.customize.selectiveRefresh = ( function( $, api ) { * @class * @augments wp.customize.Class * @since 4.5.0 - * - * @param {string} id Unique identifier for the control instance. - * @param {object} options Options hash for the control instance. - * @param {object} options.params - * @param {string} options.params.type Type of partial (e.g. nav_menu, widget, etc) - * @param {string} options.params.selector jQuery selector to find the container element in the page. - * @param {array} options.params.settings The IDs for the settings the partial relates to. - * @param {string} options.params.primarySetting The ID for the primary setting the partial renders. - * @param {bool} options.params.fallbackRefresh Whether to refresh the entire preview in case of a partial refresh failure. */ Partial = self.Partial = api.Class.extend(/** @lends wp.customize.SelectiveRefresh.Partial.prototype */{ id: null, + /** + * Default params. + * + * @since 4.9.0 + * @var {object} + */ + defaults: { + selector: null, + primarySetting: null, + containerInclusive: false, + fallbackRefresh: true // Note this needs to be false in a front-end editing context. + }, + /** * Constructor. * * @since 4.5.0 * - * @param {string} id - Partial ID. - * @param {Object} options - * @param {Object} options.params + * @param {string} id - Unique identifier for the partial instance. + * @param {object} options - Options hash for the partial instance. + * @param {string} options.type - Type of partial (e.g. nav_menu, widget, etc) + * @param {string} options.selector - jQuery selector to find the container element in the page. + * @param {array} options.settings - The IDs for the settings the partial relates to. + * @param {string} options.primarySetting - The ID for the primary setting the partial renders. + * @param {bool} options.fallbackRefresh - Whether to refresh the entire preview in case of a partial refresh failure. + * @param {object} [options.params] - Deprecated wrapper for the above properties. */ initialize: function( id, options ) { var partial = this; @@ -62,13 +71,10 @@ wp.customize.selectiveRefresh = ( function( $, api ) { partial.params = _.extend( { - selector: null, - settings: [], - primarySetting: null, - containerInclusive: false, - fallbackRefresh: true // Note this needs to be false in a front-end editing context. + settings: [] }, - options.params || {} + partial.defaults, + options.params || options ); partial.deferred = {}; @@ -917,7 +923,10 @@ wp.customize.selectiveRefresh = ( function( $, api ) { var Constructor, partial = self.partial( id ); if ( ! partial ) { Constructor = self.partialConstructor[ data.type ] || self.Partial; - partial = new Constructor( id, { params: data } ); + partial = new Constructor( + id, + _.extend( { params: data }, data ) // Inclusion of params alias is for back-compat for custom partials that expect to augment this property. + ); self.partial.add( partial ); } else { _.extend( partial.params, data ); diff --git a/wp-includes/js/customize-selective-refresh.min.js b/wp-includes/js/customize-selective-refresh.min.js index 2652e96a3f..dade17e782 100644 --- a/wp-includes/js/customize-selective-refresh.min.js +++ b/wp-includes/js/customize-selective-refresh.min.js @@ -1 +1 @@ -wp.customize.selectiveRefresh=function(a,b){"use strict";var c,d,e;return c={ready:a.Deferred(),editShortcutVisibility:new b.Value,data:{partials:{},renderQueryVar:"",l10n:{shiftClickToEdit:""}},currentRequest:null},_.extend(c,b.Events),d=c.Partial=b.Class.extend({id:null,initialize:function(b,c){var d=this;c=c||{},d.id=b,d.params=_.extend({selector:null,settings:[],primarySetting:null,containerInclusive:!1,fallbackRefresh:!0},c.params||{}),d.deferred={},d.deferred.ready=a.Deferred(),d.deferred.ready.done(function(){d.ready()})},ready:function(){var b=this;_.each(b.placements(),function(d){a(d.container).attr("title",c.data.l10n.shiftClickToEdit),b.createEditShortcutForPlacement(d)}),a(document).on("click",b.params.selector,function(c){c.shiftKey&&(c.preventDefault(),_.each(b.placements(),function(d){a(d.container).is(c.currentTarget)&&b.showControl()}))})},createEditShortcutForPlacement:function(b){var c,d,e,f,g=this;b.container&&(d=a(b.container),e="head",f="area, audio, base, bdi, bdo, br, button, canvas, col, colgroup, command, datalist, embed, head, hr, html, iframe, img, input, keygen, label, link, map, math, menu, meta, noscript, object, optgroup, option, param, progress, rp, rt, ruby, script, select, source, style, svg, table, tbody, textarea, tfoot, thead, title, tr, track, video, wbr",!d.length||d.is(f)||d.closest(e).length||(c=g.createEditShortcut(),c.on("click",function(a){a.preventDefault(),a.stopPropagation(),g.showControl()}),g.addEditShortcutToPlacement(b,c)))},addEditShortcutToPlacement:function(b,c){var d=a(b.container);d.prepend(c),d.is(":visible")&&"none"!==d.css("display")||c.addClass("customize-partial-edit-shortcut-hidden")},getEditShortcutClassName:function(){var a,b=this;return a=b.id.replace(/]/g,"").replace(/\[/g,"-"),"customize-partial-edit-shortcut-"+a},getEditShortcutTitle:function(){var a=this,b=c.data.l10n;switch(a.getType()){case"widget":return b.clickEditWidget;case"blogname":return b.clickEditTitle;case"blogdescription":return b.clickEditTitle;case"nav_menu":return b.clickEditMenu;default:return b.clickEditMisc}},getType:function(){var a,b=this;return a=b.params.primarySetting||_.first(b.settings())||"unknown",b.params.type?b.params.type:a.match(/^nav_menu_instance\[/)?"nav_menu":a.match(/^widget_.+\[\d+]$/)?"widget":a},createEditShortcut:function(){var b,c,d,e,f=this;return b=f.getEditShortcutTitle(),c=a("",{"class":"customize-partial-edit-shortcut "+f.getEditShortcutClassName()}),d=a("