Version Description
- Make LazyLoad a static class so that it's easier to change its hooks
- Hook in at a higher priority for content filters
Download this release
Release Info
Developer | batmoo |
Plugin | Lazy Load |
Version | 0.3 |
Comparing to | |
See all releases |
Code changes from version 0.2 to 0.3
- lazy-load.php +11 -11
- readme.txt +6 -1
lazy-load.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/**
|
3 |
* Plugin Name: Lazy Load
|
4 |
* 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.
|
6 |
*
|
7 |
* Code by the WordPress.com VIP team, TechCrunch 2011 Redesign team, and Jake Goldman (10up LLC).
|
8 |
* Uses jQuery.sonar by Dave Artz (AOL): http://www.artzstudio.com/files/jquery-boston-2010/jquery.sonar/
|
@@ -12,26 +12,26 @@
|
|
12 |
|
13 |
class LazyLoad_Images {
|
14 |
|
15 |
-
const version = '0.
|
16 |
|
17 |
-
function
|
18 |
-
add_action( 'wp_enqueue_scripts', array(
|
19 |
-
add_filter( 'the_content', array(
|
20 |
-
add_filter( 'post_thumbnail_html', array(
|
21 |
}
|
22 |
|
23 |
function add_scripts() {
|
24 |
-
wp_enqueue_script( 'wpcom-lazy-load-images',
|
25 |
-
wp_enqueue_script( 'jquery-sonar',
|
26 |
}
|
27 |
|
28 |
function add_image_placeholders( $content ) {
|
29 |
// Don't lazyload for feeds, previews, mobile
|
30 |
-
if( is_feed() || ( function_exists( 'is_mobile' ) && is_mobile() )
|
31 |
return $content;
|
32 |
|
33 |
// In case you want to change the placeholder image
|
34 |
-
$placeholder_image = apply_filters( 'lazyload_images_placeholder_image',
|
35 |
|
36 |
// This is a pretty simple regex, but it works
|
37 |
$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 );
|
@@ -44,4 +44,4 @@ class LazyLoad_Images {
|
|
44 |
}
|
45 |
}
|
46 |
|
47 |
-
|
2 |
/**
|
3 |
* Plugin Name: Lazy Load
|
4 |
* 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
|
6 |
*
|
7 |
* Code by the WordPress.com VIP team, TechCrunch 2011 Redesign team, and Jake Goldman (10up LLC).
|
8 |
* Uses jQuery.sonar by Dave Artz (AOL): http://www.artzstudio.com/files/jquery-boston-2010/jquery.sonar/
|
12 |
|
13 |
class LazyLoad_Images {
|
14 |
|
15 |
+
const version = '0.3';
|
16 |
|
17 |
+
function init() {
|
18 |
+
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'add_scripts' ) );
|
19 |
+
add_filter( 'the_content', array( __CLASS__, 'add_image_placeholders' ), 11 );
|
20 |
+
add_filter( 'post_thumbnail_html', array( __CLASS__, 'add_image_placeholders' ), 11 );
|
21 |
}
|
22 |
|
23 |
function add_scripts() {
|
24 |
+
wp_enqueue_script( 'wpcom-lazy-load-images', self::get_url( 'js/lazy-load.js' ), array( 'jquery', 'jquery-sonar' ), self::version, true );
|
25 |
+
wp_enqueue_script( 'jquery-sonar', self::get_url( 'js/jquery.sonar.min.js' ), array( 'jquery' ), self::version, true );
|
26 |
}
|
27 |
|
28 |
function add_image_placeholders( $content ) {
|
29 |
// Don't lazyload for feeds, previews, mobile
|
30 |
+
if( is_feed() || is_preview() || ( function_exists( 'is_mobile' ) && is_mobile() ) )
|
31 |
return $content;
|
32 |
|
33 |
// In case you want to change the placeholder image
|
34 |
+
$placeholder_image = apply_filters( 'lazyload_images_placeholder_image', self::get_url( 'images/1x1.trans.gif' ) );
|
35 |
|
36 |
// This is a pretty simple regex, but it works
|
37 |
$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 );
|
44 |
}
|
45 |
}
|
46 |
|
47 |
+
LazyLoad_Images::init();
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: batmoo, automattic, jakemgold, get10up
|
|
3 |
Tags: lazy load, images, front-end optimization
|
4 |
Requires at least: 3.2
|
5 |
Tested up to: 3.3
|
6 |
-
Stable tag: 0.
|
7 |
|
8 |
Lazy load images to improve page load times and server bandwidth. Images are loaded only when visible to the user.
|
9 |
|
@@ -27,6 +27,11 @@ No applicable screenshots
|
|
27 |
|
28 |
== Changelog ==
|
29 |
|
|
|
|
|
|
|
|
|
|
|
30 |
= 0.2 =
|
31 |
|
32 |
* Adds noscript tags to allow the image to show up in no-js contexts (including crawlers), props smub
|
3 |
Tags: lazy load, images, front-end optimization
|
4 |
Requires at least: 3.2
|
5 |
Tested up to: 3.3
|
6 |
+
Stable tag: 0.3
|
7 |
|
8 |
Lazy load images to improve page load times and server bandwidth. Images are loaded only when visible to the user.
|
9 |
|
27 |
|
28 |
== Changelog ==
|
29 |
|
30 |
+
= 0.3 =
|
31 |
+
|
32 |
+
* Make LazyLoad a static class so that it's easier to change its hooks
|
33 |
+
* Hook in at a higher priority for content filters
|
34 |
+
|
35 |
= 0.2 =
|
36 |
|
37 |
* Adds noscript tags to allow the image to show up in no-js contexts (including crawlers), props smub
|