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,135 @@
<?php
/**
* Creates a new panel.
*
* @package Kirki
* @subpackage Custom Sections Module
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki;
/**
* Panel.
*/
class Panel {
/**
* The panel ID.
*
* @access protected
* @since 1.0
* @var string
*/
protected $id;
/**
* The panel arguments.
*
* @access protected
* @since 1.0
* @var array
*/
protected $args;
/**
* An array of our panel types.
*
* @access private
* @var array
*/
private $panel_types = [
'default' => 'WP_Customize_Panel',
'kirki-nested' => '\Kirki\Panel_Types\Nested',
];
/**
* Constructor.
*
* @access public
* @since 1.0
* @param string $id The panel ID.
* @param array $args The panel args.
*/
public function __construct( $id, $args = [] ) {
$this->id = $id;
$this->args = $args;
$this->panel_types = apply_filters( 'kirki_panel_types', $this->panel_types );
if ( $this->args ) {
add_action( 'customize_register', [ $this, 'add_panel' ] );
}
add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_scrips' ] );
}
/**
* Add the panel using the Customizer API.
*
* @access public
* @since 1.0
* @param object $wp_customize The customizer object.
*/
public function add_panel( $wp_customize ) {
// Figure out the type of this panel.
$this->args['type'] = isset( $this->args['type'] ) ? $this->args['type'] : 'default';
if ( isset( $this->args['panel'] ) && ! empty( $this->args['panel'] ) ) {
$this->args['type'] = 'kirki-nested';
}
$this->args['type'] = false === strpos( $this->args['type'], 'kirki-' ) ? 'kirki-' . $this->args['type'] : $this->args['type'];
$this->args['type'] = 'kirki-default' === $this->args['type'] ? 'default' : $this->args['type'];
// Get the class we'll be using to create this panel.
$panel_classname = $this->panel_types[ $this->args['type'] ];
// Fallback to the default panel type if the custom class doesn't exist.
$panel_classname = class_exists( $panel_classname ) ? $panel_classname : 'WP_Customize_Panel';
// Add the panel.
$wp_customize->add_panel(
new $panel_classname(
$wp_customize,
$this->id,
apply_filters( 'kirki_panel_args', $this->args, $this->id )
)
);
// Run an action after the panel has been added.
do_action( 'kirki_panel_added', $this->id, $this->args );
}
/**
* Removes the panel.
*
* @access public
* @since 1.0
* @return void
*/
public function remove() {
add_action( 'customize_register', [ $this, 'remove_panel' ], 9999 );
}
/**
* Add the panel using the Customizer API.
*
* @access public
* @since 1.0
* @param object $wp_customize The customizer object.
*/
public function remove_panel( $wp_customize ) {
$wp_customize->remove_panel( $this->id );
}
/**
* Enqueues any necessary scripts and styles.
*
* @access public
* @since 1.0
*/
public function enqueue_scrips() {
wp_enqueue_script( 'kirki-panels', URL::get_from_path( __DIR__ . '/script.js' ), [ 'jquery', 'customize-base', 'customize-controls' ], '1.0', false );
}
}

View file

@ -0,0 +1,63 @@
<?php
/**
* Nested section.
*
* @package Kirki
* @subpackage Custom Sections Module
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 3.0.0
*/
namespace Kirki\Panel_Types;
/**
* Nested panel.
*/
class Nested extends \WP_Customize_Panel {
/**
* The parent panel.
*
* @access public
* @since 3.0.0
* @var string
*/
public $panel;
/**
* Type of this panel.
*
* @access public
* @since 3.0.0
* @var string
*/
public $type = 'kirki-nested';
/**
* Gather the parameters passed to client JavaScript via JSON.
*
* @access public
* @since 3.0.0
* @return array The array to be exported to the client as JSON.
*/
public function json() {
$array = wp_array_slice_assoc(
(array) $this,
[
'id',
'description',
'priority',
'type',
'panel',
]
);
$array['title'] = html_entity_decode( $this->title, ENT_QUOTES, get_bloginfo( 'charset' ) );
$array['content'] = $this->get_content();
$array['active'] = $this->active();
$array['instanceNumber'] = $this->instance_number;
return $array;
}
}

View file

@ -0,0 +1,109 @@
/**
* @see https://wordpress.stackexchange.com/a/256103/17078
*/
( function() {
var _panelEmbed,
_panelIsContextuallyActive,
_panelAttachEvents;
wp.customize.bind( 'pane-contents-reflowed', function() {
var panels = [];
// Reflow Panels.
wp.customize.panel.each( function( panel ) {
if ( 'kirki-nested' !== panel.params.type || _.isUndefined( panel.params.panel ) ) {
return;
}
panels.push( panel );
} );
panels.sort( wp.customize.utils.prioritySort ).reverse();
jQuery.each( panels, function( i, panel ) {
var parentContainer = jQuery( '#sub-accordion-panel-' + panel.params.panel );
parentContainer.children( '.panel-meta' ).after( panel.headContainer );
} );
} );
// Extend Panel.
_panelEmbed = wp.customize.Panel.prototype.embed;
_panelIsContextuallyActive = wp.customize.Panel.prototype.isContextuallyActive;
_panelAttachEvents = wp.customize.Panel.prototype.attachEvents;
wp.customize.Panel = wp.customize.Panel.extend( {
attachEvents: function() {
var panel = this;
if ( 'kirki-nested' !== this.params.type || _.isUndefined( this.params.panel ) ) {
_panelAttachEvents.call( this );
return;
}
_panelAttachEvents.call( this );
panel.expanded.bind( function( expanded ) {
if ( expanded ) {
wp.customize.panel( panel.params.panel ).contentContainer.addClass( 'current-panel-parent' );
} else {
wp.customize.panel( panel.params.panel ).contentContainer.removeClass( 'current-panel-parent' );
}
} );
panel.container.find( '.customize-panel-back' ).off( 'click keydown' ).on( 'click keydown', function( event ) {
if ( wp.customize.utils.isKeydownButNotEnterEvent( event ) ) {
return;
}
event.preventDefault(); // Keep this AFTER the key filter above
if ( panel.expanded() ) {
wp.customize.panel( panel.params.panel ).expand();
}
} );
},
embed: function() {
var panel = this,
parentContainer;
if ( 'kirki-nested' !== this.params.type || _.isUndefined( this.params.panel ) ) {
_panelEmbed.call( this );
return;
}
_panelEmbed.call( this );
parentContainer = jQuery( '#sub-accordion-panel-' + this.params.panel );
parentContainer.append( panel.headContainer );
},
isContextuallyActive: function() {
var panel = this,
activeCount = 0,
children;
if ( 'kirki-nested' !== this.params.type ) {
return _panelIsContextuallyActive.call( this );
}
children = this._children( 'panel', 'section' );
wp.customize.panel.each( function( child ) {
if ( ! child.params.panel || child.params.panel !== panel.id ) {
return;
}
children.push( child );
} );
children.sort( wp.customize.utils.prioritySort );
_( children ).each( function( child ) {
if ( child.active() && child.isContextuallyActive() ) {
activeCount += 1;
}
} );
return ( 0 !== activeCount );
}
} );
}( jQuery ) );