BJ Lazy Load - Version 0.5.4

Version Description

Custom placeholder. Skip selected images.

Download this release

Release Info

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

Code changes from version 0.5.2 to 0.5.4

Files changed (3) hide show
  1. admin.php +13 -2
  2. bj-lazy-load.php +39 -21
  3. readme.txt +13 -3
admin.php CHANGED
@@ -48,8 +48,19 @@ class BJLL_Admin_Page extends scbAdminPage {
48
  'type' => 'select',
49
  'name' => 'theme_loader_function',
50
  'value' => array( 'wp_footer', 'wp_head' ),
51
-
52
- )
 
 
 
 
 
 
 
 
 
 
 
53
  ) );
54
 
55
  }
48
  'type' => 'select',
49
  'name' => 'theme_loader_function',
50
  'value' => array( 'wp_footer', 'wp_head' ),
51
+ ),
52
+ array(
53
+ 'title' => __( 'Placeholder Image URL', 'bj_lazy_load' ),
54
+ 'type' => 'text',
55
+ 'name' => 'placeholder_url',
56
+ 'desc' => __( 'Leave blank for default', 'bj_lazy_load' ),
57
+ ),
58
+ array(
59
+ 'title' => __( 'Skip images with classes', 'bj_lazy_load' ),
60
+ 'type' => 'text',
61
+ 'name' => 'skip_classes',
62
+ 'desc' => __( 'Comma separated. Example: "no-lazy, lazy-ignore, image-235"', 'bj_lazy_load' ),
63
+ ),
64
  ) );
65
 
66
  }
bj-lazy-load.php CHANGED
@@ -3,7 +3,7 @@
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.5.2
7
  Author: Bjørn Johansen
8
  Author URI: http://twitter.com/bjornjohansen
9
  License: GPL2
@@ -31,27 +31,35 @@ require_once( dirname(__FILE__) . '/scb/load.php' );
31
  if ( ! class_exists( 'BJLL' ) ) {
32
  class BJLL {
33
 
34
- const version = '0.5.2';
35
  protected $_placeholder_url;
 
36
 
37
  protected static $_instance;
38
 
39
  function __construct() {
40
 
41
- $this->_placeholder_url = plugins_url( '/img/placeholder.gif', __FILE__ );
42
-
43
  add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
44
 
45
  $options = self::_get_options();
46
 
 
 
 
 
 
 
 
 
 
47
 
48
- if ( $options->get('filter_content') == 'yes' ) {
49
  add_filter( 'the_content', array( $this, 'filter' ), 200 );
50
  }
51
- if ( $options->get('filter_post_thumbnails') == 'yes' ) {
52
  add_filter( 'post_thumbnail_html', array( $this, 'filter' ), 200 );
53
  }
54
- if ( $options->get('filter_gravatars') == 'yes' ) {
55
  add_filter( 'get_avatar', array( $this, 'filter' ), 200 );
56
  }
57
  }
@@ -103,23 +111,31 @@ if ( ! class_exists( 'BJLL' ) ) {
103
 
104
  $search = array();
105
  $replace = array();
 
 
 
 
 
106
 
107
  foreach ( $matches[0] as $imgHTML ) {
108
 
109
- // replace the src and add the data-src attribute
110
- $replaceHTML = preg_replace( '/<img(.*?)src=/i', '<img$1src="' . $this->_placeholder_url . '" data-lazy-type="image" data-lazy-src=', $imgHTML );
111
-
112
- // add the lazy class to the img element
113
- if ( preg_match( '/class="/i', $replaceHTML ) ) {
114
- $replaceHTML = preg_replace( '/class="(.*?)"/i', 'class="lazy lazy-hidden $1"', $replaceHTML );
115
- } else {
116
- $replaceHTML = preg_replace( '/<img/i', '<img class="lazy lazy-hidden"', $replaceHTML );
 
 
 
 
 
 
 
 
117
  }
118
-
119
- $replaceHTML .= '<noscript>' . $imgHTML . '</noscript>';
120
-
121
- array_push( $search, $imgHTML );
122
- array_push( $replace, $replaceHTML );
123
  }
124
 
125
  $content = str_replace( $search, $replace, $content );
@@ -157,7 +173,9 @@ if ( ! class_exists( 'BJLL' ) ) {
157
  'filter_gravatars' => 'yes',
158
  'lazy_load_images' => 'yes',
159
  'lazy_load_iframes' => 'yes',
160
- 'theme_loader_function' => 'wp_footer'
 
 
161
  ) );
162
  }
163
 
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.5.4
7
  Author: Bjørn Johansen
8
  Author URI: http://twitter.com/bjornjohansen
9
  License: GPL2
31
  if ( ! class_exists( 'BJLL' ) ) {
32
  class BJLL {
33
 
34
+ const version = '0.5.4';
35
  protected $_placeholder_url;
36
+ protected $_skip_classes;
37
 
38
  protected static $_instance;
39
 
40
  function __construct() {
41
 
 
 
42
  add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
43
 
44
  $options = self::_get_options();
45
 
46
+ $skip_classes = $options->get( 'skip_classes' );
47
+ if ( strlen( trim( $skip_classes ) ) ) {
48
+ $this->_skip_classes = array_map( 'trim', explode( ',', $options->get( 'skip_classes' ) ) );
49
+ }
50
+
51
+ $this->_placeholder_url = $options->get( 'placeholder_url' );
52
+ if ( ! strlen( $this->_placeholder_url ) ) {
53
+ $this->_placeholder_url = plugins_url( '/img/placeholder.gif', __FILE__ );
54
+ }
55
 
56
+ if ( $options->get( 'filter_content' ) == 'yes' ) {
57
  add_filter( 'the_content', array( $this, 'filter' ), 200 );
58
  }
59
+ if ( $options->get( 'filter_post_thumbnails' ) == 'yes' ) {
60
  add_filter( 'post_thumbnail_html', array( $this, 'filter' ), 200 );
61
  }
62
+ if ( $options->get( 'filter_gravatars' ) == 'yes' ) {
63
  add_filter( 'get_avatar', array( $this, 'filter' ), 200 );
64
  }
65
  }
111
 
112
  $search = array();
113
  $replace = array();
114
+
115
+ if ( is_array( $this->_skip_classes ) ) {
116
+ $skip_images_preg_quoted = array_map( 'preg_quote', $this->_skip_classes );
117
+ $skip_images_regex = sprintf( '/class=".*(%s).*"/', implode( '|', $skip_images_preg_quoted ) );
118
+ }
119
 
120
  foreach ( $matches[0] as $imgHTML ) {
121
 
122
+ // don't to the replacement if a skip class is provided and the image has the class
123
+ if ( ! ( is_array( $this->_skip_classes ) && preg_match( $skip_images_regex, $imgHTML ) ) ) {
124
+ // replace the src and add the data-src attribute
125
+ $replaceHTML = preg_replace( '/<img(.*?)src=/i', '<img$1src="' . $this->_placeholder_url . '" data-lazy-type="image" data-lazy-src=', $imgHTML );
126
+
127
+ // add the lazy class to the img element
128
+ if ( preg_match( '/class="/i', $replaceHTML ) ) {
129
+ $replaceHTML = preg_replace( '/class="(.*?)"/i', 'class="lazy lazy-hidden $1"', $replaceHTML );
130
+ } else {
131
+ $replaceHTML = preg_replace( '/<img/i', '<img class="lazy lazy-hidden"', $replaceHTML );
132
+ }
133
+
134
+ $replaceHTML .= '<noscript>' . $imgHTML . '</noscript>';
135
+
136
+ array_push( $search, $imgHTML );
137
+ array_push( $replace, $replaceHTML );
138
  }
 
 
 
 
 
139
  }
140
 
141
  $content = str_replace( $search, $replace, $content );
173
  'filter_gravatars' => 'yes',
174
  'lazy_load_images' => 'yes',
175
  'lazy_load_iframes' => 'yes',
176
+ 'theme_loader_function' => 'wp_footer',
177
+ 'placeholder_url' => '',
178
+ 'skip_classes' => ''
179
  ) );
180
  }
