first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
/**
* Handler for Assets loader
*/
function CherryAssetsLoader( tags, context ) {
'use strict';
tags.forEach( function( item ) {
if ( 'body' === context ) {
jQuery( 'body' ).append( item );
} else {
jQuery( 'head' ).append( item );
}
} );
}

View File

@@ -0,0 +1 @@
function CherryAssetsLoader(a,b){"use strict";a.forEach(function(a){"body"===b?jQuery("body").append(a):jQuery("head").append(a)})}

View File

@@ -0,0 +1,2 @@
var cherryAssets%1$s = %2$s;
CherryAssetsLoader( cherryAssets%1$s, '%3$s' );

View File

@@ -0,0 +1,145 @@
<?php
/**
* Module Name: Assets Loader
* Description: The module allows you deferred loading scripts and styles.
* Author: Cherry Team
* Author URI: http://www.cherryframework.com/
* License: GPLv3
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* @package Cherry_Framework
* @subpackage Modules
* @author Cherry Team <cherryframework@gmail.com>
* @copyright Copyright (c) 2012 - 2017, Cherry Team
* @link http://www.cherryframework.com/
* @license http://www.gnu.org/licenses/gpl-3.0.html
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
// If class `Cherry5_Assets_Loader` doesn't exists yet.
if ( ! class_exists( 'Cherry5_Assets_Loader' ) ) {
/**
* Cherry5_Assets_Loader class.
*/
class Cherry5_Assets_Loader {
/**
* Module slug
*
* @var string
*/
public $module_slug = 'cherry5-assets-loader';
/**
* Module arguments
*
* @since 1.0.0
* @var array
* @access private
*/
private $args = array();
/**
* Core instance
*
* @since 1.0.0
* @var object
* @access private
*/
private $core = null;
/**
* CSS handle object for deferred loading.
*
* @var array
*/
public static $css_handle = array();
/**
* JS handle object for deferred loading.
*
* @var array
*/
public static $js_handle = array();
/**
* Is module hooks initialized or not.
*
* @var boolean
*/
public static $initialized = false;
/**
* Module directory path.
*
* @since 1.5.0
* @var srting.
*/
public static $module_path = null;
/**
* Class constructor.
*
* @since 1.0.0
* @access public
* @return void
*/
public function __construct( $core = null, $args = array() ) {
self::$module_path = $args['module_path'];
$this->args = $args;
$this->init();
if ( ! empty( $this->args['css'] ) && is_array( $this->args['css'] ) ) {
self::$css_handle->add_handles( $this->args['css'] );
}
if ( ! empty( $this->args['js'] ) && is_array( $this->args['js'] ) ) {
self::$js_handle->add_handles( $this->args['js'] );
}
}
/**
* Initialize module hooks
*
* @return bool|void
*/
public function init() {
if ( true === self::$initialized ) {
return null;
}
require_once 'inc/cherry5-assets-loader-handle.php';
require_once 'inc/cherry5-assets-loader-handle-css.php';
require_once 'inc/cherry5-assets-loader-handle-js.php';
self::$css_handle = new Cherry5_Assets_Loader_Handle_CSS();
self::$js_handle = new Cherry5_Assets_Loader_Handle_JS();
self::$initialized = true;
ob_start();
include 'assets/min/append.min.js';
$append_handler = ob_get_clean();
wp_add_inline_script( 'cherry-js-core', $append_handler );
}
/**
* Returns new module instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance( $core, $args ) {
return new self( $core, $args );
}
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* CSS lodaer handler class
*
* @package Cherry_Framework
* @author Cherry Team <cherryframework@gmail.com>
* @copyright Copyright (c) 2012 - 2017, Cherry Team
* @link http://www.cherryframework.com/
* @license http://www.gnu.org/licenses/gpl-3.0.html
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Cherry5_Assets_Loader_Handle_CSS' ) ) {
/**
* Define Cherry5_Assets_Loader_Handle_CSS class
*/
class Cherry5_Assets_Loader_Handle_CSS extends Cherry5_Assets_Loader_Handle {
/**
* Handles list
*
* @var array
*/
public $handles = array();
/**
* Handles list
*
* @var array
*/
public $prepared_handles = array();
/**
* Define required properies
*/
public function __construct() {
$this->context = 'style';
$this->init();
}
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* JS lodaer handler class
*
* @package Cherry_Framework
* @author Cherry Team <cherryframework@gmail.com>
* @copyright Copyright (c) 2012 - 2017, Cherry Team
* @link http://www.cherryframework.com/
* @license http://www.gnu.org/licenses/gpl-3.0.html
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Cherry5_Assets_Loader_Handle_JS' ) ) {
/**
* Define Cherry5_Assets_Loader_Handle_JS class
*/
class Cherry5_Assets_Loader_Handle_JS extends Cherry5_Assets_Loader_Handle {
/**
* Handles list
*
* @var array
*/
public $handles = array();
/**
* Handles list
*
* @var array
*/
public $prepared_handles = array();
/**
* Define required properies
*/
public function __construct() {
$this->context = 'script';
$this->init();
}
}
}

View File

@@ -0,0 +1,113 @@
<?php
/**
* Base lodaer handler class
*
* @package Cherry_Framework
* @author Cherry Team <cherryframework@gmail.com>
* @copyright Copyright (c) 2012 - 2017, Cherry Team
* @link http://www.cherryframework.com/
* @license http://www.gnu.org/licenses/gpl-3.0.html
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Cherry5_Assets_Loader_Handle' ) ) {
/**
* Define Cherry5_Assets_Loader_Handle class
*/
class Cherry5_Assets_Loader_Handle {
/**
* Handles list
*
* @var array
*/
public $handles = array();
/**
* Handles list
*
* @var array
*/
public $prepared_handles = array();
/**
* Handlex context (defined in child classes)
*
* @var string
*/
public $context = null;
/**
* Initalize defer loading
*
* @return void
*/
public function init() {
if ( null !== $this->context ) {
add_filter( $this->context . '_loader_tag', array( $this, 'defer' ), 10, 3 );
add_action( 'wp_footer', array( $this, 'print_tags_var' ), 99 );
}
}
/**
* Store tag for deferred loading.
*
* @return string
*/
public function defer( $tag, $handle, $src ) {
if ( in_array( $handle, $this->handles ) ) {
$this->prepared_handles[] = $tag;
$tag = '';
}
return $tag;
}
/**
* Add new handles into list before processing
*/
public function add_handles( $handles = array() ) {
$this->handles = array_merge( $this->handles, $handles );
$this->handles = array_unique( $this->handles );
}
/**
* Print stored handles.
*
* @return void|null
*/
public function print_tags_var() {
if ( empty( $this->prepared_handles ) || null === $this->context ) {
return;
}
$path = Cherry5_Assets_Loader::$module_path . 'assets/var.js';
ob_start();
include $path;
$var_template = ob_get_clean();
$js_context = ( 'style' === $this->context ) ? 'head' : 'body';
$var = sprintf(
$var_template,
ucfirst( $this->context ),
json_encode( $this->prepared_handles ),
$js_context
);
echo '<script type="text/javascript">' . $var . '</script>';
}
}
}