Update to Kirki 4.2.0

This commit is contained in:
AlxMedia 2023-08-04 15:41:48 +02:00
parent cbfd4f27e4
commit 77ecd4ca69
440 changed files with 6230 additions and 5211 deletions

View file

@ -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.

View file

@ -0,0 +1,2 @@
.customize-control-kirki-dimension .has-label-bottom .kirki-control-label{color:#333;font-size:11px;font-weight:500;margin-top:3px;text-align:center}.customize-control-kirki-dimension .has-label-bottom .kirki-control-input{background-color:#f7f7f7}.customize-control-kirki-dimension .has-label-bottom .kirki-control-input:focus{background-color:#fff}
/*# sourceMappingURL=control.css.map */

View file

@ -0,0 +1 @@
{"mappings":"AAEI,0EAIE,UAAA,CADA,cAAA,CAEA,eAAA,CAJA,cAAA,CACA,iBCEN,CDII,0EACE,wBCFN,CDIM,gFACE,qBCFR","sources":["src/control.scss","%3Cinput%20css%20bqm70f%3E"],"sourcesContent":[".customize-control-kirki-dimension {\r\n .has-label-bottom {\r\n .kirki-control-label {\r\n margin-top: 3px;\r\n text-align: center;\r\n font-size: 11px;\r\n color: #333;\r\n font-weight: 500;\r\n }\r\n\r\n .kirki-control-input {\r\n background-color: #f7f7f7;\r\n\r\n &:focus {\r\n background-color: #fff;\r\n }\r\n }\r\n }\r\n}\r\n",".customize-control-kirki-dimension .has-label-bottom .kirki-control-label {\n margin-top: 3px;\n text-align: center;\n font-size: 11px;\n color: #333;\n font-weight: 500;\n}\n.customize-control-kirki-dimension .has-label-bottom .kirki-control-input {\n background-color: #f7f7f7;\n}\n.customize-control-kirki-dimension .has-label-bottom .kirki-control-input:focus {\n background-color: #fff;\n}\n/*# sourceMappingURL=control.css.map */\n"],"names":[],"version":3,"file":"control.css.map"}

View file

@ -0,0 +1,2 @@
wp.customize.controlConstructor["kirki-dimension"]=wp.customize.kirkiDynamicControl.extend({initKirkiControl:function(i){var n;(i=i||this).kirkiNotifications(),i.container.on("change keyup paste","input",(function(){n=jQuery(this).val(),i.setting.set(n)}))},kirkiNotifications:function(){var i=this,n=void 0!==i.params.choices&&void 0!==i.params.choices.accept_unitless&&!0===i.params.choices.accept_unitless;wp.customize(i.id,(function(t){t.bind((function(e){var a="long_title";!1!==i.validateCssValue(e)||n&&!isNaN(e)?t.notifications.remove(a):t.notifications.add(a,new wp.customize.Notification(a,{type:"warning",message:dimensionkirkiL10n["invalid-value"]}))}))}))},validateCssValue:function(i){var n,t,e,a=this,o=!0;return!i||""===i||0===i||"0"===i||"auto"===i||"inherit"===i||"initial"===i||0<=i.indexOf("calc(")&&0<=i.indexOf(")")||(n=parseFloat(i),!(t=i.replace(n,""))||(2<=(e=i.split(" ")).length?(e.forEach((function(i){i&&!a.validateCssValue(i)&&(o=!1)})),o):!isNaN(n)&&-1!==["fr","rem","em","ex","%","px","cm","mm","in","pt","pc","ch","vh","vw","vmin","vmax"].indexOf(t)))}});
//# sourceMappingURL=control.js.map

View file

@ -0,0 +1 @@
{"mappings":"AAGAA,GAAGC,UAAUC,mBAAmB,mBAAqBF,GAAGC,UAAUE,oBAAoBC,OAAQ,CAE7FC,iBAAkB,SAAUC,GAC3B,IAAIC,GACJD,EAAUA,GAAWE,MAGbC,qBAGRH,EAAQI,UAAUC,GAAI,qBAAsB,SAAS,WACpDJ,EAAQK,OAAQJ,MAAOK,MACvBP,EAAQQ,QAAQC,IAAKR,0BAgBZ,iBAEHC,KAAKQ,OAAa,IAAiCV,EAAAW,OAAcC,cAAW,IACxEZ,EAAiBW,OAAQC,QAAOC,kBAAU,IAAoBb,EAACW,OAAAC,QAAAC,6BACtEb,EAAec,IAAA,SAAAN,KACfO,MAAA,SAASd,GACV,IAACe,EAAA,kBAEOhB,EAAAiB,iBAA0BhB,IAAAS,IAAAQ,MAAAjB,GAMtBO,EAAEW,cAAlBC,OAA4BJ,GANUR,EAAAW,cAAAE,IAAAL,EAAA,IAAAtB,GAAAC,UAAA2B,aAAAN,EAAA,CAEnCO,KAAA,UACDC,QAAAC,mBAAA,4CAMgC,SAAAxB,OAY/ByB,EAAcC,EAASC,EAZU5B,EAAIE,KAYP2B,GAAiB,EAKjD,OAAA5B,GAAY,KAAGA,GAAY,IAAKA,GAAA,MAAAA,GAAA,SAAAA,GAAA,YAAAA,GAAA,YAAAA,GAG5B,GAAGA,EAAM6B,QAAS,UAAc,GAAE7B,EAAA6B,QAAA,OAGtCJ,EACCK,WAAW9B,KAIZ0B,EAAA1B,EAAY+B,QAAMN,EAAU,OAQ3B,MAFCzB,EAAAgC,MAAA,MAEMC,QACPN,EAAAO,SAAA,SAAAC,GAEoDA,IAAApC,EAAAiB,iBAAAmB,KAAAP,GAAA,MAErDA,mBAzCuC,CAAE,KAAK,MAAM,KAAM,KAAM,IAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAQ,KAC3G,KAKmB,KAClB,OAIyB","sources":["src/control.js"],"sourcesContent":["import \"./control.scss\";\r\n\r\n/* global dimensionkirkiL10n */\r\nwp.customize.controlConstructor['kirki-dimension'] = wp.customize.kirkiDynamicControl.extend( {\r\n\r\n\tinitKirkiControl: function( control ) {\r\n\t\tvar value;\r\n\t\tcontrol = control || this;\r\n\r\n\t\t// Notifications.\r\n\t\tcontrol.kirkiNotifications();\r\n\r\n\t\t// Save the value\r\n\t\tcontrol.container.on( 'change keyup paste', 'input', function() {\r\n\t\t\tvalue = jQuery( this ).val();\r\n\t\t\tcontrol.setting.set( value );\r\n\t\t} );\r\n\t},\r\n\r\n\t/**\r\n\t * Handles notifications.\r\n\t *\r\n\t * @returns {void}\r\n\t */\r\n\tkirkiNotifications: function() {\r\n\r\n\t\tvar control = this,\r\n\t\t\tacceptUnitless = ( 'undefined' !== typeof control.params.choices && 'undefined' !== typeof control.params.choices.accept_unitless && true === control.params.choices.accept_unitless );\r\n\r\n\t\twp.customize( control.id, function( setting ) {\r\n\t\t\tsetting.bind( function( value ) {\r\n\t\t\t\tvar code = 'long_title';\r\n\r\n\t\t\t\tif ( false === control.validateCssValue( value ) && ( ! acceptUnitless || isNaN( value ) ) ) {\r\n\t\t\t\t\tsetting.notifications.add( code, new wp.customize.Notification( code, {\r\n\t\t\t\t\t\ttype: 'warning',\r\n\t\t\t\t\t\tmessage: dimensionkirkiL10n['invalid-value']\r\n\t\t\t\t\t} ) );\r\n\t\t\t\t} else {\r\n\t\t\t\t\tsetting.notifications.remove( code );\r\n\t\t\t\t}\r\n\t\t\t} );\r\n\t\t} );\r\n\t},\r\n\r\n\tvalidateCssValue: function( value ) {\r\n\r\n\t\tvar control = this,\r\n\t\t\tvalidUnits = [ 'fr', 'rem', 'em', 'ex', '%', 'px', 'cm', 'mm', 'in', 'pt', 'pc', 'ch', 'vh', 'vw', 'vmin', 'vmax' ],\r\n\t\t\tnumericValue,\r\n\t\t\tunit,\r\n\t\t\tmultiples,\r\n\t\t\tmultiplesValid = true;\r\n\r\n\t\t// Whitelist values.\r\n\t\tif ( ! value || '' === value || 0 === value || '0' === value || 'auto' === value || 'inherit' === value || 'initial' === value ) {\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\t// Skip checking if calc().\r\n\t\tif ( 0 <= value.indexOf( 'calc(' ) && 0 <= value.indexOf( ')' ) ) {\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\t// Get the numeric value.\r\n\t\tnumericValue = parseFloat( value );\r\n\r\n\t\t// Get the unit\r\n\t\tunit = value.replace( numericValue, '' );\r\n\r\n\t\t// Allow unitless.\r\n\t\tif ( ! unit ) {\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\t// Check for multiple values.\r\n\t\tmultiples = value.split( ' ' );\r\n\t\tif ( 2 <= multiples.length ) {\r\n\t\t\tmultiples.forEach( function( item ) {\r\n\t\t\t\tif ( item && ! control.validateCssValue( item ) ) {\r\n\t\t\t\t\tmultiplesValid = false;\r\n\t\t\t\t}\r\n\t\t\t});\r\n\r\n\t\t\treturn multiplesValid;\r\n\t\t}\r\n\r\n\t\t// Check the validity of the numeric value and units.\r\n\t\treturn ( ! isNaN( numericValue ) && -1 !== validUnits.indexOf( unit ) );\r\n\t}\r\n} );\r\n"],"names":["wp","customize","controlConstructor","kirkiDynamicControl","extend","initKirkiControl","control","value","this","kirkiNotifications","container","on","jQuery","val","setting","set","acceptUnitless","params","choices","accept_unitless","id","bind","code","validateCssValue","isNaN","notifications","remove","add","Notification","type","message","dimensionkirkiL10n","numericValue","unit","multiples","multiplesValid","indexOf","parseFloat","replace","split","length","forEach","item"],"version":3,"file":"control.js.map"}

View file

@ -0,0 +1,159 @@
<?php
/**
* Customizer Control: dimension
*
* @package kirki-framework/control-dimension
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Control;
use Kirki\Control\Base;
use Kirki\URL;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* A text control with validation for CSS units.
*
* @since 1.0
*/
class Dimension extends Base {
/**
* The control type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-dimension';
/**
* The version. Used in scripts & styles for cache-busting.
*
* @static
* @access public
* @since 1.0
* @var string
*/
public static $control_ver = '1.0';
/**
* Enqueue control related scripts/styles.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue() {
parent::enqueue();
// Enqueue the script.
wp_enqueue_script( 'kirki-control-dimension', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false );
// Enqueue the style.
wp_enqueue_style( 'kirki-control-dimension-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver );
wp_localize_script(
'kirki-control-dimension',
'dimensionkirkiL10n',
[
'invalid-value' => esc_html__( 'Invalid Value', 'kirki' ),
]
);
}
/**
* Get the URL for the control folder.
*
* This is a static method because there are more controls in the Kirki framework
* that use colorpickers, and they all need to enqueue the same assets.
*
* @static
* @access public
* @since 1.0
* @return string
*/
public static function get_control_path_url() {
return URL::get_from_path( dirname( __DIR__ ) );
}
/**
* 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() {
$input_class = 'kirki-control-input';
if ( isset( $this->input_attrs['class'] ) ) {
$input_class .= ' ' . $this->input_attrs['class'];
unset( $this->input_attrs['class'] );
}
// Get the basics from the parent class.
parent::to_json();
// Input class name.
$this->json['inputClass'] = $input_class;
// Label position.
$this->json['labelPosition'] = 'top';
if ( isset( $this->choices['label_position'] ) && 'bottom' === $this->choices['label_position'] ) {
$this->json['labelPosition'] = 'bottom';
}
// Input id.
$this->json['inputId'] = '_customize-input-' . $this->id;
}
/**
* 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()}.
*
* @see WP_Customize_Control::print_template()
*
* @access protected
* @since 1.0
* @return void
*/
protected function content_template() {
?>
<div class="kirki-control-form <# if ('bottom' === data.labelPosition) { #>has-label-bottom<# } #>">
<# if ( 'top' === data.labelPosition ) { #>
<label class="kirki-control-label" for="{{ data.inputId }}">
<# if ( data.label ) { #><span class="customize-control-title">{{{ data.label }}}</span><# } #>
<# if ( data.description ) { #><span class="description customize-control-description">{{{ data.description }}}</span><# } #>
</label>
<# } #>
<div class="kirki-input-control">
<# var val = ( data.value && _.isString( data.value ) ) ? data.value.replace( '%%', '%' ) : ''; #>
<input id="{{ data.inputId }}" {{{ data.inputAttrs }}} type="text" value="{{ val }}" class="{{ data.inputClass }}" />
</div>
<# if ( 'bottom' === data.labelPosition ) { #>
<label class="kirki-control-label" for="{{ data.inputId }}">
<# if ( data.label ) { #>{{{ data.label }}} <# } #>
</label>
<# } #>
</div>
<?php
}
}

View file

@ -0,0 +1,84 @@
<?php
/**
* Override field methods
*
* @package Kirki
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
use Kirki\Field;
/**
* Field overrides.
*/
class Dimension extends Field {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-dimension';
/**
* The control class-name.
*
* @access protected
* @since 0.1
* @var string
*/
protected $control_class = '\Kirki\Control\Dimension';
/**
* Whether we should register the control class for JS-templating or not.
*
* @access protected
* @since 0.1
* @var bool
*/
protected $control_has_js_template = true;
/**
* Filter arguments before creating the setting.
*
* @access public
* @since 0.1
* @param array $args The field arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array
*/
public function filter_setting_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] ) {
$args = parent::filter_setting_args( $args, $wp_customize );
// Set the sanitize-callback if none is defined.
if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) {
$args['sanitize_callback'] = 'sanitize_text_field';
}
}
return $args;
}
/**
* Filter arguments before creating the control.
*
* @access public
* @since 0.1
* @param array $args The field arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array
*/
public function filter_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['type'] = 'kirki-dimension';
}
return $args;
}
}

