diff --git a/wp-admin/js/customize-controls.js b/wp-admin/js/customize-controls.js index 275424e0d4..0ea60ceee2 100644 --- a/wp-admin/js/customize-controls.js +++ b/wp-admin/js/customize-controls.js @@ -869,6 +869,11 @@ control.setting.set( false ); } }); + + this.setting.bind( function ( value ) { + picker.val( value ); + picker.wpColorPicker( 'color', value ); + }); } }); diff --git a/wp-admin/js/customize-controls.min.js b/wp-admin/js/customize-controls.min.js index 5232df0e26..125fa49305 100644 --- a/wp-admin/js/customize-controls.min.js +++ b/wp-admin/js/customize-controls.min.js @@ -1 +1 @@ -!function(a,b){var c,d,e,f,g,h=wp.customize;h.Setting=h.Value.extend({initialize:function(a,b,c){h.Value.prototype.initialize.call(this,b,c),this.id=a,this.transport=this.transport||"refresh",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()])}}}),c=function(a,c){b.each(c,function(b,c){a[c].bind(function(b,c){a.parent&&b!==c&&a.parent.trigger("change",a)})})},e=function(a){var b,c,d;b=this,a=a||{},d=function(){b.container.find(":focusable:first").focus(),b.container[0].scrollIntoView(!0)},a.completeCallback?(c=a.completeCallback,a.completeCallback=function(){d(),c()}):a.completeCallback=d,b.expand?b.expand(a):a.completeCallback()},f=function(a){return"keydown"===a.type&&13!==a.which},g=function(a,c){var d=a.length===c.length&&-1===_.map(_.zip(a,c),function(a){return b(a[0]).is(a[1])}).indexOf(!1);return d},d=h.Class.extend({defaultActiveArguments:{duration:"fast"},defaultExpandedArguments:{duration:"fast"},initialize:function(a,d){var e=this;e.id=a,e.params={},b.extend(e,d||{}),e.container=b(e.params.content),e.deferred={ready:new b.Deferred},e.priority=new h.Value,e.active=new h.Value,e.activeArgumentsQueue=[],e.expanded=new h.Value,e.expandedArgumentsQueue=[],e.active.bind(function(a){var c=e.activeArgumentsQueue.shift();c=b.extend({},e.defaultActiveArguments,c),a=a&&e.isContextuallyActive(),e.onChangeActive(a,c)}),e.expanded.bind(function(a){var c=e.expandedArgumentsQueue.shift();c=b.extend({},e.defaultExpandedArguments,c),e.onChangeExpanded(a,c)}),e.attachEvents(),c(e,["priority","active"]),e.priority.set(isNaN(e.params.priority)?100:e.params.priority),e.active.set(e.params.active),e.expanded.set(!1)},ready:function(){},_children:function(a,b){var c=this,d=[];return h[b].each(function(b){b[a].get()===c.id&&d.push(b)}),d.sort(function(a,b){return a.priority()-b.priority()}),d},isContextuallyActive:function(){throw new Error("Must override with subclass.")},onChangeActive:function(a,b){var c="resolved"===h.previewer.deferred.active.state()?b.duration:0;a?this.container.stop(!0,!0).slideDown(c,b.completeCallback):this.container.stop(!0,!0).slideUp(c,b.completeCallback)},_toggleActive:function(a,b){var c=this;return b=b||{},a&&this.active.get()||!a&&!this.active.get()?(b.unchanged=!0,c.onChangeActive(c.active.get(),b),!1):(b.unchanged=!1,this.activeArgumentsQueue.push(b),this.active.set(a),!0)},activate:function(a){return this._toggleActive(!0,a)},deactivate:function(a){return this._toggleActive(!1,a)},onChangeExpanded:function(){throw new Error("Must override with subclass.")},_toggleExpanded:function(a,b){var c=this;return b=b||{},a&&this.expanded.get()||!a&&!this.expanded.get()?(b.unchanged=!0,c.onChangeExpanded(c.expanded.get(),b),!1):(b.unchanged=!1,this.expandedArgumentsQueue.push(b),this.expanded.set(a),!0)},expand:function(a){return this._toggleExpanded(!0,a)},collapse:function(a){return this._toggleExpanded(!1,a)},focus:e}),h.Section=d.extend({initialize:function(a,e){var f=this;d.prototype.initialize.call(f,a,e),f.id=a,f.panel=new h.Value,f.panel.bind(function(a){b(f.container).toggleClass("control-subsection",!!a)}),f.panel.set(f.params.panel||""),c(f,["panel"]),f.embed(),f.deferred.ready.done(function(){f.ready()})},embed:function(){var a,c=this;a=function(a){var d;a?h.panel(a,function(a){a.deferred.ready.done(function(){d=a.container.find("ul:first"),c.container.parent().is(d)||d.append(c.container),c.deferred.ready.resolve()})}):(d=b("#customize-theme-controls").children("ul"),c.container.parent().is(d)||d.append(c.container),c.deferred.ready.resolve())},c.panel.bind(a),a(c.panel.get())},attachEvents:function(){var a=this;a.container.find(".accordion-section-title").on("click keydown",function(b){f(b)||(b.preventDefault(),a.expanded()?a.collapse():a.expand())})},isContextuallyActive:function(){var a=this,b=a.controls(),c=0;return _(b).each(function(a){a.active()&&(c+=1)}),0!==c},controls:function(){return this._children("section","control")},onChangeExpanded:function(a,b){var c,d=this,e=d.container.find(".accordion-section-content");a?(c=b.unchanged?b.completeCallback:function(){e.stop().slideDown(b.duration,b.completeCallback),d.container.addClass("open")},b.allowMultiple||h.section.each(function(a){a!==d&&a.collapse({duration:b.duration})}),d.panel()?h.panel(d.panel()).expand({duration:b.duration,completeCallback:c}):c()):(d.container.removeClass("open"),e.slideUp(b.duration,b.completeCallback))}}),h.Panel=d.extend({initialize:function(a,b){var c=this;d.prototype.initialize.call(c,a,b),c.embed(),c.deferred.ready.done(function(){c.ready()})},embed:function(){var a=this,c=b("#customize-theme-controls > ul");a.container.parent().is(c)||c.append(a.container),a.deferred.ready.resolve()},attachEvents:function(){var a,b=this;b.container.find(".accordion-section-title").on("click keydown",function(a){f(a)||(a.preventDefault(),b.expanded()||b.expand())}),a=b.container.find(".panel-meta:first"),a.find("> .accordion-section-title").on("click keydown",function(c){if(!f(c)&&(c.preventDefault(),!a.hasClass("cannot-expand"))){var d=a.find(".accordion-section-content:first");a.hasClass("open")?(a.toggleClass("open"),d.slideUp(b.defaultExpandedArguments.duration)):(d.slideDown(b.defaultExpandedArguments.duration),a.toggleClass("open"))}})},sections:function(){return this._children("panel","section")},isContextuallyActive:function(){var a=this,b=a.sections(),c=0;return _(b).each(function(a){a.active()&&a.isContextuallyActive()&&(c+=1)}),0!==c},onChangeExpanded:function(a,b){if(b.unchanged)return void(b.completeCallback&&b.completeCallback());var c,d,e=this,f=e.container.closest(".accordion-section"),g=f.closest(".wp-full-overlay"),i=f.closest(".accordion-container"),j=i.find(".open"),k=g.find("#customize-theme-controls > ul > .accordion-section > .accordion-section-title").add("#customize-info > .accordion-section-title"),l=g.find(".control-panel-back"),m=f.find(".accordion-section-title").first(),n=f.find(".control-panel-content");a?(h.section.each(function(a){a.panel()||a.collapse({duration:0})}),h.panel.each(function(a){e!==a&&a.collapse({duration:0})}),n.show(0,function(){c=n.offset().top,d=i.scrollTop(),n.css("margin-top",45-c-d),f.addClass("current-panel"),g.addClass("in-sub-panel"),i.scrollTop(0),b.completeCallback&&b.completeCallback()}),k.attr("tabindex","-1"),l.attr("tabindex","0"),l.focus()):(j.removeClass("open"),f.removeClass("current-panel"),g.removeClass("in-sub-panel"),n.delay(180).hide(0,function(){n.css("margin-top","inherit"),b.completeCallback&&b.completeCallback()}),k.attr("tabindex","0"),l.attr("tabindex","-1"),m.focus(),i.scrollTop(0))}}),h.Control=h.Class.extend({defaultActiveArguments:{duration:"fast"},initialize:function(a,d){var e,f,g,i=this;i.params={},b.extend(i,d||{}),i.id=a,i.selector="#customize-control-"+a.replace(/\]/g,"").replace(/\[/g,"-"),i.templateSelector="customize-control-"+i.params.type+"-content",i.container=b(i.params.content?i.params.content:i.selector),i.deferred={ready:new b.Deferred},i.section=new h.Value,i.priority=new h.Value,i.active=new h.Value,i.activeArgumentsQueue=[],i.elements=[],e=i.container.find("[data-customize-setting-link]"),f={},e.each(function(){var a,c=b(this);if(c.is(":radio")){if(a=c.prop("name"),f[a])return;f[a]=!0,c=e.filter('[name="'+a+'"]')}h(c.data("customizeSettingLink"),function(a){var b=new h.Element(c);i.elements.push(b),b.sync(a),b.set(a())})}),i.active.bind(function(a){var c=i.activeArgumentsQueue.shift();c=b.extend({},i.defaultActiveArguments,c),i.onChangeActive(a,c)}),i.section.set(i.params.section),i.priority.set(isNaN(i.params.priority)?10:i.params.priority),i.active.set(i.params.active),c(i,["section","priority","active"]),g=b.map(i.params.settings,function(a){return a}),h.apply(h,g.concat(function(){var a;i.settings={};for(a in i.params.settings)i.settings[a]=h(i.params.settings[a]);i.setting=i.settings["default"]||null,i.embed()})),i.deferred.ready.done(function(){i.ready()})},embed:function(){var a,b=this;a=function(a){var c;a&&h.section(a,function(a){a.deferred.ready.done(function(){c=a.container.find("ul:first"),b.container.parent().is(c)||(c.append(b.container),b.renderContent()),b.deferred.ready.resolve()})})},b.section.bind(a),a(b.section.get())},ready:function(){},expand:function(a){h.section(this.section()).expand(a)},focus:e,onChangeActive:function(a,b){a?this.container.slideDown(b.duration,b.completeCallback):this.container.slideUp(b.duration,b.completeCallback)},toggle:function(a){return this.onChangeActive(a,this.defaultActiveArguments)},activate:d.prototype.activate,deactivate:d.prototype.deactivate,dropdownInit:function(){var a=this,b=this.container.find(".dropdown-status"),c=this.params,d=!1,e=function(a){"string"==typeof a&&c.statuses&&c.statuses[a]?b.html(c.statuses[a]).show():b.hide()};this.container.on("click keydown",".dropdown",function(b){f(b)||(b.preventDefault(),d||a.container.toggleClass("open"),a.container.hasClass("open")&&a.container.parent().parent().find("li.library-selected").focus(),d=!0,setTimeout(function(){d=!1},400))}),this.setting.bind(e),e(this.setting())},renderContent:function(){var a,c=this;0!==b("#tmpl-"+c.templateSelector).length&&(a=wp.template(c.templateSelector),a&&c.container&&c.container.append(a(c.params)))}}),h.ColorControl=h.Control.extend({ready:function(){var a=this,b=this.container.find(".color-picker-hex");b.val(a.setting()).wpColorPicker({change:function(){a.setting.set(b.wpColorPicker("color"))},clear:function(){a.setting.set(!1)}})}}),h.UploadControl=h.Control.extend({ready:function(){var a=this;this.params.removed=this.params.removed||"",this.success=b.proxy(this.success,this),this.uploader=b.extend({container:this.container,browser:this.container.find(".upload"),dropzone:this.container.find(".upload-dropzone"),success:this.success,plupload:{},params:{}},this.uploader||{}),a.params.extensions&&(a.uploader.plupload.filters=[{title:h.l10n.allowedFiles,extensions:a.params.extensions}]),a.params.context&&(a.uploader.params["post_data[context]"]=this.params.context),h.settings.theme.stylesheet&&(a.uploader.params["post_data[theme]"]=h.settings.theme.stylesheet),this.uploader=new wp.Uploader(this.uploader),this.remover=this.container.find(".remove"),this.remover.on("click keydown",function(b){f(b)||(a.setting.set(a.params.removed),b.preventDefault())}),this.removerVisibility=b.proxy(this.removerVisibility,this),this.setting.bind(this.removerVisibility),this.removerVisibility(this.setting.get())},success:function(a){this.setting.set(a.get("url"))},removerVisibility:function(a){this.remover.toggle(a!=this.params.removed)}}),h.ImageControl=h.UploadControl.extend({ready:function(){var a,c=this;this.uploader={init:function(){var a,b;this.supports.dragdrop||(a=c.container.find(".upload-fallback"),b=a.children().detach(),this.browser.detach().empty().append(b),a.append(this.browser).show())}},h.UploadControl.prototype.ready.call(this),this.thumbnail=this.container.find(".preview-thumbnail img"),this.thumbnailSrc=b.proxy(this.thumbnailSrc,this),this.setting.bind(this.thumbnailSrc),this.library=this.container.find(".library"),this.tabs={},a=this.library.find(".library-content"),this.library.children("ul").children("li").each(function(){var d=b(this),e=d.data("customizeTab"),f=a.filter('[data-customize-tab="'+e+'"]');c.tabs[e]={both:d.add(f),link:d,panel:f}}),this.library.children("ul").on("click keydown","li",function(a){if(!f(a)){var d=b(this).data("customizeTab"),e=c.tabs[d];a.preventDefault(),e.link.hasClass("library-selected")||(c.selected.both.removeClass("library-selected"),c.selected=e,c.selected.both.addClass("library-selected"))}}),this.library.on("click keydown","a",function(a){if(!f(a)){var d=b(this).data("customizeImageValue");d&&(c.setting.set(d),a.preventDefault())}}),this.tabs.uploaded&&(this.tabs.uploaded.target=this.library.find(".uploaded-target"),this.tabs.uploaded.panel.find(".thumbnail").length||this.tabs.uploaded.both.addClass("hidden")),a.each(function(){var a=c.tabs[b(this).data("customizeTab")];return a.link.hasClass("hidden")?void 0:(c.selected=a,a.both.addClass("library-selected"),!1)}),this.dropdownInit()},success:function(a){h.UploadControl.prototype.success.call(this,a),this.tabs.uploaded&&this.tabs.uploaded.target.length&&(this.tabs.uploaded.both.removeClass("hidden"),a.element=b('').data("customizeImageValue",a.get("url")).append('').appendTo(this.tabs.uploaded.target))},thumbnailSrc:function(a){/^(https?:)?\/\//.test(a)?this.thumbnail.prop("src",a).show():this.thumbnail.hide()}}),h.HeaderControl=h.Control.extend({ready:function(){this.btnRemove=b("#customize-control-header_image .actions .remove"),this.btnNew=b("#customize-control-header_image .actions .new"),_.bindAll(this,"openMedia","removeImage"),this.btnNew.on("click",this.openMedia),this.btnRemove.on("click",this.removeImage),h.HeaderTool.currentHeader=new h.HeaderTool.ImageModel,new h.HeaderTool.CurrentView({model:h.HeaderTool.currentHeader,el:".current .container"}),new h.HeaderTool.ChoiceListView({collection:h.HeaderTool.UploadsList=new h.HeaderTool.ChoiceList,el:".choices .uploaded .list"}),new h.HeaderTool.ChoiceListView({collection:h.HeaderTool.DefaultsList=new h.HeaderTool.DefaultsList,el:".choices .default .list"}),h.HeaderTool.combinedList=h.HeaderTool.CombinedList=new h.HeaderTool.CombinedList([h.HeaderTool.UploadsList,h.HeaderTool.DefaultsList])},calculateImageSelectOptions:function(a,b){var c,d,e,f,g,i,j=parseInt(_wpCustomizeHeader.data.width,10),k=parseInt(_wpCustomizeHeader.data.height,10),l=!!parseInt(_wpCustomizeHeader.data["flex-width"],10),m=!!parseInt(_wpCustomizeHeader.data["flex-height"],10);return g=a.get("width"),f=a.get("height"),this.headerImage=new h.HeaderTool.ImageModel,this.headerImage.set({themeWidth:j,themeHeight:k,themeFlexWidth:l,themeFlexHeight:m,imageWidth:g,imageHeight:f}),b.set("canSkipCrop",!this.headerImage.shouldBeCropped()),c=j/k,d=g,e=f,d/e>c?(k=e,j=k*c):(j=d,k=j/c),i={handles:!0,keys:!0,instance:!0,persistent:!0,imageWidth:g,imageHeight:f,x1:0,y1:0,x2:j,y2:k},m===!1&&l===!1&&(i.aspectRatio=j+":"+k),m===!1&&(i.maxHeight=k),l===!1&&(i.maxWidth=j),i},openMedia:function(a){var b=_wpMediaViewsL10n;a.preventDefault(),this.frame=wp.media({button:{text:b.selectAndCrop,close:!1},states:[new wp.media.controller.Library({title:b.chooseImage,library:wp.media.query({type:"image"}),multiple:!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(a){var b=a.post_content,c=a.attachment_id,d=a.width,e=a.height;this.setImageFromURL(b,c,d,e)},onSkippedCrop:function(a){var b=a.get("url"),c=a.get("width"),d=a.get("height");this.setImageFromURL(b,a.id,c,d)},setImageFromURL:function(a,b,c,d){var e,f={};f.url=a,f.thumbnail_url=a,f.timestamp=_.now(),b&&(f.attachment_id=b),c&&(f.width=c),d&&(f.height=d),e=new h.HeaderTool.ImageModel({header:f,choice:a.split("/").pop()}),h.HeaderTool.UploadsList.add(e),h.HeaderTool.currentHeader.set(e.toJSON()),e.save(),e.importImage()},removeImage:function(){h.HeaderTool.currentHeader.trigger("hide"),h.HeaderTool.CombinedList.trigger("control:removeImage")}}),h.defaultConstructor=h.Setting,h.control=new h.Values({defaultConstructor:h.Control}),h.section=new h.Values({defaultConstructor:h.Section}),h.panel=new h.Values({defaultConstructor:h.Panel}),h.PreviewFrame=h.Messenger.extend({sensitivity:2e3,initialize:function(a,c){var d=b.Deferred();d.promise(this),this.container=a.container,this.signature=a.signature,b.extend(a,{channel:h.PreviewFrame.uuid()}),h.Messenger.prototype.initialize.call(this,a,c),this.add("previewUrl",a.previewUrl),this.query=b.extend(a.query||{},{customize_messenger_channel:this.channel()}),this.run(d)},run:function(a){var c=this,d=!1,e=!1;this._ready&&this.unbind("ready",this._ready),this._ready=function(){e=!0,d&&a.resolveWith(c)},this.bind("ready",this._ready),this.bind("ready",function(a){if(a){var c={panel:a.activePanels,section:a.activeSections,control:a.activeControls};b.each(c,function(a,c){c&&b.each(c,function(b,c){var d=h[a](b);d&&d.active(c)})})}}),this.request=b.ajax(this.previewUrl(),{type:"POST",data:this.query,xhrFields:{withCredentials:!0}}),this.request.fail(function(){a.rejectWith(c,["request failure"])}),this.request.done(function(f){var g,h=c.request.getResponseHeader("Location"),i=c.signature;return h&&h!==c.previewUrl()?void a.rejectWith(c,["redirect",h]):"0"===f?void c.login(a):"-1"===f?void a.rejectWith(c,["cheatin"]):(g=f.lastIndexOf(i),-1===g||g")?void a.rejectWith(c,["unsigned"]):(f=f.slice(0,g)+f.slice(g+i.length),c.iframe=b("