elementor
1 year ago
logs
1 month ago
strong-testimonials-beaver-block
1 year ago
submodules
8 months ago
class-strong-gutemberg.php
1 year ago
class-strong-log.php
1 year ago
class-strong-mail.php
1 year ago
class-strong-testimonials-average-shortcode.php
1 year ago
class-strong-testimonials-count-shortcode.php
1 year ago
class-strong-testimonials-defaults.php
1 month ago
class-strong-testimonials-form.php
1 month ago
class-strong-testimonials-order.php
1 year ago
class-strong-testimonials-privacy.php
1 year ago
class-strong-testimonials-render.php
1 month ago
class-strong-testimonials-templates.php
1 year ago
class-strong-testimonials-view-shortcode.php
2 days ago
class-strong-testimonials-view-widget.php
1 year ago
class-strong-view-display.php
1 month ago
class-strong-view-form.php
2 days ago
class-strong-view-slideshow.php
1 month ago
class-strong-view.php
11 months ago
class-walker-strong-category-checklist-front.php
1 year ago
deprecated.php
1 year ago
filters.php
1 month ago
functions-activation.php
1 month ago
functions-content.php
11 months ago
functions-image.php
5 months ago
functions-rating.php
1 year ago
functions-template-form.php
2 days ago
functions-template.php
4 months ago
functions-views.php
1 year ago
functions.php
1 month ago
l10n-polylang.php
1 year ago
l10n-wpml.php
1 year ago
post-types.php
2 days ago
retro.php
1 year ago
scripts.php
1 month ago
scripts.php
287 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Register scripts and styles. |
| 4 | */ |
| 5 | |
| 6 | function wpmtst_scripts() { |
| 7 | |
| 8 | $plugin_version = get_option( 'wpmtst_plugin_version' ); |
| 9 | $options = get_option( 'wpmtst_options' ); |
| 10 | $compat_options = apply_filters( 'wpmtst_compat_options', get_option( 'wpmtst_compat_options', array() ) ); |
| 11 | |
| 12 | $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 13 | |
| 14 | /** |
| 15 | * Page controller |
| 16 | * |
| 17 | * @since 2.28.0 |
| 18 | */ |
| 19 | wp_register_script( |
| 20 | 'wpmtst-controller', |
| 21 | WPMTST_PUBLIC_URL . "js/controller{$min}.js", |
| 22 | array( 'jquery' ), |
| 23 | $plugin_version, |
| 24 | true |
| 25 | ); |
| 26 | |
| 27 | /** |
| 28 | * Key : Description |
| 29 | * ----------------------------------------------------------------- |
| 30 | * (blank) : No Pjax support |
| 31 | * universal : Universal (timer) |
| 32 | * observer : Target nodes added + timer |
| 33 | * event : Event emitter |
| 34 | * - Pjax by MoOx @link https://github.com/MoOx/pjax |
| 35 | * script : Specific script |
| 36 | * - Barba @link http://barbajs.org/index.html |
| 37 | * |
| 38 | * Remember: array top level is converted to strings! |
| 39 | */ |
| 40 | $ajax = $compat_options['ajax']; |
| 41 | $controller = $compat_options['controller']; |
| 42 | |
| 43 | //TODO Use defaults + array_merge instead |
| 44 | $parms = array( |
| 45 | 'initializeOn' => isset( $controller['initialize_on'] ) ? $controller['initialize_on'] : '', |
| 46 | 'method' => isset( $ajax['method'] ) ? $ajax['method'] : '', |
| 47 | 'universalTimer' => isset( $ajax['universal_timer'] ) ? $ajax['universal_timer'] * 1000 : 0, |
| 48 | 'observerTimer' => isset( $ajax['observer_timer'] ) ? $ajax['observer_timer'] * 1000 : 0, |
| 49 | 'event' => isset( $ajax['event'] ) ? $ajax['event'] : '', |
| 50 | 'script' => isset( $ajax['script'] ) ? $ajax['script'] : '', |
| 51 | 'containerId' => isset( $ajax['container_id'] ) ? $ajax['container_id'] : '', |
| 52 | 'addedNodeId' => isset( $ajax['addednode_id'] ) ? $ajax['addednode_id'] : '', |
| 53 | 'debug' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && apply_filters( 'debug_strong_controller', true ), |
| 54 | ); |
| 55 | wp_localize_script( 'wpmtst-controller', 'strongControllerParms', $parms ); |
| 56 | |
| 57 | /** |
| 58 | * Simple pagination |
| 59 | */ |
| 60 | wp_register_script( |
| 61 | 'wpmtst-pager', |
| 62 | WPMTST_PUBLIC_URL . "js/lib/strongpager/jquery-strongpager{$min}.js", |
| 63 | array( 'jquery', 'imagesloaded' ), |
| 64 | false, |
| 65 | true |
| 66 | ); |
| 67 | |
| 68 | /** |
| 69 | * imagesLoaded, if less than WordPress 4.6 |
| 70 | */ |
| 71 | if ( ! wp_script_is( 'imagesloaded', 'registered' ) ) { |
| 72 | wp_register_script( |
| 73 | 'imagesloaded', |
| 74 | WPMTST_PUBLIC_URL . 'js/lib/imagesloaded/imagesloaded.pkgd.min.js', |
| 75 | array(), |
| 76 | WPMTST_VERSION, |
| 77 | true |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Masonry |
| 83 | */ |
| 84 | wp_register_style( |
| 85 | 'wpmtst-masonry-style', |
| 86 | WPMTST_PUBLIC_URL . 'css/masonry.css', |
| 87 | array(), |
| 88 | $plugin_version |
| 89 | ); |
| 90 | |
| 91 | /** |
| 92 | * Columns |
| 93 | */ |
| 94 | wp_register_style( |
| 95 | 'wpmtst-columns-style', |
| 96 | WPMTST_PUBLIC_URL . 'css/columns.css', |
| 97 | array(), |
| 98 | $plugin_version |
| 99 | ); |
| 100 | |
| 101 | /** |
| 102 | * Grid |
| 103 | */ |
| 104 | wp_register_style( |
| 105 | 'wpmtst-grid-style', |
| 106 | WPMTST_PUBLIC_URL . 'css/grid.css', |
| 107 | array(), |
| 108 | $plugin_version |
| 109 | ); |
| 110 | |
| 111 | /** |
| 112 | * Ratings |
| 113 | */ |
| 114 | $deps = array(); |
| 115 | |
| 116 | wp_register_style( |
| 117 | 'wpmtst-rating-form', |
| 118 | WPMTST_PUBLIC_URL . 'css/rating-form.css', |
| 119 | $deps, |
| 120 | $plugin_version |
| 121 | ); |
| 122 | |
| 123 | wp_register_style( |
| 124 | 'wpmtst-rating-display', |
| 125 | WPMTST_PUBLIC_URL . 'css/rating-display.css', |
| 126 | $deps, |
| 127 | $plugin_version |
| 128 | ); |
| 129 | |
| 130 | /** |
| 131 | * Form handling |
| 132 | */ |
| 133 | wp_register_script( |
| 134 | 'wpmtst-validation-plugin', |
| 135 | WPMTST_PUBLIC_URL . "js/lib/validate/jquery-validate{$min}.js", |
| 136 | array( 'jquery' ), |
| 137 | '1.21.0', |
| 138 | true |
| 139 | ); |
| 140 | |
| 141 | wp_register_script( |
| 142 | 'wpmtst-form-validation', |
| 143 | WPMTST_PUBLIC_URL . "js/lib/form-validation/form-validation{$min}.js", |
| 144 | array( 'wpmtst-validation-plugin', 'jquery-form' ), |
| 145 | $plugin_version, |
| 146 | true |
| 147 | ); |
| 148 | |
| 149 | /** |
| 150 | * Localize jQuery Validate plugin. |
| 151 | * |
| 152 | * @since 1.16.0 |
| 153 | */ |
| 154 | $locale = get_locale(); |
| 155 | if ( 'en_US' !== $locale ) { |
| 156 | |
| 157 | $lang_parts = explode( '_', $locale ); |
| 158 | |
| 159 | $lang_files = array( |
| 160 | 'messages_' . $locale . '.min.js', |
| 161 | 'messages_' . $lang_parts[0] . '.min.js', |
| 162 | ); |
| 163 | |
| 164 | foreach ( $lang_files as $file ) { |
| 165 | $path = WPMTST_PUBLIC . 'js/lib/validate/localization/' . $file; |
| 166 | $url = WPMTST_PUBLIC_URL . 'js/lib/validate/localization/' . $file; |
| 167 | if ( file_exists( $path ) ) { |
| 168 | wp_register_script( 'wpmtst-validation-lang', $url, array( 'wpmtst-validation-plugin' ), false, true ); |
| 169 | break; |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Slider |
| 176 | */ |
| 177 | wp_register_script( |
| 178 | 'jquery-actual', |
| 179 | WPMTST_PUBLIC_URL . "js/lib/actual/jquery-actual{$min}.js", |
| 180 | array( 'jquery' ), |
| 181 | '1.0.16', |
| 182 | true |
| 183 | ); |
| 184 | |
| 185 | wp_register_script( |
| 186 | 'verge', |
| 187 | WPMTST_PUBLIC_URL . "js/lib/verge/verge{$min}.js", |
| 188 | array(), |
| 189 | '1.10.2', |
| 190 | true |
| 191 | ); |
| 192 | |
| 193 | wp_register_script( |
| 194 | 'wpmtst-slider', |
| 195 | WPMTST_PUBLIC_URL . "js/lib/strongslider/jquery-strongslider{$min}.js", |
| 196 | array( 'jquery-actual', 'imagesloaded', 'underscore', 'verge', 'wp-i18n' ), |
| 197 | $plugin_version, |
| 198 | true |
| 199 | ); |
| 200 | |
| 201 | /** |
| 202 | * Read more in place |
| 203 | */ |
| 204 | wp_register_script( |
| 205 | 'wpmtst-readmore', |
| 206 | WPMTST_PUBLIC_URL . "js/lib/readmore/readmore{$min}.js", |
| 207 | array(), |
| 208 | $plugin_version, |
| 209 | true |
| 210 | ); |
| 211 | |
| 212 | wp_register_style( |
| 213 | 'wpmtst-animate', |
| 214 | WPMTST_PUBLIC_URL . 'css/animate.min.css', |
| 215 | array(), |
| 216 | '' |
| 217 | ); |
| 218 | /* |
| 219 | * Lozad Lazy Loading |
| 220 | */ |
| 221 | wp_register_script( |
| 222 | 'wpmtst-lozad', |
| 223 | WPMTST_PUBLIC_URL . "js/lib/lozad/lozad{$min}.js", |
| 224 | array(), |
| 225 | $plugin_version, |
| 226 | true |
| 227 | ); |
| 228 | |
| 229 | wp_register_script( |
| 230 | 'wpmtst-lozad-load', |
| 231 | WPMTST_PUBLIC_URL . "js/lib/lozad/lozad-load{$min}.js", |
| 232 | array(), |
| 233 | $plugin_version, |
| 234 | true |
| 235 | ); |
| 236 | |
| 237 | wp_register_style( |
| 238 | 'wpmtst-lazyload-css', |
| 239 | WPMTST_PUBLIC_URL . 'css/lazyload.css', |
| 240 | array(), |
| 241 | '' |
| 242 | ); |
| 243 | |
| 244 | /* |
| 245 | * JS random order |
| 246 | */ |
| 247 | wp_register_script( |
| 248 | 'wpmtst-random', |
| 249 | WPMTST_PUBLIC_URL . "js/lib/randomjs/random{$min}.js", |
| 250 | array( 'jquery' ), |
| 251 | $plugin_version, |
| 252 | true |
| 253 | ); |
| 254 | } |
| 255 | add_action( 'wp_enqueue_scripts', 'wpmtst_scripts' ); |
| 256 | |
| 257 | /** |
| 258 | * @param $tag |
| 259 | * @param $handle |
| 260 | * |
| 261 | * @return mixed |
| 262 | */ |
| 263 | function wpmtst_defer_scripts( $tag, $handle ) { |
| 264 | $scripts_to_defer = array( |
| 265 | // pagination |
| 266 | 'wpmtst-pager', |
| 267 | // form |
| 268 | 'wpmtst-validation-plugin', |
| 269 | 'wpmtst-validation-lang', |
| 270 | 'wpmtst-form-validation', |
| 271 | // slider |
| 272 | 'jquery-actual', |
| 273 | 'verge', |
| 274 | 'wpmtst-slider', |
| 275 | 'wpmtst-readmore', |
| 276 | 'jquery-masonry', |
| 277 | //'wpmtst-admin-views-script', |
| 278 | ); |
| 279 | |
| 280 | if ( in_array( $handle, $scripts_to_defer, true ) ) { |
| 281 | return str_replace( ' src', ' defer src', $tag ); |
| 282 | } |
| 283 | |
| 284 | return $tag; |
| 285 | } |
| 286 | add_filter( 'script_loader_tag', 'wpmtst_defer_scripts', 10, 2 ); |
| 287 |