WordPress.org

Plugin Directory

Changeset 567472


Ignore:
Timestamp:
07/04/12 17:43:26 (22 months ago)
Author:
batmoo
Message:

Update to 0.4

  • New helper function
  • Support for WP.com infinite scroll
  • Prevent circular lazy-load references
Location:
lazy-load/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lazy-load/trunk/js/lazy-load.js

    r467076 r567472  
    11(function($) { 
    2     $( 'img[data-lazy-src]' ).bind( 'scrollin', { distance: 200 }, function() { 
    3         var img = this, 
    4             $img = jQuery(img), 
    5             src = $img.attr( 'data-lazy-src' ); 
    6         $img.unbind( 'scrollin' ) // remove event binding 
    7             .hide() 
    8             .removeAttr( 'data-lazy-src' ) 
    9             .attr( 'data-lazy-loaded', 'true' );; 
    10         img.src = src; 
    11         $img.fadeIn(); 
    12     }); 
     2    lazy_load_init(); 
     3    $( 'body' ).bind( 'post-load', lazy_load_init ); // Work with WP.com infinite scroll 
     4 
     5    function lazy_load_init() { 
     6        jQuery( 'img[data-lazy-src]' ).bind( 'scrollin', { distance: 200 }, function() { 
     7            var img = this, 
     8                $img = jQuery(img), 
     9                src = $img.attr( 'data-lazy-src' ); 
     10            $img.unbind( 'scrollin' ) // remove event binding 
     11                .hide() 
     12                .removeAttr( 'data-lazy-src' ) 
     13                .attr( 'data-lazy-loaded', 'true' );; 
     14            img.src = src; 
     15            $img.fadeIn(); 
     16        }); 
     17    } 
    1318})(jQuery); 
  • lazy-load/trunk/lazy-load.php

    r498772 r567472  
    33 * Plugin Name: Lazy Load 
    44 * Description: Lazy load images to improve page load times. Uses jQuery.sonar to only load an image when it's visible in the viewport. 
    5  * Version: 0.3 
     5 * Version: 0.4 
    66 * 
    77 * Code by the WordPress.com VIP team, TechCrunch 2011 Redesign team, and Jake Goldman (10up LLC). 
     
    1515class LazyLoad_Images { 
    1616 
    17     const version = '0.3'; 
     17    const version = '0.4'; 
    1818 
    1919    function init() { 
    2020        add_action( 'wp_enqueue_scripts', array( __CLASS__, 'add_scripts' ) ); 
    21         add_filter( 'the_content', array( __CLASS__, 'add_image_placeholders' ), 11 ); 
     21        add_filter( 'the_content', array( __CLASS__, 'add_image_placeholders' ), 99 ); // run this later, so other content filters have run, including image_add_wh on WP.com 
    2222        add_filter( 'post_thumbnail_html', array( __CLASS__, 'add_image_placeholders' ), 11 ); 
    2323    } 
     
    3333            return $content; 
    3434 
     35        // Don't lazy-load if the content has already been run through previously 
     36        if ( false !== strpos( $content, 'data-lazy-src' ) ) 
     37            return $content; 
     38 
    3539        // In case you want to change the placeholder image 
    3640        $placeholder_image = apply_filters( 'lazyload_images_placeholder_image', self::get_url( 'images/1x1.trans.gif' ) ); 
    3741 
    3842        // This is a pretty simple regex, but it works 
    39         $content = preg_replace( '#<img([^>]+?)src=[\'"]([^\'">]*)[\'"]([^>]*)>#', sprintf( '<img${1}src="%s" data-lazy-src="${2}"${3}><noscript><img${1}src="${2}"${3}></noscript>', $placeholder_image ), $content ); 
     43        $content = preg_replace( '#<img([^>]+?)src=[\'"]?([^\'"\s>]+)[\'"]?([^>]*)>#', sprintf( '<img${1}src="%s" data-lazy-src="${2}"${3}><noscript><img${1}src="${2}"${3}></noscript>', $placeholder_image ), $content ); 
    4044 
    4145        return $content; 
     
    4751} 
    4852 
     53function lazyload_images_add_placeholders( $content ) { 
     54    LazyLoad_Images::add_image_placeholders( $content ); 
     55} 
     56 
    4957LazyLoad_Images::init(); 
    5058 
  • lazy-load/trunk/readme.txt

    r498776 r567472  
    11=== Lazy Load === 
    2 Contributors: batmoo, automattic, jakemgold, get10up 
     2Contributors: batmoo, automattic, jakemgold, 10up 
    33Tags: lazy load, images, front-end optimization 
    44Requires at least: 3.2 
    5 Tested up to: 3.3 
    6 Stable tag: 0.3 
     5Tested up to: 3.4.1 
     6Stable tag: 0.4 
    77 
    88Lazy load images to improve page load times and server bandwidth. Images are loaded only when visible to the user. 
     
    4040== Changelog == 
    4141 
     42= 0.4 = 
     43 
     44* New helper function to lazy load non-post content 
     45* Prevent circular lazy-loading 
     46 
    4247= 0.3 = 
    4348 
Note: See TracChangeset for help on using the changeset viewer.