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AAQuB,UAAAuC,MAAerC,KAAQpB,EAAGE,GAC7CT,GAAAsD,MAAA1B,SAAA,mCAAArB","sources":["src/dynamic-control.js"],"sourcesContent":["/**\r\n * The majority of the code in this file\r\n * is derived from the wp-customize-posts plugin\r\n * and the work of @westonruter to whom I am very grateful.\r\n *\r\n * @see https://github.com/xwp/wp-customize-posts\r\n */\r\n\r\n(function () {\r\n\t'use strict';\r\n\r\n\t/**\r\n\t * A dynamic color-alpha control.\r\n\t *\r\n\t * @class\r\n\t * @augments wp.customize.Control\r\n\t * @augments wp.customize.Class\r\n\t */\r\n\twp.customize.kirkiDynamicControl = wp.customize.Control.extend({\r\n\r\n\t\tinitialize: function (id, options) {\r\n\t\t\tvar control = this,\r\n\t\t\t\targs = options || {};\r\n\r\n\t\t\targs.params = args.params || {};\r\n\t\t\tif (!args.params.type) {\r\n\t\t\t\targs.params.type = 'kirki-generic';\r\n\t\t\t}\r\n\r\n\t\t\tlet className;\r\n\r\n\t\t\tif (args.content) {\r\n\t\t\t\tlet splits = args.content.split('class=\"');\r\n\t\t\t\tsplits = splits[1].split('\"');\r\n\t\t\t\tclassName = splits[0];\r\n\t\t\t} else {\r\n\t\t\t\tclassName = 'customize-control customize-control-' + args.params.type;\r\n\t\t\t}\r\n\r\n\t\t\tif (!args.params.wrapper_attrs && args.params.wrapper_atts) {\r\n\t\t\t\targs.params.wrapper_attrs = args.params.wrapper_atts;\r\n\t\t\t}\r\n\r\n\t\t\t// Hijack the container to add wrapper_attrs.\r\n      args.params.content = jQuery(\"<li></li>\");\r\n\t\t\targs.params.content.attr('id', 'customize-control-' + id.replace(/]/g, '').replace(/\\[/g, '-'));\r\n\t\t\targs.params.content.attr('class', className);\r\n\r\n\t\t\t_.each(args.params.wrapper_attrs, function (val, key) {\r\n\t\t\t\tif ('class' === key) {\r\n\t\t\t\t\tval = val.replace('{default_class}', className);\r\n\t\t\t\t}\r\n\r\n\t\t\t\targs.params.content.attr(key, val);\r\n\t\t\t});\r\n\r\n\t\t\tcontrol.propertyElements = [];\r\n\t\t\twp.customize.Control.prototype.initialize.call(control, id, args);\r\n\t\t\twp.hooks.doAction('kirki.dynamicControl.init.after', id, control, args);\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * Add bidirectional data binding links between inputs and the setting(s).\r\n\t\t *\r\n\t\t * This is copied from wp.customize.Control.prototype.initialize(). It\r\n\t\t * should be changed in Core to be applied once the control is embedded.\r\n\t\t *\r\n\t\t * @private\r\n\t\t * @returns {void}\r\n\t\t */\r\n\t\t_setUpSettingRootLinks: function () {\r\n\t\t\tvar control = this,\r\n\t\t\t\tnodes = control.container.find('[data-customize-setting-link]');\r\n\r\n\t\t\tnodes.each(function () {\r\n\t\t\t\tvar node = jQuery(this);\r\n\r\n\t\t\t\twp.customize(node.data('customizeSettingLink'), function (setting) {\r\n\t\t\t\t\tvar element = new wp.customize.Element(node);\r\n\t\t\t\t\tcontrol.elements.push(element);\r\n\t\t\t\t\telement.sync(setting);\r\n\t\t\t\t\telement.set(setting());\r\n\t\t\t\t});\r\n\t\t\t});\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * Add bidirectional data binding links between inputs and the setting properties.\r\n\t\t *\r\n\t\t * @private\r\n\t\t * @returns {void}\r\n\t\t */\r\n\t\t_setUpSettingPropertyLinks: function () {\r\n\t\t\tvar control = this,\r\n\t\t\t\tnodes;\r\n\r\n\t\t\tif (!control.setting) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tnodes = control.container.find('[data-customize-setting-property-link]');\r\n\r\n\t\t\tnodes.each(function () {\r\n\t\t\t\tvar node = jQuery(this),\r\n\t\t\t\t\telement,\r\n\t\t\t\t\tpropertyName = node.data('customizeSettingPropertyLink');\r\n\r\n\t\t\t\telement = new wp.customize.Element(node);\r\n\t\t\t\tcontrol.propertyElements.push(element);\r\n\t\t\t\telement.set(control.setting()[propertyName]);\r\n\r\n\t\t\t\telement.bind(function (newPropertyValue) {\r\n\t\t\t\t\tvar newSetting = control.setting();\r\n\t\t\t\t\tif (newPropertyValue === newSetting[propertyName]) {\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tnewSetting = _.clone(newSetting);\r\n\t\t\t\t\tnewSetting[propertyName] = newPropertyValue;\r\n\t\t\t\t\tcontrol.setting.set(newSetting);\r\n\t\t\t\t});\r\n\t\t\t\tcontrol.setting.bind(function (newValue) {\r\n\t\t\t\t\tif (newValue[propertyName] !== element.get()) {\r\n\t\t\t\t\t\telement.set(newValue[propertyName]);\r\n\t\t\t\t\t}\r\n\t\t\t\t});\r\n\t\t\t});\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * @inheritdoc\r\n\t\t */\r\n\t\tready: function () {\r\n\t\t\tvar control = this;\r\n\r\n\t\t\tcontrol._setUpSettingRootLinks();\r\n\t\t\tcontrol._setUpSettingPropertyLinks();\r\n\r\n\t\t\twp.customize.Control.prototype.ready.call(control);\r\n\r\n\t\t\tcontrol.deferred.embedded.done(function () {\r\n\t\t\t\tcontrol.initKirkiControl();\r\n\t\t\t\twp.hooks.doAction('kirki.dynamicControl.ready.deferred.embedded.done', control);\r\n\t\t\t});\r\n\t\t\twp.hooks.doAction('kirki.dynamicControl.ready.after', control);\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * Embed the control in the document.\r\n\t\t *\r\n\t\t * Override the embed() method to do nothing,\r\n\t\t * so that the control isn't embedded on load,\r\n\t\t * unless the containing section is already expanded.\r\n\t\t *\r\n\t\t * @returns {void}\r\n\t\t */\r\n\t\tembed: function () {\r\n\t\t\tvar control = this,\r\n\t\t\t\tsectionId = control.section();\r\n\r\n\t\t\tif (!sectionId) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\twp.customize.section(sectionId, function (section) {\r\n\t\t\t\tif ('kirki-expanded' === section.params.type || section.expanded() || wp.customize.settings.autofocus.control === control.id) {\r\n\t\t\t\t\tcontrol.actuallyEmbed();\r\n\t\t\t\t} else {\r\n\t\t\t\t\tsection.expanded.bind(function (expanded) {\r\n\t\t\t\t\t\tif (expanded) {\r\n\t\t\t\t\t\t\tcontrol.actuallyEmbed();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t});\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t\twp.hooks.doAction('kirki.dynamicControl.embed.after', control);\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * Deferred embedding of control when actually\r\n\t\t *\r\n\t\t * This function is called in Section.onChangeExpanded() so the control\r\n\t\t * will only get embedded when the Section is first expanded.\r\n\t\t *\r\n\t\t * @returns {void}\r\n\t\t */\r\n\t\tactuallyEmbed: function () {\r\n\t\t\tvar control = this;\r\n\t\t\tif ('resolved' === control.deferred.embedded.state()) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tcontrol.renderContent();\r\n\t\t\tcontrol.deferred.embedded.resolve(); // This triggers control.ready().\r\n\t\t\twp.hooks.doAction('kirki.dynamicControl.actuallyEmbed.after', control);\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * This is not working with autofocus.\r\n\t\t *\r\n\t\t * @param {object} [args] Args.\r\n\t\t * @returns {void}\r\n\t\t */\r\n\t\tfocus: function (args) {\r\n\t\t\tvar control = this;\r\n\t\t\tcontrol.actuallyEmbed();\r\n\t\t\twp.customize.Control.prototype.focus.call(control, args);\r\n\t\t\twp.hooks.doAction('kirki.dynamicControl.focus.after', control);\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * Additional actions that run on ready.\r\n\t\t *\r\n\t\t * @param {object} control - The control object. If undefined fallsback to the this.\r\n\t\t * @returns {void}\r\n\t\t */\r\n\t\tinitKirkiControl: function (control) {\r\n\t\t\tcontrol = control || this;\r\n\t\t\twp.hooks.doAction('kirki.dynamicControl.initKirkiControl', this);\r\n\r\n\t\t\t// Save the value\r\n\t\t\tcontrol.container.on('change keyup paste click', 'input', function () {\r\n\t\t\t\tcontrol.setting.set(jQuery(this).val());\r\n\t\t\t});\r\n\t\t}\r\n\t});\r\n}());\r\n\r\n(function (api) {\r\n\r\n\t/**\r\n\t * Set the value and trigger all bound callbacks.\r\n\t *\r\n\t * @since 1.0\r\n\t * @param {object} to - New value.\r\n\t * @returns {Object} - this\r\n\t */\r\n\tapi.Value.prototype.set = function (to) {\r\n\t\tvar from = this._value,\r\n\t\t\tparentSetting,\r\n\t\t\tnewVal;\r\n\r\n\t\tto = this._setter.apply(this, arguments);\r\n\t\tto = this.validate(to);\r\n\r\n\t\t// Bail if the sanitized value is null or unchanged.\r\n\t\tif (null === to || _.isEqual(from, to)) {\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Start Kirki mod.\r\n\t\t */\r\n\t\tif (this.id && api.control(this.id) && api.control(this.id).params && api.control(this.id).params.parent_setting) {\r\n\t\t\tparentSetting = api.control(this.id).params.parent_setting;\r\n\t\t\tnewVal = {};\r\n\t\t\tnewVal[this.id.replace(parentSetting + '[', '').replace(']', '')] = to;\r\n\t\t\tapi.control(parentSetting).setting.set(jQuery.extend({}, api.control(parentSetting).setting._value, newVal));\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * End Kirki mod.\r\n\t\t */\r\n\r\n\t\tthis._value = to;\r\n\t\tthis._dirty = true;\r\n\r\n\t\tthis.callbacks.fireWith(this, [to, from]);\r\n\r\n\t\treturn this;\r\n\t};\r\n\r\n\t/**\r\n\t * Get the value.\r\n\t *\r\n\t * @returns {mixed} - Returns the value.\r\n\t */\r\n\tapi.Value.prototype.get = function () {\r\n\r\n\t\t// Start Kirki mod.\r\n\t\tvar parentSetting;\r\n\t\tif (this.id && api.control(this.id) && api.control(this.id).params && api.control(this.id).params.parent_setting) {\r\n\t\t\tparentSetting = api.control(this.id).params.parent_setting;\r\n\t\t\treturn api.control(parentSetting).setting.get()[this.id.replace(parentSetting + '[', '').replace(']', '')];\r\n\t\t}\r\n\t\t// End Kirki mod.\r\n\r\n\t\treturn this._value;\r\n\t};\r\n}(wp.customize));\r\n"],"names":["kirkiDynamicControl","wp","customize","Control","extend","id","options","className","control","this","args","params","type","content","splits","split","wrapper_attrs","wrapper_atts","jQuery","attr","replace","_","each","val","key","propertyElements","prototype","initialize","call","doAction","container","find","node","data","setting","element","Element","elements","push","sync","set","propertyName","bind","newPropertyValue","newSetting","clone","newValue","get","_setUpSettingRootLinks","_setUpSettingPropertyLinks","ready","deferred","embedded","done","initKirkiControl","hooks","sectionId","section","expanded","settings","autofocus","actuallyEmbed","state","renderContent","resolve","focus"],"version":3,"file":"control.js.map"}