mirror of
https://ghproxy.net/https://github.com/AlxMedia/curver.git
synced 2025-08-28 11:50:25 +08:00
Update to Kirki 4.0.22
This commit is contained in:
parent
4ff905c2c6
commit
a02e711106
493 changed files with 29670 additions and 39886 deletions
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019 kirki-framework
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,5 @@
|
|||
# control-base
|
||||
|
||||
This package serves as a base for other controls.
|
||||
|
||||
By itself the `\Kirki\Control\Base` doesn't do anything. It is simply an object that all other Kirki controls should extend to avoid code duplication.
|
2
functions/kirki/packages/kirki-framework/control-base/dist/control.css
vendored
Normal file
2
functions/kirki/packages/kirki-framework/control-base/dist/control.css
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
@media screen and (min-width:1667px){.rtl .wp-full-overlay.expanded{margin-left:0;margin-right:300px}.wp-full-overlay.expanded{margin-left:300px}}#customize-theme-controls .customize-pane-child.open{overflow:visible}.wp-full-overlay-sidebar{width:300px}.expanded .wp-full-overlay-footer{max-width:299px}.kirki-w100{width:100%}.kirki-w50{width:50%}.kirki-w45{width:45%}.kirki-w40{width:40%}.kirki-w33{width:33.3333%}.kirki-w30{width:30%}.kirki-w25{width:25%}.kirki-w20{width:20%}.kirki-w15{width:15%}.kirki-w10{width:10%}.kirki-w5{width:5%}.control-section-kirki-default,.control-section-kirki-outer{min-height:100%}.customize-control-has-small-gap{margin-bottom:9px}.customize-control-is-gapless{margin-bottom:0}.customize-control-kirki-hidden-field{height:0;margin-bottom:0}.customize-control-kirki,.customize-control-kirki *{box-sizing:border-box}.customize-control-kirki.kirki-group-item{clear:none}.kirki-group-item{clear:none;float:left;padding-left:3px;padding-right:3px}.kirki-group-item.kirki-group-start{padding-left:0;padding-right:3px}.kirki-group-item.kirki-group-break,.kirki-group-item.kirki-group-end{padding-left:3px;padding-right:0}.kirki-group-item.kirki-group-end:after{clear:both;content:"";display:block;height:0;width:100%}.customize-control-kirki{position:relative}.customize-control-kirki .kirki-control-label,.customize-control-kirki label.customize-control-title{display:block}.customize-control-kirki .kirki-control-form{position:relative}.customize-control-kirki .kirki-control-form textarea{display:block;width:100%}
|
||||
/*# sourceMappingURL=control.css.map */
|
2
functions/kirki/packages/kirki-framework/control-base/dist/control.js
vendored
Normal file
2
functions/kirki/packages/kirki-framework/control-base/dist/control.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
!function(){var t;wp.customize.kirkiDynamicControl=wp.customize.Control.extend({initialize:function(t,e){var i,n=this,o=e||{};if(o.params=o.params||{},o.params.type||(o.params.type="kirki-generic"),o.content){var r=o.content.split('class="');r=r[1].split('"'),i=r[0]}else i="customize-control customize-control-"+o.params.type;!o.params.wrapper_attrs&&o.params.wrapper_atts&&(o.params.wrapper_attrs=o.params.wrapper_atts),o.params.content=jQuery("<li></li>"),o.params.content.attr("id","customize-control-"+t.replace(/]/g,"").replace(/\[/g,"-")),o.params.content.attr("class",i),_.each(o.params.wrapper_attrs,(function(t,e){"class"===e&&(t=t.replace("{default_class}",i)),o.params.content.attr(e,t)})),n.propertyElements=[],wp.customize.Control.prototype.initialize.call(n,t,o),wp.hooks.doAction("kirki.dynamicControl.init.after",t,n,o)},_setUpSettingRootLinks:function(){var t=this;t.container.find("[data-customize-setting-link]").each((function(){var e=jQuery(this);wp.customize(e.data("customizeSettingLink"),(function(i){var n=new wp.customize.Element(e);t.elements.push(n),n.sync(i),n.set(i())}))}))},_setUpSettingPropertyLinks:function(){var t=this;t.setting&&t.container.find("[data-customize-setting-property-link]").each((function(){var e,i=jQuery(this),n=i.data("customizeSettingPropertyLink");e=new wp.customize.Element(i),t.propertyElements.push(e),e.set(t.setting()[n]),e.bind((function(e){var i=t.setting();e!==i[n]&&((i=_.clone(i))[n]=e,t.setting.set(i))})),t.setting.bind((function(t){t[n]!==e.get()&&e.set(t[n])}))}))},ready:function(){var t=this;t._setUpSettingRootLinks(),t._setUpSettingPropertyLinks(),wp.customize.Control.prototype.ready.call(t),t.deferred.embedded.done((function(){t.initKirkiControl(),wp.hooks.doAction("kirki.dynamicControl.ready.deferred.embedded.done",t)})),wp.hooks.doAction("kirki.dynamicControl.ready.after",t)},embed:function(){var t=this,e=t.section();e&&(wp.customize.section(e,(function(e){"kirki-expanded"===e.params.type||e.expanded()||wp.customize.settings.autofocus.control===t.id?t.actuallyEmbed():e.expanded.bind((function(e){e&&t.actuallyEmbed()}))})),wp.hooks.doAction("kirki.dynamicControl.embed.after",t))},actuallyEmbed:function(){var t=this;"resolved"!==t.deferred.embedded.state()&&(t.renderContent(),t.deferred.embedded.resolve(),wp.hooks.doAction("kirki.dynamicControl.actuallyEmbed.after",t))},focus:function(t){var e=this;e.actuallyEmbed(),wp.customize.Control.prototype.focus.call(e,t),wp.hooks.doAction("kirki.dynamicControl.focus.after",e)},initKirkiControl:function(t){t=t||this,wp.hooks.doAction("kirki.dynamicControl.initKirkiControl",this),t.container.on("change keyup paste click","input",(function(){t.setting.set(jQuery(this).val())}))}}),(t=wp.customize).Value.prototype.set=function(e){var i,n,o=this._value;return e=this._setter.apply(this,arguments),null===(e=this.validate(e))||_.isEqual(o,e)||(this.id&&t.control(this.id)&&t.control(this.id).params&&t.control(this.id).params.parent_setting&&(i=t.control(this.id).params.parent_setting,(n={})[this.id.replace(i+"[","").replace("]","")]=e,t.control(i).setting.set(jQuery.extend({},t.control(i).setting._value,n))),this._value=e,this._dirty=!0,this.callbacks.fireWith(this,[e,o])),this},t.Value.prototype.get=function(){var e;return this.id&&t.control(this.id)&&t.control(this.id).params&&t.control(this.id).params.parent_setting?(e=t.control(this.id).params.parent_setting,t.control(e).setting.get()[this.id.replace(e+"[","").replace("]","")]):this._value}}();
|
||||
//# sourceMappingURL=control.js.map
|
|
@ -0,0 +1,347 @@
|
|||
<?php
|
||||
/**
|
||||
* Customizer Controls Base.
|
||||
*
|
||||
* Extend this in other controls.
|
||||
*
|
||||
* @package kirki-framework/control-base
|
||||
* @copyright Copyright (c) 2019, Ari Stathopoulos (@aristath)
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
namespace Kirki\Control;
|
||||
|
||||
use Kirki\URL;
|
||||
|
||||
/**
|
||||
* A base for controls.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class Base extends \WP_Customize_Control {
|
||||
|
||||
/**
|
||||
* Used to automatically generate all CSS output.
|
||||
*
|
||||
* Whitelisting property for use in Kirki modules.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @var array
|
||||
*/
|
||||
public $output = [];
|
||||
|
||||
/**
|
||||
* Data type
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @var string
|
||||
*/
|
||||
public $option_type = 'theme_mod';
|
||||
|
||||
/**
|
||||
* Option name (if using options).
|
||||
*
|
||||
* Whitelisting property for use in Kirki modules.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @var string
|
||||
*/
|
||||
public $option_name = false;
|
||||
|
||||
/**
|
||||
* The kirki_config we're using for this control
|
||||
*
|
||||
* Whitelisting property for use in Kirki modules.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @var string
|
||||
*/
|
||||
public $kirki_config = 'global';
|
||||
|
||||
/**
|
||||
* Whitelisting the "preset" argument for use in Kirki modules.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @var array
|
||||
*/
|
||||
public $preset = [];
|
||||
|
||||
/**
|
||||
* Whitelisting the "css_vars" argument for use in Kirki modules.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @var string
|
||||
*/
|
||||
public $css_vars = '';
|
||||
|
||||
/**
|
||||
* The version. Used in scripts & styles for cache-busting.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @var string
|
||||
*/
|
||||
public static $control_ver = '1.0.4';
|
||||
|
||||
/**
|
||||
* Parent setting.
|
||||
*
|
||||
* Used for composite controls to denote the setting that should be saved.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.1
|
||||
* @var string
|
||||
*/
|
||||
public $parent_setting;
|
||||
|
||||
/**
|
||||
* Wrapper attributes.
|
||||
*
|
||||
* The value of this property will be rendered to the wrapper element.
|
||||
* Can be 'class', 'id', 'data-*', and other attributes.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.1
|
||||
* @var array
|
||||
*/
|
||||
public $wrapper_attrs = [];
|
||||
|
||||
/**
|
||||
* Backwards compatibility support for `$wrapper_attrs`.
|
||||
*
|
||||
* Kirki v3 already has this `$wrapper_atts` property.
|
||||
* It was not published in the documentation, and more for internal use.
|
||||
*
|
||||
* The `WP_Customize_Control` is using `input_attrs` not `input_atts` (see, attrs vs atts).
|
||||
* So Kirki uses `$wrapper_attrs` for consistency and keep the old `$wrapper_atts` backwards compatibility.
|
||||
*
|
||||
* This property could be removed in the future.
|
||||
* Please use `$wrapper_attrs` instead.
|
||||
*
|
||||
* @since 1.1
|
||||
* @deprecated 1.0.1 This variable could be removed in the future. Please use `$wrapper_attrs` instead.
|
||||
* @var array
|
||||
*/
|
||||
public $wrapper_atts = [];
|
||||
|
||||
/**
|
||||
* Wrapper options.
|
||||
*
|
||||
* This won't be rendered automatically to the wrapper element.
|
||||
* The purpose is to allow us to have custom options so we can manage it when needed.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.1
|
||||
* @var array
|
||||
*/
|
||||
public $wrapper_opts = [];
|
||||
|
||||
/**
|
||||
* Extra script dependencies.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @return array
|
||||
*/
|
||||
public function kirki_script_dependencies() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue control related scripts/styles.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue() {
|
||||
|
||||
// Enqueue the styles.
|
||||
wp_enqueue_style( 'kirki-control-base', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver );
|
||||
|
||||
// Enqueue the scripts.
|
||||
wp_enqueue_script( 'kirki-control-base', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'customize-controls' ], self::$control_ver, false );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the control wrapper and calls $this->render_content() for the internals.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
protected function render() {
|
||||
|
||||
$id = 'customize-control-' . str_replace( [ '[', ']' ], [ '-', '' ], $this->id );
|
||||
$class = 'customize-control customize-control-kirki customize-control-' . $this->type;
|
||||
$gap = isset( $this->wrapper_opts['gap'] ) ? $this->wrapper_opts['gap'] : 'default';
|
||||
$tag = isset( $this->wrapper_opts['tag'] ) ? $this->wrapper_opts['tag'] : 'li';
|
||||
|
||||
switch ( $gap ) {
|
||||
case 'small':
|
||||
$class .= ' customize-control-has-small-gap';
|
||||
break;
|
||||
|
||||
case 'none':
|
||||
$class .= ' customize-control-is-gapless';
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if ( empty( $this->wrapper_attrs ) && ! empty( $this->wrapper_atts ) ) {
|
||||
$this->wrapper_attrs = $this->wrapper_atts;
|
||||
}
|
||||
|
||||
if ( isset( $this->wrapper_attrs['id'] ) ) {
|
||||
$id = $this->wrapper_attrs['id'];
|
||||
}
|
||||
|
||||
if ( ! isset( $this->wrapper_attrs['data-kirki-setting'] ) ) {
|
||||
$this->wrapper_attrs['data-kirki-setting'] = $this->id;
|
||||
}
|
||||
|
||||
if ( ! isset( $this->wrapper_attrs['data-kirki-setting-link'] ) ) {
|
||||
if ( isset( $this->settings['default'] ) ) {
|
||||
$this->wrapper_attrs['data-kirki-setting-link'] = $this->settings['default']->id;
|
||||
}
|
||||
}
|
||||
|
||||
$data_attrs = '';
|
||||
|
||||
foreach ( $this->wrapper_attrs as $attr_key => $attr_value ) {
|
||||
if ( 0 === strpos( $attr_key, 'data-' ) ) {
|
||||
$data_attrs .= ' ' . esc_attr( $attr_key ) . '="' . esc_attr( $attr_value ) . '"';
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $this->wrapper_attrs['class'] ) ) {
|
||||
$class = str_ireplace( '{default_class}', $class, $this->wrapper_attrs['class'] );
|
||||
}
|
||||
|
||||
// ! Consider to esc $data_attrs.
|
||||
// ? What function we can use to escape string like data-xx="yy"?
|
||||
printf( '<' . esc_attr( $tag ) . ' id="%s" class="%s"%s>', esc_attr( $id ), esc_attr( $class ), $data_attrs );
|
||||
$this->render_content();
|
||||
echo '</' . esc_attr( $tag ) . '>';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the parameters passed to the JavaScript via JSON.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @see WP_Customize_Control::to_json()
|
||||
* @return void
|
||||
*/
|
||||
public function to_json() {
|
||||
|
||||
// Get the basics from the parent class.
|
||||
parent::to_json();
|
||||
|
||||
// Default value.
|
||||
$this->json['default'] = $this->setting->default;
|
||||
|
||||
if ( isset( $this->default ) ) {
|
||||
$this->json['default'] = $this->default;
|
||||
}
|
||||
|
||||
// Output.
|
||||
$this->json['output'] = $this->output;
|
||||
|
||||
// Value.
|
||||
$this->json['value'] = $this->value();
|
||||
|
||||
// Choices.
|
||||
$this->json['choices'] = $this->choices;
|
||||
|
||||
// The link.
|
||||
$this->json['link'] = $this->get_link();
|
||||
|
||||
// The ID.
|
||||
$this->json['id'] = $this->id;
|
||||
|
||||
// Translation strings.
|
||||
$this->json['l10n'] = $this->l10n();
|
||||
|
||||
// The ajaxurl in case we need it.
|
||||
$this->json['ajaxurl'] = admin_url( 'admin-ajax.php' );
|
||||
|
||||
// Input attributes.
|
||||
$this->json['inputAttrs'] = '';
|
||||
|
||||
if ( is_array( $this->input_attrs ) ) {
|
||||
foreach ( $this->input_attrs as $attr => $value ) {
|
||||
$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" ';
|
||||
}
|
||||
}
|
||||
|
||||
// The kirki-config.
|
||||
$this->json['kirkiConfig'] = $this->kirki_config;
|
||||
|
||||
// The option-type.
|
||||
$this->json['kirkiOptionType'] = $this->option_type;
|
||||
|
||||
// The option-name.
|
||||
$this->json['kirkiOptionName'] = $this->option_name;
|
||||
|
||||
// The preset.
|
||||
$this->json['preset'] = $this->preset;
|
||||
|
||||
// The CSS-Variables.
|
||||
$this->json['css-var'] = $this->css_vars;
|
||||
|
||||
// Parent setting.
|
||||
$this->json['parent_setting'] = $this->parent_setting;
|
||||
|
||||
// Wrapper Attributes.
|
||||
$this->json['wrapper_attrs'] = $this->wrapper_attrs;
|
||||
$this->json['wrapper_atts'] = $this->wrapper_attrs; // For backward compatibility - Could be removed in the future.
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the control's content.
|
||||
*
|
||||
* Allows the content to be overridden without having to rewrite the wrapper in `$this::render()`.
|
||||
* Control content can alternately be rendered in JS. See WP_Customize_Control::print_template().
|
||||
*
|
||||
* @access protected
|
||||
* @since 1.0
|
||||
* @return void
|
||||
*/
|
||||
protected function render_content() {}
|
||||
|
||||
/**
|
||||
* An Underscore (JS) template for this control's content (but not its container).
|
||||
*
|
||||
* Class variables for this control class are available in the `data` JS object;
|
||||
* export custom variables by overriding {@see WP_Customize_Control::to_json()}.
|
||||
*
|
||||
* @access protected
|
||||
* @since 1.0
|
||||
* @see WP_Customize_Control::print_template()
|
||||
* @return void
|
||||
*/
|
||||
protected function content_template() {}
|
||||
|
||||
/**
|
||||
* Returns an array of translation strings.
|
||||
*
|
||||
* @access protected
|
||||
* @since 3.0.0
|
||||
* @return array
|
||||
*/
|
||||
protected function l10n() {
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
import "./control.scss";
|
||||
import "./dynamic-control";
|
|
@ -0,0 +1,289 @@
|
|||
/**
|
||||
* The majority of the code in this file
|
||||
* is derived from the wp-customize-posts plugin
|
||||
* and the work of @westonruter to whom I am very grateful.
|
||||
*
|
||||
* @see https://github.com/xwp/wp-customize-posts
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* A dynamic color-alpha control.
|
||||
*
|
||||
* @class
|
||||
* @augments wp.customize.Control
|
||||
* @augments wp.customize.Class
|
||||
*/
|
||||
wp.customize.kirkiDynamicControl = wp.customize.Control.extend({
|
||||
|
||||
initialize: function (id, options) {
|
||||
let control = this;
|
||||
let args = options || {};
|
||||
|
||||
args.params = args.params || {};
|
||||
|
||||
if (!args.params.type) {
|
||||
args.params.type = 'kirki-generic';
|
||||
}
|
||||
|
||||
let className;
|
||||
|
||||
if (args.content) {
|
||||
let splits = args.content.split('class="');
|
||||
splits = splits[1].split('"');
|
||||
className = splits[0];
|
||||
} else {
|
||||
className = 'customize-control customize-control-' + args.params.type;
|
||||
}
|
||||
|
||||
if (!args.params.wrapper_attrs && args.params.wrapper_atts) {
|
||||
args.params.wrapper_attrs = args.params.wrapper_atts;
|
||||
}
|
||||
|
||||
// Hijack the container to add wrapper_attrs.
|
||||
args.params.content = jQuery("<li></li>");
|
||||
args.params.content.attr('id', 'customize-control-' + id.replace(/]/g, '').replace(/\[/g, '-'));
|
||||
args.params.content.attr('class', className);
|
||||
|
||||
_.each(args.params.wrapper_attrs, function (val, key) {
|
||||
if ('class' === key) {
|
||||
val = val.replace('{default_class}', className);
|
||||
}
|
||||
|
||||
args.params.content.attr(key, val);
|
||||
});
|
||||
|
||||
control.propertyElements = [];
|
||||
wp.customize.Control.prototype.initialize.call(control, id, args);
|
||||
wp.hooks.doAction('kirki.dynamicControl.init.after', id, control, args);
|
||||
},
|
||||
|
||||
/**
|
||||
* Add bidirectional data binding links between inputs and the setting(s).
|
||||
*
|
||||
* This is copied from wp.customize.Control.prototype.initialize(). It
|
||||
* should be changed in Core to be applied once the control is embedded.
|
||||
*
|
||||
* @private
|
||||
* @returns {void}
|
||||
*/
|
||||
_setUpSettingRootLinks: function () {
|
||||
var control = this,
|
||||
nodes = control.container.find('[data-customize-setting-link]');
|
||||
|
||||
nodes.each(function () {
|
||||
var node = jQuery(this);
|
||||
|
||||
wp.customize(node.data('customizeSettingLink'), function (setting) {
|
||||
var element = new wp.customize.Element(node);
|
||||
control.elements.push(element);
|
||||
element.sync(setting);
|
||||
element.set(setting());
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Add bidirectional data binding links between inputs and the setting properties.
|
||||
*
|
||||
* @private
|
||||
* @returns {void}
|
||||
*/
|
||||
_setUpSettingPropertyLinks: function () {
|
||||
var control = this,
|
||||
nodes;
|
||||
|
||||
if (!control.setting) {
|
||||
return;
|
||||
}
|
||||
|
||||
nodes = control.container.find('[data-customize-setting-property-link]');
|
||||
|
||||
nodes.each(function () {
|
||||
var node = jQuery(this),
|
||||
element,
|
||||
propertyName = node.data('customizeSettingPropertyLink');
|
||||
|
||||
element = new wp.customize.Element(node);
|
||||
control.propertyElements.push(element);
|
||||
element.set(control.setting()[propertyName]);
|
||||
|
||||
element.bind(function (newPropertyValue) {
|
||||
var newSetting = control.setting();
|
||||
if (newPropertyValue === newSetting[propertyName]) {
|
||||
return;
|
||||
}
|
||||
newSetting = _.clone(newSetting);
|
||||
newSetting[propertyName] = newPropertyValue;
|
||||
control.setting.set(newSetting);
|
||||
});
|
||||
control.setting.bind(function (newValue) {
|
||||
if (newValue[propertyName] !== element.get()) {
|
||||
element.set(newValue[propertyName]);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ready: function () {
|
||||
var control = this;
|
||||
|
||||
control._setUpSettingRootLinks();
|
||||
control._setUpSettingPropertyLinks();
|
||||
|
||||
wp.customize.Control.prototype.ready.call(control);
|
||||
|
||||
control.deferred.embedded.done(function () {
|
||||
control.initKirkiControl();
|
||||
wp.hooks.doAction('kirki.dynamicControl.ready.deferred.embedded.done', control);
|
||||
});
|
||||
wp.hooks.doAction('kirki.dynamicControl.ready.after', control);
|
||||
},
|
||||
|
||||
/**
|
||||
* Embed the control in the document.
|
||||
*
|
||||
* Override the embed() method to do nothing,
|
||||
* so that the control isn't embedded on load,
|
||||
* unless the containing section is already expanded.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
embed: function () {
|
||||
var control = this,
|
||||
sectionId = control.section();
|
||||
|
||||
if (!sectionId) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp.customize.section(sectionId, function (section) {
|
||||
if ('kirki-expanded' === section.params.type || section.expanded() || wp.customize.settings.autofocus.control === control.id) {
|
||||
control.actuallyEmbed();
|
||||
} else {
|
||||
section.expanded.bind(function (expanded) {
|
||||
if (expanded) {
|
||||
control.actuallyEmbed();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
wp.hooks.doAction('kirki.dynamicControl.embed.after', control);
|
||||
},
|
||||
|
||||
/**
|
||||
* Deferred embedding of control when actually
|
||||
*
|
||||
* This function is called in Section.onChangeExpanded() so the control
|
||||
* will only get embedded when the Section is first expanded.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
actuallyEmbed: function () {
|
||||
var control = this;
|
||||
if ('resolved' === control.deferred.embedded.state()) {
|
||||
return;
|
||||
}
|
||||
control.renderContent();
|
||||
control.deferred.embedded.resolve(); // This triggers control.ready().
|
||||
wp.hooks.doAction('kirki.dynamicControl.actuallyEmbed.after', control);
|
||||
},
|
||||
|
||||
/**
|
||||
* This is not working with autofocus.
|
||||
*
|
||||
* @param {object} [args] Args.
|
||||
* @returns {void}
|
||||
*/
|
||||
focus: function (args) {
|
||||
var control = this;
|
||||
control.actuallyEmbed();
|
||||
wp.customize.Control.prototype.focus.call(control, args);
|
||||
wp.hooks.doAction('kirki.dynamicControl.focus.after', control);
|
||||
},
|
||||
|
||||
/**
|
||||
* Additional actions that run on ready.
|
||||
*
|
||||
* @param {object} control - The control object. If undefined fallsback to the this.
|
||||
* @returns {void}
|
||||
*/
|
||||
initKirkiControl: function (control) {
|
||||
control = control || this;
|
||||
wp.hooks.doAction('kirki.dynamicControl.initKirkiControl', this);
|
||||
|
||||
// Save the value
|
||||
control.container.on('change keyup paste click', 'input', function () {
|
||||
control.setting.set(jQuery(this).val());
|
||||
});
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
(function (api) {
|
||||
|
||||
/**
|
||||
* Set the value and trigger all bound callbacks.
|
||||
*
|
||||
* @since 1.0
|
||||
* @param {object} to - New value.
|
||||
* @returns {Object} - this
|
||||
*/
|
||||
api.Value.prototype.set = function (to) {
|
||||
var from = this._value,
|
||||
parentSetting,
|
||||
newVal;
|
||||
|
||||
to = this._setter.apply(this, arguments);
|
||||
to = this.validate(to);
|
||||
|
||||
// Bail if the sanitized value is null or unchanged.
|
||||
if (null === to || _.isEqual(from, to)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Kirki mod.
|
||||
*/
|
||||
if (this.id && api.control(this.id) && api.control(this.id).params && api.control(this.id).params.parent_setting) {
|
||||
parentSetting = api.control(this.id).params.parent_setting;
|
||||
newVal = {};
|
||||
newVal[this.id.replace(parentSetting + '[', '').replace(']', '')] = to;
|
||||
api.control(parentSetting).setting.set(jQuery.extend({}, api.control(parentSetting).setting._value, newVal));
|
||||
}
|
||||
|
||||
/**
|
||||
* End Kirki mod.
|
||||
*/
|
||||
|
||||
this._value = to;
|
||||
this._dirty = true;
|
||||
|
||||
this.callbacks.fireWith(this, [to, from]);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the value.
|
||||
*
|
||||
* @returns {mixed} - Returns the value.
|
||||
*/
|
||||
api.Value.prototype.get = function () {
|
||||
|
||||
// Start Kirki mod.
|
||||
var parentSetting;
|
||||
if (this.id && api.control(this.id) && api.control(this.id).params && api.control(this.id).params.parent_setting) {
|
||||
parentSetting = api.control(this.id).params.parent_setting;
|
||||
return api.control(parentSetting).setting.get()[this.id.replace(parentSetting + '[', '').replace(']', '')];
|
||||
}
|
||||
// End Kirki mod.
|
||||
|
||||
return this._value;
|
||||
};
|
||||
}(wp.customize));
|
Loading…
Add table
Add a link
Reference in a new issue