181
 
readme.txt CHANGED
@@ -4,8 +4,8 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: images, iframes, lazy loading, jquery, javascript, optimize, performance, bandwidth
5
  Author URI: http://twitter.com/bjornjohansen
6
  Requires at least: 3.3
7
- Tested up to: 3.4.1
8
- Stable tag: 0.5.2
9
 
10
  Lazy loading makes your site load faster and saves bandwidth. Uses jQuery and degrades gracefully for non-js users. Works with both images and iframes.
11
 
@@ -35,7 +35,7 @@ if ( class_exists( 'BJLL' ) ) {
35
  $img = BJLL::filter( $img );
36
  }
37
  echo $img;
38
- ?>`
39
 
40
  == Frequently Asked Questions ==
41
 
@@ -56,6 +56,13 @@ Check your HTML source or see the magic at work in Web Inspector, FireBug or sim
56
 
57
  == Changelog ==
58
 
 
 
 
 
 
 
 
59
  = Version 0.5.2 =
60
  * Added the fadeIn effect
61
 
@@ -119,6 +126,9 @@ Check your HTML source or see the magic at work in Web Inspector, FireBug or sim
119
 
120
  == Upgrade Notice ==
121
 
 
 
 
122
  = 0.5.2 =
123
  Added fadeIn effect
124
 
4
  Tags: images, iframes, lazy loading, jquery, javascript, optimize, performance, bandwidth
5
  Author URI: http://twitter.com/bjornjohansen
6
  Requires at least: 3.3
7
+ Tested up to: 3.5
8
+ Stable tag: 0.5.4
9
 
10
  Lazy loading makes your site load faster and saves bandwidth. Uses jQuery and degrades gracefully for non-js users. Works with both images and iframes.
11
 
35
  $img = BJLL::filter( $img );
36
  }
37
  echo $img;
38
+ ?>`
39
 
40
  == Frequently Asked Questions ==
41
 
56
 
57
  == Changelog ==
58
 
59
+ = Version 0.5.4 =
60
+ * Possible to skip lazy loading of certain images with specified classnames
61
+ * Made the placeholder image override an option setting in wp-admin
62
+
63
+ = Version 0.5.3 =
64
+ * Added filter: bj_lazy_load_placeholder_url - override placeholder image (should be an option setting in the future)
65
+
66
  = Version 0.5.2 =
67
  * Added the fadeIn effect
68
 
126
 
127
  == Upgrade Notice ==
128
 
129
+ = 0.5.4 =
130
+ Custom placeholder. Skip selected images.
131
+
132
  = 0.5.2 =
133
  Added fadeIn effect
134