BJ Lazy Load - Version 0.2.1

Version Description

More options and faster loading.

Download this release

Release Info

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

Code changes from version 0.2 to 0.2.1

Files changed (5) hide show
  1. bj-lazy-load.php +290 -0
  2. bj-lazyload.php +0 -185
  3. js/bjll.js +9 -1
  4. js/bjll.min.js +11 -0
  5. readme.txt +23 -5
bj-lazy-load.php ADDED
@@ -0,0 +1,290 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
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.1
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
15
+ published by the Free Software Foundation.
16
+
17
+ This program is distributed in the hope that it will be useful,
18
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ GNU General Public License for more details.
21
+
22
+ You should have received a copy of the GNU General Public License
23
+ along with this program; if not, write to the Free Software
24
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
+
26
+ */
27
+
28
+
29
+ class BJLL {
30
+
31
+ const version = '0.2.1';
32
+ private $_placeholder_url;
33
+
34
+ function __construct() {
35
+
36
+ $this->_placeholder_url = plugins_url('/img/placeholder.gif', __FILE__);
37
+
38
+ add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
39
+
40
+ add_action( 'wp_ajax_BJLL_get_images', array($this, 'get_images_json') );
41
+ add_action( 'wp_ajax_nopriv_BJLL_get_images', array($this, 'get_images_json') );
42
+
43
+ add_filter('the_content', array($this, 'filter_post_images'), 200);
44
+
45
+ if (intval(get_option('bjll_filter_post_thumbnails', 1))) {
46
+ add_filter( 'post_thumbnail_html', array($this, 'filter_post_thumbnail_html'), 10 );
47
+ }
48
+ }
49
+
50
+ public function enqueue_scripts() {
51
+ /*
52
+ wp_enqueue_script('JAIL', plugins_url('/js/jail.min.js', __FILE__), array('jquery'), '0.9.7', true);
53
+ wp_enqueue_script( 'BJLL', plugins_url('/js/bjll.js', __FILE__), array( 'jquery', 'JAIL' ), self::version, true );
54
+ */
55
+ wp_enqueue_script( 'BJLL', plugins_url('/js/bjll.min.js', __FILE__), array( 'jquery' ), self::version, true );
56
+
57
+ /* We don't need this (yet)
58
+ wp_localize_script( 'BJLL', 'BJLL', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
59
+ */
60
+
61
+ wp_localize_script( 'BJLL', 'BJLL', array(
62
+ 'timeout' => get_option('bjll_timeout', 10),
63
+ 'effect' => get_option('bjll_effect', 'fadeIn'),
64
+ 'speed' => get_option('bjll_speed', 400),
65
+ 'event' => get_option('bjll_event', 'load+scroll'),
66
+ 'callback' => get_option('bjll_callback', ''),
67
+ //'callbackAfterEachImage' => get_option('bjll_callbackAfterEachImage', ''),
68
+ 'placeholder' => get_option('bjll_placeholder', ''),
69
+ 'offset' => get_option('bjll_offset', 200),
70
+ 'ignoreHiddenImages' => get_option('bjll_ignoreHiddenImages', 0),
71
+ ) );
72
+ }
73
+
74
+ public function get_images_json() {
75
+ echo json_encode($_POST['attachmentIDs']);
76
+ exit;
77
+ }
78
+
79
+ public function filter_post_images($content) {
80
+
81
+ $matches = array();
82
+ preg_match_all('/<img\s+.*?>/', $content, $matches);
83
+
84
+ $search = array();
85
+ $replace = array();
86
+
87
+ foreach ($matches[0] as $imgHTML) {
88
+
89
+ $replaceHTML = $this->_get_placeholder_html($imgHTML);
90
+
91
+ array_push($search, $imgHTML);
92
+ array_push($replace, $replaceHTML);
93
+ }
94
+
95
+ $content = str_replace($search, $replace, $content);
96
+
97
+ return $content;
98
+ }
99
+
100
+ public function filter_post_thumbnail_html( $html ) {
101
+
102
+ $html = $this->_get_placeholder_html($html);
103
+
104
+ return $html;
105
+
106
+ }
107
+
108
+ protected function _get_placeholder_html ($html) {
109
+
110
+ $orig_html = $html;
111
+
112
+ // replace the src and add the data-href attribute
113
+ $html = preg_replace( '/<img(.*?)src=/i', '<img$1src="'.$this->_placeholder_url.'" data-href=', $html );
114
+
115
+ // add the lazy class to the img element
116
+ if (preg_match('/class="/i', $html)) {
117
+ $html = preg_replace('/class="(.*?)"/i', ' class="lazy $1"', $html);
118
+ } else {
119
+ $html = preg_replace('/<img/i', '<img class="lazy"', $html);
120
+ }
121
+
122
+ $html .= '<noscript>' . $orig_html . '</noscript>';
123
+
124
+ return $html;
125
+ }
126
+
127
+ }
128
+
129
+ class BJLL_Admin {
130
+
131
+ function __construct () {
132
+ add_action('admin_menu', array($this, 'plugin_menu'));
133
+ add_action('admin_init', array($this, 'register_settings'));
134
+ }
135
+
136
+ function plugin_menu() {
137
+ add_options_page('BJ Lazy Load', 'BJ Lazy Load', 'manage_options', 'bjll', array($this, 'plugin_options_page'));
138
+ }
139
+
140
+ function register_settings() {
141
+ //register_setting( $option_group, $option_name, $sanitize_callback );
142
+ register_setting( 'bjll_options', 'bjll_filter_post_thumbnails', 'intval' );
143
+
144
+ //add_settings_section( $id, $title, $callback, $page );
145
+ add_settings_section('bjll_general', __('General'), array('BJLL_Admin','settings_section_general'), 'bjll');
146
+
147
+ //add_settings_field( $id, $title, $callback, $page, $section, $args );
148
+ add_settings_field('bjll_filter_post_thumbnails', __('Lazy load post thumbnails'), array('BJLL_Admin', 'setting_field_filter_post_thumbnails'), 'bjll', 'bjll_general', array('label_for' => 'bjll_filter_post_thumbnails'));
149
+
150
+ register_setting( 'bjll_options', 'bjll_timeout', 'intval' );
151
+ register_setting( 'bjll_options', 'bjll_effect' );
152
+ register_setting( 'bjll_options', 'bjll_speed', 'intval' );
153
+ register_setting( 'bjll_options', 'bjll_event', array('BJLL_Admin', 'sanitize_setting_event') );
154
+ register_setting( 'bjll_options', 'bjll_callback' );
155
+ register_setting( 'bjll_options', 'bjll_callbackAfterEachImage' );
156
+ register_setting( 'bjll_options', 'bjll_placeholder' );
157
+ register_setting( 'bjll_options', 'bjll_offset', 'intval' );
158
+ register_setting( 'bjll_options', 'bjll_ignoreHiddenImages', 'intval' );
159
+
160
+ add_settings_section('bjll_loader', __('Loader'), array('BJLL_Admin','settings_section_loader'), 'bjll');
161
+
162
+ add_settings_field('bjll_timeout', __('Timeout'), array('BJLL_Admin', 'setting_field_timeout'), 'bjll', 'bjll_loader', array('label_for' => 'bjll_timeout'));
163
+ add_settings_field('bjll_effect', __('jQuery Effect'), array('BJLL_Admin', 'setting_field_effect'), 'bjll', 'bjll_loader', array('label_for' => 'bjll_effect'));
164
+ add_settings_field('bjll_speed', __('Effect Speed'), array('BJLL_Admin', 'setting_field_speed'), 'bjll', 'bjll_loader', array('label_for' => 'bjll_speed'));
165
+ add_settings_field('bjll_event', __('Trigger Event'), array('BJLL_Admin', 'setting_field_event'), 'bjll', 'bjll_loader', array('label_for' => 'bjll_event'));
166
+ add_settings_field('bjll_offset', __('Offset/Threshold'), array('BJLL_Admin', 'setting_field_offset'), 'bjll', 'bjll_loader', array('label_for' => 'bjll_offset'));
167
+ add_settings_field('bjll_ignoreHiddenImages', __('Ignore Hidden Images'), array('BJLL_Admin', 'setting_field_ignoreHiddenImages'), 'bjll', 'bjll_loader', array('label_for' => 'bjll_ignoreHiddenImages'));
168
+
169
+ }
170
+
171
+ function sanitize_setting_event ($val) {
172
+ $validoptions = self::_get_valid_setting_options_event();
173
+ if (!in_array($val, $validoptions)) {
174
+ // get previous saved value
175
+ $val = get_option('bjll_event', 'load+scroll');
176
+ if (!in_array($val, $validoptions)) {
177
+ // if still not valid, set to our default
178
+ $val = $validoptions[0];
179
+ }
180
+ }
181
+ return $val;
182
+ }
183
+
184
+ function sanitize_setting_effect ($val) {
185
+ if (!strlen($val)) {
186
+ $val = null;
187
+ }
188
+ return $val;
189
+ }
190
+
191
+ private static function _get_valid_setting_options_event() {
192
+ return array('load+scroll', 'load', 'click', 'mouseover', 'scroll');
193
+ }
194
+
195
+
196
+ function settings_section_general() {
197
+ }
198
+
199
+ function settings_section_loader() {
200
+ }
201
+
202
+ function setting_field_filter_post_thumbnails() {
203
+
204
+ $checked = '';
205
+ if (intval(get_option('bjll_filter_post_thumbnails', 1))) {
206
+ $checked = ' checked="checked"';
207
+ }
208
+
209
+ echo '<input id="bjll_filter_post_thumbnails" name="bjll_filter_post_thumbnails" type="checkbox" value="1" ' . $checked . ' />';
210
+
211
+ }
212
+ function setting_field_ignoreHiddenImages() {
213
+
214
+ $checked = '';
215
+ if (intval(get_option('bjll_ignoreHiddenImages', 0))) {
216
+ $checked = ' checked="checked"';
217
+ }
218
+
219
+ echo '<input id="bjll_ignoreHiddenImages" name="bjll_ignoreHiddenImages" type="checkbox" value="1" ' . $checked . ' /> whether to ignore hidden images to be loaded - Default: false/unchecked (so hidden images are loaded)';
220
+
221
+ }
222
+ function setting_field_event() {
223
+
224
+ $options = self::_get_valid_setting_options_event();
225
+
226
+ $currentval = get_option('bjll_event');
227
+
228
+ echo '<select id="bjll_event" name="bjll_event" type="checkbox">';
229
+ foreach ($options as $option) {
230
+ $selected = '';
231
+ if ($option == $currentval) {
232
+ $selected = ' selected="selected"';
233
+ }
234
+ echo sprintf('<option value="%1$s"%2$s>%1$s</option>', $option, $selected);
235
+ }
236
+ echo '</select> event that triggers the image to load. Default: load+scroll';
237
+ }
238
+ function setting_field_timeout() {
239
+ $val = get_option('bjll_timeout', 10);
240
+ echo '<input id="bjll_timeout" name="bjll_timeout" type="text" value="' . $val . '" /> number of msec after that the images will be loaded - Default: 10';
241
+ }
242
+ function setting_field_effect() {
243
+ $val = get_option('bjll_effect', '');
244
+ if (strtolower($val) == 'null') {
245
+ $val = '';
246
+ }
247
+ echo '<input id="bjll_effect" name="bjll_effect" type="text" value="' . $val . '" /> any jQuery effect that makes the images display (e.g. "fadeIn") - Default: NULL<p>NOTE: If you are loading a large number of images, it is best to NOT use this setting. Effects calls are very expensive. Even a simple show() can have a major impact on the browser&rsquo;s responsiveness.</p>';
248
+ }
249
+ function setting_field_speed() {
250
+ $val = get_option('bjll_speed', 400);
251
+ echo '<input id="bjll_speed" name="bjll_speed" type="text" value="' . $val . '" /> string or number determining how long the animation will run - Default: 400';
252
+ }
253
+ function setting_field_offset() {
254
+ $val = get_option('bjll_offset', 200);
255
+ echo '<input id="bjll_offset" name="bjll_offset" type="text" value="' . $val . '" /> an offset of "500" would cause any images that are less than 500px below the bottom of the window or 500px above the top of the window to load. - Default: 200';
256
+ }
257
+
258
+ function plugin_options_page() {
259
+ if (!current_user_can('manage_options')) {
260
+ wp_die( __('You do not have sufficient permissions to access this page.') );
261
+ }
262
+ ?>
263
+ <div class="wrap">
264
+ <h2>BJ Lazy Load <?php _e('Settings'); ?></h2>
265
+ <form method="post" action="options.php">
266
+ <?php settings_fields('bjll_options'); ?>
267
+ <?php do_settings_sections('bjll'); ?>
268
+
269
+ <p class="submit">
270
+ <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
271
+ </p>
272
+ </form>
273
+ </div>
274
+ <?php
275
+ }
276
+
277
+ }
278
+
279
+ /*
280
+ is_admin() will return true when trying to make an ajax request
281
+ if (!is_admin() && !is_feed()) {
282
+ */
283
+ if (!is_feed()) {
284
+ new BJLL;
285
+ }
286
+
287
+ if (is_admin()) {
288
+ new BJLL_Admin;
289
+ }
290
+
bj-lazyload.php DELETED
@@ -1,185 +0,0 @@
1
- <?php
2
- /*
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
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
15
- published by the Free Software Foundation.
16
-
17
- This program is distributed in the hope that it will be useful,
18
- but WITHOUT ANY WARRANTY; without even the implied warranty of
19
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
- GNU General Public License for more details.
21
-
22
- You should have received a copy of the GNU General Public License
23
- along with this program; if not, write to the Free Software
24
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
-
26
- */
27
-
28
-
29
- class BJLL {
30
-
31
- private $_placeholder_url;
32
-
33
- function __construct() {
34
-
35
- $this->_placeholder_url = plugins_url('/img/placeholder.gif', __FILE__);
36
-
37
- add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
38
-
39
- add_action( 'wp_ajax_BJLL_get_images', array($this, 'get_images_json') );
40
- add_action( 'wp_ajax_nopriv_BJLL_get_images', array($this, 'get_images_json') );
41
-
42
- add_filter('the_content', array($this, 'filter_post_images'), 200);
43
-
44
- if (intval(get_option('bjll_filter_post_thumbnails', 1))) {
45
- add_filter( 'post_thumbnail_html', array($this, 'filter_post_thumbnail_html'), 10 );
46
- }
47
- }
48
-
49
- public function enqueue_scripts() {
50
- wp_enqueue_script('JAIL', plugins_url('/js/jail.min.js', __FILE__), array('jquery'), '0.9.7', true);
51
-
52
- wp_enqueue_script( 'BJLL', plugins_url('/js/bjll.js', __FILE__), array( 'jquery', 'JAIL' ), '0.1', true );
53
-
54
- /* We don't need this (yet)
55
- wp_localize_script( 'BJLL', 'BJLL', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
56
- */
57
- }
58
-
59
- public function get_images_json() {
60
- echo json_encode($_POST['attachmentIDs']);
61
- exit;
62
- }
63
-
64
- public function filter_post_images($content) {
65
-
66
- $matches = array();
67
- preg_match_all('/<img\s+.*?>/', $content, $matches);
68
-
69
- $search = array();
70
- $replace = array();
71
-
72
- foreach ($matches[0] as $imgHTML) {
73
-
74
- $replaceHTML = $this->_get_placeholder_html($imgHTML);
75
-
76
- array_push($search, $imgHTML);
77
- array_push($replace, $replaceHTML);
78
- }
79
-
80
- $content = str_replace($search, $replace, $content);
81
-
82
- return $content;
83
- }
84
-
85
- public function filter_post_thumbnail_html( $html ) {
86
-
87
- $html = $this->_get_placeholder_html($html);
88
-
89
- return $html;
90
-
91
- }
92
-
93
- protected function _get_placeholder_html ($html) {
94
-
95
- $orig_html = $html;
96
-
97
- // replace the src and add the data-href attribute
98
- $html = preg_replace( '/<img(.*?)src=/i', '<img$1src="'.$this->_placeholder_url.'" data-href=', $html );
99
-
100
- // add the lazy class to the img element
101
- if (preg_match('/class="/i', $html)) {
102
- $html = preg_replace('/class="(.*?)"/i', ' class="lazy $1"', $html);
103
- } else {
104
- $html = preg_replace('/<img/i', '<img class="lazy"', $html);
105
- }
106
-
107
- $html .= '<noscript>' . $orig_html . '</noscript>';
108
-
109
- return $html;
110
- }
111
-
112
- }
113
-
114
- class BJLL_Admin {
115
-
116
- function __construct () {
117
- add_action('admin_menu', array($this, 'plugin_menu'));
118
- add_action( 'admin_init', array($this, 'register_settings'));
119
- }
120
-
121
- function plugin_menu() {
122
- add_options_page('BJ Lazy Load', 'BJ Lazy Load', 'manage_options', 'bjll', array($this, 'plugin_options_page'));
123
- }
124
-
125
- function register_settings() {
126
- //register_setting( $option_group, $option_name, $sanitize_callback );
127
- register_setting( 'bjll_options', 'bjll_filter_post_thumbnails', 'intval' );
128
-
129
- //add_settings_section( $id, $title, $callback, $page );
130
- add_settings_section('bjll_general', __('General'), array('BJLL_Admin','settings_section_general'), 'bjll');
131
-
132
- //add_settings_field( $id, $title, $callback, $page, $section, $args );
133
- add_settings_field('bjll_filter_post_thumbnails', __('Lazy load post thumbnails'), array('BJLL_Admin', 'setting_field_filter_post_thumbnails'), 'bjll', 'bjll_general');
134
-
135
-
136
- }
137
-
138
- function settings_section_general() {
139
- }
140
-
141
- function setting_field_filter_post_thumbnails() {
142
-
143
- $checked = '';
144
- if (intval(get_option('bjll_filter_post_thumbnails', 1))) {
145
- $checked = ' checked="checked"';
146
- }
147
-
148
- echo '<input id="bjll_filter_post_thumbnails" name="bjll_filter_post_thumbnails" type="checkbox" value="1" ' . $checked . ' />';
149
-
150
- }
151
-
152
- function plugin_options_page() {
153
- if (!current_user_can('manage_options')) {
154
- wp_die( __('You do not have sufficient permissions to access this page.') );
155
- }
156
- ?>
157
- <div class="wrap">
158
- <h2>BJ Lazy Load <?php _e('Settings'); ?></h2>
159
- <p><?php _e('More settings will be available in the near future.'); ?></p>
160
- <form method="post" action="options.php">
161
- <?php settings_fields('bjll_options'); ?>
162
- <?php do_settings_sections('bjll'); ?>
163
-
164
- <p class="submit">
165
- <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
166
- </p>
167
- </form>
168
- </div>
169
- <?php
170
- }
171
-
172
- }
173
-
174
- /*
175
- is_admin() will return true when trying to make an ajax request
176
- if (!is_admin() && !is_feed()) {
177
- */
178
- if (!is_feed()) {
179
- new BJLL;
180
- }
181
-
182
- if (is_admin()) {
183
- new BJLL_Admin;
184
- }
185
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/bjll.js CHANGED
@@ -1,3 +1,11 @@
1
  (function($) {
2
- jQuery('img.lazy').jail();
 
 
 
 
 
 
 
 
3
  })(jQuery);
