| @@ -8,8 +8,29 @@ | ||
| 8 | 8 | |
| 9 | 9 | class RegisterScripts { |
| 10 | 10 | public static function get_register_styles() { |
| 11 | 11 | return apply_filters('ablocks/register_styles', [ |
| 12 | + 'ablocks-prism-style' => [ | |
| 13 | + 'path' => ABLOCKS_ASSETS_PATH . 'library/prism/prism.css', | |
| 14 | + 'url' => ABLOCKS_ASSETS_URL . 'library/prism/prism.css', | |
| 15 | + 'deps' => array(), | |
| 16 | + 'ver' => false, | |
| 17 | + 'media' => 'all' | |
| 18 | + ], | |
| 19 | + 'ablocks-prism-line-numbers-style' => [ | |
| 20 | + 'path' => ABLOCKS_ASSETS_PATH . 'library/prism/prism-line-numbers.css', | |
| 21 | + 'url' => ABLOCKS_ASSETS_URL . 'library/prism/prism-line-numbers.css', | |
| 22 | + 'deps' => array(), | |
| 23 | + 'ver' => false, | |
| 24 | + 'media' => 'all' | |
| 25 | + ], | |
| 26 | + 'ablocks-prism-line-highlight-style' => [ | |
| 27 | + 'path' => ABLOCKS_ASSETS_PATH . 'library/prism/prism-line-highlight.css', | |
| 28 | + 'url' => ABLOCKS_ASSETS_URL . 'library/prism/prism-line-highlight.css', | |
| 29 | + 'deps' => array(), | |
| 30 | + 'ver' => false, | |
| 31 | + 'media' => 'all' | |
| 32 | + ], | |
| 12 | 33 | 'ablocks-leaflet-style' => [ |
| 13 | 34 | 'path' => ABLOCKS_ASSETS_PATH . 'library/leaflet/leaflet.css', |
| 14 | 35 | 'url' => ABLOCKS_ASSETS_URL . 'library/leaflet/leaflet.css', |
| 15 | 36 | 'deps' => array(), |
| @@ -36,8 +57,15 @@ | ||
| 36 | 57 | 'deps' => array(), |
| 37 | 58 | 'ver' => false, |
| 38 | 59 | 'media' => 'all' |
| 39 | 60 | ], |
| 61 | + 'ablocks-plyr-style' => [ | |
| 62 | + 'path' => ABLOCKS_ASSETS_PATH . 'library/plyr/plyr.css', | |
| 63 | + 'url' => ABLOCKS_ASSETS_URL . 'library/plyr/plyr.css', | |
| 64 | + 'deps' => array(), | |
| 65 | + 'ver' => false, | |
| 66 | + 'media' => 'all' | |
| 67 | + ], | |
| 40 | 68 | 'ablocks-common-style' => [ |
| 41 | 69 | 'path' => ABLOCKS_ASSETS_PATH . 'build/blocks-common.css', |
| 42 | 70 | 'url' => ABLOCKS_ASSETS_URL . 'build/blocks-common.css', |
| 43 | 71 | 'deps' => array(), |
| @@ -46,15 +74,50 @@ | ||
| 46 | 74 | ], |
| 47 | 75 | ]); |
| 48 | 76 | } |
| 49 | 77 | public static function get_register_scripts() { |
| 78 | + $script_loading_strategy = \ABlocks\Helper::get_script_loading_strategy(); | |
| 79 | + $args = [ 'strategy' => $script_loading_strategy ]; | |
| 50 | 80 | return apply_filters('ablocks/register_scripts', [ |
| 81 | + // Data-only handle (no src) that hosts the single frontend | |
| 82 | + // ABlocksGlobal payload. Every aBlocks frontend script depends on it | |
| 83 | + // — directly, or transitively through ablocks-common-script — so WP | |
| 84 | + // prints the object exactly once per page instead of once per block | |
| 85 | + // script handle (asset-generation off) or once per combined template | |
| 86 | + // script (asset-generation on). See Assets::localize_globals_once(). | |
| 87 | + 'ablocks-globals' => [ | |
| 88 | + 'url' => false, | |
| 89 | + 'deps' => array(), | |
| 90 | + 'ver' => ABLOCKS_VERSION, | |
| 91 | + 'args' => array(), | |
| 92 | + ], | |
| 93 | + 'ablocks-prism-script' => [ | |
| 94 | + 'path' => ABLOCKS_ASSETS_PATH . 'library/prism/prism.js', | |
| 95 | + 'url' => ABLOCKS_ASSETS_URL . 'library/prism/prism.js', | |
| 96 | + 'deps' => array(), | |
| 97 | + 'ver' => false, | |
| 98 | + 'args' => $args | |
| 99 | + ], | |
| 100 | + 'ablocks-prism-line-numbers-script' => [ | |
| 101 | + 'path' => ABLOCKS_ASSETS_PATH . 'library/prism/prism-line-numbers.js', | |
| 102 | + 'url' => ABLOCKS_ASSETS_URL . 'library/prism/prism-line-numbers.js', | |
| 103 | + 'deps' => array(), | |
| 104 | + 'ver' => false, | |
| 105 | + 'args' => $args | |
| 106 | + ], | |
| 107 | + 'ablocks-prism-line-highlight-script' => [ | |
| 108 | + 'path' => ABLOCKS_ASSETS_PATH . 'library/prism/prism-line-highlight.js', | |
| 109 | + 'url' => ABLOCKS_ASSETS_URL . 'library/prism/prism-line-highlight.js', | |
| 110 | + 'deps' => array(), | |
| 111 | + 'ver' => false, | |
| 112 | + 'args' => $args | |
| 113 | + ], | |
| 51 | 114 | 'ablocks-leaflet-script' => [ |
| 52 | 115 | 'path' => ABLOCKS_ASSETS_PATH . 'library/leaflet/leaflet.js', |
| 53 | 116 | 'url' => ABLOCKS_ASSETS_URL . 'library/leaflet/leaflet.js', |
| 54 | 117 | 'deps' => array(), |
| 55 | 118 | 'ver' => false, |
| 56 | - 'args' => false, | |
| 119 | + 'args' => $args | |
| 57 | 120 | ], |
| 58 | 121 | 'ablocks-leaflet-full-screen-script' => [ |
| 59 | 122 | 'path' => ABLOCKS_ASSETS_PATH . 'library/leaflet/Leaflet.fullscreen.js', |
| 60 | 123 | 'url' => ABLOCKS_ASSETS_URL . 'library/leaflet/Leaflet.fullscreen.js', |
| @@ -59,9 +122,9 @@ | ||
| 59 | 122 | 'path' => ABLOCKS_ASSETS_PATH . 'library/leaflet/Leaflet.fullscreen.js', |
| 60 | 123 | 'url' => ABLOCKS_ASSETS_URL . 'library/leaflet/Leaflet.fullscreen.js', |
| 61 | 124 | 'deps' => array(), |
| 62 | 125 | 'ver' => false, |
| 63 | - 'args' => false, | |
| 126 | + 'args' => $args | |
| 64 | 127 | ], |
| 65 | 128 | 'ablocks-swiper-script' => [ |
| 66 | 129 | 'path' => ABLOCKS_ASSETS_PATH . 'library/swiper/swiper-bundle.min.js', |
| 67 | 130 | 'url' => ABLOCKS_ASSETS_URL . 'library/swiper/swiper-bundle.min.js', |
| @@ -66,9 +129,9 @@ | ||
| 66 | 129 | 'path' => ABLOCKS_ASSETS_PATH . 'library/swiper/swiper-bundle.min.js', |
| 67 | 130 | 'url' => ABLOCKS_ASSETS_URL . 'library/swiper/swiper-bundle.min.js', |
| 68 | 131 | 'deps' => array(), |
| 69 | 132 | 'ver' => false, |
| 70 | - 'args' => false, | |
| 133 | + 'args' => $args | |
| 71 | 134 | ], |
| 72 | 135 | 'ablocks-chart.js-script' => [ |
| 73 | 136 | 'path' => ABLOCKS_ASSETS_PATH . 'library/chart/chart.js', |
| 74 | 137 | 'url' => ABLOCKS_ASSETS_URL . 'library/chart/chart.js', |
| @@ -73,16 +136,28 @@ | ||
| 73 | 136 | 'path' => ABLOCKS_ASSETS_PATH . 'library/chart/chart.js', |
| 74 | 137 | 'url' => ABLOCKS_ASSETS_URL . 'library/chart/chart.js', |
| 75 | 138 | 'deps' => array(), |
| 76 | 139 | 'ver' => false, |
| 77 | - 'args' => false, | |
| 140 | + 'args' => $args | |
| 78 | 141 | ], |
| 142 | + 'ablocks-plyr-script' => [ | |
| 143 | + 'path' => ABLOCKS_ASSETS_PATH . 'library/plyr/plyr.js', | |
| 144 | + 'url' => ABLOCKS_ASSETS_URL . 'library/plyr/plyr.js', | |
| 145 | + 'deps' => array(), | |
| 146 | + 'ver' => false, | |
| 147 | + 'args' => true, | |
| 148 | + 'dependencies' => ABLOCKS_ASSETS_PATH . 'build/blocks-common.asset.php' | |
| 149 | + ], | |
| 79 | 150 | 'ablocks-common-script' => [ |
| 80 | 151 | 'path' => ABLOCKS_ASSETS_PATH . 'build/blocks-common.js', |
| 81 | 152 | 'url' => ABLOCKS_ASSETS_URL . 'build/blocks-common.js', |
| 82 | - 'deps' => array(), | |
| 153 | + // Every block script depends on this handle (see | |
| 154 | + // BlockBaseAbstract::get_script_depends), so hanging | |
| 155 | + // ablocks-globals off it makes the payload reachable from any | |
| 156 | + // rendered block without touching each block's own deps. | |
| 157 | + 'deps' => array( 'ablocks-globals' ), | |
| 83 | 158 | 'ver' => false, |
| 84 | - 'args' => true, | |
| 159 | + 'args' => $args, | |
| 85 | 160 | 'dependencies' => ABLOCKS_ASSETS_PATH . 'build/blocks-common.asset.php' |
| 86 | 161 | ], |
| 87 | 162 | ]); |
| 88 | 163 | } |