Changeset 2256987
- Timestamp:
- 03/09/2020 12:07:54 AM (6 years ago)
- Location:
- rocket-footer-js/trunk
- Files:
-
- 6 added
- 12 edited
-
assets/css/lazyload.css (modified) (1 diff)
-
assets/js/jquery.lazyloadxt.video.js (modified) (2 diffs)
-
assets/js/lazysizes.min.js (added)
-
assets/js/polyfill/custom-event.js (added)
-
assets/js/polyfill/custom-event.min.js (added)
-
assets/js/polyfill/intersection-observer.min.js (added)
-
assets/js/polyfill/mutation-observer.min.js (added)
-
lib/Rocket/Footer/JS.php (modified) (1 diff)
-
lib/Rocket/Footer/JS/Cache/Manager.php (modified) (6 diffs)
-
lib/Rocket/Footer/JS/Integration/FusionFramework.php (modified) (1 diff)
-
lib/Rocket/Footer/JS/Integration/Manager.php (modified) (1 diff)
-
lib/Rocket/Footer/JS/Integration/RevolutionSlider.php (modified) (1 diff)
-
lib/Rocket/Footer/JS/Integration/VisualComposer.php (added)
-
lib/Rocket/Footer/JS/Lazyload/HubSpotForms.php (modified) (2 diffs)
-
lib/Rocket/Footer/JS/Lazyload/Videos.php (modified) (4 diffs)
-
lib/Rocket/Footer/JS/Request.php (modified) (5 diffs)
-
readme.txt (modified) (1 diff)
-
rocket-footer-js.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
rocket-footer-js/trunk/assets/css/lazyload.css
r2091973 r2256987 8 8 transition: opacity 300ms; 9 9 } 10 11 .lazy_background.lazyload, .lazy_background.lazyloadwait { 12 background-image: none !important; 13 } -
rocket-footer-js/trunk/assets/js/jquery.lazyloadxt.video.js
r1923735 r2256987 9 9 options.selector += ',video,iframe[data-src]'; 10 10 options.videoPoster = 'data-poster'; 11 12 function load () { 13 this.dispatchEvent(new CustomEvent('load')); 14 } 11 15 12 16 $(document).on('lazyshow', 'video', function (e, $el) { … … 24 28 changed = true; 25 29 } 26 }) ;27 30 }).on('loadeddata', load); 31 $el.on('loadeddata', load); 28 32 // reload video 29 33 if (changed) { 30 34 this.load(); 35 // Video.JS compatibility 36 var vjs, vsrc; 37 if (typeof videojs !== 'undefined' && (vjs = $el.closest('.video-js'))) { 38 if (((vsrc = $el.attr('src')) && vsrc) || (((vsrc = $el.children('source').attr('src')) && vsrc))) { 39 videojs(vjs.get(0)).src(vsrc) 40 } 41 } 31 42 } 32 43 $el.triggerHandler('load') -
rocket-footer-js/trunk/lib/Rocket/Footer/JS.php
r2186620 r2256987 25 25 * Plugin version 26 26 */ 27 const VERSION = '3.2. 2';27 const VERSION = '3.2.3'; 28 28 /** 29 29 * -
rocket-footer-js/trunk/lib/Rocket/Footer/JS/Cache/Manager.php
r2175460 r2256987 31 31 public function init() { 32 32 add_action( 'after_rocket_clean_domain', [ $this, 'purge_cache' ], 10, 0 ); 33 add_action( 'after_rocket_clean_domain', [ $this, 'do_preload' ], 10, 0 );34 33 add_action( 'wp_rocket_start_preload', 'run_rocket_sitemap_preload', 10, 0 ); 35 34 add_action( 'after_rocket_clean_post', [ $this, 'purge_post' ] ); 36 35 add_action( 'after_rocket_clean_term', [ $this, 'purge_term' ] ); 37 36 add_action( 'after_rocket_clean_file', [ $this, 'purge_url' ] ); 37 add_action( 'wp_rocket_start_preload', 'run_rocket_sitemap_preload', 10, 0 ); 38 add_action( 'rocket_footer_js_purge_cache', [ $this, 'do_purge_cache' ] ); 39 if ( is_admin() && $this->get_admin_cache_flag() ) { 40 add_action( 'admin_notices', [ $this, 'cache_purge_notice' ] ); 41 } 38 42 $this->store->set_prefix( JS::TRANSIENT_PREFIX ); 39 43 $interval = 0; … … 43 47 $this->store->set_expire( apply_filters( 'rocket_footer_js_cache_expire_period', $interval ) ); 44 48 $this->store->set_max_branch_length( apply_filters( 'rocket_footer_js_max_branch_length', 50 ) ); 49 } 50 51 private function get_admin_cache_flag() { 52 return get_transient( $this->get_admin_cache_flag_name() ); 53 } 54 55 private function get_admin_cache_flag_name() { 56 return "{$this->plugin->get_safe_slug()}_cache_purging"; 57 } 58 59 public function purge_cache() { 60 if ( $this->get_admin_cache_flag() && ! wp_next_scheduled( 'rocket_footer_js_purge_cache' ) ) { 61 $this->clear_admin_cache_flag(); 62 } 63 if ( $this->get_admin_cache_flag() ) { 64 return; 65 } 66 $size = $this->store->get_cache_fragment( [ 'count' ] ); 67 68 if ( $size > apply_filters( 'rocket_footer_js_background_cache_purge_item_threshold', 25, $size ) && ! wp_doing_cron() ) { 69 wp_schedule_single_event( time(), 'rocket_footer_js_purge_cache' ); 70 $this->set_admin_cache_flag(); 71 72 return; 73 } 74 $this->do_purge_cache(); 75 } 76 77 private function clear_admin_cache_flag() { 78 delete_transient( "{$this->plugin->get_safe_slug()}_cache_purging" ); 79 } 80 81 private function set_admin_cache_flag() { 82 set_transient( $this->get_admin_cache_flag_name(), true, DAY_IN_SECONDS ); 83 } 84 85 public function do_purge_cache() { 86 $this->set_admin_cache_flag(); 87 $this->store->delete_cache_branch(); 88 $this->delete_minify_files(); 89 $this->clear_admin_cache_flag(); 90 remove_action( 'after_rocket_clean_domain', [ $this, 'purge_cache' ] ); 91 rocket_clean_domain(); 92 $this->do_preload(); 93 } 94 95 private function delete_minify_files() { 96 rocket_rrmdir( $this->plugin->get_cache_path() ); 45 97 } 46 98 … … 55 107 56 108 /** 57 *58 */59 public function purge_cache() {60 $this->store->delete_cache_branch();61 rocket_rrmdir( $this->plugin->get_cache_path() );62 }63 64 /**65 109 * @param \WP_Post $post 66 110 */ 67 111 public function purge_post( $post ) { 68 $this->store->delete_cache_branch( [ 'cache', "post_{$post->ID}" ] ); 112 $path = [ 'cache', "post_{$post->ID}" ]; 113 $this->delete_cache_file( $path ); 114 } 115 116 private function delete_cache_file( $path ) { 117 $cache = $this->store->get_cache_fragment( array_merge( $path, [ 'cache_1' ] ) ); 118 if ( ! empty( $cache ) ) { 119 foreach ( $cache as $item ) { 120 $item = explode( '_', $item ); 121 $item = end( $item ); 122 $item = $this->store->get_cache_fragment( array_merge( $path, [ $item ] ) ); 123 if ( ! empty( $item['filename'] ) ) { 124 $this->plugin->wp_filesystem->delete( $item['filename'] ); 125 } 126 } 127 } 128 $this->store->delete_cache_branch( $path ); 69 129 } 70 130 … … 73 133 */ 74 134 public function purge_term( $term ) { 75 $this->store->delete_cache_branch( [ 'cache', "term_{$term->term_id}" ] ); 135 $path = [ 'cache', "term_{$term->term_id}" ]; 136 $this->delete_cache_file( $path ); 76 137 } 77 138 … … 80 141 */ 81 142 public function purge_url( $url ) { 82 $url = md5( $url ); 83 $this->store->delete_cache_branch( [ 'cache', "url_{$url}" ] ); 143 $url = md5( $url ); 144 $path = [ 'cache', "url_{$url}" ]; 145 $this->delete_cache_file( $path ); 84 146 } 85 147 … … 96 158 return $this->store; 97 159 } 160 161 public function cache_purge_notice() { 162 $class = 'notice notice-info'; 163 $message = __( sprintf( '%s is currently purging the JS minify cache in the background', $this->plugin->get_plugin_info( 'Name' ) ), $this->plugin->get_safe_slug() ); 164 165 printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) ); 166 } 98 167 } -
rocket-footer-js/trunk/lib/Rocket/Footer/JS/Integration/FusionFramework.php
r2129570 r2256987 49 49 'add_fusion_image_srcset_filter', 50 50 ] ); 51 add_filter( 'rocket_footer_js_load_script_image_hacks', '__return_true' ); 51 52 } 52 53 } -
rocket-footer-js/trunk/lib/Rocket/Footer/JS/Integration/Manager.php
r2175460 r2256987 48 48 'EssentialAddonsElementor', 49 49 'WPUltimatePostGrid', 50 'VisualComposer', 50 51 ]; 51 52 -
rocket-footer-js/trunk/lib/Rocket/Footer/JS/Integration/RevolutionSlider.php
r2175460 r2256987 10 10 if ( function_exists( 'rev_slider_shortcode' ) ) { 11 11 add_filter( 'option_revslider-global-settings', [ $this, 'modify_settings' ] ); 12 add_filter( 'rocket_footer_js_load_script_image_hacks', '__return_true' ); 12 13 } 13 14 } -
rocket-footer-js/trunk/lib/Rocket/Footer/JS/Lazyload/HubSpotForms.php
r2129570 r2256987 72 72 73 73 $tag->remove(); 74 $this->tags->flag_removed(); 75 $this->tags->rewind(); 74 76 } 75 77 … … 81 83 $this->set_no_minify(); 82 84 83 $nodes = $this->xpath->query( '//script[co mtains(@src, "js.hsforms.net")]' );85 $nodes = $this->xpath->query( '//script[contains(@src, "js.hsforms.net")]' ); 84 86 /** @var \Rocket\Footer\JS\DOMElement $node */ 85 87 foreach ( $nodes as $node ) { -
rocket-footer-js/trunk/lib/Rocket/Footer/JS/Lazyload/Videos.php
r2175460 r2256987 81 81 $thumbnail_size = $tag->getAttribute( 'data-thumbnail-size' ); 82 82 $thumbnail_alt = $tag->getAttribute( 'data-thumbnail-alt' ); 83 84 $tag->setAttribute( ( $data_src ? 'data-' : '' ) . 'src', $this->maybe_set_autoplay( $original_src, $tag ) );85 83 if ( ! empty( $info ) && 'video' === $info->type ) { 84 if ( $tag->hasAttribute( 'autoplay' ) ) { 85 continue; 86 } 87 88 $tag->setAttribute( ( $data_src ? 'data-' : '' ) . 'src', $this->maybe_set_autoplay( $original_src, $tag ) ); 86 89 if ( empty( $thumbnail_alt ) ) { 87 90 $thumbnail_alt = $info->title; … … 236 239 $urls[] = http_build_url( $size_url ); 237 240 } 241 } 242 if ( 'i.vimeocdn.com' === $url['host'] ) { 243 $size_url = $url; 244 $video_id = explode( '_', pathinfo( $url['path'], PATHINFO_FILENAME ) ); 245 $video_id = $video_id[0]; 246 $ext = pathinfo( $url['path'], PATHINFO_EXTENSION ); 247 $size_url['path'] = "/video/{$video_id}.{$ext}"; 248 $urls[] = http_build_url( $size_url ); 238 249 } 239 250 if ( ! empty( $urls ) ) { … … 364 375 $type = 'youtube'; 365 376 } 377 if ( 'vimeo.com' === $url['host'] || 'www.vimeo.com' === $url['host'] || 'player.vimeo.com' === $url['host'] ) { 378 $type = 'vimeo'; 379 } 366 380 if ( null !== $type ) { 367 381 return $type; … … 388 402 } 389 403 404 if ( 'vimeo.com' === $url['host'] || 'www.vimeo.com' === $url['host'] ) { 405 return pathinfo( $url['path'], PATHINFO_FILENAME ); 406 } 407 390 408 return false; 391 409 } -
rocket-footer-js/trunk/lib/Rocket/Footer/JS/Request.php
r2129570 r2256987 40 40 add_action( 'save_post', 'rocket_clean_post' ); 41 41 add_action( 'shutdown', [ $this, 'maybe_ajax_spoof' ], - 1 ); 42 add_filter( 'rocket_lazyload_script_tag', [ $this, 'strip_no_minify' ] ); 43 } 42 44 45 public function strip_no_minify( $script ) { 46 return str_replace( 'data-no-minify="1"', '', $script ); 43 47 } 44 48 … … 69 73 } 70 74 75 $suffix = ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? 'min.' : ''; 76 71 77 if ( wp_script_is( $dep, 'registered' ) ) { 72 78 wp_deregister_style( 'jquery-lazyloadxt-fadein-css' ); … … 76 82 $script = wp_scripts()->registered[ $dep ]; 77 83 wp_deregister_script( $dep ); 78 wp_enqueue_script( 'rocket-footer-js-video-mutation-observer-polyfill', plugins_url( 'assets/js/polyfill/mutation-observer.js', $this->plugin->get_plugin_file() ) ); 79 wp_enqueue_script( 'rocket-footer-js-video-intersection-observer-polyfill', plugins_url( 'assets/js/polyfill/intersection-observer.js', $this->plugin->get_plugin_file() ) ); 84 wp_enqueue_script( 'rocket-footer-js-video-mutation-observer-polyfill', plugins_url( "assets/js/polyfill/mutation-observer.{$suffix}js", $this->plugin->get_plugin_file() ) ); 85 wp_enqueue_script( 'rocket-footer-js-video-intersection-observer-polyfill', plugins_url( "assets/js/polyfill/intersection-observer.{$suffix}js", $this->plugin->get_plugin_file() ) ); 86 wp_enqueue_script( 'rocket-footer-js-custom-event-polyfill', plugins_url( "assets/js/polyfill/custom-event.{$suffix}js", $this->plugin->get_plugin_file() ) ); 80 87 wp_enqueue_script( 'jquery-lazyloadxt-dummy', plugins_url( 'assets/js/lazysizes.lazyloadxt.compat.js', $this->plugin->get_plugin_file(), [ 'jquery' ] ) ); 81 88 foreach ( $script->extra as $key => $data ) { … … 86 93 'rocket-footer-js-video-mutation-observer-polyfill', 87 94 'rocket-footer-js-video-intersection-observer-polyfill', 95 'rocket-footer-js-custom-event-polyfill', 88 96 ]; 89 97 … … 93 101 } 94 102 95 wp_enqueue_script( 'rocket-footer-js-lazysizes', plugins_url( 'assets/js/lazysizes.js', $this->plugin->get_plugin_file(), $lazysize_deps ) ); 96 wp_enqueue_script( 'jquery-lazyloadxt.widget', plugins_url( 'assets/js/jquery.lazyloadxt.widget.js', $this->plugin->get_plugin_file() ), [ $dep ] ); 97 wp_enqueue_script( 'jquery-lazyloadxt.videoembed', plugins_url( 'assets/js/jquery.lazyloadxt.videoembed.js', $this->plugin->get_plugin_file() ), [ $dep ] ); 98 wp_enqueue_script( 'jquery-lazyloadxt.video', plugins_url( 'assets/js/jquery.lazyloadxt.video.js', $this->plugin->get_plugin_file() ), [ $dep ] ); 99 wp_enqueue_script( 'jquery-lazyloadxt.bg', plugins_url( 'assets/js/jquery.lazyloadxt.bg.js', $this->plugin->get_plugin_file() ), [ $dep ] ); 100 wp_enqueue_script( 'jquery.lazyloadxt.imagefixes', plugins_url( 'assets/js/jquery.lazyloadxt.imagefixes.js', $this->plugin->get_plugin_file() ), [ $dep ] ); 103 wp_enqueue_script( 'rocket-footer-js-lazysizes', plugins_url( "assets/js/lazysizes.{$suffix}js", $this->plugin->get_plugin_file(), $lazysize_deps ) ); 104 if ( apply_filters( 'rocket_footer_js_load_script_lazy_load_widgets', true ) ) { 105 wp_enqueue_script( 'jquery-lazyloadxt.widget', plugins_url( 'assets/js/jquery.lazyloadxt.widget.js', $this->plugin->get_plugin_file() ), [ $dep ] ); 106 } 107 if ( apply_filters( 'rocket_footer_js_load_script_lazy_load_video_embed', true ) ) { 108 wp_enqueue_script( 'jquery-lazyloadxt.videoembed', plugins_url( 'assets/js/jquery.lazyloadxt.videoembed.js', $this->plugin->get_plugin_file() ), [ $dep ] ); 109 wp_enqueue_style( 'rocket-footer-js-video-lazyload', plugins_url( 'assets/css/video-lazyload.css', $this->plugin->get_plugin_file() ) ); 110 } 111 if ( apply_filters( 'rocket_footer_js_load_script_lazy_load_video', true ) ) { 112 wp_enqueue_script( 'jquery-lazyloadxt.video', plugins_url( 'assets/js/jquery.lazyloadxt.video.js', $this->plugin->get_plugin_file() ), [ $dep ] ); 113 } 114 if ( apply_filters( 'rocket_footer_js_load_script_lazy_load_bg', true ) ) { 115 wp_enqueue_script( 'jquery-lazyloadxt.bg', plugins_url( 'assets/js/jquery.lazyloadxt.bg.js', $this->plugin->get_plugin_file() ), [ $dep ] ); 116 } 117 if ( apply_filters( 'rocket_footer_js_load_script_image_hacks', false ) ) { 118 wp_enqueue_script( 'jquery.lazyloadxt.imagefixes', plugins_url( 'assets/js/jquery.lazyloadxt.imagefixes.js', $this->plugin->get_plugin_file() ), [ $dep ] ); 119 } 101 120 wp_enqueue_style( 'rocket-footer-js-lazyload', plugins_url( 'assets/css/lazyload.css', $this->plugin->get_plugin_file() ) ); 102 wp_enqueue_style( 'rocket-footer-js-video-lazyload', plugins_url( 'assets/css/video-lazyload.css', $this->plugin->get_plugin_file() ) ); 121 103 122 } 104 123 -
rocket-footer-js/trunk/readme.txt
r2186620 r2256987 66 66 == Changelog == 67 67 68 ### 3.2.3 ### 69 70 * Bug: Fix typo in HubSpotForms module and fix broken code 71 * Bug: Handle edge case of HTML5 video not fully lazyloading due to jQuery not triggering on loadeddata event 72 * Feature: Add a pseudo css API to allow any elements background image to be lazyloaded 73 * Enhancement: Add filters around enqueuing auxiliary scripts & default to not load the imagefixes script so that modules can flag it on at runtime 74 * Enhancement: Add micro-optimization by serving preminified versions of polyfills and lazysizes 75 * Enhancement: Improve cache management by deleting cache files when the objects are purged to handle edge cases 76 * Enhancement: Add support for purging cache via cron, using rocket_footer_js_background_cache_purge_item_threshold filter, and preload cache if enabled after 77 * Enhancement: Videos Module: Only set src/data-src if this is a video. If video is autoplay before we process it, skip it 78 * Enhancement: Videos Module: Add vimeo support 79 * Compatibility: Videos Module: Add videojs compatibility 80 * Compatibility: Add visual composer compatibility to lazy load background images 81 * Compatibility: Add custom event polyfill 82 * Compatibility: Add compatibility with wp-rocket's lazyload 83 68 84 ### 3.2.2 ### 69 85 -
rocket-footer-js/trunk/rocket-footer-js.php
r2186620 r2256987 5 5 * Plugin URI: https://github.com/pcfreak30/rocket-footer-js 6 6 * Description: Unofficial WP-Rocket addon to force all JS both external and inline to the footer 7 * Version: 3.2. 27 * Version: 3.2.3 8 8 * Author: Derrick Hammer 9 9 * Author URI: https://www.derrickhammer.com
Note: See TracChangeset
for help on using the changeset viewer.