Skip to content

Commit

Permalink
ADD: lazy load images for theme Next: #1649 PART 4
Browse files Browse the repository at this point in the history
This add compare fir `lazy` classname and if it true, will add 'data-original' attrubute to replace it with `src` attrubute, to make image load lazy.
If no `lazy` class defined, image tag will work at standart state.
  • Loading branch information
ivan-nginx authored May 28, 2017
1 parent 83469c6 commit 0279623
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/plugins/tag/img.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = function(ctx) {
var height;
var title;
var alt;
var lazysrc = '';
var src;
var item = '';
var i = 0;
Expand Down Expand Up @@ -85,7 +86,14 @@ module.exports = function(ctx) {
alt = match[2];
}

// Find lazy load classname
if (classes[0] === 'lazy') {
lazysrc = src;
src = '/images/loading.gif';
}

var attrs = {
'data-original': lazysrc,
src: src,
class: classes.join(' '),
width: width,
Expand Down

0 comments on commit 0279623

Please sign in to comment.