Initial commit

This commit is contained in:
Alexander Agnarson 2020-03-11 14:44:42 +01:00
commit b0607606ae
369 changed files with 85494 additions and 0 deletions

View file

@ -0,0 +1,68 @@
<?php
/**
* Automatic preset scripts calculation for Kirki controls.
*
* @package Kirki
* @category Modules
* @author Ari Stathopoulos (@aristath)
* @copyright Copyright (c) 2019, Ari Stathopoulos (@aristath)
* @license https://opensource.org/licenses/MIT
* @since 3.0.26
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Adds styles to the customizer.
*/
class Kirki_Modules_Preset {
/**
* The object instance.
*
* @static
* @access private
* @since 3.0.26
* @var object
*/
private static $instance;
/**
* Constructor.
*
* @access protected
* @since 3.0.26
*/
protected function __construct() {
add_action( 'customize_controls_print_footer_scripts', array( $this, 'customize_controls_print_footer_scripts' ) );
}
/**
* Gets an instance of this object.
* Prevents duplicate instances which avoid artefacts and improves performance.
*
* @static
* @access public
* @since 3.0.26
* @return object
*/
public static function get_instance() {
if ( ! self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Enqueue scripts.
*
* @access public
* @since 3.0.26
*/
public function customize_controls_print_footer_scripts() {
wp_enqueue_script( 'kirki-preset', trailingslashit( Kirki::$url ) . 'modules/preset/preset.js', array( 'jquery' ), KIRKI_VERSION, false );
}
}

View file

@ -0,0 +1,32 @@
/* global kirkiSetSettingValue */
jQuery( document ).ready( function() {
// Loop Controls.
wp.customize.control.each( function( control ) {
// Check if we have a preset defined.
if ( control.params && control.params.preset && ! _.isEmpty( control.params.preset ) ) {
wp.customize( control.id, function( value ) {
// Listen to value changes.
value.bind( function( to ) {
// Loop preset definitions.
_.each( control.params.preset, function( preset, valueToListen ) {
// Check if the value set want is the same as the one we're looking for.
if ( valueToListen === to ) {
// Loop settings defined inside the preset.
_.each( preset.settings, function( controlValue, controlID ) {
// Set the value.
kirkiSetSettingValue.set( controlID, controlValue );
} );
}
} );
} );
} );
}
} );
} );