1
  (function($) {
2
+
3
+ BJLL.timeout = parseInt(BJLL.timeout);
4
+ BJLL.offset = parseInt(BJLL.offset);
5
+ BJLL.speed = parseInt(BJLL.speed);
6
+ BJLL.ignoreHiddenImages = parseInt(BJLL.ignoreHiddenImages);
7
+
8
+ if (!BJLL.effect.length) BJLL.effect = null;
9
+
10
+ $('img.lazy').jail(BJLL);
11
  })(jQuery);
js/bjll.min.js ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * JqueryAsynchImageLoader (JAIL) : plugin for jQuery
3
+ *
4
+ * Developed by
5
+ * Sebastiano Armeli-Battana (@sebarmeli) - http://www.sebastianoarmelibattana.com
6
+ * Dual licensed under the MIT or GPL Version 3 licenses.
7
+ * @version 0.9.7
8
+ */
9
+ ;(function(a){var b=a(window);a.fn.asynchImageLoader=a.fn.jail=function(d){d=a.extend({timeout:10,effect:false,speed:400,selector:null,offset:0,event:"load+scroll",callback:jQuery.noop,callbackAfterEachImage:jQuery.noop,placeholder:false,ignoreHiddenImages:false},d);var c=this;a.jail.initialStack=this;this.data("triggerEl",(d.selector)?a(d.selector):b);if(d.placeholder!==false){c.each(function(){a(this).attr("src",d.placeholder);});}if(/^load/.test(d.event)){a.asynchImageLoader.later.call(this,d);}else{a.asynchImageLoader.onEvent.call(this,d,c);}return this;};a.asynchImageLoader=a.jail={_purgeStack:function(c){var d=0;while(true){if(d===c.length){break;}else{if(c[d].getAttribute("data-href")){d++;}else{c.splice(d,1);}}}},_loadOnEvent:function(g){var f=a(this),d=g.data.options,c=g.data.images;a.asynchImageLoader._loadImageIfVisible(d,f);f.unbind(d.event,a.asynchImageLoader._loadOnEvent);a.asynchImageLoader._purgeStack(c);if(!!d.callback){a.asynchImageLoader._purgeStack(a.jail.initialStack);a.asynchImageLoader._launchCallback(a.jail.initialStack,d);}},_bufferedEventListener:function(g){var c=g.data.images,d=g.data.options,f=c.data("triggerEl");clearTimeout(c.data("poller"));c.data("poller",setTimeout(function(){c.each(function e(){a.asynchImageLoader._loadImageIfVisible(d,this,f);});a.asynchImageLoader._purgeStack(c);if(!!d.callback){a.asynchImageLoader._purgeStack(a.jail.initialStack);a.asynchImageLoader._launchCallback(a.jail.initialStack,d);}},d.timeout));},onEvent:function(d,c){c=c||this;if(d.event==="scroll"||d.selector){var e=c.data("triggerEl");if(c.length>0){e.bind(d.event,{images:c,options:d},a.asynchImageLoader._bufferedEventListener);if(d.event==="scroll"||!d.selector){b.resize({images:c,options:d},a.asynchImageLoader._bufferedEventListener);}return;}else{if(!!e){e.unbind(d.event,a.asynchImageLoader._bufferedEventListener);}}}else{c.bind(d.event,{options:d,images:c},a.asynchImageLoader._loadOnEvent);}},later:function(d){var c=this;if(d.event==="load"){c.each(function(){a.asynchImageLoader._loadImageIfVisible(d,this,c.data("triggerEl"));});}a.asynchImageLoader._purgeStack(c);a.asynchImageLoader._launchCallback(c,d);setTimeout(function(){if(d.event==="load"){c.each(function(){a.asynchImageLoader._loadImage(d,a(this));});}else{c.each(function(){a.asynchImageLoader._loadImageIfVisible(d,this,c.data("triggerEl"));});}a.asynchImageLoader._purgeStack(c);a.asynchImageLoader._launchCallback(c,d);if(d.event==="load+scroll"){d.event="scroll";a.asynchImageLoader.onEvent(d,c);}},d.timeout);},_launchCallback:function(c,d){if(c.length===0&&!a.jail.isCallback){d.callback.call(this,d);a.jail.isCallback=true;}},_loadImageIfVisible:function(e,h,g){var f=a(h),d=(/scroll/i.test(e.event))?g:b,c=true;if(e.ignoreHiddenImages){c=a.jail._isVisibleInOverflownContainer(f,e)&&f.is(":visible");}if(c&&a.asynchImageLoader._isInTheScreen(d,f,e.offset)){a.asynchImageLoader._loadImage(e,f);}},_isInTheScreen:function(j,c,h){var f=j[0]===window,n=(f?{top:0,left:0}:j.offset()),g=n.top+(f?j.scrollTop():0),i=n.left+(f?j.scrollLeft():0),e=i+j.width(),k=g+j.height(),m=c.offset(),l=c.width(),d=c.height();return(g-h)<=(m.top+d)&&(k+h)>=m.top&&(i-h)<=(m.left+l)&&(e+h)>=m.left;},_loadImage:function(c,d){d.hide();d.attr("src",d.attr("data-href"));d.removeAttr("data-href");if(c.effect){if(c.speed){d[c.effect](c.speed);}else{d[c.effect]();}}else{d.show();}c.callbackAfterEachImage.call(this,d,c);},_isVisibleInOverflownContainer:function(e,d){var f=e.parent(),c=true;while(f.get(0).tagName!=="BODY"){if(f.css("overflow")==="hidden"){if(!a.jail._isInTheScreen(f,e,d.offset)){c=false;break;}}if(f.css("visibility")==="hidden"||e.css("visibility")==="hidden"){c=false;break;}f=f.parent();}return c;}};}(jQuery));
10
+ /* bjll.js by Bjørn Johansen (@bjornjohansen) */
11
+ (function($){BJLL.timeout=parseInt(BJLL.timeout);BJLL.offset=parseInt(BJLL.offset);BJLL.speed=parseInt(BJLL.speed);BJLL.ignoreHiddenImages=parseInt(BJLL.ignoreHiddenImages);if(!BJLL.effect.length)BJLL.effect=null;$('img.lazy').jail(BJLL)})(jQuery);
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.2
7
  Tested up to: 3.3
