Skip to content

Commit

Permalink
Updated plugin with unique id for each iframe and callback for append…
Browse files Browse the repository at this point in the history
… event
  • Loading branch information
Viktor Bergehall committed Feb 17, 2017
1 parent 808d7ff commit c3c38f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/lazyframe.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions src/lazyframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const Lazyframe = () => {
debounce: 250,
lazyload: true,
initinview: false,
onLoad: (l) => {}
onLoad: (l) => {},
onAppend: (l) => {}
};

const constants = {
Expand Down Expand Up @@ -100,7 +101,12 @@ const Lazyframe = () => {
settings: setup(el),
};

lazyframe.el.addEventListener('click', () => lazyframe.el.appendChild(lazyframe.iframe));
lazyframe.el.addEventListener('click', () => {
lazyframe.el.appendChild(lazyframe.iframe);

const iframe = el.querySelectorAll('iframe');
lazyframe.settings.onAppend.call(this, iframe[0]);
});

if (settings.lazyload) {
build(lazyframe);
Expand Down Expand Up @@ -317,6 +323,7 @@ const Lazyframe = () => {
settings.src = constants.src[settings.vendor](settings);
}

iframeNode.setAttribute('id', `lazyframe-${settings.id}`);
iframeNode.setAttribute('src', settings.src);
iframeNode.setAttribute('frameborder', 0);
iframeNode.setAttribute('allowfullscreen', '');
Expand Down

0 comments on commit c3c38f0

Please sign in to comment.