Skip to content

Commit

Permalink
feat: add lazyload to iframe related tags (#3798)
Browse files Browse the repository at this point in the history
- iframe
- jsfiddle
- vimeo
- youtube
  • Loading branch information
ikeq authored and SukkaW committed Oct 27, 2019
1 parent 3a3e101 commit 7398d30
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/plugins/tag/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function iframeTag(args, content) {
const width = args[1] && args[1] !== 'default' ? args[1] : '100%';
const height = args[2] && args[2] !== 'default' ? args[2] : '300';

return `<iframe src="${url}" width="${width}" height="${height}" frameborder="0" allowfullscreen></iframe>`;
return `<iframe src="${url}" width="${width}" height="${height}" frameborder="0" loading="lazy" allowfullscreen></iframe>`;
}

module.exports = iframeTag;
2 changes: 1 addition & 1 deletion lib/plugins/tag/jsfiddle.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function jsfiddleTag(args, content) {
const width = args[3] && args[3] !== 'default' ? args[3] : '100%';
const height = args[4] && args[4] !== 'default' ? args[4] : '300';

return `<iframe scrolling="no" width="${width}" height="${height}" src="//jsfiddle.net/${id}/embedded/${tabs}/${skin}" frameborder="0" allowfullscreen></iframe>`;
return `<iframe scrolling="no" width="${width}" height="${height}" src="//jsfiddle.net/${id}/embedded/${tabs}/${skin}" frameborder="0" loading="lazy" allowfullscreen></iframe>`;
}

module.exports = jsfiddleTag;
2 changes: 1 addition & 1 deletion lib/plugins/tag/vimeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
function vimeoTag(args, content) {
const id = args[0];

return `<div class="video-container"><iframe src="//player.vimeo.com/video/${id}" frameborder="0" allowfullscreen></iframe></div>`;
return `<div class="video-container"><iframe src="//player.vimeo.com/video/${id}" frameborder="0" loading="lazy" allowfullscreen></iframe></div>`;
}

module.exports = vimeoTag;
2 changes: 1 addition & 1 deletion lib/plugins/tag/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
function youtubeTag(args, content) {
const id = args[0];

return `<div class="video-container"><iframe src="//www.youtube.com/embed/${id}" frameborder="0" allowfullscreen></iframe></div>`;
return `<div class="video-container"><iframe src="//www.youtube.com/embed/${id}" frameborder="0" loading="lazy" allowfullscreen></iframe></div>`;
}

module.exports = youtubeTag;
3 changes: 3 additions & 0 deletions test/scripts/tags/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('iframe', () => {
$('iframe').attr('height').should.eql('300');
$('iframe').attr('frameborder').should.eql('0');
$('iframe').attr('allowfullscreen').should.eql('');
$('iframe').attr('loading').should.eql('lazy');
});

it('width', () => {
Expand All @@ -23,6 +24,7 @@ describe('iframe', () => {
$('iframe').attr('height').should.eql('300');
$('iframe').attr('frameborder').should.eql('0');
$('iframe').attr('allowfullscreen').should.eql('');
$('iframe').attr('loading').should.eql('lazy');
});

it('height', () => {
Expand All @@ -33,5 +35,6 @@ describe('iframe', () => {
$('iframe').attr('height').should.eql('600');
$('iframe').attr('frameborder').should.eql('0');
$('iframe').attr('allowfullscreen').should.eql('');
$('iframe').attr('loading').should.eql('lazy');
});
});
1 change: 1 addition & 0 deletions test/scripts/tags/vimeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ describe('vimeo', () => {
$('iframe').attr('src').should.eql('//player.vimeo.com/video/foo');
$('iframe').attr('frameborder').should.eql('0');
$('iframe').attr('allowfullscreen').should.eql('');
$('iframe').attr('loading').should.eql('lazy');
});
});
1 change: 1 addition & 0 deletions test/scripts/tags/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ describe('youtube', () => {
$('iframe').attr('src').should.eql('//www.youtube.com/embed/foo');
$('iframe').attr('frameborder').should.eql('0');
$('iframe').attr('allowfullscreen').should.eql('');
$('iframe').attr('loading').should.eql('lazy');
});
});

0 comments on commit 7398d30

Please sign in to comment.