| 1 |
<?php |
| 2 |
if ( !defined( 'ABSPATH' ) ) { exit; } |
| 3 |
|
| 4 |
if( !class_exists('BBlocksEnqueueScripts') ){ |
| 5 |
class BBlocksEnqueueScripts{ |
| 6 |
function __construct(){ |
| 7 |
add_action( 'enqueue_block_editor_assets', [$this, 'enqueueBlockEditorAssets'] ); |
| 8 |
add_action( 'enqueue_block_assets', [$this, 'enqueueBockAssets'] ); |
| 9 |
add_action( 'wp_enqueue_scripts', [$this, 'enqueueScripts'] ); |
| 10 |
add_filter( 'script_loader_tag', [$this, 'scriptLoaderTag'], 10, 3 ); |
| 11 |
} |
| 12 |
|
| 13 |
function enqueueBlockEditorAssets(){ |
| 14 |
wp_enqueue_script( 'b-blocks-template-library-script', B_BLOCKS_BUILD . 'template-library.js', [ 'wp-api', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-dom-ready', 'wp-i18n', 'wp-util', 'react', 'react-dom' ], B_BLOCKS_VERSION, false ); |
| 15 |
wp_set_script_translations( 'b-blocks-template-library-script', 'b-blocks', B_BLOCKS_DIR_PATH . 'languages' ); |
| 16 |
|
| 17 |
wp_enqueue_style( 'b-blocks-template-library-style', B_BLOCKS_BUILD . 'template-library.css', [], B_BLOCKS_VERSION ); |
| 18 |
|
| 19 |
wp_enqueue_script( 'b-blocks-index-script', B_BLOCKS_BUILD . 'index.js', [ 'wp-api', 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n', 'wp-rich-text', 'wp-util', 'jquery', 'jquery-ui-draggable', 'aos', 'modelViewer', 'easyTicker', 'swiper', 'dotLottiePlayer', 'lottieInteractivity', 'chartJS', 'plyr', 'textillate', 'goodShare' ], B_BLOCKS_VERSION, false ); |
| 20 |
wp_set_script_translations( 'b-blocks-index-script', 'b-blocks', B_BLOCKS_DIR_PATH . 'languages' ); |
| 21 |
|
| 22 |
$disabledBlocks = get_option( 'bBlocksDisabledBlocks', [] ); |
| 23 |
$disabledBlocks = is_array( $disabledBlocks ) ? $disabledBlocks : []; |
| 24 |
wp_localize_script( 'b-blocks-index-script', 'bBlocksDisabledBlocks', $disabledBlocks ); |
| 25 |
|
| 26 |
wp_localize_script( 'b-blocks-index-script', 'bBlocksGlobal', [ 'assetsUrl' => B_BLOCKS_ASSETS ] ); |
| 27 |
|
| 28 |
wp_enqueue_style( 'b-blocks-index-style', B_BLOCKS_BUILD . 'index.css', [ 'fontAwesome', 'b-blocks-style' ], B_BLOCKS_VERSION ); |
| 29 |
|
| 30 |
wp_add_inline_script('b-blocks-index-script', 'const bBlocksPremiumChecker = ' . wp_json_encode( BBlocks\Inc\Utils::isPro() ) . '; ', 'before' ); |
| 31 |
} |
| 32 |
|
| 33 |
function enqueueBockAssets(){ |
| 34 |
wp_register_script( 'easyTicker', B_BLOCKS_ASSETS . 'js/easy-ticker.min.js', [ 'jquery' ], '3.2.1', true ); // Posts |
| 35 |
wp_register_script( 'swiper', B_BLOCKS_ASSETS . 'js/swiper.min.js', [], '8.0.7', true ); // Slider |
| 36 |
wp_register_script( 'dotLottiePlayer', B_BLOCKS_ASSETS . 'js/dotlottie-player.js', [], '1.5.7', true ); // Lottie Player |
| 37 |
wp_register_script( 'lottieInteractivity', B_BLOCKS_ASSETS . 'js/lottie-interactivity.min.js', [ 'dotLottiePlayer' ], '1.5.2', true ); // Lottie Player |
| 38 |
wp_register_script( 'chartJS', B_BLOCKS_ASSETS . 'js/chart.min.js', [], '3.5.1', true ); // Chart |
| 39 |
wp_register_script( 'plyr', B_BLOCKS_ASSETS . 'js/plyr.js', [], '3.7.2', true ); // Video |
| 40 |
wp_register_script( 'textillate', B_BLOCKS_ASSETS . 'js/jquery.textillate.min.js', [ 'jquery' ], '0.6.1', true ); // Animated Text |
| 41 |
wp_register_script( 'goodShare', B_BLOCKS_ASSETS . 'js/goodshare.min.js', [], B_BLOCKS_VERSION, true ); // Social Share |
| 42 |
wp_register_script( 'modelViewer', B_BLOCKS_ASSETS . 'js/model-viewer.min.js', [], B_BLOCKS_VERSION, true ); // 3D Viewer |
| 43 |
wp_register_script( 'aos', B_BLOCKS_ASSETS . 'js/aos.js', [], '3.0.0', true ); // Button |
| 44 |
wp_register_script( 'fancybox', B_BLOCKS_ASSETS . 'js/fancybox.min.js', [], '4.0', true ); // Image Gallery |
| 45 |
wp_register_script( 'mailtoui', B_BLOCKS_ASSETS . 'js/mailtoui-min.js', [], '1.0.3', true ); // Mailto |
| 46 |
// wp_register_script( 'facebookEmbbed', B_BLOCKS_ASSETS . 'js/facebook-embbed.js', [], B_BLOCKS_VERSION, true ); // Facebook Embbed |
| 47 |
// wp_register_script( 'facebookPage', B_BLOCKS_ASSETS . 'js/facebook-page.js', [], B_BLOCKS_VERSION, true ); // Facebook Page |
| 48 |
|
| 49 |
//Accordion |
| 50 |
wp_register_script('zebra_accordion', B_BLOCKS_ASSETS . 'js/zebra_accordion.min.js', ['jquery'], B_BLOCKS_VERSION, true); |
| 51 |
|
| 52 |
wp_register_style( 'fontAwesome', B_BLOCKS_ASSETS . 'css/font-awesome.min.css', [], '6.4.2' ); // Icon |
| 53 |
wp_register_style( 'swiper', B_BLOCKS_ASSETS . 'css/swiper.min.css', [], '8.0.7' ); // Slider |
| 54 |
wp_register_style( 'animate', B_BLOCKS_ASSETS . 'css/animate.min.css', [], '4.1.1' ); // Animated Text |
| 55 |
wp_register_style( 'plyr', B_BLOCKS_ASSETS . 'css/plyr.css', [], '3.7.2' ); // Video |
| 56 |
wp_register_style( 'aos', B_BLOCKS_ASSETS . 'css/aos.css', [], '3.0.0' ); // Button |
| 57 |
wp_register_style( 'fancybox', B_BLOCKS_ASSETS . 'css/fancybox.min.css', '', '4.0', 'all' ); // Image Gallery |
| 58 |
|
| 59 |
wp_enqueue_style( 'b-blocks-style', B_BLOCKS_BUILD . 'script.css', [], B_BLOCKS_VERSION ); // Style |
| 60 |
} |
| 61 |
|
| 62 |
function enqueueScripts(){ |
| 63 |
wp_enqueue_script( 'b-blocks-advanced-script', B_BLOCKS_BUILD . 'advanced.js', [], B_BLOCKS_VERSION, true ); |
| 64 |
wp_enqueue_script( 'b-blocks-script', B_BLOCKS_BUILD . 'script.js', [], B_BLOCKS_VERSION, true ); |
| 65 |
wp_add_inline_script('b-blocks-script', 'const bBlocksPremiumChecker = ' . wp_json_encode( BBlocks\Inc\Utils::isPro() ) . '; ', 'before' ); |
| 66 |
} |
| 67 |
|
| 68 |
function scriptLoaderTag( $tag, $handle, $src ){ |
| 69 |
if ( 'modelViewer' !== $handle ) { |
| 70 |
return $tag; |
| 71 |
} |
| 72 |
$tag = '<script type="module" src="' . esc_url( $src ) . '"></script>'; |
| 73 |
return $tag; |
| 74 |
} |
| 75 |
} |
| 76 |
new BBlocksEnqueueScripts(); |
| 77 |
} |