Plugin Directory

Changeset 2256987


Ignore:
Timestamp:
03/09/2020 12:07:54 AM (6 years ago)
Author:
pcfreak30
Message:

*Version bump to 3.2.3

Location:
rocket-footer-js/trunk
Files:
6 added
12 edited

Legend:

Unmodified
Added
Removed
  • rocket-footer-js/trunk/assets/css/lazyload.css

    r2091973 r2256987  
    88    transition: opacity 300ms;
    99}
     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  
    99    options.selector += ',video,iframe[data-src]';
    1010    options.videoPoster = 'data-poster';
     11
     12    function load () {
     13        this.dispatchEvent(new CustomEvent('load'));
     14    }
    1115
    1216    $(document).on('lazyshow', 'video', function (e, $el) {
     
    2428                    changed = true;
    2529                }
    26             });
    27 
     30            }).on('loadeddata', load);
     31        $el.on('loadeddata', load);
    2832        // reload video
    2933        if (changed) {
    3034            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            }
    3142        }
    3243        $el.triggerHandler('load')
  • rocket-footer-js/trunk/lib/Rocket/Footer/JS.php

    r2186620 r2256987  
    2525     * Plugin version
    2626     */
    27     const VERSION = '3.2.2';
     27    const VERSION = '3.2.3';
    2828    /**
    2929     *
  • rocket-footer-js/trunk/lib/Rocket/Footer/JS/Cache/Manager.php

    r2175460 r2256987  
    3131    public function init() {
    3232        add_action( 'after_rocket_clean_domain', [ $this, 'purge_cache' ], 10, 0 );
    33         add_action( 'after_rocket_clean_domain', [ $this, 'do_preload' ], 10, 0 );
    3433        add_action( 'wp_rocket_start_preload', 'run_rocket_sitemap_preload', 10, 0 );
    3534        add_action( 'after_rocket_clean_post', [ $this, 'purge_post' ] );
    3635        add_action( 'after_rocket_clean_term', [ $this, 'purge_term' ] );
    3736        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        }
    3842        $this->store->set_prefix( JS::TRANSIENT_PREFIX );
    3943        $interval = 0;
     
    4347        $this->store->set_expire( apply_filters( 'rocket_footer_js_cache_expire_period', $interval ) );
    4448        $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() );
    4597    }
    4698
     
    55107
    56108    /**
    57      *
    58      */
    59     public function purge_cache() {
    60         $this->store->delete_cache_branch();
    61         rocket_rrmdir( $this->plugin->get_cache_path() );
    62     }
    63 
    64     /**
    65109     * @param \WP_Post $post
    66110     */
    67111    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 );
    69129    }
    70130
     
    73133     */
    74134    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 );
    76137    }
    77138
     
    80141     */
    81142    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 );
    84146    }
    85147
     
    96158        return $this->store;
    97159    }
     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    }
    98167}
  • rocket-footer-js/trunk/lib/Rocket/Footer/JS/Integration/FusionFramework.php

    r2129570 r2256987  
    4949                'add_fusion_image_srcset_filter',
    5050            ] );
     51            add_filter( 'rocket_footer_js_load_script_image_hacks', '__return_true' );
    5152        }
    5253    }
  • rocket-footer-js/trunk/lib/Rocket/Footer/JS/Integration/Manager.php

    r2175460 r2256987  
    4848        'EssentialAddonsElementor',
    4949        'WPUltimatePostGrid',
     50        'VisualComposer',
    5051    ];
    5152
  • rocket-footer-js/trunk/lib/Rocket/Footer/JS/Integration/RevolutionSlider.php

    r2175460 r2256987  
    1010        if ( function_exists( 'rev_slider_shortcode' ) ) {
    1111            add_filter( 'option_revslider-global-settings', [ $this, 'modify_settings' ] );
     12            add_filter( 'rocket_footer_js_load_script_image_hacks', '__return_true' );
    1213        }
    1314    }
  • rocket-footer-js/trunk/lib/Rocket/Footer/JS/Lazyload/HubSpotForms.php

    r2129570 r2256987  
    7272
    7373        $tag->remove();
     74        $this->tags->flag_removed();
     75        $this->tags->rewind();
    7476    }
    7577
     
    8183        $this->set_no_minify();
    8284
    83         $nodes = $this->xpath->query( '//script[comtains(@src, "js.hsforms.net")]' );
     85        $nodes = $this->xpath->query( '//script[contains(@src, "js.hsforms.net")]' );
    8486        /** @var \Rocket\Footer\JS\DOMElement $node */
    8587        foreach ( $nodes as $node ) {
  • rocket-footer-js/trunk/lib/Rocket/Footer/JS/Lazyload/Videos.php

    r2175460 r2256987  
    8181            $thumbnail_size        = $tag->getAttribute( 'data-thumbnail-size' );
    8282            $thumbnail_alt         = $tag->getAttribute( 'data-thumbnail-alt' );
    83 
    84             $tag->setAttribute( ( $data_src ? 'data-' : '' ) . 'src', $this->maybe_set_autoplay( $original_src, $tag ) );
    8583            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 ) );
    8689                if ( empty( $thumbnail_alt ) ) {
    8790                    $thumbnail_alt = $info->title;
     
    236239                $urls[]           = http_build_url( $size_url );
    237240            }
     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 );
    238249        }
    239250        if ( ! empty( $urls ) ) {
     
    364375            $type = 'youtube';
    365376        }
     377        if ( 'vimeo.com' === $url['host'] || 'www.vimeo.com' === $url['host'] || 'player.vimeo.com' === $url['host'] ) {
     378            $type = 'vimeo';
     379        }
    366380        if ( null !== $type ) {
    367381            return $type;
     
    388402        }
    389403
     404        if ( 'vimeo.com' === $url['host'] || 'www.vimeo.com' === $url['host'] ) {
     405            return pathinfo( $url['path'], PATHINFO_FILENAME );
     406        }
     407
    390408        return false;
    391409    }
  • rocket-footer-js/trunk/lib/Rocket/Footer/JS/Request.php

    r2129570 r2256987  
    4040        add_action( 'save_post', 'rocket_clean_post' );
    4141        add_action( 'shutdown', [ $this, 'maybe_ajax_spoof' ], - 1 );
     42        add_filter( 'rocket_lazyload_script_tag', [ $this, 'strip_no_minify' ] );
     43    }
    4244
     45    public function strip_no_minify( $script ) {
     46        return str_replace( 'data-no-minify="1"', '', $script );
    4347    }
    4448
     
    6973        }
    7074
     75        $suffix = ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? 'min.' : '';
     76
    7177        if ( wp_script_is( $dep, 'registered' ) ) {
    7278            wp_deregister_style( 'jquery-lazyloadxt-fadein-css' );
     
    7682            $script = wp_scripts()->registered[ $dep ];
    7783            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() ) );
    8087            wp_enqueue_script( 'jquery-lazyloadxt-dummy', plugins_url( 'assets/js/lazysizes.lazyloadxt.compat.js', $this->plugin->get_plugin_file(), [ 'jquery' ] ) );
    8188            foreach ( $script->extra as $key => $data ) {
     
    8693                'rocket-footer-js-video-mutation-observer-polyfill',
    8794                'rocket-footer-js-video-intersection-observer-polyfill',
     95                'rocket-footer-js-custom-event-polyfill',
    8896            ];
    8997
     
    93101            }
    94102
    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            }
    101120            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
    103122        }
    104123
  • rocket-footer-js/trunk/readme.txt

    r2186620 r2256987  
    6666== Changelog ==
    6767
     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
    6884### 3.2.2 ###
    6985
  • rocket-footer-js/trunk/rocket-footer-js.php

    r2186620 r2256987  
    55 * Plugin URI:       https://github.com/pcfreak30/rocket-footer-js
    66 * Description:       Unofficial WP-Rocket addon to force all JS both external and inline to the footer
    7  * Version:           3.2.2
     7 * Version:           3.2.3
    88 * Author:            Derrick Hammer
    99 * Author URI:        https://www.derrickhammer.com
Note: See TracChangeset for help on using the changeset viewer.