mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-09 12:20:25 +01:00
0e21d32900
This upgrades a number of devDependencies. Some of these include changes to how the tasks are configured. Uglify: There are deprecated options from 2.x to 4.x, see: https://github.com/gruntjs/grunt-contrib-uglify#options Autoprefixer: Browserslist now warns when passing in the browser list, so that is put into package.json As with most changes to uglify, this changes every minified JS file. Fixes #48203. Built from https://develop.svn.wordpress.org/trunk@46408 git-svn-id: http://core.svn.wordpress.org/trunk@46206 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 line
10 KiB
JavaScript
1 line
10 KiB
JavaScript
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&&(!(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.preview.send("focus-control-for-setting",t)},preparePlacement:function(e){s(e.container).addClass("customize-partial-refreshing")},_pendingRefreshPromise:null,refresh:function(){var e,n=this;return e=c.requestPartial(n),n._pendingRefreshPromise||(_.each(n.placements(),function(e){n.preparePlacement(e)}),e.done(function(e){_.each(e,function(e){n.renderContent(e)})}),e.fail(function(e,t){n.fallback(e,t)}),(n._pendingRefreshPromise=e).always(function(){n._pendingRefreshPromise=null})),e},renderContent:function(t){var e,n,r=this;if(!t.container)return r.fallback(new Error("no_container"),[t]),!1;if(t.container=s(t.container),!1===t.addedContent)return r.fallback(new Error("missing_render"),[t]),!1;if(!_.isString(t.addedContent))return r.fallback(new Error("non_string_content"),[t]),!1;c.orginalDocumentWrite=document.write,document.write=function(){throw new Error(c.data.l10n.badDocumentWrite)};try{if(e=t.addedContent,wp.emoji&&wp.emoji.parse&&!s.contains(document.head,t.container[0])&&(e=wp.emoji.parse(e)),r.params.containerInclusive)n=s(e),t.context=_.extend(t.context,n.data("customize-partial-placement-context")||{}),n.data("customize-partial-placement-context",t.context),t.removedNodes=t.container,t.container=n,t.removedNodes.replaceWith(t.container),t.container.attr("title",c.data.l10n.shiftClickToEdit);else{for(t.removedNodes=document.createDocumentFragment();t.container[0].firstChild;)t.removedNodes.appendChild(t.container[0].firstChild);t.container.html(e)}t.container.removeClass("customize-render-content-error")}catch(e){"undefined"!=typeof console&&console.error&&console.error(r.id,e),r.fallback(e,[t])}return document.write=c.orginalDocumentWrite,c.orginalDocumentWrite=null,r.createEditShortcutForPlacement(t),t.container.removeClass("customize-partial-refreshing"),t.container.data("customize-partial-content-rendered",!0),wp.mediaelement&&wp.mediaelement.initialize(),wp.playlist&&wp.playlist.initialize(),c.trigger("partial-content-rendered",t),!0},fallback:function(){this.params.fallbackRefresh&&c.requestFullRefresh()}}),c.Placement=d=r.Class.extend({partial:null,container:null,startNode:null,endNode:null,context:null,addedContent:null,removedNodes:null,initialize:function(e){if(!(e=_.extend({},e||{})).partial||!e.partial.extended(t))throw new Error("Missing partial");e.context=e.context||{},e.container&&(e.container=s(e.container)),_.extend(this,e)}}),c.partialConstructor={},c.partial=new r.Values({defaultConstructor:t}),c.getCustomizeQuery=function(){var n={};return r.each(function(e,t){e._dirty&&(n[t]=e())}),{wp_customize:"on",nonce:r.settings.nonce.preview,customize_theme:r.settings.theme.stylesheet,customized:JSON.stringify(n),customize_changeset_uuid:r.settings.changeset.uuid}},c._pendingPartialRequests={},c._debouncedTimeoutId=null,c._currentRequest=null,c.requestFullRefresh=function(){r.preview.send("refresh")},c.requestPartial=function(e){var t;return c._debouncedTimeoutId&&(clearTimeout(c._debouncedTimeoutId),c._debouncedTimeoutId=null),c._currentRequest&&(c._currentRequest.abort(),c._currentRequest=null),(t=c._pendingPartialRequests[e.id])&&"pending"===t.deferred.state()||(t={deferred:s.Deferred(),partial:e},c._pendingPartialRequests[e.id]=t),e=null,c._debouncedTimeoutId=setTimeout(function(){var e,n,a,t;c._debouncedTimeoutId=null,e=c.getCustomizeQuery(),a={},n={},_.each(c._pendingPartialRequests,function(e,t){a[t]=e.partial.placements(),c.partial.has(t)?n[t]=_.map(a[t],function(e){return e.context||{}}):e.deferred.rejectWith(e.partial,[new Error("partial_removed"),a[t]])}),e.partials=JSON.stringify(n),e[c.data.renderQueryVar]="1",(t=c._currentRequest=wp.ajax.send(null,{data:e,url:r.settings.url.self})).done(function(t){c.trigger("render-partials-response",t),t.errors&&"undefined"!=typeof console&&console.warn&&_.each(t.errors,function(e){console.warn(e)}),_.each(c._pendingPartialRequests,function(r,i){var e;_.isArray(t.contents[i])?(e=_.map(t.contents[i],function(e,t){var n=a[i][t];return n?n.addedContent=e:n=new d({partial:r.partial,addedContent:e}),n}),r.deferred.resolveWith(r.partial,[e])):r.deferred.rejectWith(r.partial,[new Error("unrecognized_partial"),a[i]])}),c._pendingPartialRequests={}}),t.fail(function(n,e){"abort"!==e&&(_.each(c._pendingPartialRequests,function(e,t){e.deferred.rejectWith(e.partial,[n,a[t]])}),c._pendingPartialRequests={})})},r.settings.timeouts.selectiveRefresh),t.deferred.promise()},c.addPartials=function(e,o){var t;e=e||document.documentElement,e=s(e),o=_.extend({triggerRendered:!0},o||{}),t=e.find("[data-customize-partial-id]"),e.is("[data-customize-partial-id]")&&(t=t.add(e)),t.each(function(){var e,t,n,r,i,a=s(this);(n=a.data("customize-partial-id"))&&(i=a.data("customize-partial-placement-context")||{},(e=c.partial(n))||((r=a.data("customize-partial-options")||{}).constructingContainerContext=a.data("customize-partial-placement-context")||{},e=new(c.partialConstructor[a.data("customize-partial-type")]||c.Partial)(n,r),c.partial.add(e)),o.triggerRendered&&!a.data("customize-partial-content-rendered")&&(t=new d({partial:e,context:i,container:a}),s(t.container).attr("title",c.data.l10n.shiftClickToEdit),e.createEditShortcutForPlacement(t),c.trigger("partial-content-rendered",t)),a.data("customize-partial-content-rendered",!0))})},r.bind("preview-ready",function(){var t,e,n;_.extend(c.data,_customizePartialRefreshExports),_.each(c.data.partials,function(e,t){var n=c.partial(t);n?_.extend(n.params,e):(n=new(c.partialConstructor[e.type]||c.Partial)(t,_.extend({params:e},e)),c.partial.add(n))}),t=function(t,n){var r=this;c.partial.each(function(e){e.isRelatedSetting(r,t,n)&&e.refresh()})},e=function(e){t.call(e,e(),null),e.bind(t)},n=function(e){t.call(e,null,e()),e.unbind(t)},r.bind("add",e),r.bind("remove",n),r.each(function(e){e.bind(t)}),c.addPartials(document.documentElement,{triggerRendered:!1}),"undefined"!=typeof MutationObserver&&(c.mutationObserver=new MutationObserver(function(e){_.each(e,function(e){c.addPartials(s(e.target))})}),c.mutationObserver.observe(document.documentElement,{childList:!0,subtree:!0})),r.selectiveRefresh.bind("partial-content-rendered",function(e){e.container&&c.addPartials(e.container)}),r.selectiveRefresh.bind("render-partials-response",function(e){e.setting_validities&&r.preview.send("selective-refresh-setting-validities",e.setting_validities)}),r.preview.bind("edit-shortcut-visibility",function(e){r.selectiveRefresh.editShortcutVisibility.set(e)}),r.selectiveRefresh.editShortcutVisibility.bind(function(e){var t,n=s(document.body);t="hidden"===e&&n.hasClass("customize-partial-edit-shortcuts-shown")&&!n.hasClass("customize-partial-edit-shortcuts-hidden"),n.toggleClass("customize-partial-edit-shortcuts-hidden",t),n.toggleClass("customize-partial-edit-shortcuts-shown","visible"===e)}),r.preview.bind("active",function(){c.partial.each(function(e){e.deferred.ready.resolve()}),c.partial.bind("add",function(e){e.deferred.ready.resolve()})})}),c}(jQuery,wp.customize); |