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

1 line
35 KiB
JavaScript

!function(p){var i,e,t,f=wp.customize;f.Setting=f.Value.extend({initialize:function(e,t,n){f.Value.prototype.initialize.call(this,t,n),this.id=e,this.transport=this.transport||"refresh",this._dirty=n.dirty||!1,this.bind(this.preview)},preview:function(){switch(this.transport){case"refresh":return this.previewer.refresh();case"postMessage":return this.previewer.send("setting",[this.id,this()])}}}),f.utils={},f.utils.bubbleChildValueChanges=function(n,e){p.each(e,function(e,t){n[t].bind(function(e,t){n.parent&&e!==t&&n.parent.trigger("change",n)})})},e=function(e){var t,n=this,i=function(){var e=n.extended(f.Panel)&&n.expanded()?n.container.find(".control-panel-content:first"):n.container;e.find(":focusable:first").focus(),e[0].scrollIntoView(!0)};(e=e||{}).completeCallback?(t=e.completeCallback,e.completeCallback=function(){i(),t()}):e.completeCallback=i,n.expand?n.expand(e):e.completeCallback()},f.utils.prioritySort=function(e,t){return e.priority()===t.priority()&&"number"==typeof e.params.instanceNumber&&"number"==typeof t.params.instanceNumber?e.params.instanceNumber-t.params.instanceNumber:e.priority()-t.priority()},f.utils.isKeydownButNotEnterEvent=function(e){return"keydown"===e.type&&13!==e.which},f.utils.areElementListsEqual=function(e,t){return e.length===t.length&&-1===_.indexOf(_.map(_.zip(e,t),function(e){return p(e[0]).is(e[1])}),!1)},i=f.Class.extend({defaultActiveArguments:{duration:"fast",completeCallback:p.noop},defaultExpandedArguments:{duration:"fast",completeCallback:p.noop},initialize:function(e,t){var n=this;n.id=e,n.params={},p.extend(n,t||{}),n.container=p(n.params.content),n.deferred={embedded:new p.Deferred},n.priority=new f.Value,n.active=new f.Value,n.activeArgumentsQueue=[],n.expanded=new f.Value,n.expandedArgumentsQueue=[],n.active.bind(function(e){var t=n.activeArgumentsQueue.shift(),t=p.extend({},n.defaultActiveArguments,t);e=e&&n.isContextuallyActive(),n.onChangeActive(e,t)}),n.expanded.bind(function(e){var t=n.expandedArgumentsQueue.shift(),t=p.extend({},n.defaultExpandedArguments,t);n.onChangeExpanded(e,t)}),n.attachEvents(),f.utils.bubbleChildValueChanges(n,["priority","active"]),n.priority.set(isNaN(n.params.priority)?100:n.params.priority),n.active.set(n.params.active),n.expanded.set(!1)},ready:function(){},_children:function(t,e){var n=this,i=[];return f[e].each(function(e){e[t].get()===n.id&&i.push(e)}),i.sort(f.utils.prioritySort),i},isContextuallyActive:function(){throw new Error("Container.isContextuallyActive() must be overridden in a subclass.")},onChangeActive:function(e,t){var n="resolved"===f.previewer.deferred.active.state()?t.duration:0;p.contains(document,this.container)?e?this.container.stop(!0,!0).slideDown(n,t.completeCallback):this.container.stop(!0,!0).slideUp(n,t.completeCallback):(this.container.toggle(e),t.completeCallback&&t.completeCallback())},_toggleActive:function(e,t){return t=t||{},e&&this.active.get()||!e&&!this.active.get()?(t.unchanged=!0,this.onChangeActive(this.active.get(),t),!1):(t.unchanged=!1,this.activeArgumentsQueue.push(t),this.active.set(e),!0)},activate:function(e){return this._toggleActive(!0,e)},deactivate:function(e){return this._toggleActive(!1,e)},onChangeExpanded:function(){throw new Error("Must override with subclass.")},_toggleExpanded:function(e,t){var n=this,i=(t=t||{}).completeCallback;return t.completeCallback=function(){i&&i.apply(n,arguments),e?n.container.trigger("expanded"):n.container.trigger("collapsed")},e&&this.expanded.get()||!e&&!this.expanded.get()?(t.unchanged=!0,this.onChangeExpanded(this.expanded.get(),t),!1):(t.unchanged=!1,this.expandedArgumentsQueue.push(t),this.expanded.set(e),!0)},expand:function(e){return this._toggleExpanded(!0,e)},collapse:function(e){return this._toggleExpanded(!1,e)},focus:e}),f.Section=i.extend({initialize:function(e,t){var n=this;i.prototype.initialize.call(n,e,t),n.id=e,n.panel=new f.Value,n.panel.bind(function(e){p(n.container).toggleClass("control-subsection",!!e)}),n.panel.set(n.params.panel||""),f.utils.bubbleChildValueChanges(n,["panel"]),n.embed(),n.deferred.embedded.done(function(){n.ready()})},embed:function(){var n=this,e=function(e){var t;e?f.panel(e,function(e){e.deferred.embedded.done(function(){t=e.container.find("ul:first"),n.container.parent().is(t)||t.append(n.container),n.deferred.embedded.resolve()})}):(t=p("#customize-theme-controls").children("ul"),n.container.parent().is(t)||t.append(n.container),n.deferred.embedded.resolve())};n.panel.bind(e),e(n.panel.get())},attachEvents:function(){var t=this;t.container.find(".accordion-section-title").on("click keydown",function(e){f.utils.isKeydownButNotEnterEvent(e)||(e.preventDefault(),t.expanded()?t.collapse():t.expand())})},isContextuallyActive:function(){var e=this.controls(),t=0;return _(e).each(function(e){e.active()&&(t+=1)}),0!==t},controls:function(){return this._children("section","control")},onChangeExpanded:function(e,t){var n=this,i=n.container.find(".accordion-section-content");e?(e=t.unchanged?t.completeCallback:function(){i.stop().slideDown(t.duration,t.completeCallback),n.container.addClass("open")},t.allowMultiple||f.section.each(function(e){e!==n&&e.collapse({duration:t.duration})}),n.panel()?f.panel(n.panel()).expand({duration:t.duration,completeCallback:e}):e()):(n.container.removeClass("open"),i.slideUp(t.duration,t.completeCallback))}}),f.ThemesSection=f.Section.extend({currentTheme:"",overlay:"",template:"",screenshotQueue:null,$window:p(window),initialize:function(){return this.$customizeSidebar=p(".wp-full-overlay-sidebar-content:first"),f.Section.prototype.initialize.apply(this,arguments)},ready:function(){var t=this;t.overlay=t.container.find(".theme-overlay"),t.template=wp.template("customize-themes-details-view"),p("body").on("keyup",function(e){t.overlay.find(".theme-wrap").is(":visible")&&(39===e.keyCode&&t.nextTheme(),37===e.keyCode&&t.previousTheme(),27===e.keyCode&&t.closeDetails())}),_.bindAll(this,"renderScreenshots")},isContextuallyActive:function(){return this.active()},attachEvents:function(){var n=this;n.container.find(".change-theme, .customize-theme").on("click keydown",function(e){f.utils.isKeydownButNotEnterEvent(e)||(e.preventDefault(),n.expanded()?n.collapse():n.expand())}),n.container.on("click keydown",".left",function(e){f.utils.isKeydownButNotEnterEvent(e)||(e.preventDefault(),n.previousTheme())}),n.container.on("click keydown",".right",function(e){f.utils.isKeydownButNotEnterEvent(e)||(e.preventDefault(),n.nextTheme())}),n.container.on("click keydown",".theme-backdrop, .close",function(e){f.utils.isKeydownButNotEnterEvent(e)||(e.preventDefault(),n.closeDetails())});var i=_.throttle(_.bind(n.renderScreenshots,this),100);n.container.on("input","#themes-filter",function(e){var t=e.currentTarget.value.toLowerCase().trim().replace("-"," "),e=n.controls();_.each(e,function(e){e.filter(t)}),i(),e=n.container.find("li.customize-control:visible").length,n.container.find(".theme-count").text(e)}),f.bind("ready",function(){_.each(n.controls().slice(0,3),function(e){e=e.params.theme.screenshot[0];e&&((new Image).src=e)})})},onChangeExpanded:function(e,t){var n,i,o,a,r,s,c,l,d,u,h;t.unchanged?t.completeCallback&&t.completeCallback():(a=(o=this).container.closest(".accordion-section"),r=a.closest(".wp-full-overlay"),c=(s=a.closest(".wp-full-overlay-sidebar-content")).find(".open"),l=r.find("#customize-theme-controls > ul > .accordion-section > .accordion-section-title").add("#customize-info > .accordion-section-title"),d=a.find(".customize-theme"),u=a.find(".change-theme"),h=a.find(".control-panel-content"),e?(f.section.each(function(e){e!==o&&e.collapse({duration:t.duration})}),f.panel.each(function(e){e.collapse({duration:0})}),h.show(0,function(){n=h.offset().top,i=s.scrollTop(),h.css("margin-top",p("#customize-header-actions").height()-n-i),a.addClass("current-panel"),r.addClass("in-themes-panel"),s.scrollTop(0),_.delay(o.renderScreenshots,10),o.$customizeSidebar.on("scroll.customize-themes-section",_.throttle(o.renderScreenshots,300)),t.completeCallback&&t.completeCallback()}),l.attr("tabindex","-1"),u.attr("tabindex","-1"),d.focus()):(c.removeClass("open"),a.removeClass("current-panel"),r.removeClass("in-themes-panel"),o.$customizeSidebar.off("scroll.customize-themes-section"),h.delay(180).hide(0,function(){h.css("margin-top","inherit"),t.completeCallback&&t.completeCallback()}),l.attr("tabindex","0"),d.attr("tabindex","0"),u.focus(),s.scrollTop(0)))},renderScreenshots:function(){var r=this;null===r.screenshotQueue&&(r.screenshotQueue=r.controls()),r.screenshotQueue.length&&(r.screenshotQueue=_.filter(r.screenshotQueue,function(e){var t=e.container.find(".theme-screenshot"),n=t.find("img");if(!n.length)return!1;if(n.is(":hidden"))return!0;var i=r.$window.scrollTop(),o=i+r.$window.height(),a=n.offset().top,n=t.height(),t=3*n,t=i-t<=a+n&&a<=o+t;return t&&e.container.trigger("render-screenshot"),!t}))},nextTheme:function(){var e=this;e.getNextTheme()&&e.showDetails(e.getNextTheme(),function(){e.overlay.find(".right").focus()})},getNextTheme:function(){var e=f.control("theme_"+this.currentTheme),t=e.container.next("li.customize-control-theme");return!!t.length&&(t=t[0].id.replace("customize-control-",""),(e=f.control(t)).params.theme)},previousTheme:function(){var e=this;e.getPreviousTheme()&&e.showDetails(e.getPreviousTheme(),function(){e.overlay.find(".left").focus()})},getPreviousTheme:function(){var e=f.control("theme_"+this.currentTheme),t=e.container.prev("li.customize-control-theme");return!!t.length&&(t=t[0].id.replace("customize-control-",""),(e=f.control(t)).params.theme)},updateLimits:function(){this.getNextTheme()||this.overlay.find(".right").addClass("disabled"),this.getPreviousTheme()||this.overlay.find(".left").addClass("disabled")},showDetails:function(e,t){var n=this;t=t||function(){},n.currentTheme=e.id,n.overlay.html(n.template(e)).fadeIn("fast").focus(),p("body").addClass("modal-open"),n.containFocus(n.overlay),n.updateLimits(),t()},closeDetails:function(){p("body").removeClass("modal-open"),this.overlay.fadeOut("fast"),f.control("theme_"+this.currentTheme).focus()},containFocus:function(t){var n;t.on("keydown",function(e){if(9===e.keyCode)return(n=p(":tabbable",t)).last()[0]!==e.target||e.shiftKey?n.first()[0]===e.target&&e.shiftKey?(n.last().focus(),!1):void 0:(n.first().focus(),!1)})}}),f.Panel=i.extend({initialize:function(e,t){var n=this;i.prototype.initialize.call(n,e,t),n.embed(),n.deferred.embedded.done(function(){n.ready()})},embed:function(){var e=p("#customize-theme-controls > ul");this.container.parent().is(e)||e.append(this.container),this.deferred.embedded.resolve()},attachEvents:function(){var t,n=this;n.container.find(".accordion-section-title").on("click keydown",function(e){f.utils.isKeydownButNotEnterEvent(e)||(e.preventDefault(),n.expanded()||n.expand())}),(t=n.container.find(".panel-meta:first")).find("> .accordion-section-title").on("click keydown",function(e){f.utils.isKeydownButNotEnterEvent(e)||(e.preventDefault(),t.hasClass("cannot-expand")||(e=t.find(".accordion-section-content:first"),t.hasClass("open")?(t.toggleClass("open"),e.slideUp(n.defaultExpandedArguments.duration)):(e.slideDown(n.defaultExpandedArguments.duration),t.toggleClass("open"))))})},sections:function(){return this._children("panel","section")},isContextuallyActive:function(){var e=this.sections(),t=0;return _(e).each(function(e){e.active()&&e.isContextuallyActive()&&(t+=1)}),0!==t},onChangeExpanded:function(e,t){var n,i,o,a,r,s,c,l,d,u,h;t.unchanged?t.completeCallback&&t.completeCallback():(a=(o=this).container.closest(".accordion-section"),r=a.closest(".wp-full-overlay"),c=(s=a.closest(".wp-full-overlay-sidebar-content")).find(".open"),l=r.find("#customize-theme-controls > ul > .accordion-section > .accordion-section-title").add("#customize-info > .accordion-section-title"),d=r.find(".control-panel-back"),u=a.find(".accordion-section-title").first(),h=a.find(".control-panel-content"),e?(f.section.each(function(e){e.panel()||e.collapse({duration:0})}),f.panel.each(function(e){o!==e&&e.collapse({duration:0})}),h.show(0,function(){h.parent().show(),n=h.offset().top,i=s.scrollTop(),h.css("margin-top",p("#customize-header-actions").height()-n-i),a.addClass("current-panel"),r.addClass("in-sub-panel"),s.scrollTop(0),t.completeCallback&&t.completeCallback()}),l.attr("tabindex","-1"),d.attr("tabindex","0"),d.focus()):(c.removeClass("open"),a.removeClass("current-panel"),r.removeClass("in-sub-panel"),h.delay(180).hide(0,function(){h.css("margin-top","inherit"),t.completeCallback&&t.completeCallback()}),l.attr("tabindex","0"),d.attr("tabindex","-1"),u.focus(),s.scrollTop(0)))}}),f.Control=f.Class.extend({defaultActiveArguments:{duration:"fast",completeCallback:p.noop},initialize:function(e,t){var i,o,a=this;a.params={},p.extend(a,t||{}),a.id=e,a.selector="#customize-control-"+e.replace(/\]/g,"").replace(/\[/g,"-"),a.templateSelector="customize-control-"+a.params.type+"-content",a.container=a.params.content?p(a.params.content):p(a.selector),a.deferred={embedded:new p.Deferred},a.section=new f.Value,a.priority=new f.Value,a.active=new f.Value,a.activeArgumentsQueue=[],a.elements=[],i=a.container.find("[data-customize-setting-link]"),o={},i.each(function(){var e,n=p(this);if(n.is(":radio")){if(e=n.prop("name"),o[e])return;o[e]=!0,n=i.filter('[name="'+e+'"]')}f(n.data("customizeSettingLink"),function(e){var t=new f.Element(n);a.elements.push(t),t.sync(e),t.set(e())})}),a.active.bind(function(e){var t=a.activeArgumentsQueue.shift(),t=p.extend({},a.defaultActiveArguments,t);a.onChangeActive(e,t)}),a.section.set(a.params.section),a.priority.set(isNaN(a.params.priority)?10:a.params.priority),a.active.set(a.params.active),f.utils.bubbleChildValueChanges(a,["section","priority","active"]),e=p.map(a.params.settings,function(e){return e}),f.apply(f,e.concat(function(){for(var e in a.settings={},a.params.settings)a.settings[e]=f(a.params.settings[e]);a.setting=a.settings["default"]||null,a.embed()})),a.deferred.embedded.done(function(){a.ready()})},embed:function(){var n=this,e=function(e){var t;e&&f.section(e,function(e){e.deferred.embedded.done(function(){t=e.container.find("ul:first"),n.container.parent().is(t)||(t.append(n.container),n.renderContent()),n.deferred.embedded.resolve()})})};n.section.bind(e),e(n.section.get())},ready:function(){},expand:function(e){f.section(this.section()).expand(e)},focus:e,onChangeActive:function(e,t){p.contains(document,this.container)?e?this.container.slideDown(t.duration,t.completeCallback):this.container.slideUp(t.duration,t.completeCallback):(this.container.toggle(e),t.completeCallback&&t.completeCallback())},toggle:function(e){return this.onChangeActive(e,this.defaultActiveArguments)},activate:i.prototype.activate,deactivate:i.prototype.deactivate,_toggleActive:i.prototype._toggleActive,dropdownInit:function(){function e(e){"string"==typeof e&&i.statuses&&i.statuses[e]?n.html(i.statuses[e]).show():n.hide()}var t=this,n=this.container.find(".dropdown-status"),i=this.params,o=!1;this.container.on("click keydown",".dropdown",function(e){f.utils.isKeydownButNotEnterEvent(e)||(e.preventDefault(),o||t.container.toggleClass("open"),t.container.hasClass("open")&&t.container.parent().parent().find("li.library-selected").focus(),o=!0,setTimeout(function(){o=!1},400))}),this.setting.bind(e),e(this.setting())},renderContent:function(){var e,t=this;0!==p("#tmpl-"+t.templateSelector).length&&(e=wp.template(t.templateSelector))&&t.container&&t.container.html(e(t.params))}}),f.ColorControl=f.Control.extend({ready:function(){var e=this,t=this.container.find(".color-picker-hex");t.val(e.setting()).wpColorPicker({change:function(){e.setting.set(t.wpColorPicker("color"))},clear:function(){e.setting.set(!1)}}),this.setting.bind(function(e){t.val(e),t.wpColorPicker("color",e)})}}),f.MediaControl=f.Control.extend({ready:function(){var e=this;_.bindAll(e,"restoreDefault","removeFile","openFrame","select","pausePlayer"),e.container.on("click keydown",".upload-button",e.openFrame),e.container.on("click keydown",".upload-button",e.pausePlayer),e.container.on("click keydown",".thumbnail-image img",e.openFrame),e.container.on("click keydown",".default-button",e.restoreDefault),e.container.on("click keydown",".remove-button",e.pausePlayer),e.container.on("click keydown",".remove-button",e.removeFile),e.container.on("click keydown",".remove-button",e.cleanupPlayer),f.section(e.section()).container.on("expanded",function(){e.player&&e.player.setControlsSize()}).on("collapsed",function(){e.pausePlayer()}),e.setting.bind(function(){e.renderContent()})},pausePlayer:function(){this.player&&this.player.pause()},cleanupPlayer:function(){this.player&&wp.media.mixin.removePlayer(this.player)},openFrame:function(e){f.utils.isKeydownButNotEnterEvent(e)||(e.preventDefault(),this.frame||this.initFrame(),this.frame.open())},initFrame:function(){this.frame=wp.media({button:{text:this.params.button_labels.frame_button},states:[new wp.media.controller.Library({title:this.params.button_labels.frame_title,library:wp.media.query({type:this.params.mime_type}),multiple:!1,date:!1})]}),this.frame.on("select",this.select)},select:function(){var e=this.frame.state().get("selection").first().toJSON(),t=window._wpmejsSettings||{};this.params.attachment=e,this.setting(e.id),(e=this.container.find("audio, video").get(0))?this.player=new MediaElementPlayer(e,t):this.cleanupPlayer()},restoreDefault:function(e){f.utils.isKeydownButNotEnterEvent(e)||(e.preventDefault(),this.params.attachment=this.params.defaultAttachment,this.setting(this.params.defaultAttachment.url))},removeFile:function(e){f.utils.isKeydownButNotEnterEvent(e)||(e.preventDefault(),this.params.attachment={},this.setting(""),this.renderContent())}}),f.UploadControl=f.MediaControl.extend({select:function(){var e=this.frame.state().get("selection").first().toJSON(),t=window._wpmejsSettings||{};this.params.attachment=e,this.setting(e.url),(e=this.container.find("audio, video").get(0))?this.player=new MediaElementPlayer(e,t):this.cleanupPlayer()},success:function(){},removerVisibility:function(){}}),f.ImageControl=f.UploadControl.extend({thumbnailSrc:function(){}}),f.BackgroundControl=f.UploadControl.extend({ready:function(){f.UploadControl.prototype.ready.apply(this,arguments)},select:function(){f.UploadControl.prototype.select.apply(this,arguments),wp.ajax.post("custom-background-add",{nonce:_wpCustomizeBackground.nonces.add,wp_customize:"on",theme:f.settings.theme.stylesheet,attachment_id:this.params.attachment.id})}}),f.HeaderControl=f.Control.extend({ready:function(){this.btnRemove=p("#customize-control-header_image .actions .remove"),this.btnNew=p("#customize-control-header_image .actions .new"),_.bindAll(this,"openMedia","removeImage"),this.btnNew.on("click",this.openMedia),this.btnRemove.on("click",this.removeImage),f.HeaderTool.currentHeader=this.getInitialHeaderImage(),new f.HeaderTool.CurrentView({model:f.HeaderTool.currentHeader,el:"#customize-control-header_image .current .container"}),new f.HeaderTool.ChoiceListView({collection:f.HeaderTool.UploadsList=new f.HeaderTool.ChoiceList,el:"#customize-control-header_image .choices .uploaded .list"}),new f.HeaderTool.ChoiceListView({collection:f.HeaderTool.DefaultsList=new f.HeaderTool.DefaultsList,el:"#customize-control-header_image .choices .default .list"}),f.HeaderTool.combinedList=f.HeaderTool.CombinedList=new f.HeaderTool.CombinedList([f.HeaderTool.UploadsList,f.HeaderTool.DefaultsList])},getInitialHeaderImage:function(){if(!f.get().header_image||!f.get().header_image_data||_.contains(["remove-header","random-default-image","random-uploaded-image"],f.get().header_image))return new f.HeaderTool.ImageModel;var e=(e=_.find(_wpCustomizeHeader.uploads,function(e){return e.attachment_id===f.get().header_image_data.attachment_id}))||{url:f.get().header_image,thumbnail_url:f.get().header_image,attachment_id:f.get().header_image_data.attachment_id};return new f.HeaderTool.ImageModel({header:e,choice:e.url.split("/").pop()})},calculateImageSelectOptions:function(e,t){var n=parseInt(_wpCustomizeHeader.data.width,10),i=parseInt(_wpCustomizeHeader.data.height,10),o=!!parseInt(_wpCustomizeHeader.data["flex-width"],10),a=!!parseInt(_wpCustomizeHeader.data["flex-height"],10),r=e.get("width"),e=e.get("height");return this.headerImage=new f.HeaderTool.ImageModel,this.headerImage.set({themeWidth:n,themeHeight:i,themeFlexWidth:o,themeFlexHeight:a,imageWidth:r,imageHeight:e}),t.set("canSkipCrop",!this.headerImage.shouldBeCropped()),(t=n/i)<r/e?n=(i=e)*t:i=(n=r)/t,!(e={handles:!0,keys:!0,instance:!0,persistent:!0,imageWidth:r,imageHeight:e,x1:0,y1:0,x2:n,y2:i})==a&&!1==o&&(e.aspectRatio=n+":"+i),!1==a&&(e.maxHeight=i),!1==o&&(e.maxWidth=n),e},openMedia:function(e){var t=_wpMediaViewsL10n;e.preventDefault(),this.frame=wp.media({button:{text:t.selectAndCrop,close:!1},states:[new wp.media.controller.Library({title:t.chooseImage,library:wp.media.query({type:"image"}),multiple:!1,date:!1,priority:20,suggestedWidth:_wpCustomizeHeader.data.width,suggestedHeight:_wpCustomizeHeader.data.height}),new wp.media.controller.Cropper({imgSelectOptions:this.calculateImageSelectOptions})]}),this.frame.on("select",this.onSelect,this),this.frame.on("cropped",this.onCropped,this),this.frame.on("skippedcrop",this.onSkippedCrop,this),this.frame.open()},onSelect:function(){this.frame.setState("cropper")},onCropped:function(e){var t=e.post_content,n=e.attachment_id,i=e.width,e=e.height;this.setImageFromURL(t,n,i,e)},onSkippedCrop:function(e){var t=e.get("url"),n=e.get("width"),i=e.get("height");this.setImageFromURL(t,e.id,n,i)},setImageFromURL:function(e,t,n,i){var o={};o.url=e,o.thumbnail_url=e,o.timestamp=_.now(),t&&(o.attachment_id=t),n&&(o.width=n),i&&(o.height=i),e=new f.HeaderTool.ImageModel({header:o,choice:e.split("/").pop()}),f.HeaderTool.UploadsList.add(e),f.HeaderTool.currentHeader.set(e.toJSON()),e.save(),e.importImage()},removeImage:function(){f.HeaderTool.currentHeader.trigger("hide"),f.HeaderTool.CombinedList.trigger("control:removeImage")}}),f.ThemeControl=f.Control.extend({touchDrag:!1,isRendered:!1,renderContent:function(){var t=this,n=arguments;f.section(t.section(),function(e){e.expanded()?(f.Control.prototype.renderContent.apply(t,n),t.isRendered=!0):e.expanded.bind(function(e){e&&!t.isRendered&&(f.Control.prototype.renderContent.apply(t,n),t.isRendered=!0)})})},ready:function(){var t=this;t.container.on("touchmove",".theme",function(){t.touchDrag=!0}),t.container.on("click keydown touchend",".theme",function(e){if(!f.utils.isKeydownButNotEnterEvent(e)){if(!0===t.touchDrag)return t.touchDrag=!1;p(e.target).is(".theme-actions .button")||(e=p(this).data("previewUrl"),p(".wp-full-overlay").addClass("customize-loading"),window.parent.location=e)}}),t.container.on("click keydown",".theme-actions .theme-details",function(e){f.utils.isKeydownButNotEnterEvent(e)||(e.preventDefault(),f.section(t.section()).showDetails(t.params.theme))}),t.container.on("render-screenshot",function(){var e=p(this).find("img"),t=e.data("src");t&&e.attr("src",t)})},filter:function(e){var t=this;-1!==(t.params.theme.name+" "+t.params.theme.description+" "+t.params.theme.tags+" "+t.params.theme.author).toLowerCase().replace("-"," ").search(e)?t.activate():t.deactivate()}}),f.defaultConstructor=f.Setting,f.control=new f.Values({defaultConstructor:f.Control}),f.section=new f.Values({defaultConstructor:f.Section}),f.panel=new f.Values({defaultConstructor:f.Panel}),f.PreviewFrame=f.Messenger.extend({sensitivity:2e3,initialize:function(e,t){var n=p.Deferred();n.promise(this),this.container=e.container,this.signature=e.signature,p.extend(e,{channel:f.PreviewFrame.uuid()}),f.Messenger.prototype.initialize.call(this,e,t),this.add("previewUrl",e.previewUrl),this.query=p.extend(e.query||{},{customize_messenger_channel:this.channel()}),this.run(n)},run:function(i){var o=this,a=!1,r=!1;this._ready&&this.unbind("ready",this._ready),this._ready=function(){r=!0,a&&i.resolveWith(o)},this.bind("ready",this._ready),this.bind("ready",function(e){this.container.addClass("iframe-ready"),e&&(e={panel:e.activePanels,section:e.activeSections,control:e.activeControls},_(e).each(function(n,e){f[e].each(function(e,t){t=!(!n||!n[t]);e.active(t)})}))}),this.request=p.ajax(this.previewUrl(),{type:"POST",data:this.query,xhrFields:{withCredentials:!0}}),this.request.fail(function(){i.rejectWith(o,["request failure"])}),this.request.done(function(e){var t=o.request.getResponseHeader("Location"),n=o.signature;t&&t!==o.previewUrl()?i.rejectWith(o,["redirect",t]):"0"!==e?"-1"!==e?-1===(t=e.lastIndexOf(n))||t<e.lastIndexOf("</html>")?i.rejectWith(o,["unsigned"]):(e=e.slice(0,t)+e.slice(t+n.length),o.iframe=p("<iframe />",{title:f.l10n.previewIframeTitle}).appendTo(o.container),o.iframe.one("load",function(){a=!0,r?i.resolveWith(o):setTimeout(function(){i.rejectWith(o,["ready timeout"])},o.sensitivity)}),o.targetWindow(o.iframe[0].contentWindow),o.targetWindow().document.open(),o.targetWindow().document.write(e),o.targetWindow().document.close()):i.rejectWith(o,["cheatin"]):o.login(i)})},login:function(n){var i=this,o=function(){n.rejectWith(i,["logged out"])};if(this.triedLogin)return o();p.get(f.settings.url.ajax,{action:"logged-in"}).fail(o).done(function(e){var t;"1"!==e&&o(),(t=p("<iframe />",{src:i.previewUrl(),title:f.l10n.previewIframeTitle}).hide()).appendTo(i.container),t.load(function(){i.triedLogin=!0,t.remove(),i.run(n)})})},destroy:function(){f.Messenger.prototype.destroy.call(this),this.request.abort(),this.iframe&&this.iframe.remove(),delete this.request,delete this.iframe,delete this.targetWindow}}),t=0,f.PreviewFrame.uuid=function(){return"preview-"+t++},f.setDocumentTitle=function(e){e=f.settings.documentTitleTmpl.replace("%s",e);document.title=e,f.trigger("title",e)},f.Previewer=f.Messenger.extend({refreshBuffer:250,initialize:function(e,t){var n,i,o,a=this,r=/^https?/;function s(){i=null,o.call(n)}p.extend(this,t||{}),this.deferred={active:p.Deferred()},this.refresh=(o=(n=this).refresh,function(){if("number"!=typeof i){if(!n.loading)return s();n.abort()}clearTimeout(i),i=setTimeout(s,n.refreshBuffer)}),this.container=f.ensure(e.container),this.allowedUrls=e.allowedUrls,this.signature=e.signature,e.url=window.location.href,f.Messenger.prototype.initialize.call(this,e),this.add("scheme",this.origin()).link(this.origin).setter(function(e){e=e.match(r);return e?e[0]:""}),this.add("previewUrl",e.previewUrl).setter(function(e){var o;return/\/wp-admin(\/|$)/.test(e.replace(/[#?].*$/,""))?null:(p.each([e.replace(r,a.scheme()),e],function(e,i){if(p.each(a.allowedUrls,function(e,t){var n;if(t=t.replace(/\/+$/,""),n=i.replace(t,""),0===i.indexOf(t)&&/^([/#?]|$)/.test(n))return o=i,!1}),o)return!1}),o||null)}),this.previewUrl.bind(this.refresh),this.scroll=0,this.bind("scroll",function(e){this.scroll=e}),this.bind("url",this.previewUrl),this.bind("documentTitle",function(e){f.setDocumentTitle(e)})},query:function(){},abort:function(){this.loading&&(this.loading.destroy(),delete this.loading)},refresh:function(){var n=this;this.send("loading-initiated"),this.abort(),this.loading=new f.PreviewFrame({url:this.url(),previewUrl:this.previewUrl(),query:this.query()||{},container:this.container,signature:this.signature}),this.loading.done(function(){this.bind("synced",function(){n.preview&&n.preview.destroy(),n.preview=this,delete n.loading,n.targetWindow(this.targetWindow()),n.channel(this.channel()),n.deferred.active.resolve(),n.send("active")}),this.send("sync",{scroll:n.scroll,settings:f.get()})}),this.loading.fail(function(e,t){n.send("loading-failed"),"redirect"===e&&t&&n.previewUrl(t),"logged out"===e&&(n.preview&&(n.preview.destroy(),delete n.preview),n.login().done(n.refresh)),"cheatin"===e&&n.cheatin()})},login:function(){var t,n,i,o=this;return this._login||(t=p.Deferred(),this._login=t.promise(),n=new f.Messenger({channel:"login",url:f.settings.url.login}),i=p("<iframe />",{src:f.settings.url.login,title:f.l10n.loginIframeTitle}).appendTo(this.container),n.targetWindow(i[0].contentWindow),n.bind("login",function(){var e=o.refreshNonces();e.always(function(){i.remove(),n.destroy(),delete o._login}),e.done(function(){t.resolve()}),e.fail(function(){o.cheatin(),t.reject()})}),this._login)},cheatin:function(){p(document.body).empty().addClass("cheatin").append("<p>"+f.l10n.cheatin+"</p>")},refreshNonces:function(){var e,t=p.Deferred();return t.promise(),(e=wp.ajax.post("customize_refresh_nonces",{wp_customize:"on",theme:f.settings.theme.stylesheet})).done(function(e){f.trigger("nonce-refresh",e),t.resolve()}),e.fail(function(){t.reject()}),t}}),f.controlConstructor={color:f.ColorControl,media:f.MediaControl,upload:f.UploadControl,image:f.ImageControl,header:f.HeaderControl,background:f.BackgroundControl,theme:f.ThemeControl},f.panelConstructor={},f.sectionConstructor={themes:f.ThemesSection},p(function(){if(f.settings=window._wpCustomizeSettings,f.l10n=window._wpCustomizeControlsL10n,f.settings){if(!p.support.postMessage||!p.support.cors&&f.settings.isCrossDomain)return window.location=f.settings.url.fallback;var n,e,t,i,o,a,r=p(document.body),s=r.children(".wp-full-overlay"),c=p("#customize-info .theme-name.site-title"),l=p(".customize-controls-close"),d=p("#save");p("#customize-controls").on("keydown",function(e){var t=13===e.which,n=p(e.target);t&&(n.is("input:not([type=button])")||n.is("select"))&&e.preventDefault()}),p("#customize-info").find("> .accordion-section-title").on("click keydown",function(e){var t;f.utils.isKeydownButNotEnterEvent(e)||(e.preventDefault(),e=(t=p(this).parent()).find(".accordion-section-content:first"),t.hasClass("cannot-expand")||(t.hasClass("open")?(t.toggleClass("open"),e.slideUp(f.Panel.prototype.defaultExpandedArguments.duration)):(e.slideDown(f.Panel.prototype.defaultExpandedArguments.duration),t.toggleClass("open"))))}),f.previewer=new f.Previewer({container:"#customize-preview",form:"#customize-controls",previewUrl:f.settings.url.preview,allowedUrls:f.settings.url.allowed,signature:"WP_CUSTOMIZER_SIGNATURE"},{nonce:f.settings.nonce,query:function(){var n={};return f.each(function(e,t){e._dirty&&(n[t]=e())}),{wp_customize:"on",theme:f.settings.theme.stylesheet,customized:JSON.stringify(n),nonce:this.nonce.preview}},save:function(){var e,t,n=this,i=f.state("processing");r.addClass("saving"),t=function(){var e=p.extend(n.query(),{nonce:n.nonce.save}),e=wp.ajax.post("customize_save",e);f.trigger("save",e),e.always(function(){r.removeClass("saving")}),e.fail(function(e){"0"===e?e="not_logged_in":"-1"===e&&(e="invalid_nonce"),"invalid_nonce"===e?n.cheatin():"not_logged_in"===e&&(n.preview.iframe.hide(),n.login().done(function(){n.save(),n.preview.iframe.show()})),f.trigger("error",e)}),e.done(function(e){f.each(function(e){e._dirty=!1}),f.trigger("saved",e)})},0===i()?t():(e=function(){0===i()&&(f.state.unbind("change",e),t())},f.state.bind("change",e))}}),p.ajaxPrefilter(function(e){/wp_customize=on/.test(e.data)&&(e.data+="&"+p.param({customize_preview_nonce:f.settings.nonce.preview}))}),f.previewer.bind("nonce",function(e){p.extend(this.nonce,e)}),f.bind("nonce-refresh",function(e){p.extend(f.settings.nonce,e),p.extend(f.previewer.nonce,e)}),p.each(f.settings.settings,function(e,t){f.create(e,e,t.value,{transport:t.transport,previewer:f.previewer,dirty:!!t.dirty})}),p.each(f.settings.panels,function(e,t){t=new(f.panelConstructor[t.type]||f.Panel)(e,{params:t});f.panel.add(e,t)}),p.each(f.settings.sections,function(e,t){t=new(f.sectionConstructor[t.type]||f.Section)(e,{params:t});f.section.add(e,t)}),p.each(f.settings.controls,function(e,t){t=new(f.controlConstructor[t.type]||f.Control)(e,{params:t,previewer:f.previewer});f.control.add(e,t)}),_.each(["panel","section","control"],function(e){var t,n=f.settings.autofocus[e];n&&f[e](n)&&(t=f[e](n)).deferred.embedded.done(function(){f.previewer.deferred.active.done(function(){t.focus()})})}),f.reflowPaneContents=_.bind(function(){var i,e,t,o=[],a=!1;document.activeElement&&(e=p(document.activeElement)),f.panel.each(function(e){var t=e.sections(),n=_.pluck(t,"container");o.push(e),i=e.container.find("ul:first"),f.utils.areElementListsEqual(n,i.children("[id]"))||(_(t).each(function(e){i.append(e.container)}),a=!0)}),f.section.each(function(e){var t=e.controls(),n=_.pluck(t,"container");e.panel()||o.push(e),i=e.container.find("ul:first"),f.utils.areElementListsEqual(n,i.children("[id]"))||(_(t).each(function(e){i.append(e.container)}),a=!0)}),o.sort(f.utils.prioritySort),t=_.pluck(o,"container"),i=p("#customize-theme-controls").children("ul"),f.utils.areElementListsEqual(t,i.children())||(_(o).each(function(e){i.append(e.container)}),a=!0),f.panel.each(function(e){var t=e.active();e.active.callbacks.fireWith(e.active,[t,t])}),f.section.each(function(e){var t=e.active();e.active.callbacks.fireWith(e.active,[t,t])}),a&&e&&e.focus()},f),f.bind("ready",f.reflowPaneContents),f.reflowPaneContents=_.debounce(f.reflowPaneContents,100),p([f.panel,f.section,f.control]).each(function(e,t){t.bind("add",f.reflowPaneContents),t.bind("change",f.reflowPaneContents),t.bind("remove",f.reflowPaneContents)}),f.previewer.previewUrl()?f.previewer.refresh():f.previewer.previewUrl(f.settings.url.home),t=new f.Values,i=t.create("saved"),o=t.create("activated"),a=t.create("processing"),t.bind("change",function(){o()?i()?(d.val(f.l10n.saved).prop("disabled",!0),l.find(".screen-reader-text").text(f.l10n.close)):(d.val(f.l10n.save).prop("disabled",!1),l.find(".screen-reader-text").text(f.l10n.cancel)):(d.val(f.l10n.activate).prop("disabled",!1),l.find(".screen-reader-text").text(f.l10n.cancel))}),i(!0),o(f.settings.theme.active),a(0),f.bind("change",function(){t("saved").set(!1)}),f.bind("saved",function(){t("saved").set(!0),t("activated").set(!0)}),o.bind(function(e){e&&f.trigger("activated")}),f.state=t,d.click(function(e){f.previewer.save(),e.preventDefault()}).keydown(function(e){9!==e.which&&(13===e.which&&f.previewer.save(),e.preventDefault())}),p("#customize-header-actions").on("click keydown",".control-panel-back",function(e){f.utils.isKeydownButNotEnterEvent(e)||(e.preventDefault(),f.panel.each(function(e){e.collapse()}))}),l.keydown(function(e){9!==e.which&&(13===e.which&&this.click(),e.preventDefault())}),p(".collapse-sidebar").on("click keydown",function(e){f.utils.isKeydownButNotEnterEvent(e)||(s.toggleClass("collapsed").toggleClass("expanded"),e.preventDefault())}),p(".customize-controls-preview-toggle").on("click keydown",function(e){f.utils.isKeydownButNotEnterEvent(e)||(s.toggleClass("preview-only"),e.preventDefault())}),c.length&&p("#customize-control-blogname input").on("input",function(){c.text(this.value)}),(n=new f.Messenger({url:f.settings.url.parent,channel:"loader"})).bind("back",function(){l.on("click.customize-controls-close",function(e){e.preventDefault(),n.send("close")})}),p(window).on("beforeunload",function(){if(!f.state("saved")())return setTimeout(function(){s.removeClass("customize-loading")},1),f.l10n.saveAlert}),p.each(["saved","change"],function(e,t){f.bind(t,function(){n.send(t)})}),f.bind("activated",function(){n.targetWindow()?n.send("activated",f.settings.url.activated):f.settings.url.activated&&(window.location=f.settings.url.activated)}),f.bind("title",function(e){n.send("title",e)}),n.send("ready"),p.each({background_image:{controls:["background_repeat","background_position_x","background_attachment"],callback:function(e){return!!e}},show_on_front:{controls:["page_on_front","page_for_posts"],callback:function(e){return"page"===e}},header_textcolor:{controls:["header_textcolor"],callback:function(e){return"blank"!==e}}},function(e,i){f(e,function(n){p.each(i.controls,function(e,t){f.control(t,function(t){function e(e){t.container.toggle(i.callback(e))}e(n.get()),n.bind(e)})})})}),f.control("display_header_text",function(t){var n="";t.elements[0].unsync(f("header_textcolor")),t.element=new f.Element(t.container.find("input")),t.element.set("blank"!==t.setting()),t.element.bind(function(e){e||(n=f("header_textcolor").get()),t.setting.set(e?n:"blank")}),t.setting.bind(function(e){t.element.set("blank"!==e)})}),f.trigger("ready"),(e=l).focus(),setTimeout(function(){e.focus()},200)}})}((wp,jQuery));