BJ Lazy Load - Version 0.3.0

Version Description

Lazy load any image in your theme

Download this release

Release Info

Developer bjornjohansen
Plugin Icon 128x128 BJ Lazy Load
Version 0.3.0
Comparing to
See all releases

Code changes from version 0.2.5 to 0.3.0

Files changed (2) hide show
  1. bj-lazy-load.php +27 -7
  2. readme.txt +26 -6
bj-lazy-load.php CHANGED
@@ -3,12 +3,12 @@
3
  Plugin Name: BJ Lazy Load
4
  Plugin URI: http://wordpress.org/extend/plugins/bj-lazy-load/
5
  Description: Lazy image loading makes your site load faster and saves bandwidth.
6
- Version: 0.2.5
7
  Author: Bjørn Johansen
8
  Author URI: http://twitter.com/bjornjohansen
9
  License: GPL2
10
 
11
- Copyright 2011 Bjørn Johansen (email : post@bjornjohansen.no)
12
 
13
  This program is free software; you can redistribute it and/or modify
14
  it under the terms of the GNU General Public License, version 2, as
@@ -28,8 +28,10 @@ License: GPL2
28
 
29
  class BJLL {
30
 
31
- const version = '0.2.5';
32
  private $_placeholder_url;
 
 
33
 
34
  function __construct() {
35
 
@@ -55,6 +57,14 @@ class BJLL {
55
  }
56
  }
57
 
 
 
 
 
 
 
 
 
58
  public function enqueue_styles() {
59
  wp_enqueue_style( 'BJLL', plugins_url( '/css/bjll.css', __FILE__ ), array(), self::version );
60
  }
@@ -138,6 +148,15 @@ var BJLL = {
138
 
139
  }
140
 
 
 
 
 
 
 
 
 
 
141
  protected function _get_placeholder_html ( $html ) {
142
 
143
  if ( class_exists( 'DOMDocument') ) {
@@ -153,7 +172,7 @@ var BJLL = {
153
 
154
  $loadhtml = sprintf( '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"><title></title></head><body>%s</body></html>', $html );
155
 
156
- $doc = DOMDocument::loadHTML( $loadhtml );
157
  if ( ! $doc ) {
158
  return $this->_get_placeholder_html_regexp( $html );
159
  }
@@ -409,13 +428,14 @@ class BJLL_Admin {
409
 
410
  }
411
 
 
412
  /*
413
  is_admin() will return true when trying to make an ajax request
414
  if (!is_admin() && !is_feed()) {
415
  */
416
- if ( ! is_feed() ) {
417
- new BJLL;
418
- }
419
 
420
  if ( is_admin() ) {
421
  new BJLL_Admin;
3
  Plugin Name: BJ Lazy Load
4
  Plugin URI: http://wordpress.org/extend/plugins/bj-lazy-load/
5
  Description: Lazy image loading makes your site load faster and saves bandwidth.
6
+ Version: 0.3.0
7
  Author: Bjørn Johansen
8
  Author URI: http://twitter.com/bjornjohansen
9
  License: GPL2
10
 
11
+ Copyright 2011–2012 Bjørn Johansen (email : post@bjornjohansen.no)
12
 
13
  This program is free software; you can redistribute it and/or modify
14
  it under the terms of the GNU General Public License, version 2, as
28
 
29
  class BJLL {
30
 
31
+ const version = '0.3.0';
32
  private $_placeholder_url;
33
+
34
+ private static $_instance;
35
 
36
  function __construct() {
37
 
57
  }
58
  }
59
 
60
+ public static function singleton() {
61
+ if (!isset(self::$_instance)) {
62
+ $className = __CLASS__;
63
+ self::$_instance = new $className;
64
+ }
65
+ return self::$_instance;
66
+ }
67
+
68
  public function enqueue_styles() {
69
  wp_enqueue_style( 'BJLL', plugins_url( '/css/bjll.css', __FILE__ ), array(), self::version );
70
  }
148
 
149
  }
150
 
151
+ static function filter ( $html ) {
152
+ $BJLL = BJLL::singleton();
153
+ return $BJLL->get_placeholder_html ( $html );
154
+ }
155
+
156
+ public function get_placeholder_html ( $html ) {
157
+ return $this->_get_placeholder_html ( $html );
158
+ }
159
+
160
  protected function _get_placeholder_html ( $html ) {
161
 
162
  if ( class_exists( 'DOMDocument') ) {
172
 
173
  $loadhtml = sprintf( '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"><title></title></head><body>%s</body></html>', $html );
174
 
175
+ $doc = @DOMDocument::loadHTML( $loadhtml );
176
  if ( ! $doc ) {
177
  return $this->_get_placeholder_html_regexp( $html );
178
  }
428
 
429
  }
430
 
431
+
432
  /*
433
  is_admin() will return true when trying to make an ajax request
434
  if (!is_admin() && !is_feed()) {
435
  */
436
+ /* 'Conditional query tags do not work before the query is run. Before then, they always return false.' */
437
+ add_action( 'wp', function() { if ( ! is_feed() ) { BJLL::singleton() ; } }, 10, 0 );
438
+
439
 
440
  if ( is_admin() ) {
441
  new BJLL_Admin;
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: images, lazy loading, jquery, javascript, optimize, performance, bandwidth
5
  Author URI: http://twitter.com/bjornjohansen
6
  Requires at least: 3.1
7
  Tested up to: 3.3
8
- Stable tag: 0.2.5
9
 
10
  Lazy image loading makes your site load faster and saves bandwidth. Uses jQuery and degrades gracefully for non-js users.
11
 
@@ -14,9 +14,11 @@ Lazy image loading makes your site load faster and saves bandwidth.
14
 
15
  This plugin replaces all your post images and post thumbnails with a placeholder and loads images as they enter the browser window when the visitor scrolls the page.
16
 
 
 
17
  Non-javascript visitors gets the original img element in noscript.
18
 
19
- Includes [JqueryAsynchImageLoader Plugin for jQuery by Sebastiano Armeli-Battana](http://www.sebastianoarmelibattana.com/projects/jail) for the real magic.
20
 
21
  = Coming soon =
22
  * Serving size optimized images for responsive design/adaptive layout
@@ -27,25 +29,40 @@ Includes [JqueryAsynchImageLoader Plugin for jQuery by Sebastiano Armeli-Battana
27
  2. Upload the 'bj-lazyload' folder to the '/wp-content/plugins/' directory,
28
  3. Activate the plugin through the 'Plugins' menu in WordPress.
29
 
 
 
 
 
 
 
 
 
 
 
30
  == Frequently Asked Questions ==
31
 
32
- = Whoa, this plugin is using Javascript. What about visitors without JS? =
33
  No worries. They get the original image in a noscript element.
34
 
35
  = Which browsers are supported? =
36
- The included Javascript is tested in Firefox 2+, Safari 3+, Opera 9+, Chrome 5+, Internet Explorer 6+
37
 
38
  = I'm using a CDN. Will this plugin interfere? =
39
  Nope. The images will still load from your CDN.
40
 
41
  = The plugin doesn't work/doesn't replace my images =
42
- Please let me know. HTML can be tricky to parse sometimes.
43
 
44
  = How can I verify that the plugin is working? =
45
- Check your HTML source or see the magic at work in FireBug or similar.
46
 
47
  == Changelog ==
48
 
 
 
 
 
 
49
  = Version 0.2.5 =
50
  * Fixes Unicode-issue with filenames
51
 
@@ -79,6 +96,9 @@ Check your HTML source or see the magic at work in FireBug or similar.
79
 
80
  == Upgrade Notice ==
81
 
 
 
 
82
  = 0.2.5 =
83
  Now works with Unicode filenames
84
 
5
  Author URI: http://twitter.com/bjornjohansen
6
  Requires at least: 3.1
7
  Tested up to: 3.3
8
+ Stable tag: 0.3.0
9
 
10
  Lazy image loading makes your site load faster and saves bandwidth. Uses jQuery and degrades gracefully for non-js users.
11
 
14
 
15
  This plugin replaces all your post images and post thumbnails with a placeholder and loads images as they enter the browser window when the visitor scrolls the page.
16
 
17
+ You can also lazy load other images in your theme, by using a simple function.
18
+
19
  Non-javascript visitors gets the original img element in noscript.
20
 
21
+ Includes [JqueryAsynchImageLoader Plugin for jQuery by Sebastiano Armeli-Battana](http://www.sebastianoarmelibattana.com/projects/jail) for the lazy loading magic.
22
 
23
  = Coming soon =
24
  * Serving size optimized images for responsive design/adaptive layout
29
  2. Upload the 'bj-lazyload' folder to the '/wp-content/plugins/' directory,
30
  3. Activate the plugin through the 'Plugins' menu in WordPress.
31
 
32
+ == Optional usage ==
33
+ If you have images output in custom templates or want to lazy load other images in your theme, you may filter the HTML through BJLL::filter():
34
+ `<?php
35
+ $img = '<img src="myimage.jpg" alt="">';
36
+ if ( class_exists( 'BJLL' ) ) {
37
+ $img = BJLL::filter( $img );
38
+ }
39
+ echo $img;
40
+ ?>`
41
+
42
  == Frequently Asked Questions ==
43
 
44
+ = Whoa, this plugin is using JavaScript. What about visitors without JS? =
45
  No worries. They get the original image in a noscript element.
46
 
47
  = Which browsers are supported? =
48
+ The included JavaScript is tested in Firefox 2+, Safari 3+, Opera 9+, Chrome 5+, Internet Explorer 6+
49
 
50
  = I'm using a CDN. Will this plugin interfere? =
51
  Nope. The images will still load from your CDN.
52
 
53
  = The plugin doesn't work/doesn't replace my images =
54
+ Probably, your theme does not call wp_footer(). Edit the plugin settings to load in wp_head() instead.
55
 
56
  = How can I verify that the plugin is working? =
57
+ Check your HTML source or see the magic at work in Web Inspector, FireBug or similar.
58
 
59
  == Changelog ==
60
 
61
+ = Version 0.3.0 =
62
+ * Added BJLL::filter() so you can lazy load any images in your theme
63
+ * Added the option to load in wp_head() instead (suboptimal, but some themes actually don't call wp_footer())
64
+ * Correctly removed the lazy loader from feeds
65
+
66
  = Version 0.2.5 =
67
  * Fixes Unicode-issue with filenames
68
 
96
 
97
  == Upgrade Notice ==
98
 
99
+ = 0.3.0 =
100
+ Lazy load any image in your theme
101
+
102
  = 0.2.5 =
103
  Now works with Unicode filenames
104