mirror of
https://ghproxy.net/https://github.com/AlxMedia/curver.git
synced 2025-08-29 00:41: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,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
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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 ) );
|
||||
}
|
||||
} );
|
Loading…
Add table
Add a link
Reference in a new issue