Version Description
Download this release
Release Info
Developer | bjornjohansen |
Plugin | BJ Lazy Load |
Version | 1.0.3 |
Comparing to | |
See all releases |
Code changes from version 1.0.2 to 1.0.3
- bj-lazy-load.php +1 -1
- inc/class-bjll.php +5 -5
- js/bj-lazy-load.js +20 -0
- js/bj-lazy-load.min.js +1 -1
- readme.txt +11 -5
bj-lazy-load.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: BJ Lazy Load
|
4 |
Plugin URI: https://wordpress.org/plugins/bj-lazy-load/
|
5 |
Description: Lazy image loading makes your site load faster and saves bandwidth.
|
6 |
-
Version: 1.0.
|
7 |
Author: Bjørn Johansen
|
8 |
Author URI: http://twitter.com/bjornjohansen
|
9 |
Text Domain: bj-lazy-load
|
3 |
Plugin Name: BJ Lazy Load
|
4 |
Plugin URI: https://wordpress.org/plugins/bj-lazy-load/
|
5 |
Description: Lazy image loading makes your site load faster and saves bandwidth.
|
6 |
+
Version: 1.0.3
|
7 |
Author: Bjørn Johansen
|
8 |
Author URI: http://twitter.com/bjornjohansen
|
9 |
Text Domain: bj-lazy-load
|
inc/class-bjll.php
CHANGED
@@ -90,11 +90,11 @@ class BJLL {
|
|
90 |
* Enqueue scripts
|
91 |
*/
|
92 |
public function enqueue_scripts() {
|
93 |
-
//$
|
94 |
-
//wp_enqueue_script( 'BJLL', plugins_url( 'js/bj-lazy-load.js',
|
95 |
-
//$
|
96 |
-
$
|
97 |
-
wp_enqueue_script( 'BJLL', plugins_url( 'js/bj-lazy-load.min.js',
|
98 |
|
99 |
$bjll_options = array();
|
100 |
$threshold = intval( self::_get_option('threshold') );
|
90 |
* Enqueue scripts
|
91 |
*/
|
92 |
public function enqueue_scripts() {
|
93 |
+
//$jsver = filemtime( dirname( dirname( __FILE__ ) ) . '/js/bj-lazy-load.js' );
|
94 |
+
//wp_enqueue_script( 'BJLL', plugins_url( 'js/bj-lazy-load.js', dirname( __FILE__ ) ), null, $jsver, true );
|
95 |
+
//$jsver = filemtime( dirname( dirname( __FILE__ ) ) . '/js/bj-lazy-load.v1.min.js' );
|
96 |
+
$jsver = 2;
|
97 |
+
wp_enqueue_script( 'BJLL', plugins_url( 'js/bj-lazy-load.min.js', dirname( __FILE__ ) ), null, $jsver, true );
|
98 |
|
99 |
$bjll_options = array();
|
100 |
$threshold = intval( self::_get_option('threshold') );
|
js/bj-lazy-load.js
CHANGED
@@ -1,9 +1,19 @@
|
|
|
|
|
|
1 |
var BJLL_options = BJLL_options || {};
|
2 |
|
3 |
var BJLL = {
|
4 |
|
|
|
|
|
5 |
check: function () {
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
if ( 'undefined' == typeof ( BJLL.threshold ) ) {
|
8 |
if ( 'undefined' != typeof ( BJLL_options.threshold ) ) {
|
9 |
BJLL.threshold = parseInt( BJLL_options.threshold );
|
@@ -14,6 +24,8 @@ var BJLL = {
|
|
14 |
|
15 |
var winH = document.documentElement.clientHeight || body.clientHeight;
|
16 |
|
|
|
|
|
17 |
var els = document.getElementsByClassName('lazy-hidden');
|
18 |
[].forEach.call( els, function( el, index, array ) {
|
19 |
|
@@ -21,13 +33,21 @@ var BJLL = {
|
|
21 |
|
22 |
if ( winH - elemRect.top + BJLL.threshold > 0 ) {
|
23 |
BJLL.show( el );
|
|
|
24 |
}
|
25 |
|
26 |
} );
|
|
|
|
|
|
|
|
|
|
|
27 |
},
|
28 |
|
29 |
show: function( el ) {
|
30 |
|
|
|
|
|
31 |
el.className = el.className.replace( /(?:^|\s)lazy-hidden(?!\S)/g , '' );
|
32 |
|
33 |
el.addEventListener( 'load', function() {
|
1 |
+
"use strict";
|
2 |
+
|
3 |
var BJLL_options = BJLL_options || {};
|
4 |
|
5 |
var BJLL = {
|
6 |
|
7 |
+
_ticking: false,
|
8 |
+
|
9 |
check: function () {
|
10 |
|
11 |
+
if ( BJLL._ticking ) {
|
12 |
+
return;
|
13 |
+
}
|
14 |
+
|
15 |
+
BJLL._ticking = true;
|
16 |
+
|
17 |
if ( 'undefined' == typeof ( BJLL.threshold ) ) {
|
18 |
if ( 'undefined' != typeof ( BJLL_options.threshold ) ) {
|
19 |
BJLL.threshold = parseInt( BJLL_options.threshold );
|
24 |
|
25 |
var winH = document.documentElement.clientHeight || body.clientHeight;
|
26 |
|
27 |
+
var updated = false;
|
28 |
+
|
29 |
var els = document.getElementsByClassName('lazy-hidden');
|
30 |
[].forEach.call( els, function( el, index, array ) {
|
31 |
|
33 |
|
34 |
if ( winH - elemRect.top + BJLL.threshold > 0 ) {
|
35 |
BJLL.show( el );
|
36 |
+
updated = true;
|
37 |
}
|
38 |
|
39 |
} );
|
40 |
+
|
41 |
+
BJLL._ticking = false;
|
42 |
+
if ( updated ) {
|
43 |
+
BJLL.check();
|
44 |
+
}
|
45 |
},
|
46 |
|
47 |
show: function( el ) {
|
48 |
|
49 |
+
console.log( el );
|
50 |
+
|
51 |
el.className = el.className.replace( /(?:^|\s)lazy-hidden(?!\S)/g , '' );
|
52 |
|
53 |
el.addEventListener( 'load', function() {
|
js/bj-lazy-load.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
var BJLL_options=BJLL_options||{},BJLL={check:function(){"undefined"==typeof BJLL.threshold&&(BJLL.threshold="undefined"!=typeof BJLL_options.threshold?parseInt(BJLL_options.threshold):200);var winH=document.documentElement.clientHeight||body.clientHeight,els=document.getElementsByClassName("lazy-hidden");[].forEach.call(els,function(el){var elemRect=el.getBoundingClientRect();winH-elemRect.top+BJLL.threshold>0&&BJLL.show(el)})},show:function(el){el.className=el.className.replace(/(?:^|\s)lazy-hidden(?!\S)/g,""),el.addEventListener("load",function(){BJLL.customEvent(el,"lazyloaded")},!1);var type=el.getAttribute("data-lazy-type");if("image"==type)el.setAttribute("src",el.getAttribute("data-lazy-src")),null!=el.getAttribute("data-srcset")&&el.setAttribute("srcset",el.getAttribute("data-srcset"));else if("iframe"==type){var s=el.getAttribute("data-lazy-src"),div=document.createElement("div");div.innerHTML=s;var iframe=div.firstChild;el.parentNode.replaceChild(iframe,el)}},customEvent:function(el,eventName){var event;document.createEvent?(event=document.createEvent("HTMLEvents"),event.initEvent(eventName,!0,!0)):(event=document.createEventObject(),event.eventType=eventName),event.eventName=eventName,document.createEvent?el.dispatchEvent(event):el.fireEvent("on"+event.eventType,event)}};window.addEventListener("load",BJLL.check,!1),window.addEventListener("scroll",BJLL.check,!1),window.addEventListener("resize",BJLL.check,!1),document.getElementsByTagName("body").item(0).addEventListener("post-load",BJLL.check,!1);
|
1 |
+
"use strict";var BJLL_options=BJLL_options||{},BJLL={_ticking:!1,check:function(){if(!BJLL._ticking){BJLL._ticking=!0,"undefined"==typeof BJLL.threshold&&(BJLL.threshold="undefined"!=typeof BJLL_options.threshold?parseInt(BJLL_options.threshold):200);var winH=document.documentElement.clientHeight||body.clientHeight,updated=!1,els=document.getElementsByClassName("lazy-hidden");[].forEach.call(els,function(el){var elemRect=el.getBoundingClientRect();winH-elemRect.top+BJLL.threshold>0&&(BJLL.show(el),updated=!0)}),BJLL._ticking=!1,updated&&BJLL.check()}},show:function(el){console.log(el),el.className=el.className.replace(/(?:^|\s)lazy-hidden(?!\S)/g,""),el.addEventListener("load",function(){BJLL.customEvent(el,"lazyloaded")},!1);var type=el.getAttribute("data-lazy-type");if("image"==type)el.setAttribute("src",el.getAttribute("data-lazy-src")),null!=el.getAttribute("data-srcset")&&el.setAttribute("srcset",el.getAttribute("data-srcset"));else if("iframe"==type){var s=el.getAttribute("data-lazy-src"),div=document.createElement("div");div.innerHTML=s;var iframe=div.firstChild;el.parentNode.replaceChild(iframe,el)}},customEvent:function(el,eventName){var event;document.createEvent?(event=document.createEvent("HTMLEvents"),event.initEvent(eventName,!0,!0)):(event=document.createEventObject(),event.eventType=eventName),event.eventName=eventName,document.createEvent?el.dispatchEvent(event):el.fireEvent("on"+event.eventType,event)}};window.addEventListener("load",BJLL.check,!1),window.addEventListener("scroll",BJLL.check,!1),window.addEventListener("resize",BJLL.check,!1),document.getElementsByTagName("body").item(0).addEventListener("post-load",BJLL.check,!1);
|
readme.txt
CHANGED
@@ -5,16 +5,18 @@ Tags: images, iframes, lazy loading, javascript, optimize, performance, bandwidt
|
|
5 |
Author URI: http://twitter.com/bjornjohansen
|
6 |
Requires at least: 3.5
|
7 |
Tested up to: 4.3
|
8 |
-
Stable tag: 1.0.
|
9 |
|
10 |
-
Lazy loading makes your site load faster and saves bandwidth. Uses no external JS libraries and degrades gracefully for non-js users.
|
11 |
|
12 |
== Description ==
|
13 |
Lazy loading makes your site load faster and saves bandwidth.
|
14 |
|
15 |
This plugin replaces all your post images, post thumbnails, gravatar images and content iframes with a placeholder and loads the content as it gets close to enter the browser window when the visitor scrolls the page. Also works with text widgets.
|
16 |
|
17 |
-
|
|
|
|
|
18 |
|
19 |
Non-javascript visitors gets the original element in noscript.
|
20 |
|
@@ -27,6 +29,8 @@ Please let me know if you have any issues. Fastest way to get a response is by T
|
|
27 |
* Hebrew (he_IL) by Imri Sagive
|
28 |
* Norwegian Bokmål (nb_NO) by Bjørn Johansen
|
29 |
|
|
|
|
|
30 |
== Installation ==
|
31 |
1. Download and unzip plugin
|
32 |
2. Upload the 'bj-lazy-load' folder to the '/wp-content/plugins/' directory,
|
@@ -52,13 +56,15 @@ No worries. They get the original element in a noscript element. No Lazy Loading
|
|
52 |
= I'm using a CDN. Will this plugin interfere? =
|
53 |
Lazy loading works just fine. The images will still load from your CDN.
|
54 |
|
55 |
-
As of version 0.6.0, serving responsive and hiDPI images will not work if you're using a CDN. Pull zones will be supported in the near future.
|
56 |
-
|
57 |
= How can I verify that the plugin is working? =
|
58 |
Check your HTML source or see the magic at work in Web Inspector, FireBug or similar.
|
59 |
|
60 |
== Changelog ==
|
61 |
|
|
|
|
|
|
|
|
|
62 |
= Version 1.0.2 =
|
63 |
* PHP 5.2 compatibility again
|
64 |
|
5 |
Author URI: http://twitter.com/bjornjohansen
|
6 |
Requires at least: 3.5
|
7 |
Tested up to: 4.3
|
8 |
+
Stable tag: 1.0.3
|
9 |
|
10 |
+
Lazy loading for images and iframes makes your site load faster and saves bandwidth. Uses no external JS libraries and degrades gracefully for non-js users.
|
11 |
|
12 |
== Description ==
|
13 |
Lazy loading makes your site load faster and saves bandwidth.
|
14 |
|
15 |
This plugin replaces all your post images, post thumbnails, gravatar images and content iframes with a placeholder and loads the content as it gets close to enter the browser window when the visitor scrolls the page. Also works with text widgets.
|
16 |
|
17 |
+
Since it works with iframes, it also covers embedded videoes from YouTube, Vimeo etc.
|
18 |
+
|
19 |
+
You can also lazy load other images and iframes in your theme, by using a simple filter.
|
20 |
|
21 |
Non-javascript visitors gets the original element in noscript.
|
22 |
|
29 |
* Hebrew (he_IL) by Imri Sagive
|
30 |
* Norwegian Bokmål (nb_NO) by Bjørn Johansen
|
31 |
|
32 |
+
<a href="https://github.com/bjornjohansen/bj-lazy-load">Development happens at GitHub</a>. Pull requests are very welcome.
|
33 |
+
|
34 |
== Installation ==
|
35 |
1. Download and unzip plugin
|
36 |
2. Upload the 'bj-lazy-load' folder to the '/wp-content/plugins/' directory,
|
56 |
= I'm using a CDN. Will this plugin interfere? =
|
57 |
Lazy loading works just fine. The images will still load from your CDN.
|
58 |
|
|
|
|
|
59 |
= How can I verify that the plugin is working? =
|
60 |
Check your HTML source or see the magic at work in Web Inspector, FireBug or similar.
|
61 |
|
62 |
== Changelog ==
|
63 |
|
64 |
+
= Version 1.0.3 =
|
65 |
+
* Fixed issue where some images wouldn’t be loaded on load under certain conditions.
|
66 |
+
* Small performance improvement
|
67 |
+
|
68 |
= Version 1.0.2 =
|
69 |
* PHP 5.2 compatibility again
|
70 |
|