View file

@ -0,0 +1,91 @@
import "./control.scss";
/* global dimensionkirkiL10n */
wp.customize.controlConstructor['kirki-dimension'] = wp.customize.kirkiDynamicControl.extend( {
initKirkiControl: function( control ) {
var value;
control = control || this;
// Notifications.
control.kirkiNotifications();
// Save the value
control.container.on( 'change keyup paste', 'input', function() {
value = jQuery( this ).val();
control.setting.set( value );
} );
},
/**
* Handles notifications.
*
* @returns {void}
*/
kirkiNotifications: function() {
var control = this,
acceptUnitless = ( 'undefined' !== typeof control.params.choices && 'undefined' !== typeof control.params.choices.accept_unitless && true === control.params.choices.accept_unitless );
wp.customize( control.id, function( setting ) {
setting.bind( function( value ) {
var code = 'long_title';
if ( false === control.validateCssValue( value ) && ( ! acceptUnitless || isNaN( value ) ) ) {
setting.notifications.add( code, new wp.customize.Notification( code, {
type: 'warning',
message: dimensionkirkiL10n['invalid-value']
} ) );
} else {
setting.notifications.remove( code );
}
} );
} );
},
validateCssValue: function( value ) {
var control = this,
validUnits = [ 'fr', 'rem', 'em', 'ex', '%', 'px', 'cm', 'mm', 'in', 'pt', 'pc', 'ch', 'vh', 'vw', 'vmin', 'vmax' ],
numericValue,
unit,
multiples,
multiplesValid = true;
// Whitelist values.
if ( ! value || '' === value || 0 === value || '0' === value || 'auto' === value || 'inherit' === value || 'initial' === value ) {
return true;
}
// Skip checking if calc().
if ( 0 <= value.indexOf( 'calc(' ) && 0 <= value.indexOf( ')' ) ) {
return true;
}
// Get the numeric value.
numericValue = parseFloat( value );
// Get the unit
unit = value.replace( numericValue, '' );
// Allow unitless.
if ( ! unit ) {
return true;
}
// Check for multiple values.
multiples = value.split( ' ' );
if ( 2 <= multiples.length ) {
multiples.forEach( function( item ) {
if ( item && ! control.validateCssValue( item ) ) {
multiplesValid = false;
}
});
return multiplesValid;
}
// Check the validity of the numeric value and units.
return ( ! isNaN( numericValue ) && -1 !== validUnits.indexOf( unit ) );
}
} );

View file

@ -0,0 +1,19 @@
.customize-control-kirki-dimension {
.has-label-bottom {
.kirki-control-label {
margin-top: 3px;
text-align: center;
font-size: 11px;
color: #333;
font-weight: 500;
}
.kirki-control-input {
background-color: #f7f7f7;
&:focus {
background-color: #fff;
}
}
}
}