Update to Kirki 4.0.22

This commit is contained in:
AlxMedia 2022-03-15 14:29:17 +01:00
parent 2b6ac38550
commit 78edeb1b25
492 changed files with 29668 additions and 39884 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,55 @@
# control-dimension
## Installation
First, install the package using composer:
```bash
composer require kirki-framework/control-dimension
```
Make sure you include the autoloader:
```php
require_once get_parent_theme_file_path( 'vendor/autoload.php' );
```
To add a control using the customizer API:
```php
/**
* Registers the control and whitelists it for JS templating.
*
* @since 1.0
* @param WP_Customize_Manager $wp_customize The WP_Customize_Manager object.
* @return void
*/
add_action( 'customize_register', function( $wp_customize ) {
$wp_customize->register_control_type( '\Kirki\Control\Dimension' );
} );
/**
* Add Customizer settings & controls.
*
* @since 1.0
* @param WP_Customize_Manager $wp_customize The WP_Customize_Manager object.
* @return void
*/
add_action( 'customize_register', function( $wp_customize ) {
// Add setting.
$wp_customize->add_setting( 'my_control', [
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'default' => '10px',
'transport' => 'refresh', // Or postMessage.
'sanitize_callback' => 'sanitize_text_field', // Or a custom sanitization callback.
] );
// Add control.
$wp_customize->add_control( new \Kirki\Control\Dimension( $wp_customize, 'my_control', [
'label' => esc_html__( 'My Control', 'theme_textdomain' ),
'section' => 'my_section',
] ) );
} );
```

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,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,159 @@
<?php
/**
* Customizer Control: dimension
*
* @package kirki-framework/control-dimension
* @copyright Copyright (c) 2019, Ari Stathopoulos (@aristath)
* @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) 2019, Ari Stathopoulos (@aristath)
* @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 ) );
}
} );