mirror of
https://ghproxy.net/https://github.com/AlxMedia/magaziner.git
synced 2025-08-28 09:43:30 +08:00
Update to Kirki 4.0.22
This commit is contained in:
parent
2b6ac38550
commit
78edeb1b25
492 changed files with 29668 additions and 39884 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,58 @@
|
|||
# control-dimensions
|
||||
|
||||
## Installation
|
||||
|
||||
First, install the package using composer:
|
||||
|
||||
```bash
|
||||
composer require kirki-framework/control-dimensions
|
||||
```
|
||||
|
||||
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\Dimensions' );
|
||||
} );
|
||||
|
||||
/**
|
||||
* 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' => [
|
||||
'top' => '10px',
|
||||
'bottom' => '3em',
|
||||
],
|
||||
'transport' => 'refresh', // Or postMessage.
|
||||
'sanitize_callback' => 'sanitize_text_field', // Or a custom sanitization callback.
|
||||
] );
|
||||
|
||||
// Add control.
|
||||
$wp_customize->add_control( new \Kirki\Control\Dimensions( $wp_customize, 'my_control', [
|
||||
'label' => esc_html__( 'My Control', 'theme_textdomain' ),
|
||||
'section' => 'my_section',
|
||||
] ) );
|
||||
} );
|
||||
```
|
2
functions/kirki/packages/kirki-framework/field-dimensions/dist/control.css
vendored
Normal file
2
functions/kirki/packages/kirki-framework/field-dimensions/dist/control.css
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
/*# sourceMappingURL=control.css.map */
|
2
functions/kirki/packages/kirki-framework/field-dimensions/dist/preview.js
vendored
Normal file
2
functions/kirki/packages/kirki-framework/field-dimensions/dist/preview.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
jQuery(document).ready((function(){wp.hooks.addFilter("kirkiPostMessageStylesOutput","kirki",(function(e,t,i,o){var r;return"kirki-dimensions"===o&&(e+=i.element+"{",_.each(t,(function(t,o){i.choice&&o!==i.choice||!1!==(r=kirkiPostMessage.util.processValue(i,t))&&(i.property?(e+=i.property,""===i.property||"top"!==o&&"bottom"!==o&&"left"!==o&&"right"!==o||(e+="-"+o),e+=":"+r+";"):e+=o+":"+r+";")})),e+="}"),e}))}));
|
||||
//# sourceMappingURL=preview.js.map
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
/**
|
||||
* Handles CSS output for dimensions fields.
|
||||
*
|
||||
* @package Kirki
|
||||
* @subpackage Controls
|
||||
* @copyright Copyright (c) 2019, Ari Stathopoulos (@aristath)
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
* @since 2.2.0
|
||||
*/
|
||||
|
||||
namespace Kirki\Field\CSS;
|
||||
|
||||
use Kirki\Module\CSS\Output;
|
||||
|
||||
/**
|
||||
* Output overrides.
|
||||
*/
|
||||
class Dimensions extends Output {
|
||||
|
||||
/**
|
||||
* Processes a single item from the `output` array.
|
||||
*
|
||||
* @access protected
|
||||
* @param array $output The `output` item.
|
||||
* @param array $value The field's value.
|
||||
*/
|
||||
protected function process_output( $output, $value ) {
|
||||
$output = wp_parse_args(
|
||||
$output,
|
||||
[
|
||||
'element' => '',
|
||||
'property' => '',
|
||||
'media_query' => 'global',
|
||||
'prefix' => '',
|
||||
'suffix' => '',
|
||||
]
|
||||
);
|
||||
|
||||
if ( ! is_array( $value ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( array_keys( $value ) as $key ) {
|
||||
|
||||
$property = ( empty( $output['property'] ) ) ? $key : $output['property'] . '-' . $key;
|
||||
if ( isset( $output['choice'] ) && $output['property'] ) {
|
||||
if ( $key === $output['choice'] ) {
|
||||
$property = $output['property'];
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ( false !== strpos( $output['property'], '%%' ) ) {
|
||||
$property = str_replace( '%%', $key, $output['property'] );
|
||||
}
|
||||
$this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $this->process_property_value( $property, $value[ $key ] ) . $output['suffix'];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,267 @@
|
|||
<?php
|
||||
/**
|
||||
* Override field methods
|
||||
*
|
||||
* @package kirki-framework/field-dimensions
|
||||
* @copyright Copyright (c) 2019, Ari Stathopoulos (@aristath)
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
namespace Kirki\Field;
|
||||
|
||||
use Kirki;
|
||||
use Kirki\Field;
|
||||
use Kirki\URL;
|
||||
|
||||
/**
|
||||
* Field overrides.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class Dimensions extends Field {
|
||||
|
||||
/**
|
||||
* The field type.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'kirki-dimensions';
|
||||
|
||||
/**
|
||||
* Extra logic for the field.
|
||||
*
|
||||
* Adds all sub-fields.
|
||||
*
|
||||
* @access public
|
||||
* @param array $args The arguments of the field.
|
||||
*/
|
||||
public function init( $args = array() ) {
|
||||
|
||||
add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
add_action( 'customize_preview_init', array( $this, 'enqueue_customize_preview_scripts' ) );
|
||||
add_filter( 'kirki_output_control_classnames', array( $this, 'output_control_classnames' ) );
|
||||
|
||||
$args['required'] = isset( $args['required'] ) ? (array) $args['required'] : array();
|
||||
|
||||
$labels = array(
|
||||
'left-top' => esc_html__( 'Left Top', 'kirki' ),
|
||||
'left-center' => esc_html__( 'Left Center', 'kirki' ),
|
||||
'left-bottom' => esc_html__( 'Left Bottom', 'kirki' ),
|
||||
'right-top' => esc_html__( 'Right Top', 'kirki' ),
|
||||
'right-center' => esc_html__( 'Right Center', 'kirki' ),
|
||||
'right-bottom' => esc_html__( 'Right Bottom', 'kirki' ),
|
||||
'center-top' => esc_html__( 'Center Top', 'kirki' ),
|
||||
'center-center' => esc_html__( 'Center Center', 'kirki' ),
|
||||
'center-bottom' => esc_html__( 'Center Bottom', 'kirki' ),
|
||||
'font-size' => esc_html__( 'Font Size', 'kirki' ),
|
||||
'font-weight' => esc_html__( 'Font Weight', 'kirki' ),
|
||||
'line-height' => esc_html__( 'Line Height', 'kirki' ),
|
||||
'font-style' => esc_html__( 'Font Style', 'kirki' ),
|
||||
'letter-spacing' => esc_html__( 'Letter Spacing', 'kirki' ),
|
||||
'word-spacing' => esc_html__( 'Word Spacing', 'kirki' ),
|
||||
'top' => esc_html__( 'Top', 'kirki' ),
|
||||
'bottom' => esc_html__( 'Bottom', 'kirki' ),
|
||||
'left' => esc_html__( 'Left', 'kirki' ),
|
||||
'right' => esc_html__( 'Right', 'kirki' ),
|
||||
'center' => esc_html__( 'Center', 'kirki' ),
|
||||
'size' => esc_html__( 'Size', 'kirki' ),
|
||||
'spacing' => esc_html__( 'Spacing', 'kirki' ),
|
||||
'width' => esc_html__( 'Width', 'kirki' ),
|
||||
'height' => esc_html__( 'Height', 'kirki' ),
|
||||
'invalid-value' => esc_html__( 'Invalid Value', 'kirki' ),
|
||||
);
|
||||
|
||||
/**
|
||||
* Add a hidden field, the label & description.
|
||||
*/
|
||||
new \Kirki\Field\Generic(
|
||||
wp_parse_args(
|
||||
array(
|
||||
'type' => 'kirki-generic',
|
||||
'default' => '',
|
||||
'wrapper_opts' => array(
|
||||
'gap' => 'small',
|
||||
),
|
||||
'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : array( __CLASS__, 'sanitize' ),
|
||||
'choices' => array(
|
||||
'type' => 'hidden',
|
||||
'parent_type' => 'kirki-dimensions',
|
||||
),
|
||||
),
|
||||
$args
|
||||
)
|
||||
);
|
||||
|
||||
$args['choices'] = isset( $args['choices'] ) ? $args['choices'] : array();
|
||||
$args['choices']['labels'] = isset( $args['choices']['labels'] ) ? $args['choices']['labels'] : array();
|
||||
|
||||
if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
|
||||
$args['transport'] = 'postMessage';
|
||||
}
|
||||
|
||||
$total_items = count( $args['default'] );
|
||||
$item_count = 0;
|
||||
|
||||
$width = 100;
|
||||
|
||||
$break_indexes = array();
|
||||
|
||||
// The 'kirki-group-break' only supports 12 group items inside a group.
|
||||
if ( 2 === $total_items ) {
|
||||
$width = 50;
|
||||
} elseif ( 3 === $total_items ) {
|
||||
$width = 33;
|
||||
} elseif ( 4 === $total_items ) {
|
||||
$width = 25;
|
||||
} elseif ( 5 === $total_items ) {
|
||||
array_push( $break_indexes, 3 );
|
||||
$width = 33;
|
||||
} elseif ( 6 === $total_items ) {
|
||||
array_push( $break_indexes, 3 );
|
||||
$width = 33;
|
||||
} elseif ( 7 === $total_items || 8 === $total_items ) {
|
||||
array_push( $break_indexes, 4 );
|
||||
$width = 25;
|
||||
} elseif ( 9 === $total_items ) {
|
||||
array_push( $break_indexes, 3, 6 );
|
||||
$width = 33;
|
||||
} elseif ( $total_items > 9 ) {
|
||||
array_push( $break_indexes, 4, 8 );
|
||||
$width = 25;
|
||||
}
|
||||
|
||||
foreach ( $args['default'] as $choice => $default ) {
|
||||
$item_count++;
|
||||
|
||||
$label = $choice;
|
||||
$label = isset( $labels[ $choice ] ) ? $labels[ $choice ] : $label;
|
||||
$label = isset( $args['choices']['labels'][ $choice ] ) ? $args['choices']['labels'][ $choice ] : $label;
|
||||
|
||||
$wrapper_attrs = array(
|
||||
'data-kirki-parent-control-type' => 'kirki-dimensions',
|
||||
'data-kirki-parent-control-setting' => $args['settings'],
|
||||
'class' => '{default_class} kirki-group-item kirki-w' . $width,
|
||||
);
|
||||
|
||||
if ( $item_count === 1 ) {
|
||||
$wrapper_attrs['class'] .= ' kirki-group-start';
|
||||
}
|
||||
|
||||
if ( in_array( $item_count, $break_indexes, true ) ) {
|
||||
$wrapper_attrs['class'] .= ' kirki-group-break';
|
||||
}
|
||||
|
||||
if ( $item_count === $total_items ) {
|
||||
$wrapper_attrs['class'] .= ' kirki-group-end';
|
||||
}
|
||||
|
||||
new \Kirki\Field\Dimension(
|
||||
wp_parse_args(
|
||||
array(
|
||||
'type' => 'kirki-dimension',
|
||||
'settings' => $args['settings'] . '[' . $choice . ']',
|
||||
'parent_setting' => $args['settings'],
|
||||
'label' => $label,
|
||||
'default' => $default,
|
||||
'wrapper_attrs' => $wrapper_attrs,
|
||||
'choices' => array(
|
||||
'label_position' => 'bottom',
|
||||
),
|
||||
'js_vars' => array(),
|
||||
'css_vars' => array(),
|
||||
'output' => array(),
|
||||
),
|
||||
$args
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes dimension controls.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @param array $value The value.
|
||||
* @return array
|
||||
*/
|
||||
public static function sanitize( $value ) {
|
||||
|
||||
if ( ! is_array( $value ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach ( $value as $key => $val ) {
|
||||
$value[ $key ] = sanitize_text_field( $val );
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Override parent method. No need to register any setting.
|
||||
*
|
||||
* @access public
|
||||
* @since 0.1
|
||||
* @param WP_Customize_Manager $wp_customize The customizer instance.
|
||||
* @return void
|
||||
*/
|
||||
public function add_setting( $wp_customize ) {}
|
||||
|
||||
/**
|
||||
* Override the parent method. No need for a control.
|
||||
*
|
||||
* @access public
|
||||
* @since 0.1
|
||||
* @param WP_Customize_Manager $wp_customize The customizer instance.
|
||||
* @return void
|
||||
*/
|
||||
public function add_control( $wp_customize ) {}
|
||||
|
||||
/**
|
||||
* Enqueue scripts & styles.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue_scripts() {
|
||||
|
||||
wp_enqueue_style( 'kirki-field-dimensions', URL::get_from_path( dirname( __DIR__ ) . '/dist/control.css' ), array(), '1.0' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue scripts & styles on customize_preview_init.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue_customize_preview_scripts() {
|
||||
|
||||
wp_enqueue_script( 'kirki-field-dimensions', URL::get_from_path( dirname( __DIR__ ) ) . '/dist/preview.js', array( 'wp-hooks' ), '1.0', true );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom output class for typography fields.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @param array $classnames The array of classnames.
|
||||
* @return array
|
||||
*/
|
||||
public function output_control_classnames( $classnames ) {
|
||||
|
||||
$classnames['kirki-dimensions'] = '\Kirki\Field\CSS\Dimensions';
|
||||
return $classnames;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/* global kirkiPostMessage */
|
||||
|
||||
import "./control.scss";
|
||||
|
||||
/**
|
||||
* Hook in the kirkiPostMessageStylesOutput filter.
|
||||
*
|
||||
* Handles postMessage styles for typography controls.
|
||||
*/
|
||||
jQuery( document ).ready( function() {
|
||||
wp.hooks.addFilter(
|
||||
'kirkiPostMessageStylesOutput',
|
||||
'kirki',
|
||||
|
||||
/**
|
||||
* Append styles for this control.
|
||||
*
|
||||
* @param {string} styles - The styles.
|
||||
* @param {Object} value - The control value.
|
||||
* @param {Object} output - The control's "output" argument.
|
||||
* @param {string} controlType - The control type.
|
||||
* @returns {string} - Returns the CSS as a string.
|
||||
*/
|
||||
function( styles, value, output, controlType ) {
|
||||
var processedValue;
|
||||
if ( 'kirki-dimensions' === controlType ) {
|
||||
styles += output.element + '{';
|
||||
_.each( value, function( val, key ) {
|
||||
if ( output.choice && key !== output.choice ) {
|
||||
return;
|
||||
}
|
||||
processedValue = kirkiPostMessage.util.processValue( output, val );
|
||||
|
||||
if ( false !== processedValue ) {
|
||||
|
||||
// Mostly used for padding, margin & position properties.
|
||||
if ( output.property ) {
|
||||
styles += output.property;
|
||||
if ( '' !== output.property && ( 'top' === key || 'bottom' === key || 'left' === key || 'right' === key ) ) {
|
||||
styles += '-' + key;
|
||||
}
|
||||
styles += ':' + processedValue + ';';
|
||||
} else {
|
||||
styles += key + ':' + processedValue + ';';
|
||||
}
|
||||
}
|
||||
} );
|
||||
styles += '}';
|
||||
}
|
||||
return styles;
|
||||
}
|
||||
);
|
||||
} );
|
Loading…
Add table
Add a link
Reference in a new issue