diff --git a/controls/js/dist/script-legacy.js b/controls/js/dist/script-legacy.js index 2931ad47c..a6ac6ea10 100644 --- a/controls/js/dist/script-legacy.js +++ b/controls/js/dist/script-legacy.js @@ -1023,6 +1023,11 @@ var kirki = { } } + if ( 'undefined' !== typeof wp.customize.control( setting ) ) { + wp.customize.control( setting ).setting.set( value ); + return; + } + parts = setting.split( '[' ), // Find the setting we're using in the control using the customizer API. diff --git a/controls/js/dist/script-legacy.min.js b/controls/js/dist/script-legacy.min.js index 6e84b6797..bca740f1d 100644 --- a/controls/js/dist/script-legacy.min.js +++ b/controls/js/dist/script-legacy.min.js @@ -1 +1 @@ -if(_.isUndefined(window.kirkiSetSettingValue))var kirkiSetSettingValue={set:function(e,t){var i,n=this,a=wp.customize.settings.controls[e];if(_.isUndefined(a))return!0;switch(n.setValue(e,t),a.type){case"kirki-background":_.isUndefined(t["background-color"])||n.setColorPicker(n.findElement(e,".kirki-color-control"),t["background-color"]),n.findElement(e,".placeholder, .thumbnail").removeClass().addClass("placeholder").html("No file selected"),_.each(["background-repeat","background-position"],function(i){_.isUndefined(t[i])||n.setSelectWoo(n.findElement(e,"."+i+" select"),t[i])}),_.each(["background-size","background-attachment"],function(i){jQuery(n.findElement(e,"."+i+' input[value="'+t+'"]')).prop("checked",!0)}),i=JSON.stringify(t).replace(/'/g,"'"),jQuery(n.findElement(e,".background-hidden-value").attr("value",i)).trigger("change");break;case"kirki-code":jQuery(n.findElement(e,".CodeMirror"))[0].CodeMirror.setValue(t);break;case"checkbox":case"kirki-switch":case"kirki-toggle":t=1===t||"1"===t||!0===t,jQuery(n.findElement(e,"input")).prop("checked",t),wp.customize.instance(e).set(t);break;case"kirki-select":case"kirki-preset":case"kirki-fontawesome":n.setSelectWoo(n.findElement(e,"select"),t);break;case"kirki-slider":jQuery(n.findElement(e,"input")).prop("value",t),jQuery(n.findElement(e,".kirki_range_value .value")).html(t);break;case"kirki-generic":(_.isUndefined(a.choices)||_.isUndefined(a.choices.element))&&(a.choices.element="input"),jQuery(n.findElement(e,a.choices.element)).prop("value",t);break;case"kirki-color":n.setColorPicker(n.findElement(e,".kirki-color-control"),t);break;case"kirki-multicheck":n.findElement(e,"input").each(function(){jQuery(this).prop("checked",!1)}),_.each(t,function(i,a){jQuery(n.findElement(e,'input[value="'+t[a]+'"]')).prop("checked",!0)});break;case"kirki-multicolor":_.each(t,function(t,i){n.setColorPicker(n.findElement(e,".multicolor-index-"+i),t)});break;case"kirki-radio-buttonset":case"kirki-radio-image":case"kirki-radio":case"kirki-dashicons":case"kirki-color-palette":case"kirki-palette":jQuery(n.findElement(e,'input[value="'+t+'"]')).prop("checked",!0);break;case"kirki-typography":_.each(["font-family","variant","subsets"],function(i){_.isUndefined(t[i])||n.setSelectWoo(n.findElement(e,"."+i+" select"),t[i])}),_.each(["font-size","line-height","letter-spacing","word-spacing"],function(i){_.isUndefined(t[i])||jQuery(n.findElement(e,"."+i+" input")).prop("value",t[i])}),_.isUndefined(t.color)||n.setColorPicker(n.findElement(e,".kirki-color-control"),t.color),i=JSON.stringify(t).replace(/'/g,"'"),jQuery(n.findElement(e,".typography-hidden-value").attr("value",i)).trigger("change");break;case"kirki-dimensions":_.each(t,function(t,i){jQuery(n.findElement(e,"."+i+" input")).prop("value",t)});break;case"kirki-repeater":case"kirki-custom":break;default:jQuery(n.findElement(e,"input")).prop("value",t)}},setColorPicker:function(e,t){e.attr("data-default-color",t).data("default-color",t).wpColorPicker("color",t)},setSelectWoo:function(e,t){jQuery(e).selectWoo().val(t).trigger("change")},setTextarea:function(e,t){jQuery(e).prop("value",t)},findElement:function(e,t){return wp.customize.control(e).container.find(t)},setValue:function(e,t,i){i=_.isUndefined(i)?100:parseInt(i,10),wp.customize.instance(e).set({}),setTimeout(function(){wp.customize.instance(e).set(t)},i)}};var kirki={initialized:!1,initialize:function(){var e=this;e.initialized||(e.util.webfonts.google.initialize(),e.initialized=!0)},control:{"kirki-radio":{init:function(e){this.template(e),kirki.input.radio.init(e)},template:function(e){e.container.html(kirki.input.radio.getTemplate({label:e.params.label,description:e.params.description,"data-id":e.id,inputAttrs:e.params.inputAttrs,default:e.params.default,value:kirki.setting.get(e.id),choices:e.params.choices}))}},"kirki-color":{init:function(e){this.template(e),kirki.input.color.init(e)},template:function(e){e.container.html(kirki.input.color.getTemplate({label:e.params.label,description:e.params.description,"data-id":e.id,mode:e.params.mode,inputAttrs:e.params.inputAttrs,"data-palette":e.params.palette,"data-default-color":e.params.default,"data-alpha":e.params.choices.alpha,value:kirki.setting.get(e.id)}))}},"kirki-generic":{init:function(e){this.template(e),_.isUndefined(e.params)||_.isUndefined(e.params.choices)||_.isUndefined(e.params.choices.element)||"textarea"!==e.params.choices.element?kirki.input.genericInput.init(e):kirki.input.textarea.init(e)},template:function(e){var t={label:e.params.label,description:e.params.description,"data-id":e.id,inputAttrs:e.params.inputAttrs,choices:e.params.choices,value:kirki.setting.get(e.id)};_.isUndefined(e.params)||_.isUndefined(e.params.choices)||_.isUndefined(e.params.choices.element)||"textarea"!==e.params.choices.element?e.container.html(kirki.input.genericInput.getTemplate(t)):e.container.html(kirki.input.textarea.getTemplate(t))}},"kirki-select":{init:function(e){this.template(e),kirki.input.select.init(e)},template:function(e){var t={label:e.params.label,description:e.params.description,"data-id":e.id,inputAttrs:e.params.inputAttrs,choices:e.params.choices,value:kirki.setting.get(e.id)};e.container.html(kirki.input.select.getTemplate(t))}}},input:{radio:{getTemplate:function(e){var t="";if((e=_.defaults(e,{choices:{},label:"",description:"",inputAttrs:"",value:"","data-id":"",default:""})).choices)return e.label&&(t+=''+e.label+""),e.description&&(t+=''+e.description+""),_.each(e.choices,function(i,n){t+=""}),'
'+t+"
"},init:function(e){jQuery('input[data-id="'+e.id+'"]').on("change keyup paste click",function(){kirki.setting.set(e.id,jQuery(this).val())})}},color:{getTemplate:function(e){var t="";return e=_.defaults(e,{label:"",description:"",mode:"full",inputAttrs:"","data-palette":!e["data-palette"]||e["data-palette"],"data-default-color":e["data-default-color"]?e["data-default-color"]:"","data-alpha":!!e["data-alpha"]&&e["data-alpha"],value:"","data-id":""}),t+="",t+='','
'+t+"
"},init:function(e){var t,i=jQuery('.kirki-color-control[data-id="'+e.id+'"]');e.choices=e.choices||{},_.isEmpty(e.choices)&&e.params.choices&&(e.choices=e.params.choices),_.isEmpty(e.choices)||i.wpColorPicker(e.choices),setTimeout(function(){(t=jQuery('.kirki-input-container[data-id="'+e.id+'"] .wp-picker-clear')).length&&t.click(function(){e.setting.set("")})},200),i.wpColorPicker({change:function(){setTimeout(function(){kirki.setting.set(e.id,i.val())},20)}})}},genericInput:{getTemplate:function(e){var t="",i=e.choices.element?e.choices.element:"input";return e=_.defaults(e,{label:"",description:"",inputAttrs:"",value:"","data-id":"",choices:{}}),t+="",'
'+t+"
"},init:function(e){jQuery('input[data-id="'+e.id+'"]').on("change keyup paste click",function(){kirki.setting.set(e.id,jQuery(this).val())})}},textarea:{getTemplate:function(e){var t="";return e=_.defaults(e,{label:"",description:"",inputAttrs:"",value:"","data-id":"",choices:{}}),t+="",'
'+t+"
"},init:function(e){jQuery('textarea[data-id="'+e.id+'"]').on("change keyup paste click",function(){kirki.setting.set(e.id,jQuery(this).val())})}},select:{getTemplate:function(e){var t,i="";if((e=_.defaults(e,{label:"",description:"",inputAttrs:"","data-id":"",choices:{},multiple:1,value:1",e.label&&(i+=''+e.label+""),e.description&&(i+=''+e.description+""),i+='",'
'+i+"
"},init:function(e){var t,i=jQuery('select[data-id="'+e.id+'"'),n=parseInt(i.data("multiple"),10),a={escapeMarkup:function(e){return e}};1",e.label&&(i+=''+e.label+""),e.description&&(i+=''+e.description+""),i+="",i+='
',e.value.url||""!==t?i+='
':i+='
'+kirkiL10n.noFileSelected+"
",i+='
',i+='",e.default&&""!==e.default&&(i+='",i+="
",'
'+i+"
"},init:function(e){}}},setting:{get:function(e){var t=e.split("["),i="",n=0,a="";return _.each(t,function(e,t){e=e.replace("]",""),0===t?i=e:i+="["+e+"]",_.isUndefined(wp.customize.instance(i))||(a=wp.customize.instance(i).get(),n=t),n"),n.params.content.attr("id","customize-control-"+e.replace(/]/g,"").replace(/\[/g,"-")),n.params.content.attr("class","customize-control customize-control-"+n.params.type)),i.propertyElements=[],wp.customize.Control.prototype.initialize.call(i,e,n)},_setUpSettingRootLinks:function(){var e=this;e.container.find("[data-customize-setting-link]").each(function(){var t=jQuery(this);wp.customize(t.data("customizeSettingLink"),function(i){var n=new wp.customize.Element(t);e.elements.push(n),n.sync(i),n.set(i())})})},_setUpSettingPropertyLinks:function(){var e=this;e.setting&&e.container.find("[data-customize-setting-property-link]").each(function(){var t,i=jQuery(this),n=i.data("customizeSettingPropertyLink");t=new wp.customize.Element(i),e.propertyElements.push(t),t.set(e.setting()[n]),t.bind(function(t){var i=e.setting();t!==i[n]&&((i=_.clone(i))[n]=t,e.setting.set(i))}),e.setting.bind(function(e){e[n]!==t.get()&&t.set(e[n])})})},ready:function(){var e=this;e._setUpSettingRootLinks(),e._setUpSettingPropertyLinks(),wp.customize.Control.prototype.ready.call(e),e.deferred.embedded.done(function(){e.initKirkiControl(e)})},embed:function(){var e=this,t=e.section();t&&wp.customize.section(t,function(t){"kirki-expanded"===t.params.type||t.expanded()||wp.customize.settings.autofocus.control===e.id?e.actuallyEmbed():t.expanded.bind(function(t){t&&e.actuallyEmbed()})})},actuallyEmbed:function(){var e=this;"resolved"!==e.deferred.embedded.state()&&(e.renderContent(),e.deferred.embedded.resolve())},focus:function(e){var t=this;t.actuallyEmbed(),wp.customize.Control.prototype.focus.call(t,e)},initKirkiControl:function(e){void 0===kirki.control[e.params.type]?this.container.on("change keyup paste click","input",function(){e.setting.set(jQuery(this).val())}):kirki.control[e.params.type].init(e)},kirkiValidateCSSValue:function(e){var t,i,n=["rem","em","ex","%","px","cm","mm","in","pt","pc","ch","vh","vw","vmin","vmax"];return"0"===e||0<=e.indexOf("calc(")&&0<=e.indexOf(")")||(t=parseFloat(e),i=e.replace(t,""),!isNaN(t)&&-1!==jQuery.inArray(i,n))}})}(),_.each(kirki.control,function(e,t){wp.customize.controlConstructor[t]=wp.customize.kirkiDynamicControl.extend({})}),wp.customize.controlConstructor["kirki-background"]=wp.customize.Control.extend({ready:function(){"use strict";var e=this;!_.isUndefined(window.kirkiControlLoader)&&_.isFunction(kirkiControlLoader)?kirkiControlLoader(e):e.initKirkiControl()},initKirkiControl:function(){var e=this,t=e.getValue(),i=e.container.find(".kirki-color-control");(_.isUndefined(t["background-image"])||""===t["background-image"])&&(e.container.find(".background-wrapper > .background-repeat").hide(),e.container.find(".background-wrapper > .background-position").hide(),e.container.find(".background-wrapper > .background-size").hide(),e.container.find(".background-wrapper > .background-attachment").hide()),i.wpColorPicker({change:function(){setTimeout(function(){e.saveValue("background-color",i.val())},100)}}),e.container.on("change",".background-repeat select",function(){e.saveValue("background-repeat",jQuery(this).val())}),e.container.on("change click",".background-size input",function(){e.saveValue("background-size",jQuery(this).val())}),e.container.on("change",".background-position select",function(){e.saveValue("background-position",jQuery(this).val())}),e.container.on("change click",".background-attachment input",function(){e.saveValue("background-attachment",jQuery(this).val())}),e.container.on("click",".background-image-upload-button",function(t){var i=wp.media({multiple:!1}).open().on("select",function(){var t,n,a,r=i.state().get("selection").first(),o=r.toJSON().sizes.full.url;_.isUndefined(r.toJSON().sizes.medium)?_.isUndefined(r.toJSON().sizes.thumbnail)||(o=r.toJSON().sizes.thumbnail.url):o=r.toJSON().sizes.medium.url,t=r.toJSON().sizes.full.url,r.toJSON().id,r.toJSON().width,r.toJSON().height,""!==t&&e.container.find(".background-wrapper > .background-repeat, .background-wrapper > .background-position, .background-wrapper > .background-size, .background-wrapper > .background-attachment").show(),e.saveValue("background-image",t),n=e.container.find(".placeholder, .thumbnail"),a=e.container.find(".background-image-upload-remove-button"),n.length&&n.removeClass().addClass("thumbnail thumbnail-image").html(''),a.length&&a.show()});t.preventDefault()}),e.container.on("click",".background-image-upload-remove-button",function(t){var i,n;t.preventDefault(),e.saveValue("background-image",""),i=e.container.find(".placeholder, .thumbnail"),n=e.container.find(".background-image-upload-remove-button"),e.container.find(".background-wrapper > .background-repeat").hide(),e.container.find(".background-wrapper > .background-position").hide(),e.container.find(".background-wrapper > .background-size").hide(),e.container.find(".background-wrapper > .background-attachment").hide(),i.length&&i.removeClass().addClass("placeholder").html("No file selected"),n.length&&n.hide()})},getValue:function(){var e=this,t={};return _.each(e.params.default,function(i,n){!1!==i&&(t[n]=i,_.isUndefined(e.setting._value[n])||(t[n]=e.setting._value[n]))}),_.each(e.setting._value,function(e,i){_.isUndefined(t[i])&&(t[i]=e)}),t},saveValue:function(e,t){"use strict";var i=this,n=jQuery("#customize-control-"+i.id.replace("[","-").replace("]","")+" .background-hidden-value"),a=jQuery(n).val(),r=JSON.parse(a);r[e]=t,i.setting.set(r),jQuery(n).attr("value",JSON.stringify(r)).trigger("change")}}),wp.customize.controlConstructor["kirki-code"]=wp.customize.kirkiDynamicControl.extend({initKirkiControl:function(){var e=this;_.isUndefined(wp.customize.CodeEditorControl)||(jQuery(e.container.find("textarea.kirki-codemirror-editor")).hide(),wp.customize.control.add(new wp.customize.CodeEditorControl(e.id,{section:e.params.section,priority:e.params.priority,label:e.params.label,editor_settings:{codemirror:{mode:e.params.choices.language}},settings:{default:e.id}})))}}),wp.customize.controlConstructor["kirki-color-palette"]=wp.customize.kirkiDynamicControl.extend({}),wp.customize.controlConstructor["kirki-dashicons"]=wp.customize.kirkiDynamicControl.extend({}),wp.customize.controlConstructor["kirki-date"]=wp.customize.kirkiDynamicControl.extend({initKirkiControl:function(){var e=this;_.isUndefined(wp.customize.DateTimeControl)||wp.customize.control.add(new wp.customize.DateTimeControl(e.id,{section:e.params.section,priority:e.params.priority,label:e.params.label,description:e.params.description,settings:{default:e.id},default:e.params.default}))}}),wp.customize.controlConstructor["kirki-dimension"]=wp.customize.kirkiDynamicControl.extend({initKirkiControl:function(){var e,t=this;t.kirkiNotifications(),this.container.on("change keyup paste","input",function(){e=jQuery(this).val(),t.setting.set(e)})},kirkiNotifications:function(){var e=this;wp.customize(e.id,function(t){t.bind(function(i){var n="long_title";!1===e.kirkiValidateCSSValue(i)?t.notifications.add(n,new wp.customize.Notification(n,{type:"warning",message:dimensionkirkiL10n["invalid-value"]})):t.notifications.remove(n)})})}}),wp.customize.controlConstructor["kirki-dimensions"]=wp.customize.kirkiDynamicControl.extend({initKirkiControl:function(){var e,t=this,i=t.params.choices.controls,n={},a=[];for(_.each(i,function(e,t){!0===e&&a.push(t)}),e=0;e