WordPress/wp-admin/js/customize-controls.min.js

4 lines
98 KiB
JavaScript
Raw Normal View History

!function(a,b){var c,d,e,f=wp.customize;f.OverlayNotification=f.Notification.extend({loading:!1,initialize:function(a,b){var c=this;f.Notification.prototype.initialize.call(c,a,b),c.containerClasses+=" notification-overlay",c.loading&&(c.containerClasses+=" notification-loading")}}),f.Notifications=f.Values.extend({alt:!1,defaultConstructor:f.Notification,initialize:function(a){var b=this;f.Values.prototype.initialize.call(b,a),b._addedIncrement=0,b._addedOrder={},b.bind("add",function(a){b.trigger("change",a)}),b.bind("removed",function(a){b.trigger("change",a)})},count:function(){return _.size(this._value)},add:function(a,b){var c,d,e=this;return"string"==typeof a?(c=a,d=b):(c=a.code,d=a),e.has(c)||(e._addedIncrement+=1,e._addedOrder[c]=e._addedIncrement),f.Values.prototype.add.call(e,c,d)},remove:function(a){var b=this;return delete b._addedOrder[a],f.Values.prototype.remove.call(this,a)},get:function(a){var b,c,d,e=this;return b=_.values(e._value),d=_.extend({sort:!1},a),d.sort&&(c={error:4,warning:3,success:2,info:1},b.sort(function(a,b){var d=0,f=0;return _.isUndefined(c[a.type])||(d=c[a.type]),_.isUndefined(c[b.type])||(f=c[b.type]),d!==f?f-d:e._addedOrder[b.code]-e._addedOrder[a.code]})),b},render:function(){var a,c,d,e=this,g=!1,h={};e.container&&e.container.length&&(a=e.get({sort:!0}),e.container.toggle(0!==a.length),e.container.is(e.previousContainer)&&_.isEqual(a,e.previousNotifications)||(d=e.container.children("ul").first(),d.length||(d=b("<ul></ul>"),e.container.append(d)),d.find("> [data-code]").remove(),_.each(e.previousNotifications,function(a){h[a.code]=a}),_.each(a,function(a){var c;!wp.a11y||h[a.code]&&_.isEqual(a.message,h[a.code].message)||wp.a11y.speak(a.message,"assertive"),c=b(a.render()),d.append(c)}),c=Boolean(_.find(a,function(a){return a.extended(f.OverlayNotification)})),e.previousNotifications&&(g=Boolean(_.find(e.previousNotifications,function(a){return a.extended(f.OverlayNotification)}))),c!==g&&(b(document.body).toggleClass("customize-loading",c),e.container.toggleClass("has-overlay-notifications",c)),e.previousNotifications=a,e.previousContainer=e.container,e.trigger("rendered")))}}),f.Setting=f.Value.extend({initialize:function(a,b,c){var d=this;f.Value.prototype.initialize.call(d,b,c),d.id=a,d.transport=d.transport||"refresh",d._dirty=c.dirty||!1,d.notifications=new f.Notifications,d.bind(d.preview)},preview:function(){var a,b=this;a=b.transport,"postMessage"!==a||f.state("previewerAlive").get()||(a="refresh"),"postMessage"===a?b.previewer.send("setting",[b.id,b()]):"refresh"===a&&b.previewer.refresh()},findControls:function(){var a=this,b=[];return f.control.each(function(c){_.each(c.settings,function(d){d.id===a.id&&b.push(c)})}),b}}),f._latestRevision=0,f._lastSavedRevision=0,f._latestSettingRevisions={},f.bind("change",function(a){f._latestRevision+=1,f._latestSettingRevisions[a.id]=f._latestRevision}),f.bind("ready",function(){f.bind("add",function(a){a._dirty&&(f._latestRevision+=1,f._latestSettingRevisions[a.id]=f._latestRevision)})}),f.dirtyValues=function(a){var b={};return f.each(function(c){var d;c._dirty&&(d=f._latestSettingRevisions[c.id],f.state("changesetStatus").get()&&a&&a.unsaved&&(_.isUndefined(d)||d<=f._lastSavedRevision)||(b[c.id]=c.get()))}),b},f.requestChangesetUpdate=function(a,c){var d,e,g,h,i={};return d=new b.Deferred,0!==f.state("processing").get()?(d.reject("already_processing"),d.promise()):(h=_.extend({title:null,date:null,autosave:!1,force:!1},c),a&&_.extend(i,a),_.each(f.dirtyValues({unsaved:!0}),function(b,c){a&&null===a[c]||(i[c]=_.extend({},i[c]||{},{value:b}))}),f.trigger("changeset-save",i,h),!h.force&&_.isEmpty(i)&&null===h.title&&null===h.date?(d.resolve({}),d.promise()):h.status?d.reject({code:"illegal_status_in_changeset_update"}).promise():h.date&&h.autosave?d.reject({code:"illegal_autosave_with_date_gmt"}).promise():(f.state("processing").set(f.state("processing").get()+1),d.always(function(){f.state("processing").set(f.state("processing").get()-1)}),g=f.previewer.query({excludeCustomizedSaved:!0}),delete g.customized,_.extend(g,{nonce:f.
b(document).one("wp-theme-install-success",function(a,b){var g,h=!1;if(d)f.notifications.remove("theme_installing"),c.loadThemePreview(e);else{if(f.control.each(function(a){"theme"===a.params.type&&a.params.theme.id===b.slug&&(h=a.params.theme,a.rerenderAsInstalled(!0))}),!h||f.control.has("installed_theme_"+h.id))return;h.type="installed",g=new f.controlConstructor.theme("installed_theme_"+h.id,{type:"theme",section:"installed_themes",theme:h,priority:0}),f.control.add(g),f.control(g.id).container.trigger("render-screenshot"),f.section.each(function(a){"themes"===a.params.type&&h.id===a.currentTheme&&a.closeDetails()})}}),c.installingThemes.push(b(a.target).data("slug")),wp.updates.installTheme({slug:e}),b(a.target).hasClass("preview")&&(d=!0,f.notifications.add(new f.OverlayNotification("theme_installing",{message:f.l10n.themeDownloading,type:"info",loading:!0}))))},loadThemePreview:function(a){var c,d,e,g=b.Deferred();return d=document.createElement("a"),d.href=location.href,e=_.extend(f.utils.parseQueryString(d.search.substr(1)),{theme:a,changeset_uuid:f.settings.changeset.uuid}),f.state("saved").get()||(e.customize_autosaved="on"),d.search=b.param(e),f.notifications.add(new f.OverlayNotification("theme_previewing",{message:f.l10n.themePreviewWait,type:"info",loading:!0})),c=function(){var a;f.state("processing").get()>0||(f.state("processing").unbind(c),a=f.requestChangesetUpdate({},{autosave:!0}),a.done(function(){g.resolve(),b(window).off("beforeunload.customize-confirm"),window.location.href=d.href}),a.fail(function(){f.notifications.remove("theme_previewing"),g.reject()}))},0===f.state("processing").get()?c():f.state("processing").bind(c),g.promise()},updateTheme:function(a){wp.updates.maybeRequestFilesystemCredentials(a),b(document).one("wp-theme-update-success",function(a,b){f.control.each(function(a){"theme"===a.params.type&&a.params.theme.id===b.slug&&(a.params.theme.hasUpdate=!1,a.rerenderAsInstalled(!0))})}),wp.updates.updateTheme({slug:b(a.target).closest(".notice").data("slug")})},deleteTheme:function(a){var c,d;c=b(a.target).data("slug"),d=f.section("installed_themes"),a.preventDefault(),window.confirm(f.settings.l10n.confirmDeleteTheme)&&(wp.updates.maybeRequestFilesystemCredentials(a),b(document).one("wp-theme-delete-success",function(){var a=f.control("installed_theme_"+c);a.container.remove(),f.control.remove(a.id),d.loaded=d.loaded-1,d.updateCount(),f.control.each(function(a){"theme"===a.params.type&&a.params.theme.id===c&&a.rerenderAsInstalled(!1)})}),wp.updates.deleteTheme({slug:c}),d.closeDetails(),d.focus())}}),f.Control=f.Class.extend({defaultActiveArguments:{duration:"fast",completeCallback:b.noop},defaults:{active:!0,priority:10},initialize:function(a,c){var d,e,g,h=this;h.params=_.extend({},h.defaults),f.Control.instanceCounter||(f.Control.instanceCounter=0),f.Control.instanceCounter++,h.params.instanceNumber||(h.params.instanceNumber=f.Control.instanceCounter),_.extend(h.params,c.params||c),h.params.content||(h.params.content=b("<li></li>",{id:"customize-control-"+a.replace(/]/g,"").replace(/\[/g,"-"),"class":"customize-control customize-control-"+h.params.type})),h.id=a,h.selector="#customize-control-"+a.replace(/\]/g,"").replace(/\[/g,"-"),h.templateSelector=h.params.templateId||"customize-control-"+h.params.type+"-content",h.params.content?h.container=b(h.params.content):h.container=b(h.selector),h.deferred={embedded:new b.Deferred},h.section=new f.Value,h.priority=new f.Value,h.active=new f.Value,h.activeArgumentsQueue=[],h.notifications=new f.Notifications({alt:h.altNotice}),h.elements=[],d=h.container.find("[data-customize-setting-link]"),e={},d.each(function(){var a,c=b(this);if(c.is(":radio")){if(a=c.prop("name"),e[a])return;e[a]=!0,c=d.filter('[name="'+a+'"]')}f(c.data("customizeSettingLink"),function(a){var b=new f.Element(c);h.elements.push(b),b.sync(a),b.set(a())})}),h.active.bind(function(a){var c=h.activeArgumentsQueue.shift();c=b.extend({},h.defaultActiveArguments,c),h.onChangeActive(a,c)}),h.section.set(h.params.section),h.priority.set(isNaN(h.params.priority)?10:h.params.
c.search=b.param(d),g.iframe=b("<iframe />",{title:f.l10n.previewIframeTitle,name:"customize-"+g.channel()}),g.iframe.attr("onmousewheel",""),k?g.iframe.attr("data-src",c.href):g.iframe.attr("src",c.href),g.iframe.appendTo(g.container),g.targetWindow(g.iframe[0].contentWindow),k&&(e=b("<form>",{action:c.href,target:g.iframe.attr("name"),method:"post",hidden:"hidden"}),e.append(b("<input>",{type:"hidden",name:"_method",value:"GET"})),_.each(g.query,function(a,c){e.append(b("<input>",{type:"hidden",name:c,value:a}))}),g.container.append(e),e.submit(),e.remove()),g.bind("iframe-loading-error",function(b){return g.iframe.remove(),0===b?void g.login(a):-1===b?void a.rejectWith(g,["cheatin"]):void a.rejectWith(g,["request failure"])}),g.iframe.one("load",function(){h=!0,i?a.resolveWith(g,[j]):setTimeout(function(){a.rejectWith(g,["ready timeout"])},g.sensitivity)})},login:function(a){var c,d=this;return c=function(){a.rejectWith(d,["logged out"])},this.triedLogin?c():void b.get(f.settings.url.ajax,{action:"logged-in"}).fail(c).done(function(e){var g;"1"!==e&&c(),g=b("<iframe />",{src:d.previewUrl(),title:f.l10n.previewIframeTitle}).hide(),g.appendTo(d.container),g.on("load",function(){d.triedLogin=!0,g.remove(),d.run(a)})})},destroy:function(){f.Messenger.prototype.destroy.call(this),this.iframe&&this.iframe.remove(),delete this.iframe,delete this.targetWindow}}),function(){var a=0;f.PreviewFrame.uuid=function(){return"preview-"+String(a++)}}(),f.setDocumentTitle=function(a){var b,c;b=f.settings.documentTitleTmpl,c=b.replace("%s",a),document.title=c,f.trigger("title",c)},f.Previewer=f.Messenger.extend({refreshBuffer:null,initialize:function(a,c){var d=this,e=document.createElement("a");b.extend(d,c||{}),d.deferred={active:b.Deferred()},d.refresh=_.debounce(function(a){return function(){var b,c;b=function(){return 0===f.state("processing").get()},b()?a.call(d):(c=function(){b()&&(a.call(d),f.state("processing").unbind(c))},f.state("processing").bind(c))}}(d.refresh),d.refreshBuffer),d.container=f.ensure(a.container),d.allowedUrls=a.allowedUrls,a.url=window.location.href,f.Messenger.prototype.initialize.call(d,a),e.href=d.origin(),d.add("scheme",e.protocol.replace(/:$/,"")),d.add("previewUrl",a.previewUrl).setter(function(a){var c,e,g,h=null,i=[];return c=document.createElement("a"),c.href=a,/\/wp-(admin|includes|content)(\/|$)/.test(c.pathname)?null:(c.search.length>1&&(e=f.utils.parseQueryString(c.search.substr(1)),delete e.customize_changeset_uuid,delete e.customize_theme,delete e.customize_messenger_channel,delete e.customize_autosaved,_.isEmpty(e)?c.search="":c.search=b.param(e)),i.push(c),d.scheme.get()+":"!==c.protocol&&(c=document.createElement("a"),c.href=i[0].href,c.protocol=d.scheme.get()+":",i.unshift(c)),g=document.createElement("a"),_.find(i,function(a){return!_.isUndefined(_.find(d.allowedUrls,function(b){if(g.href=b,c.protocol===g.protocol&&c.host===g.host&&0===c.pathname.indexOf(g.pathname.replace(/\/$/,"")))return h=a.href,!0}))}),h)}),d.bind("ready",d.ready),d.deferred.active.done(_.bind(d.keepPreviewAlive,d)),d.bind("synced",function(){d.send("active")}),d.previewUrl.bind(d.refresh),d.scroll=0,d.bind("scroll",function(a){d.scroll=a}),d.bind("url",function(a){var b,c=!1;d.scroll=0,b=function(){c=!0},d.previewUrl.bind(b),d.previewUrl.set(a),d.previewUrl.unbind(b),c||d.refresh()}),d.bind("documentTitle",function(a){f.setDocumentTitle(a)})},ready:function(a){var b,c=this,d={};d.settings=f.get(),d["settings-modified-while-loading"]=c.settingsModifiedWhileLoading,("resolved"!==c.deferred.active.state()||c.loading)&&(d.scroll=c.scroll),d["edit-shortcut-visibility"]=f.state("editShortcutVisibility").get(),c.send("sync",d),a.currentUrl&&(c.previewUrl.unbind(c.refresh),c.previewUrl.set(a.currentUrl),c.previewUrl.bind(c.refresh)),b={panel:a.activePanels,section:a.activeSections,control:a.activeControls},_(b).each(function(a,b){f[b].each(function(c,d){var e=_.isUndefined(f.settings[b+"s"][d]);e&&_.isUndefined(a[d])||(a[d]?c.activate():c.deactivate())})}),a.settingValidities&&f._handleSettingValidities({settingValidities
"page"===a()&&d&&e&&d===e?a.notifications.add(new f.Notification(h,{type:"error",message:f.l10n.pageOnFrontError})):a.notifications.remove(h)};a.bind(d),b.bind(d),c.bind(d),d.call(a,a()),f.control("show_on_front",function(a){a.deferred.embedded.done(function(){a.container.append(a.getNotificationsContainerElement())})})}),function(){var a=b.Deferred();f.section("custom_css",function(b){b.deferred.embedded.done(function(){b.expanded()?a.resolve(b):b.expanded.bind(function(c){c&&a.resolve(b)})})}),a.done(function(a){var b=f.control("custom_css");a.container.find(".section-description-buttons .section-description-close").on("click",function(){a.container.find(".section-meta .customize-section-description:first").removeClass("open").slideUp(),a.container.find(".customize-help-toggle").attr("aria-expanded","false").focus()}),b&&!b.setting.get()&&(a.container.find(".section-meta .customize-section-description:first").addClass("open").show().trigger("toggled"),a.container.find(".customize-help-toggle").attr("aria-expanded","true"))})}(),f.control("changeset_status","changeset_scheduled_date",function(a,c){b.when(a.deferred.embedded,c.deferred.embedded).done(function(){var b,d,e,g,h,i,j=1e3;b=a.container.find("input[type=radio][name]"),d=new f.Element(b),a.elements.push(d),d.sync(f.state("selectedChangesetStatus")),d.set(f.state("selectedChangesetStatus").get()),c.notifications.alt=!0,c.deferred.embedded.done(function(){f.state("selectedChangesetDate").sync(c.setting),f.state("selectedChangesetDate").set(c.setting())}),g=function(){f.state("selectedChangesetStatus").set("publish"),f.previewer.save()},i=function(){var a="future"===f.state("changesetStatus").get()&&"future"===f.state("selectedChangesetStatus").get()&&f.state("changesetDate").get()&&f.state("selectedChangesetDate").get()===f.state("changesetDate").get()&&f.utils.getRemainingTime(f.state("changesetDate").get())>=0;a&&!h?h=setInterval(function(){var a=f.utils.getRemainingTime(f.state("changesetDate").get());f.state("remainingTimeToPublish").set(a),a<=0&&(clearInterval(h),h=0,g())},j):!a&&h&&(clearInterval(h),h=0)},f.state("changesetDate").bind(i),f.state("selectedChangesetDate").bind(i),f.state("changesetStatus").bind(i),f.state("selectedChangesetStatus").bind(i),i(),c.active.validate=function(){return"future"===d.get()},e=function(a){c.active.set("future"===a)},e(d.get()),d.bind(e),f.state("saving").bind(function(a){a&&"future"===f.state("selectedChangesetStatus").get()&&c.toggleFutureDateNotification(!c.isFutureDate())})})}),f.control("header_video",function(a){a.deferred.embedded.done(function(){var b=function(){var b=f.section(a.section()),c="video_header_not_available";b&&(a.active.get()?b.notifications.remove(c):b.notifications.add(new f.Notification(c,{type:"info",message:f.l10n.videoHeaderNotice})))};b(),a.active.bind(b)})}),f.previewer.bind("selective-refresh-setting-validities",function(a){f._handleSettingValidities({settingValidities:a,focusInvalidControl:!1})}),f.previewer.bind("focus-control-for-setting",function(a){var b=[];f.control.each(function(c){var d=_.pluck(c.settings,"id");-1!==_.indexOf(d,a)&&b.push(c)}),b.length&&(b.sort(function(a,b){return a.priority()-b.priority()}),b[0].focus())}),f.previewer.bind("refresh",function(){f.previewer.refresh()}),f.state("paneVisible").bind(function(a){var c;c=window.matchMedia?window.matchMedia("screen and ( max-width: 640px )").matches:b(window).width()<=640,f.state("editShortcutVisibility").set(a||c?"visible":"hidden")}),window.matchMedia&&window.matchMedia("screen and ( max-width: 640px )").addListener(function(){var a=f.state("paneVisible");a.callbacks.fireWith(a,[a.get(),a.get()])}),f.previewer.bind("edit-shortcut-visibility",function(a){f.state("editShortcutVisibility").set(a)}),f.state("editShortcutVisibility").bind(function(a){f.previewer.send("edit-shortcut-visibility",a)}),f.bind("change",a),b(document).one("wp-before-tinymce-init",function(){(!window.tinymce.ui.FloatPanel.zIndex||window.tinymce.ui.FloatPanel.zIndex<500001)&&(window.tinymce.ui.FloatPanel.zIndex=500001)}),d.addClass("ready"),f.trigge