BJ Lazy Load - Version 0.2.4

Version Description

Better localization

Download this release

Release Info

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

Code changes from version 0.2.3 to 0.2.4

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.2.3
7
  Author: Bjørn Johansen
8
  Author URI: http://twitter.com/bjornjohansen
9
  License: GPL2
@@ -28,43 +28,43 @@ License: GPL2
28
 
29
  class BJLL {
30
 
31
- const version = '0.2.3';
32
  private $_placeholder_url;
33
 
34
  function __construct() {
35
 
36
- $this->_placeholder_url = plugins_url('/img/placeholder.gif', __FILE__);
37
 
38
- if (get_option('bjll_include_css', 1)) {
39
- add_action('wp_print_styles', array($this, 'enqueue_styles'));
40
  }
41
 
42
- if (get_option('bjll_include_js', 1)) {
43
- add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
44
  }
45
 
46
- add_action('wp_print_footer_scripts', array($this, 'output_js_options'));
47
 
48
- add_action( 'wp_ajax_BJLL_get_images', array($this, 'get_images_json') );
49
- add_action( 'wp_ajax_nopriv_BJLL_get_images', array($this, 'get_images_json') );
50
 
51
- add_filter('the_content', array($this, 'filter_post_images'), 200);
52
 
53
- if (intval(get_option('bjll_filter_post_thumbnails', 1))) {
54
- add_filter( 'post_thumbnail_html', array($this, 'filter_post_thumbnail_html'), 10 );
55
  }
56
  }
57
 
58
  public function enqueue_styles() {
59
- wp_enqueue_style( 'BJLL', plugins_url('/css/bjll.css', __FILE__), array(), self::version);
60
  }
61
 
62
  public function enqueue_scripts() {
63
 
64
- //wp_enqueue_script('JAIL', plugins_url('/js/jail.min.js', __FILE__), array('jquery'), '0.9.7', true);
65
- //wp_enqueue_script( 'BJLL', plugins_url('/js/bjll.js', __FILE__), array( 'jquery', 'JAIL' ), self::version, true );
66
 
67
- wp_enqueue_script( 'BJLL', plugins_url('/js/bjll.min.js', __FILE__), array( 'jquery' ), self::version, true );
68
 
69
  }
70
 
@@ -87,14 +87,14 @@ class BJLL {
87
  /* <![CDATA[ */
88
  var BJLL = {
89
  options: {
90
- timeout: <?php echo intval(get_option('bjll_timeout', 10)); ?>,
91
- effect: <?php echo (strlen($val = get_option('bjll_effect', '')) ? '"'.$val.'"' : 'null'); ?>,
92
- speed: <?php echo intval(get_option('bjll_speed', 400)); ?>,
93
- event: "<?php echo get_option('bjll_event', 'load+scroll'); ?>",
94
- callback: "<?php echo get_option('bjll_callback', ''); ?>",
95
- placeholder: "<?php echo get_option('bjll_placeholder', ''); ?>",
96
- offset: <?php echo intval(get_option('bjll_offset', '')); ?>,
97
- ignoreHiddenImages: <?php echo intval(get_option('bjll_ignoreHiddenImages', 0)); ?>
98
 
99
  },
100
  ajaxurl: "<?php echo admin_url( 'admin-ajax.php' ); ?>"
@@ -105,99 +105,99 @@ var BJLL = {
105
  }
106
 
107
  public function get_images_json() {
108
- echo json_encode($_POST['attachmentIDs']);
109
  exit;
110
  }
111
 
112
- public function filter_post_images($content) {
113
 
114
  $matches = array();
115
- preg_match_all('/<img\s+.*?>/', $content, $matches);
116
 
117
  $search = array();
118
  $replace = array();
119
 
120
- foreach ($matches[0] as $imgHTML) {
121
 
122
- $replaceHTML = $this->_get_placeholder_html($imgHTML);
123
 
124
- array_push($search, $imgHTML);
125
- array_push($replace, $replaceHTML);
126
  }
127
 
128
- $content = str_replace($search, $replace, $content);
129
 
130
  return $content;
131
  }
132
 
133
  public function filter_post_thumbnail_html( $html ) {
134
 
135
- $html = $this->_get_placeholder_html($html);
136
 
137
  return $html;
138
 
139
  }
140
 
141
- protected function _get_placeholder_html ($html) {
142
 
143
- if (class_exists('DOMDocument')) {
144
- $html = $this->_get_placeholder_html_dom($html);
145
  } else {
146
- $html = $this->_get_placeholder_html_regexp($html);
147
  }
148
 
149
  return $html;
150
  }
151
 
152
- protected function _get_placeholder_html_dom ($html) {
153
 
154
- $doc = DOMDocument::loadHTML($html);
155
- if (!$doc) {
156
- return $this->_get_placeholder_html_regexp($html);
157
  }
158
 
159
- $images = $doc->getElementsByTagName('img');
160
 
161
- $img = $images->item(0);
162
 
163
- //foreach ($images as $img) {
164
 
165
- $noscriptImg = $img->cloneNode(true);
166
- $noscript = $doc->createElement('noscript');
167
- $noscript->appendChild($noscriptImg);
168
 
169
- $src = $img->getAttribute('src');
170
- $class = $img->getAttribute('class');
171
 
172
  $class .= ' lazy lazy-hidden';
173
 
174
  $img->setAttribute( 'data-href' , $src );
175
  $img->setAttribute( 'src' , $this->_placeholder_url );
176
- $img->setAttribute( 'class' , trim($class) );
177
 
178
- $img->parentNode->appendChild($noscript);
179
 
180
  //}
181
 
182
  $rethtml = $doc->saveHTML();
183
 
184
- $rethtml = substr($rethtml, strpos($rethtml, '<body>') + 6);
185
- $rethtml = substr($rethtml, 0, strpos($rethtml, '</body>'));
186
 
187
  return $rethtml;
188
  }
189
- protected function _get_placeholder_html_regexp ($html) {
190
  $orig_html = $html;
191
 
192
  /**/
193
  // replace the src and add the data-href attribute
194
- $html = preg_replace( '/<img(.*?)src=/i', '<img$1src="'.$this->_placeholder_url.'" data-href=', $html );
195
 
196
  // add the lazy class to the img element
197
- if (preg_match('/class="/i', $html)) {
198
- $html = preg_replace('/class="(.*?)"/i', ' class="lazy lazy-hidden $1"', $html);
199
  } else {
200
- $html = preg_replace('/<img/i', '<img class="lazy lazy-hidden"', $html);
201
  }
202
 
203
  $html .= '<noscript>' . $orig_html . '</noscript>';
@@ -216,52 +216,57 @@ var BJLL = {
216
  class BJLL_Admin {
217
 
218
  function __construct () {
219
- add_action('admin_menu', array($this, 'plugin_menu'));
220
- add_action('admin_init', array($this, 'register_settings'));
 
 
 
 
 
221
  }
222
 
223
- function plugin_menu() {
224
- add_options_page('BJ Lazy Load', 'BJ Lazy Load', 'manage_options', 'bjll', array($this, 'plugin_options_page'));
225
  }
226
 
227
- function register_settings() {
228
  register_setting( 'bjll_options', 'bjll_filter_post_thumbnails', 'intval' );
229
  register_setting( 'bjll_options', 'bjll_include_js', 'intval' );
230
  register_setting( 'bjll_options', 'bjll_include_css', 'intval' );
231
 
232
- add_settings_section('bjll_general', __('General'), array('BJLL_Admin','settings_section_general'), 'bjll');
233
 
234
- 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'));
235
- add_settings_field('bjll_include_js', __('Include JS'), array('BJLL_Admin', 'setting_field_include_js'), 'bjll', 'bjll_general', array('label_for' => 'bjll_include_js'));
236
- add_settings_field('bjll_include_css', __('Include CSS'), array('BJLL_Admin', 'setting_field_include_css'), 'bjll', 'bjll_general', array('label_for' => 'bjll_include_css'));
237
 
238
  register_setting( 'bjll_options', 'bjll_timeout', 'intval' );
239
  register_setting( 'bjll_options', 'bjll_effect' );
240
  register_setting( 'bjll_options', 'bjll_speed', 'intval' );
241
- register_setting( 'bjll_options', 'bjll_event', array('BJLL_Admin', 'sanitize_setting_event') );
242
  register_setting( 'bjll_options', 'bjll_callback' );
243
  register_setting( 'bjll_options', 'bjll_callbackAfterEachImage' );
244
  register_setting( 'bjll_options', 'bjll_placeholder' );
245
  register_setting( 'bjll_options', 'bjll_offset', 'intval' );
246
  register_setting( 'bjll_options', 'bjll_ignoreHiddenImages', 'intval' );
247
 
248
- add_settings_section('bjll_loader', __('Loader'), array('BJLL_Admin','settings_section_loader'), 'bjll');
249
 
250
- add_settings_field('bjll_timeout', __('Timeout'), array('BJLL_Admin', 'setting_field_timeout'), 'bjll', 'bjll_loader', array('label_for' => 'bjll_timeout'));
251
- add_settings_field('bjll_effect', __('jQuery Effect'), array('BJLL_Admin', 'setting_field_effect'), 'bjll', 'bjll_loader', array('label_for' => 'bjll_effect'));
252
- add_settings_field('bjll_speed', __('Effect Speed'), array('BJLL_Admin', 'setting_field_speed'), 'bjll', 'bjll_loader', array('label_for' => 'bjll_speed'));
253
- add_settings_field('bjll_event', __('Trigger Event'), array('BJLL_Admin', 'setting_field_event'), 'bjll', 'bjll_loader', array('label_for' => 'bjll_event'));
254
- add_settings_field('bjll_offset', __('Offset/Threshold'), array('BJLL_Admin', 'setting_field_offset'), 'bjll', 'bjll_loader', array('label_for' => 'bjll_offset'));
255
- add_settings_field('bjll_ignoreHiddenImages', __('Ignore Hidden Images'), array('BJLL_Admin', 'setting_field_ignoreHiddenImages'), 'bjll', 'bjll_loader', array('label_for' => 'bjll_ignoreHiddenImages'));
256
 
257
  }
258
 
259
- function sanitize_setting_event ($val) {
260
  $validoptions = self::_get_valid_setting_options_event();
261
- if (!in_array($val, $validoptions)) {
262
  // get previous saved value
263
- $val = get_option('bjll_event', 'load+scroll');
264
- if (!in_array($val, $validoptions)) {
265
  // if still not valid, set to our default
266
  $val = $validoptions[0];
267
  }
@@ -269,107 +274,120 @@ class BJLL_Admin {
269
  return $val;
270
  }
271
 
272
- function sanitize_setting_effect ($val) {
273
- if (!strlen($val)) {
274
  $val = null;
275
  }
276
  return $val;
277
  }
278
 
279
- private static function _get_valid_setting_options_event() {
280
- return array('load+scroll', 'load', 'click', 'mouseover', 'scroll');
281
  }
282
 
283
 
284
- function settings_section_general() {
285
  }
286
 
287
- function settings_section_loader() {
288
  }
289
 
290
- function setting_field_filter_post_thumbnails() {
291
  $checked = '';
292
- if (intval(get_option('bjll_filter_post_thumbnails', 1))) {
293
  $checked = ' checked="checked"';
294
  }
295
 
296
  echo '<input id="bjll_filter_post_thumbnails" name="bjll_filter_post_thumbnails" type="checkbox" value="1" ' . $checked . ' />';
297
  }
298
- function setting_field_include_js() {
 
299
  $checked = '';
300
- if (intval(get_option('bjll_include_js', 1))) {
301
  $checked = ' checked="checked"';
302
  }
303
 
304
- echo '<input id="bjll_include_js" name="bjll_include_js" type="checkbox" value="1" ' . $checked . ' /> Needed for the plugin to work, but <a href="http://developer.yahoo.com/performance/rules.html#num_http" target="_blank">for best performance you should include it in your combined JS</a>';
 
305
  }
306
- function setting_field_include_css() {
 
307
  $checked = '';
308
- if (intval(get_option('bjll_include_css', 1))) {
309
  $checked = ' checked="checked"';
310
  }
311
 
312
- echo '<input id="bjll_include_css" name="bjll_include_css" type="checkbox" value="1" ' . $checked . ' /> Needed for the plugin to work, but <a href="http://developer.yahoo.com/performance/rules.html#num_http" target="_blank">for best performance you should include it in your combined CSS</a>';
 
313
  }
314
- function setting_field_ignoreHiddenImages() {
315
 
316
  $checked = '';
317
- if (intval(get_option('bjll_ignoreHiddenImages', 0))) {
318
  $checked = ' checked="checked"';
319
  }
320
 
321
- 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)';
 
322
 
323
  }
324
- function setting_field_event() {
325
 
326
  $options = self::_get_valid_setting_options_event();
327
 
328
- $currentval = get_option('bjll_event');
329
 
330
  echo '<select id="bjll_event" name="bjll_event" type="checkbox">';
331
- foreach ($options as $option) {
332
  $selected = '';
333
- if ($option == $currentval) {
334
  $selected = ' selected="selected"';
335
  }
336
- echo sprintf('<option value="%1$s"%2$s>%1$s</option>', $option, $selected);
337
  }
338
- echo '</select> event that triggers the image to load. Default: load+scroll';
 
339
  }
340
- function setting_field_timeout() {
341
- $val = get_option('bjll_timeout', 10);
342
- echo '<input id="bjll_timeout" name="bjll_timeout" type="text" value="' . $val . '" /> number of msec after that the images will be loaded - Default: 10';
 
343
  }
344
- function setting_field_effect() {
345
- $val = get_option('bjll_effect', '');
346
- if (strtolower($val) == 'null') {
347
  $val = '';
348
  }
349
- 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>';
 
 
 
 
350
  }
351
- function setting_field_speed() {
352
- $val = get_option('bjll_speed', 400);
353
- echo '<input id="bjll_speed" name="bjll_speed" type="text" value="' . $val . '" /> string or number determining how long the animation will run - Default: 400';
 
354
  }
355
- function setting_field_offset() {
356
- $val = get_option('bjll_offset', 200);
357
- 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';
 
358
  }
359
 
360
- function plugin_options_page() {
361
- if (!current_user_can('manage_options')) {
362
- wp_die( __('You do not have sufficient permissions to access this page.') );
363
  }
364
  ?>
365
  <div class="wrap">
366
- <h2>BJ Lazy Load <?php _e('Settings'); ?></h2>
367
  <form method="post" action="options.php">
368
- <?php settings_fields('bjll_options'); ?>
369
- <?php do_settings_sections('bjll'); ?>
370
 
371
  <p class="submit">
372
- <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
373
  </p>
374
  </form>
375
  </div>
@@ -382,11 +400,11 @@ class BJLL_Admin {
382
  is_admin() will return true when trying to make an ajax request
383
  if (!is_admin() && !is_feed()) {
384
  */
385
- if (!is_feed()) {
386
  new BJLL;
387
  }
388
 
389
- if (is_admin()) {
390
  new BJLL_Admin;
391
  }
392
 
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.4
7
  Author: Bjørn Johansen
8
  Author URI: http://twitter.com/bjornjohansen
9
  License: GPL2
28
 
29
  class BJLL {
30
 
31
+ const version = '0.2.4';
32
  private $_placeholder_url;
33
 
34
  function __construct() {
35
 
36
+ $this->_placeholder_url = plugins_url( '/img/placeholder.gif', __FILE__ );
37
 
38
+ if (get_option( 'bjll_include_css', 1 )) {
39
+ add_action( 'wp_print_styles', array($this, 'enqueue_styles' ) );
40
  }
41
 
42
+ if (get_option( 'bjll_include_js', 1 )) {
43
+ add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
44
  }
45
 
46
+ add_action( 'wp_print_footer_scripts', array( $this, 'output_js_options' ) );
47
 
48
+ add_action( 'wp_ajax_BJLL_get_images', array( $this, 'get_images_json' ) );
49
+ add_action( 'wp_ajax_nopriv_BJLL_get_images', array( $this, 'get_images_json') );
50
 
51
+ add_filter( 'the_content', array( $this, 'filter_post_images' ), 200 );
52
 
53
+ if ( intval( get_option( 'bjll_filter_post_thumbnails', 1 ) ) ) {
54
+ add_filter( 'post_thumbnail_html', array( $this, 'filter_post_thumbnail_html' ), 10 );
55
  }
56
  }
57
 
58
  public function enqueue_styles() {
59
+ wp_enqueue_style( 'BJLL', plugins_url( '/css/bjll.css', __FILE__ ), array(), self::version );
60
  }
61
 
62
  public function enqueue_scripts() {
63
 
64
+ //wp_enqueue_script( 'JAIL', plugins_url( '/js/jail.min.js', __FILE__ ), array( 'jquery'), '0.9.7', true );
65
+ //wp_enqueue_script( 'BJLL', plugins_url( '/js/bjll.js', __FILE__ ), array( 'jquery', 'JAIL' ), self::version, true );
66
 
67
+ wp_enqueue_script( 'BJLL', plugins_url( '/js/bjll.min.js', __FILE__ ), array( 'jquery' ), self::version, true );
68
 
69
  }
70
 
87
  /* <![CDATA[ */
88
  var BJLL = {
89
  options: {
90
+ timeout: <?php echo intval( get_option( 'bjll_timeout', 10 ) ); ?>,
91
+ effect: <?php echo ( strlen($val = get_option('bjll_effect', '')) ? '"' . $val . '"' : 'null' ); ?>,
92
+ speed: <?php echo intval( get_option( 'bjll_speed', 400 ) ); ?>,
93
+ event: "<?php echo get_option( 'bjll_event', 'load+scroll' ); ?>",
94
+ callback: "<?php echo get_option( 'bjll_callback', '' ); ?>",
95
+ placeholder: "<?php echo get_option( 'bjll_placeholder', '' ); ?>",
96
+ offset: <?php echo intval( get_option( 'bjll_offset', '' ) ); ?>,
97
+ ignoreHiddenImages: <?php echo intval( get_option( 'bjll_ignoreHiddenImages', 0 ) ); ?>
98
 
99
  },
100
  ajaxurl: "<?php echo admin_url( 'admin-ajax.php' ); ?>"
105
  }
106
 
107
  public function get_images_json() {
108
+ echo json_encode( $_POST['attachmentIDs'] );
109
  exit;
110
  }
111
 
112
+ public function filter_post_images( $content ) {
113
 
114
  $matches = array();
115
+ preg_match_all( '/<img\s+.*?>/', $content, $matches );
116
 
117
  $search = array();
118
  $replace = array();
119
 
120
+ foreach ( $matches[0] as $imgHTML ) {
121
 
122
+ $replaceHTML = $this->_get_placeholder_html( $imgHTML );
123
 
124
+ array_push( $search, $imgHTML );
125
+ array_push( $replace, $replaceHTML );
126
  }
127
 
128
+ $content = str_replace( $search, $replace, $content );
129
 
130
  return $content;
131
  }
132
 
133
  public function filter_post_thumbnail_html( $html ) {
134
 
135
+ $html = $this->_get_placeholder_html( $html );
136
 
137
  return $html;
138
 
139
  }
140
 
141
+ protected function _get_placeholder_html ( $html ) {
142
 
143
+ if ( class_exists( 'DOMDocument') ) {
144
+ $html = $this->_get_placeholder_html_dom( $html );
145
  } else {
146
+ $html = $this->_get_placeholder_html_regexp( $html );
147
  }
148
 
149
  return $html;
150
  }
151
 
152
+ protected function _get_placeholder_html_dom ( $html ) {
153
 
154
+ $doc = DOMDocument::loadHTML( $html );
155
+ if ( ! $doc ) {
156
+ return $this->_get_placeholder_html_regexp( $html );
157
  }
158
 
159
+ $images = $doc->getElementsByTagName( 'img' );
160
 
161
+ $img = $images->item( 0 );
162
 
163
+ //foreach ( $images as $img ) {
164
 
165
+ $noscriptImg = $img->cloneNode( true );
166
+ $noscript = $doc->createElement( 'noscript' );
167
+ $noscript->appendChild( $noscriptImg );
168
 
169
+ $src = $img->getAttribute( 'src' );
170
+ $class = $img->getAttribute( 'class' );
171
 
172
  $class .= ' lazy lazy-hidden';
173
 
174
  $img->setAttribute( 'data-href' , $src );
175
  $img->setAttribute( 'src' , $this->_placeholder_url );
176
+ $img->setAttribute( 'class' , trim( $class ) );
177
 
178
+ $img->parentNode->appendChild( $noscript );
179
 
180
  //}
181
 
182
  $rethtml = $doc->saveHTML();
183
 
184
+ $rethtml = substr( $rethtml, strpos( $rethtml, '<body>' ) + 6 );
185
+ $rethtml = substr( $rethtml, 0, strpos( $rethtml, '</body>' ) );
186
 
187
  return $rethtml;
188
  }
189
+ protected function _get_placeholder_html_regexp ( $html ) {
190
  $orig_html = $html;
191
 
192
  /**/
193
  // replace the src and add the data-href attribute
194
+ $html = preg_replace( '/<img(.*?)src=/i', '<img$1src="' . $this->_placeholder_url . '" data-href=', $html );
195
 
196
  // add the lazy class to the img element
197
+ if ( preg_match( '/class="/i', $html ) ) {
198
+ $html = preg_replace( '/class="(.*?)"/i', ' class="lazy lazy-hidden $1"', $html );
199
  } else {
200
+ $html = preg_replace( '/<img/i', '<img class="lazy lazy-hidden"', $html );
201
  }
202
 
203
  $html .= '<noscript>' . $orig_html . '</noscript>';
216
  class BJLL_Admin {
217
 
218
  function __construct () {
219
+ add_action( 'init', array( $this, 'load_i18n' ) );
220
+ add_action( 'admin_menu', array( $this, 'plugin_menu' ) );
221
+ add_action( 'admin_init', array( $this, 'register_settings' ) );
222
+ }
223
+
224
+ function load_i18n() {;
225
+ load_plugin_textdomain( 'bj-lazy-load', false, basename( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'lang' );
226
  }
227
 
228
+ function plugin_menu () {
229
+ add_options_page( 'BJ Lazy Load', 'BJ Lazy Load', 'manage_options', 'bjll', array( $this, 'plugin_options_page' ) );
230
  }
231
 
232
+ function register_settings () {
233
  register_setting( 'bjll_options', 'bjll_filter_post_thumbnails', 'intval' );
234
  register_setting( 'bjll_options', 'bjll_include_js', 'intval' );
235
  register_setting( 'bjll_options', 'bjll_include_css', 'intval' );
236
 
237
+ add_settings_section( 'bjll_general', __('General'), array( 'BJLL_Admin', 'settings_section_general' ), 'bjll' );
238
 
239
+ add_settings_field( 'bjll_filter_post_thumbnails', __( 'Lazy load post thumbnails', 'bj-lazy-load' ), array( 'BJLL_Admin', 'setting_field_filter_post_thumbnails' ), 'bjll', 'bjll_general', array( 'label_for' => 'bjll_filter_post_thumbnails' ) );
240
+ add_settings_field( 'bjll_include_js', __( 'Include JS', 'bj-lazy-load' ), array( 'BJLL_Admin', 'setting_field_include_js'), 'bjll', 'bjll_general', array( 'label_for' => 'bjll_include_js' ) );
241
+ add_settings_field( 'bjll_include_css', __( 'Include CSS', 'bj-lazy-load' ), array( 'BJLL_Admin', 'setting_field_include_css'), 'bjll', 'bjll_general', array( 'label_for' => 'bjll_include_css' ) );
242
 
243
  register_setting( 'bjll_options', 'bjll_timeout', 'intval' );
244
  register_setting( 'bjll_options', 'bjll_effect' );
245
  register_setting( 'bjll_options', 'bjll_speed', 'intval' );
246
+ register_setting( 'bjll_options', 'bjll_event', array( 'BJLL_Admin', 'sanitize_setting_event' ) );
247
  register_setting( 'bjll_options', 'bjll_callback' );
248
  register_setting( 'bjll_options', 'bjll_callbackAfterEachImage' );
249
  register_setting( 'bjll_options', 'bjll_placeholder' );
250
  register_setting( 'bjll_options', 'bjll_offset', 'intval' );
251
  register_setting( 'bjll_options', 'bjll_ignoreHiddenImages', 'intval' );
252
 
253
+ add_settings_section( 'bjll_loader', __( 'JAIL Settings', 'bj-lazy-load' ), array( 'BJLL_Admin','settings_section_loader' ), 'bjll' );
254
 
255
+ add_settings_field( 'bjll_timeout', __( 'Timeout', 'bj-lazy-load' ), array( 'BJLL_Admin', 'setting_field_timeout' ), 'bjll', 'bjll_loader', array( 'label_for' => 'bjll_timeout' ) );
256
+ add_settings_field( 'bjll_effect', __( 'jQuery Effect', 'bj-lazy-load' ), array('BJLL_Admin', 'setting_field_effect' ), 'bjll', 'bjll_loader', array( 'label_for' => 'bjll_effect' ) );
257
+ add_settings_field( 'bjll_speed', __( 'Effect Speed', 'bj-lazy-load' ), array('BJLL_Admin', 'setting_field_speed' ), 'bjll', 'bjll_loader', array( 'label_for' => 'bjll_speed' ) );
258
+ add_settings_field( 'bjll_event', __( 'Trigger Event', 'bj-lazy-load' ), array('BJLL_Admin', 'setting_field_event' ), 'bjll', 'bjll_loader', array( 'label_for' => 'bjll_event' ) );
259
+ add_settings_field( 'bjll_offset', __( 'Offset/Threshold', 'bj-lazy-load' ), array('BJLL_Admin', 'setting_field_offset' ), 'bjll', 'bjll_loader', array( 'label_for' => 'bjll_offset' ) );
260
+ add_settings_field( 'bjll_ignoreHiddenImages', __( 'Ignore Hidden Images', 'bj-lazy-load' ), array( 'BJLL_Admin', 'setting_field_ignoreHiddenImages' ), 'bjll', 'bjll_loader', array( 'label_for' => 'bjll_ignoreHiddenImages' ) );
261
 
262
  }
263
 
264
+ function sanitize_setting_event ( $val ) {
265
  $validoptions = self::_get_valid_setting_options_event();
266
+ if ( ! in_array( $val, $validoptions ) ) {
267
  // get previous saved value
268
+ $val = get_option( 'bjll_event', 'load+scroll' );
269
+ if ( ! in_array( $val, $validoptions ) ) {
270
  // if still not valid, set to our default
271
  $val = $validoptions[0];
272
  }
274
  return $val;
275
  }
276
 
277
+ function sanitize_setting_effect ( $val ) {
278
+ if ( ! strlen( $val ) ) {
279
  $val = null;
280
  }
281
  return $val;
282
  }
283
 
284
+ private static function _get_valid_setting_options_event () {
285
+ return array( 'load+scroll', 'load', 'click', 'mouseover', 'scroll' );
286
  }
287
 
288
 
289
+ function settings_section_general () {
290
  }
291
 
292
+ function settings_section_loader () {
293
  }
294
 
295
+ function setting_field_filter_post_thumbnails () {
296
  $checked = '';
297
+ if ( intval( get_option( 'bjll_filter_post_thumbnails', 1 ) ) ) {
298
  $checked = ' checked="checked"';
299
  }
300
 
301
  echo '<input id="bjll_filter_post_thumbnails" name="bjll_filter_post_thumbnails" type="checkbox" value="1" ' . $checked . ' />';
302
  }
303
+
304
+ function setting_field_include_js () {
305
  $checked = '';
306
+ if ( intval( get_option( 'bjll_include_js', 1 ) ) ) {
307
  $checked = ' checked="checked"';
308
  }
309
 
310
+ echo '<input id="bjll_include_js" name="bjll_include_js" type="checkbox" value="1" ' . $checked . ' /> ';
311
+ _e( 'Needed for the plugin to work, but <a href="http://developer.yahoo.com/performance/rules.html#num_http" target="_blank">for best performance you should include it in your combined JS</a>', 'bj-lazy-load' );
312
  }
313
+
314
+ function setting_field_include_css () {
315
  $checked = '';
316
+ if ( intval( get_option( 'bjll_include_css', 1 ) ) ) {
317
  $checked = ' checked="checked"';
318
  }
319
 
320
+ echo '<input id="bjll_include_css" name="bjll_include_css" type="checkbox" value="1" ' . $checked . ' /> ';
321
+ _e( 'Needed for the plugin to work, but <a href="http://developer.yahoo.com/performance/rules.html#num_http" target="_blank">for best performance you should include it in your combined CSS</a>' , 'bj-lazy-load');
322
  }
323
+ function setting_field_ignoreHiddenImages () {
324
 
325
  $checked = '';
326
+ if ( intval( get_option( 'bjll_ignoreHiddenImages', 0 ) ) ) {
327
  $checked = ' checked="checked"';
328
  }
329
 
330
+ echo '<input id="bjll_ignoreHiddenImages" name="bjll_ignoreHiddenImages" type="checkbox" value="1" ' . $checked . ' /> ';
331
+ _e( 'Whether to ignore hidden images to be loaded - Default: false/unchecked (so hidden images are loaded)', 'bj-lazy-load' );
332
 
333
  }
334
+ function setting_field_event () {
335
 
336
  $options = self::_get_valid_setting_options_event();
337
 
338
+ $currentval = get_option( 'bjll_event' );
339
 
340
  echo '<select id="bjll_event" name="bjll_event" type="checkbox">';
341
+ foreach ( $options as $option ) {
342
  $selected = '';
343
+ if ( $option == $currentval ) {
344
  $selected = ' selected="selected"';
345
  }
346
+ echo sprintf( '<option value="%1$s"%2$s>%1$s</option>', $option, $selected );
347
  }
348
+ echo '</select> ';
349
+ _e( 'Event that triggers the image to load. Default: load+scroll', 'bj-lazy-load' );
350
  }
351
+ function setting_field_timeout () {
352
+ $val = get_option( 'bjll_timeout', 10 );
353
+ echo '<input id="bjll_timeout" name="bjll_timeout" type="text" value="' . $val . '" /> ';
354
+ _e( 'Number of msec after that the images will be loaded - Default: 10', 'bj-lazy-load' );
355
  }
356
+ function setting_field_effect () {
357
+ $val = get_option( 'bjll_effect', '' );
358
+ if ( 'null' == strtolower( $val ) ) {
359
  $val = '';
360
  }
361
+ echo '<input id="bjll_effect" name="bjll_effect" type="text" value="' . $val . '" />';
362
+ _e( 'Any jQuery effect that makes the images display (e.g. "fadeIn") - Default: NULL', 'bj-lazy-load');
363
+ echo '<p>';
364
+ _e( '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.', 'bj-lazy-load' );
365
+ echo '</p>';
366
  }
367
+ function setting_field_speed () {
368
+ $val = get_option( 'bjll_speed', 400 );
369
+ echo '<input id="bjll_speed" name="bjll_speed" type="text" value="' . $val . '" /> ';
370
+ _e( 'string or number determining how long the animation will run - Default: 400', 'bj-lazy-load' );
371
  }
372
+ function setting_field_offset () {
373
+ $val = get_option( 'bjll_offset', 200 );
374
+ echo '<input id="bjll_offset" name="bjll_offset" type="text" value="' . $val . '" /> ';
375
+ _e( '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', 'bj-lazy-load' );
376
  }
377
 
378
+ function plugin_options_page () {
379
+ if ( ! current_user_can( 'manage_options' ) ) {
380
+ wp_die( __( 'You do not have sufficient permissions to access this page.', 'bj-lazy-load' ) );
381
  }
382
  ?>
383
  <div class="wrap">
384
+ <h2>BJ Lazy Load <?php _e( 'Settings' ); ?></h2>
385
  <form method="post" action="options.php">
386
+ <?php settings_fields( 'bjll_options' ); ?>
387
+ <?php do_settings_sections( 'bjll' ); ?>
388
 
389
  <p class="submit">
390
+ <input type="submit" class="button-primary" value="<?php _e( 'Save Changes' ) ?>" />
391
  </p>
392
  </form>
393
  </div>
400
  is_admin() will return true when trying to make an ajax request
401
  if (!is_admin() && !is_feed()) {
402
  */
403
+ if ( ! is_feed() ) {
404
  new BJLL;
405
  }
406
 
407
+ if ( is_admin() ) {
408
  new BJLL_Admin;
409
  }
410
 
lang/bj-lazy-load-nb_NO.mo ADDED
Binary file
lang/bj-lazy-load-nb_NO.po ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2010 BJ Lazy Load
2
+ # This file is distributed under the same license as the BJ Lazy Load package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: BJ Lazy Load 0.2.4\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/bj-lazy-load\n"
7
+ "POT-Creation-Date: 2011-12-14 20:06:30+00:00\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2011-12-14 21:39+0100\n"
12
+ "Last-Translator: Bjørn Johansen <bjorn@gandalf.no>\n"
13
+ "Language-Team: <post@bjornjohansen.no>\n"
14
+ "X-Poedit-Language: Norwegian Bokmal\n"
15
+ "X-Poedit-Country: NORWAY\n"
16
+
17
+ #: bj-lazy-load.php:234
18
+ msgid "Lazy load post thumbnails"
19
+ msgstr "Lat lasting av fremhevede bilder"
20
+
21
+ #: bj-lazy-load.php:235
22
+ msgid "Include JS"
23
+ msgstr "Inkludér JS"
24
+
25
+ #: bj-lazy-load.php:236
26
+ msgid "Include CSS"
27
+ msgstr "Inkludér CSS"
28
+
29
+ #: bj-lazy-load.php:248
30
+ msgid "JAIL Settings"
31
+ msgstr "JAIL-innstillinger"
32
+
33
+ #: bj-lazy-load.php:250
34
+ msgid "Timeout"
35
+ msgstr "Tidsterskel"
36
+
37
+ #: bj-lazy-load.php:251
38
+ msgid "jQuery Effect"
39
+ msgstr "jQuery-effekt"
40
+
41
+ #: bj-lazy-load.php:252
42
+ msgid "Effect Speed"
43
+ msgstr "Effekthastighet"
44
+
45
+ #: bj-lazy-load.php:253
46
+ msgid "Trigger Event"
47
+ msgstr "Handlingsutløser"
48
+
49
+ #: bj-lazy-load.php:254
50
+ msgid "Offset/Threshold"
51
+ msgstr "Avstand/terskel"
52
+
53
+ #: bj-lazy-load.php:255
54
+ msgid "Ignore Hidden Images"
55
+ msgstr "Ignorer skjulte bilder"
56
+
57
+ #: bj-lazy-load.php:306
58
+ msgid "Needed for the plugin to work, but <a href=\"http://developer.yahoo.com/performance/rules.html#num_http\" target=\"_blank\">for best performance you should include it in your combined JS</a>"
59
+ msgstr "Nødvendig for at innstikket skal fungere, men <a href=\"http://developer.yahoo.com/performance/rules.html#num_http\" target=\"_blank\">for best ytelse bør du inkludere det i din kombinerte JS-fil</a>"
60
+
61
+ #: bj-lazy-load.php:316
62
+ msgid "Needed for the plugin to work, but <a href=\"http://developer.yahoo.com/performance/rules.html#num_http\" target=\"_blank\">for best performance you should include it in your combined CSS</a>"
63
+ msgstr "Nødvendig for at innstikket skal fungere, men <a href=\"http://developer.yahoo.com/performance/rules.html#num_http\" target=\"_blank\">for best ytelse bør du inkludere det i din kombinerte CSS-fil</a>"
64
+
65
+ #: bj-lazy-load.php:326
66
+ msgid "Whether to ignore hidden images to be loaded - Default: false/unchecked (so hidden images are loaded)"
67
+ msgstr "Om skjulte bilder skal ignoreres - Standard: usann/ikke valgt (slik at skjulte bilder også lastes)"
68
+
69
+ #: bj-lazy-load.php:344
70
+ msgid "Event that triggers the image to load. Default: load+scroll"
71
+ msgstr "Handling som utløser lasting av bilde. Standard: load+scroll"
72
+
73
+ #: bj-lazy-load.php:349
74
+ msgid "Number of msec after that the images will be loaded - Default: 10"
75
+ msgstr "Antall msec etter handling som bildene lastes - Standard: 10"
76
+
77
+ #: bj-lazy-load.php:357
78
+ msgid "Any jQuery effect that makes the images display (e.g. \"fadeIn\") - Default: NULL"
79
+ msgstr "Hvilken som helst jQuery-effekt som skal vise bildene (f.eks. \"fadeIn\") - Standard: NULL"
80
+
81
+ #: bj-lazy-load.php:359
82
+ msgid "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."
83
+ msgstr "MERK: Hvis du laster mange bilder, er det best å IKKE bruke denne innstillingen. Effektkall er veldig ressurskrevende. Til og med en enkel show() kan ha større innvirknign på nettleserens reaksjonsevne."
84
+
85
+ #: bj-lazy-load.php:365
86
+ msgid "string or number determining how long the animation will run - Default: 400"
87
+ msgstr "streng eller tall som angir hvor lenge animasjonen skal kjøres - Standard: 400"
88
+
89
+ #: bj-lazy-load.php:370
90
+ msgid "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"
91
+ msgstr "En terskel på \"500\" vil laste bilder som er mindre enn 500px under nedre kant av vinduet eller 500px over øvre kant av vinduet. - Standard: 200"
92
+
93
+ #: bj-lazy-load.php:375
94
+ msgid "You do not have sufficient permissions to access this page."
95
+ msgstr "Du har ikke tilstrekkelig tilgangsnivå til denne siden."
96
+
97
+ #. Description of the plugin/theme
98
+ msgid "Lazy image loading makes your site load faster and saves bandwidth."
99
+ msgstr "Lat bildelasting gjør nettsteder raskere og sparer båndbredde."
100
+
lang/bj-lazy-load.pot ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2010 BJ Lazy Load
2
+ # This file is distributed under the same license as the BJ Lazy Load package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: BJ Lazy Load 0.2.4\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/bj-lazy-load\n"
7
+ "POT-Creation-Date: 2011-12-14 20:06:30+00:00\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2010-MO-DA HO:MI+ZONE\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+
15
+ #: bj-lazy-load.php:234
16
+ msgid "Lazy load post thumbnails"
17
+ msgstr ""
18
+
19
+ #: bj-lazy-load.php:235
20
+ msgid "Include JS"
21
+ msgstr ""
22
+
23
+ #: bj-lazy-load.php:236
24
+ msgid "Include CSS"
25
+ msgstr ""
26
+
27
+ #: bj-lazy-load.php:248
28
+ msgid "JAIL Settings"
29
+ msgstr ""
30
+
31
+ #: bj-lazy-load.php:250
32
+ msgid "Timeout"
33
+ msgstr ""
34
+
35
+ #: bj-lazy-load.php:251
36
+ msgid "jQuery Effect"
37
+ msgstr ""
38
+
39
+ #: bj-lazy-load.php:252
40
+ msgid "Effect Speed"
41
+ msgstr ""
42
+
43
+ #: bj-lazy-load.php:253
44
+ msgid "Trigger Event"
45
+ msgstr ""
46
+
47
+ #: bj-lazy-load.php:254
48
+ msgid "Offset/Threshold"
49
+ msgstr ""
50
+
51
+ #: bj-lazy-load.php:255
52
+ msgid "Ignore Hidden Images"
53
+ msgstr ""
54
+
55
+ #: bj-lazy-load.php:306
56
+ msgid ""
57
+ "Needed for the plugin to work, but <a href=\"http://developer.yahoo.com/"
58
+ "performance/rules.html#num_http\" target=\"_blank\">for best performance you "
59
+ "should include it in your combined JS</a>"
60
+ msgstr ""
61
+
62
+ #: bj-lazy-load.php:316
63
+ msgid ""
64
+ "Needed for the plugin to work, but <a href=\"http://developer.yahoo.com/"
65
+ "performance/rules.html#num_http\" target=\"_blank\">for best performance you "
66
+ "should include it in your combined CSS</a>"
67
+ msgstr ""
68
+
69
+ #: bj-lazy-load.php:326
70
+ msgid ""
71
+ "Whether to ignore hidden images to be loaded - Default: false/unchecked (so "
72
+ "hidden images are loaded)"
73
+ msgstr ""
74
+
75
+ #: bj-lazy-load.php:344
76
+ msgid "Event that triggers the image to load. Default: load+scroll"
77
+ msgstr ""
78
+
79
+ #: bj-lazy-load.php:349
80
+ msgid "Number of msec after that the images will be loaded - Default: 10"
81
+ msgstr ""
82
+
83
+ #: bj-lazy-load.php:357
84
+ msgid ""
85
+ "Any jQuery effect that makes the images display (e.g. \"fadeIn\") - Default: "
86
+ "NULL"
87
+ msgstr ""
88
+
89
+ #: bj-lazy-load.php:359
90
+ msgid ""
91
+ "NOTE: If you are loading a large number of images, it is best to NOT use "
92
+ "this setting. Effects calls are very expensive. Even a simple show() can "
93
+ "have a major impact on the browser&rsquo;s responsiveness."
94
+ msgstr ""
95
+
96
+ #: bj-lazy-load.php:365
97
+ msgid ""
98
+ "string or number determining how long the animation will run - Default: 400"
99
+ msgstr ""
100
+
101
+ #: bj-lazy-load.php:370
102
+ msgid ""
103
+ "An offset of \"500\" would cause any images that are less than 500px below "
104
+ "the bottom of the window or 500px above the top of the window to load. - "
105
+ "Default: 200"
106
+ msgstr ""
107
+
108
+ #: bj-lazy-load.php:375
109
+ msgid "You do not have sufficient permissions to access this page."
110
+ msgstr ""
111
+
112
+ #. Description of the plugin/theme
113
+ msgid "Lazy image loading makes your site load faster and saves bandwidth."
114
+ msgstr ""
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.3
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,7 @@ 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
- * Serving size optimized images for responsive layouts/adaptive designs
23
  * (Got more ideas? Tell me!)
24
 
25
  == Installation ==
@@ -46,6 +46,13 @@ Check your HTML source or see the magic at work in FireBug or similar.
46
 
47
  == Changelog ==
48
 
 
 
 
 
 
 
 
49
  = Version 0.2.3 =
50
  * Now using DOMDocument for better HTML parsing. Old regexp parsing as fallback if DOMDocument is not available.
51
 
@@ -69,6 +76,9 @@ Check your HTML source or see the magic at work in FireBug or similar.
69
 
70
  == Upgrade Notice ==
71
 
 
 
 
72
  = 0.2.3 =
73
  Improved image replacement
74
 
5
  Author URI: http://twitter.com/bjornjohansen
6
  Requires at least: 3.2
7
  Tested up to: 3.3
8
+ Stable tag: 0.2.4
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 design/adaptive layout
23
  * (Got more ideas? Tell me!)
24
 
25
  == Installation ==
46
 
47
  == Changelog ==
48
 
49
+ = Version 0.2.4 =
50
+ * Now (more) compliant to the WP coding style guidelines.
51
+ * All strings localized
52
+ * Translations get loaded
53
+ * POT file included (send me your translations)
54
+ * Norwegian translation included
55
+
56
  = Version 0.2.3 =
57
  * Now using DOMDocument for better HTML parsing. Old regexp parsing as fallback if DOMDocument is not available.
58
 
76
 
77
  == Upgrade Notice ==
78
 
79
+ = 0.2.4 =
80
+ Better localization
81
+
82
  = 0.2.3 =
83
  Improved image replacement
84