WordPress/wp-includes/js/customize-selective-refresh...

1 line
11 KiB
JavaScript
Raw Normal View History

wp.customize.selectiveRefresh=function(s,r){"use strict";var c,t,d;return c={ready:s.Deferred(),editShortcutVisibility:new r.Value,data:{partials:{},renderQueryVar:"",l10n:{shiftClickToEdit:""}},currentRequest:null},_.extend(c,r.Events),t=c.Partial=r.Class.extend({id:null,defaults:{selector:null,primarySetting:null,containerInclusive:!1,fallbackRefresh:!0},initialize:function(e,t){var n=this;t=t||{},n.id=e,n.params=_.extend({settings:[]},n.defaults,t.params||t),n.deferred={},n.deferred.ready=s.Deferred(),n.deferred.ready.done(function(){n.ready()})},ready:function(){var n=this;_.each(n.placements(),function(e){s(e.container).attr("title",c.data.l10n.shiftClickToEdit),n.createEditShortcutForPlacement(e)}),s(document).on("click",n.params.selector,function(t){t.shiftKey&&(t.preventDefault(),_.each(n.placements(),function(e){s(e.container).is(t.currentTarget)&&n.showControl()}))})},createEditShortcutForPlacement:function(e){var t,n,r=this;e.container&&("head","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",!(n=s(e.container)).length||n.is("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")||n.closest("head").length||((t=r.createEditShortcut()).on("click",function(e){e.preventDefault(),e.stopPropagation(),r.showControl()}),r.addEditShortcutToPlacement(e,t)))},addEditShortcutToPlacement:function(e,t){var n=s(e.container);n.prepend(t),n.is(":visible")&&"none"!==n.css("display")||t.addClass("customize-partial-edit-shortcut-hidden")},getEditShortcutClassName:function(){return"customize-partial-edit-shortcut-"+this.id.replace(/]/g,"").replace(/\[/g,"-")},getEditShortcutTitle:function(){var e=c.data.l10n;switch(this.getType()){case"widget":return e.clickEditWidget;case"blogname":case"blogdescription":return e.clickEditTitle;case"nav_menu":return e.clickEditMenu;default:return e.clickEditMisc}},getType:function(){var e,t=this;return e=t.params.primarySetting||_.first(t.settings())||"unknown",t.params.type?t.params.type:e.match(/^nav_menu_instance\[/)?"nav_menu":e.match(/^widget_.+\[\d+]$/)?"widget":e},createEditShortcut:function(){var e,t,n,r;return e=this.getEditShortcutTitle(),t=s("<span>",{class:"customize-partial-edit-shortcut "+this.getEditShortcutClassName()}),n=s("<button>",{"aria-label":e,title:e,class:"customize-partial-edit-shortcut-button"}),r=s('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M13.89 3.39l2.71 2.72c.46.46.42 1.24.03 1.64l-8.01 8.02-5.56 1.16 1.16-5.58s7.6-7.63 7.99-8.03c.39-.39 1.22-.39 1.68.07zm-2.73 2.79l-5.59 5.61 1.11 1.11 5.54-5.65zm-2.97 8.23l5.58-5.6-1.07-1.08-5.59 5.6z"/></svg>'),n.append(r),t.append(n),t},placements:function(){var e,n=this;return(e=n.params.selector||"")&&(e+=", "),e+='[data-customize-partial-id="'+n.id+'"]',s(e).map(function(){var e,t=s(this);if(e=t.data("customize-partial-placement-context"),_.isString(e)&&"{"===e.substr(0,1))throw new Error("context JSON parse error");return new d({partial:n,container:t,context:e})}).get()},settings:function(){var e=this;return e.params.settings&&0!==e.params.settings.length?e.params.settings:e.params.primarySetting?[e.params.primarySetting]:[e.id]},isRelatedSetting:function(e){return _.isString(e)&&(e=r(e)),!!e&&-1!==_.indexOf(this.settings(),e.id)},showControl:function(){var e=this,t=e.params.primarySetting;t||(t=_.first(e.settings())),"nav_menu"===e.getType()&&(e.params.navMenuArgs.theme_location?t="nav_menu_locations["+e.params.navMenuArgs.theme_location+"]":e.params.navMenuArgs.menu&&(t="nav_menu["+String(e.params.navMenuArgs.menu)+"]")),r.pre