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

4 lines
109 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")},render:function(){var a=f.Notification.prototype.render.call(this);return a.on("keydown",_.bind(this.handleEscape,this)),a},handleEscape:function(a){var b=this;27===a.which&&(a.stopPropagation(),b.dismissible&&b.parent&&b.parent.remove(b.code))}}),f.Notifications=f.Values.extend({alt:!1,defaultConstructor:f.Notification,initialize:function(a){var b=this;f.Values.prototype.initialize.call(b,a),_.bindAll(b,"constrainFocus"),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,g=this,h=!1,i=[],j={};g.container&&g.container.length&&(a=g.get({sort:!0}),g.container.toggle(0!==a.length),g.container.is(g.previousContainer)&&_.isEqual(a,g.previousNotifications)||(d=g.container.children("ul").first(),d.length||(d=b("<ul></ul>"),g.container.append(d)),d.find("> [data-code]").remove(),_.each(g.previousNotifications,function(a){j[a.code]=a}),_.each(a,function(a){var c;!wp.a11y||j[a.code]&&_.isEqual(a.message,j[a.code].message)||wp.a11y.speak(a.message,"assertive"),c=b(a.render()),a.container=c,d.append(c),a.extended(f.OverlayNotification)&&i.push(a)}),c=Boolean(i.length),g.previousNotifications&&(h=Boolean(_.find(g.previousNotifications,function(a){return a.extended(f.OverlayNotification)}))),c!==h&&(b(document.body).toggleClass("customize-loading",c),g.container.toggleClass("has-overlay-notifications",c),c?(g.previousActiveElement=document.activeElement,b(document).on("keydown",g.constrainFocus)):b(document).off("keydown",g.constrainFocus)),c?(g.focusContainer=i[i.length-1].container,g.focusContainer.prop("tabIndex",-1),e=g.focusContainer.find(":focusable"),e.length?e.first().focus():g.focusContainer.focus()):g.previousActiveElement&&(b(g.previousActiveElement).focus(),g.previousActiveElement=null),g.previousNotifications=a,g.previousContainer=g.container,g.trigger("rendered")))},constrainFocus:function(a){var c,d=this;a.stopPropagation(),9===a.which&&(c=d.focusContainer.find(":focusable"),0===c.length&&(c=d.focusContainer),b.contains(d.focusContainer[0],a.target)&&b.contains(d.focusContainer[0],document.activeElement)?c.last().is(a.target)&&!a.shiftKey?(a.preventDefault(),c.first().focus()):c.first().is(a.target)&&a.shiftKey&&(a.preventDefault(),c.last().focus()):(a.preventDefault(),c.first().focus()))}}),f.Setting=f.Value.extend({defaults:{transport:"refresh",dirty:!1},initialize:function(a,b,c){var d,e=this;d=_.extend({previewer:f.previewer},e.defaults,c||{}),f.Value.prototype.initialize.call(e,b,d),e.id=a,e._dirty=d.dirty,e.notifications=new f.Notifications,e.bind(e.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",functi
g.addClass("in-sub-panel"),k[0].expand({completeCallback:b.completeCallback})):(d._animateChangeExpanded(function(){i.attr("tabindex","-1"),j.attr("tabindex","0"),j.focus(),e.css("top",""),h.scrollTop(0),b.completeCallback&&b.completeCallback()}),e.addClass("current-panel"),g.addClass("in-sub-panel")),f.state("expandedPanel").set(d)):!a&&e.hasClass("current-panel")&&(c=e.hasClass("skip-transition"),c?e.removeClass("skip-transition"):d._animateChangeExpanded(function(){i.attr("tabindex","0"),j.attr("tabindex","-1"),i.focus(),e.css("top",""),b.completeCallback&&b.completeCallback()}),g.removeClass("in-sub-panel"),e.removeClass("current-panel"),d===f.state("expandedPanel").get()&&f.state("expandedPanel").set(!1))},renderContent:function(){var a,c=this;a=0!==b("#tmpl-"+c.templateSelector+"-content").length?wp.template(c.templateSelector+"-content"):wp.template("customize-panel-default-content"),a&&c.headContainer&&c.contentContainer.html(a(_.extend({id:c.id},c.params)))}}),f.ThemesPanel=f.Panel.extend({initialize:function(a,b){var c=this;c.installingThemes=[],f.Panel.prototype.initialize.call(c,a,b)},canSwitchTheme:function(a){return!(!a||a!==f.settings.theme.stylesheet)||"publish"===f.state("selectedChangesetStatus").get()&&(""===f.state("changesetStatus").get()||"auto-draft"===f.state("changesetStatus").get())},attachEvents:function(){function a(){c.canSwitchTheme()?c.notifications.remove("theme_switch_unavailable"):c.notifications.add(new f.Notification("theme_switch_unavailable",{message:f.l10n.themePreviewUnavailable,type:"warning"}))}var c=this;f.Panel.prototype.attachEvents.apply(c),f.settings.theme._filesystemCredentialsNeeded&&c.notifications.add(new f.Notification("theme_install_unavailable",{message:f.l10n.themeInstallUnavailable,type:"info",dismissible:!0})),a(),f.state("selectedChangesetStatus").bind(a),f.state("changesetStatus").bind(a),c.contentContainer.on("click",".customize-theme",function(){c.collapse()}),c.contentContainer.on("click",".customize-themes-section-title, .customize-themes-mobile-back",function(){b(".wp-full-overlay").toggleClass("showing-themes")}),c.contentContainer.on("click",".theme-install",function(a){c.installTheme(a)}),c.contentContainer.on("click",".update-theme, #update-theme",function(a){a.preventDefault(),a.stopPropagation(),c.updateTheme(a)}),c.contentContainer.on("click",".delete-theme",function(a){c.deleteTheme(a)}),_.bindAll(c,"installTheme","updateTheme")},onChangeExpanded:function(a,b){var c,d,e=this,g=!1;return f.Panel.prototype.onChangeExpanded.apply(this,[a,b]),b.unchanged?void(b.completeCallback&&b.completeCallback()):(c=e.headContainer.closest(".wp-full-overlay"),void(a?(c.addClass("in-themes-panel").delay(200).find(".customize-themes-full-container").addClass("animate"),_.delay(function(){c.addClass("themes-panel-expanded")},200),600<window.innerWidth&&(d=e.sections(),_.each(d,function(a){a.expanded()&&(g=!0)}),!g&&d.length>0&&d[0].expand())):c.removeClass("in-themes-panel themes-panel-expanded").find(".customize-themes-full-container").removeClass("animate")))},installTheme:function(a){var c,d,e,g=this,h=b(a.target).data("slug"),i=b.Deferred();return c=b(a.target).hasClass("preview"),f.settings.theme._filesystemCredentialsNeeded?(i.reject({errorCode:"theme_install_unavailable"}),i.promise()):g.canSwitchTheme(h)?_.contains(g.installingThemes,h)?(i.reject({errorCode:"theme_already_installing"}),i.promise()):(wp.updates.maybeRequestFilesystemCredentials(a),d=function(a){var b,d=!1;if(c)f.notifications.remove("theme_installing"),g.loadThemePreview(h);else{if(f.control.each(function(b){"theme"===b.params.type&&b.params.theme.id===a.slug&&(d=b.params.theme,b.rerenderAsInstalled(!0))}),!d||f.control.has("installed_theme_"+d.id))return void i.resolve(a);d.type="installed",b=new f.controlConstructor.theme("installed_theme_"+d.id,{type:"theme",section:"installed_themes",theme:d,priority:0}),f.control.add(b),f.control(b.id).container.trigger("render-screenshot"),f.section.each(function(a){"themes"===a.params.type&&d.id===a.currentTheme&&a.closeDetails()})}i.resolve(a)},g.install
b.selectionStart=c.selectionEnd=d+1),a.stopPropagation(),a.preventDefault()))}),a.deferred.codemirror.rejectWith(a)}}),f.DateTimeControl=f.Control.extend({ready:function(){var a=this;if(a.inputElements={},a.invalidDate=!1,_.bindAll(a,"populateSetting","updateDaysForMonth","populateDateInputs"),!a.setting)throw new Error("Missing setting");a.container.find(".date-input").each(function(){var c,d,e=b(this);c=e.data("component"),d=new f.Element(e),a.inputElements[c]=d,a.elements.push(d),e.on("change",function(){a.invalidDate&&a.notifications.add(new f.Notification("invalid_date",{message:f.l10n.invalidDate}))}),e.on("input",_.debounce(function(){a.invalidDate||a.notifications.remove("invalid_date")})),e.on("blur",_.debounce(function(){a.invalidDate||a.populateDateInputs()}))}),a.inputElements.month.bind(a.updateDaysForMonth),a.inputElements.year.bind(a.updateDaysForMonth),a.populateDateInputs(),a.setting.bind(a.populateDateInputs),_.each(a.inputElements,function(b){b.bind(a.populateSetting)})},parseDateTime:function(a){var b,c,d=this,e=12;return a&&(b=a.match(/^(\d\d\d\d)-(\d\d)-(\d\d)(?: (\d\d):(\d\d)(?::(\d\d))?)?$/)),b?(b.shift(),c={year:b.shift(),month:b.shift(),day:b.shift(),hour:b.shift()||"00",minute:b.shift()||"00",second:b.shift()||"00"},d.params.includeTime&&d.params.twelveHourFormat&&(c.hour=parseInt(c.hour,10),c.meridian=c.hour>=e?"pm":"am",c.hour=c.hour%e?String(c.hour%e):String(e),delete c.second),c):null},validateInputs:function(){var a,b,c=this;return c.invalidDate=!1,a=["year","day"],c.params.includeTime&&a.push("hour","minute"),_.find(a,function(a){var d,e,f,g;return d=c.inputElements[a],b=d.element.get(0),e=parseInt(d.element.attr("max"),10),f=parseInt(d.element.attr("min"),10),g=parseInt(d(),10),c.invalidDate=isNaN(g)||g>e||g<f,c.invalidDate||b.setCustomValidity(""),c.invalidDate}),c.inputElements.meridian&&!c.invalidDate&&(b=c.inputElements.meridian.element.get(0),"am"!==c.inputElements.meridian.get()&&"pm"!==c.inputElements.meridian.get()?c.invalidDate=!0:b.setCustomValidity("")),c.invalidDate?b.setCustomValidity(f.l10n.invalidValue):b.setCustomValidity(""),(!c.section()||f.section.has(c.section())&&f.section(c.section()).expanded())&&_.result(b,"reportValidity"),c.invalidDate},updateDaysForMonth:function(){var a,b,c,d,e=this;c=parseInt(e.inputElements.month(),10),b=parseInt(e.inputElements.year(),10),d=parseInt(e.inputElements.day(),10),c&&b&&(a=new Date(b,c,0).getDate(),e.inputElements.day.element.attr("max",a),d>a&&e.inputElements.day(String(a)))},populateSetting:function(){var a,b=this;return!(b.validateInputs()||!b.params.allowPastDate&&!b.isFutureDate())&&(a=b.convertInputDateToString(),b.setting.set(a),!0)},convertInputDateToString:function(){var a,b,c,d,e=this,f="";return d=function(a,b){var c;return String(a).length<b&&(c=b-String(a).length,a=Math.pow(10,c).toString().substr(1)+String(a)),a},c=function(a){var b=parseInt(e.inputElements[a].get(),10);return _.contains(["month","day","hour","minute"],a)?b=d(b,2):"year"===a&&(b=d(b,4)),b},a=["year","-","month","-","day"],e.params.includeTime&&(b=e.inputElements.meridian?e.convertHourToTwentyFourHourFormat(e.inputElements.hour(),e.inputElements.meridian()):e.inputElements.hour(),a=a.concat([" ",d(b,2),":","minute",":","00"])),_.each(a,function(a){f+=e.inputElements[a]?c(a):a}),f},isFutureDate:function(){var a=this;return 0<f.utils.getRemainingTime(a.convertInputDateToString())},convertHourToTwentyFourHourFormat:function(a,b){var c,d,e=12;return d=parseInt(a,10),isNaN(d)?"":(c="pm"===b&&d<e?d+e:"am"===b&&e===d?d-e:d,String(c))},populateDateInputs:function(){var a,b=this;return!!(a=b.parseDateTime(b.setting.get()))&&(_.each(b.inputElements,function(b,c){var d=a[c];"month"===c||"meridian"===c?(d=d.replace(/^0/,""),b.set(d)):(d=parseInt(d,10),b.element.is(document.activeElement)?d!==parseInt(b(),10)&&b.set(String(d)):b.set(a[c]))}),!0)},toggleFutureDateNotification:function(a){var b,c,d=this;return b="not_future_date",a?(c=new f.Notification(b,{type:"error",message:f.l10n.futureDateError}),d.notifications.add(c)):d.notifications.remove(b),d}}),f.Previe
f.notifications.add(new c("changeset_locked",{lockUser:f.settings.changeset.lockUser,allowOverride:Boolean(a&&a.allowOverride)}))}var c=f.OverlayNotification.extend({templateId:"customize-changeset-locked-notification",lockUser:null,initialize:function(a,b){var c,d,e=this;c=a||"changeset_locked",d=_.extend({type:"warning",containerClasses:"",lockUser:{}},b),d.containerClasses+=" notification-changeset-locked",f.OverlayNotification.prototype.initialize.call(e,c,d)},render:function(){var a,b,c,d,e=this;return b=_.extend({allowOverride:!1,returnUrl:f.settings.url["return"],previewUrl:f.previewer.previewUrl.get(),frontendPreviewUrl:f.previewer.getFrontendPreviewUrl()},this),a=f.OverlayNotification.prototype.render.call(b),f.requestChangesetUpdate({},{autosave:!0}).fail(function(b){b.autosaved||a.find(".notice-error").prop("hidden",!1).text(b.message||f.l10n.unknownRequestFail)}),c=a.find(".customize-notice-take-over-button"),c.on("click",function(b){b.preventDefault(),d||(c.addClass("disabled"),d=wp.ajax.post("customize_override_changeset_lock",{wp_customize:"on",customize_theme:f.settings.theme.stylesheet,customize_changeset_uuid:f.settings.changeset.uuid,nonce:f.settings.nonce.override_lock}),d.done(function(){f.notifications.remove(e.code),f.state("changesetLocked").set(!1)}),d.fail(function(b){var e=b.message||f.l10n.unknownRequestFail;a.find(".notice-error").prop("hidden",!1).text(e),d.always(function(){c.removeClass("disabled")})}),d.always(function(){d=null}))}),a}});f.settings.changeset.lockUser&&a({allowOverride:!0}),b(document).on("heartbeat-send.update_lock_notice",function(a,b){b.check_changeset_lock=!0}),b(document).on("heartbeat-tick.update_lock_notice",function(b,c){var d,e="changeset_locked";c.customize_changeset_lock_user&&(d=f.notifications(e),d&&d.lockUser.id!==f.settings.changeset.lockUser.id&&f.notifications.remove(e),a({lockUser:c.customize_changeset_lock_user}))}),f.bind("error",function(b){"changeset_locked"===b.code&&b.lock_user&&a({lockUser:b.lock_user})})}(),function(){function a(){var a,c;return a=document.createElement("a"),a.href=location.href,c=f.utils.parseQueryString(a.search.substr(1)),f.settings.changeset.latestAutoDraftUuid?c.changeset_uuid=f.settings.changeset.latestAutoDraftUuid:c.customize_autosaved="on",c["return"]=f.settings.url["return"],a.search=b.param(c),a.href}function c(a){var c,d=document.createElement("a"),e=0;d.href=location.href,c=f.utils.parseQueryString(d.search.substr(1)),_.each(a,function(a){"undefined"!=typeof c[a]&&(e+=1,delete c[a])}),0!==e&&(d.search=b.param(c),history.replaceState({},document.title,d.href))}function d(){h||(wp.ajax.post("customize_dismiss_autosave_or_lock",{wp_customize:"on",customize_theme:f.settings.theme.stylesheet,customize_changeset_uuid:f.settings.changeset.uuid,nonce:f.settings.nonce.dismiss_autosave_or_lock,dismiss_autosave:!0}),h=!0)}function e(){var b,c="autosave_available";f.notifications.add(new f.Notification(c,{message:f.l10n.autosaveNotice,type:"warning",dismissible:!0,render:function(){var b,c=f.Notification.prototype.render.call(this);return b=c.find("a"),b.prop("href",a()),b.on("click",function(b){b.preventDefault(),location.replace(a())}),c.find(".notice-dismiss").on("click",d),c}})),b=function(){d(),f.notifications.remove(c),f.unbind("change",b),f.state("changesetStatus").unbind(b)},f.bind("change",b),f.state("changesetStatus").bind(b)}var g=[],h=!1;f.settings.changeset.autosaved&&(f.state("saved").set(!1),g.push("customize_autosaved")),f.settings.changeset.branching||f.settings.changeset.status&&"auto-draft"!==f.settings.changeset.status||g.push("changeset_uuid"),g.length>0&&c(g),(f.settings.changeset.latestAutoDraftUuid||f.settings.changeset.hasAutosaveRevision)&&e()}(),f.previewer.previewUrl()?f.previewer.refresh():f.previewer.previewUrl(f.settings.url.home),i.click(function(a){f.previewer.save(),a.preventDefault()}).keydown(function(a){9!==a.which&&(13===a.which&&f.previewer.save(),a.preventDefault())}),h.keydown(function(a){9!==a.which&&(13===a.which&&this.click(),a.preventDefault())}),b(".collapse-sidebar").on("click",func