8
- Stable tag: 0.2
9
 
10
  Lazy image loading makes your site load faster and saves bandwidth. Uses jQuery and degrades gracefully for non-js users.
11
 
@@ -19,7 +19,6 @@ Non-javascript visitors gets the original img element in noscript.
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
- * More options like defining a threshold, loading effects, custom placeholder etc.
23
  * Serving size optimized images for responsive layouts/adaptive designs
24
  * (Got more ideas? Tell me!)
25
 
@@ -33,17 +32,25 @@ Includes [JqueryAsynchImageLoader Plugin for jQuery by Sebastiano Armeli-Battana
33
  = Whoa, this plugin is using Javascript. What about visitors without JS? =
34
  No worries. They get the original image in a noscript element.
35
 
 
 
 
36
  = I'm using a CDN. Will this plugin interfere? =
37
- Nope. The image will load from your CDN.
38
 
39
  = The plugin doesn't work/doesn't replace my images =
40
- Your HTML should be standards compliant.
41
 
42
  = How can I verify that the plugin is working? =
43
  Check your HTML source or see the magic at work in FireBug or similar.
44
 
45
  == Changelog ==
46
 
 
 
 
 
 
47
  = Version 0.2 =
48
  * Added options panel in admin
49
  * Added option to lazy load post thumbnails
@@ -51,4 +58,15 @@ Check your HTML source or see the magic at work in FireBug or similar.
51
 
52
  = Version 0.1 =
53
  * Released 2011-12-05
54
- * It works (or at least it does for me)
 
 
 
 
 
 
 
 
 
 
 
5
  Author URI: http://twitter.com/bjornjohansen
6
  Requires at least: 3.2
7
  Tested up to: 3.3
8
+ Stable tag: 0.2.1
9
 
10
  Lazy image loading makes your site load faster and saves bandwidth. Uses jQuery and degrades gracefully for non-js users.
11
 
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 layouts/adaptive designs
23
  * (Got more ideas? Tell me!)
24
 
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.1 =
50
+ * Added options: Timeout, effect, speed, event, offset, ignoreHiddenImages
51
+ * Combining the two JS files for faster loading
52
+ * Renamed the plugin file from bj-lazyload.php to bj-lazy-load.php to better fit with the plugin name
53
+
54
  = Version 0.2 =
55
  * Added options panel in admin
56
  * Added option to lazy load post thumbnails
58
 
59
  = Version 0.1 =
60
  * Released 2011-12-05
61
+ * It works (or at least it does for me)
62
+
63
+ == Upgrade Notice ==
64
+
65
+ = 0.2.1 =
66
+ More options and faster loading.
67
+
68
+ = 0.2 =
69
+ Lazy load post thumbnails too and stays out of your feeds.
70
+
71
+
72
+