diff --git a/.build/.uglifyjs b/.build/.uglifyjs index 597e260..36dfc8c 100644 --- a/.build/.uglifyjs +++ b/.build/.uglifyjs @@ -6,7 +6,6 @@ "reserved": [], "toplevel": false }, - "nameCache": {}, "output": { "ascii_only": true, "beautify": false, diff --git a/README.md b/README.md index 8dd1f40..ef8feee 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ [![NPM](https://nodei.co/npm/@shinsenter/defer.js.png?downloads=true)](https://www.npmjs.com/package/@shinsenter/defer.js) - **Package**: [@shinsenter/defer.js](https://www.npmjs.com/package/@shinsenter/defer.js) -- **Version**: 2.3.0 +- **Version**: 2.4.0 - **Author**: Mai Nhut Tan - **Copyright**: 2021 AppSeeds - **License**: [MIT](https://raw.githubusercontent.com/shinsenter/defer.js/master/LICENSE) @@ -90,7 +90,7 @@ or load it from a CDN like below example. My Awesome Page - + @@ -111,7 +111,7 @@ instead of `defer.min.js`. ```html - + @@ -345,7 +345,7 @@ you should load `IntersectionObserver` polyfill library right after the `defer.min.js` script tag as following example: ```html - + diff --git a/dist/defer.min.js b/dist/defer.min.js index f39836e..12090ee 100644 --- a/dist/defer.min.js +++ b/dist/defer.min.js @@ -1,2 +1,2 @@ /*@shinsenter/defer.js*/ -!function(c,i,t){var u,r=/^data-(.+)/,a='IntersectionObserver',o=/p/.test(i.readyState),f=[],s=f.slice,l='lazied',d='load',e='pageshow',h='forEach',m='hasAttribute',v='setAttribute',p='shift';function y(e){i.head.appendChild(e)}function b(e){return s.call(e.attributes)}function I(e,n,t,o){return o=(o=n?i.getElementById(n):o)||i.createElement(e),n&&(o.id=n),t&&(o.onload=t),o}function g(e,n){return s.call((n||i).querySelectorAll(e))}function E(e,n,t,o){for(n=b(e);n[0];)t=n[p](),(o=r.exec(t.name))&&e[v](o[1],t.value);g('source',e)[h](E),d in e&&e[d]()}function n(e){u(function(r){r=g(e||'[type=deferjs]'),function e(n,t,o,i){if(n=r[p]()){for(n.parentNode.removeChild(n),(t=I(n.nodeName)).text=n.text,o=b(n);o[0];)'type'!=(i=o[p]()).name&&t[v](i.name,i.value);t.src&&!t[m]('async')?(t.onload=t.onerror=e,y(t)):(y(t),e())}}()})}(u=function(e,n){o?t(e,n):f.push(e,n)}).all=n,u.js=function(n,t,e,o){u(function(e){(e=I('SCRIPT',t,o)).src=n,y(e)},e)},u.css=function(n,t,e,o){u(function(e){(e=I('LINK',t,o)).rel='stylesheet',e.href=n,y(e)},e)},u.dom=function(e,n,t,o,i){function r(e){o&&!1===o(e)||(E(e),t&&(e.className+=' '+t))}u(function(t){t=a in c&&new c[a](function(e){e[h](function(e,n){e.isIntersecting&&(n=e.target)&&(t.unobserve(n),r(n))})},i),g(e||'[data-src]')[h](function(e){e[m](l)||(e[v](l,''),t?t.observe(e):r(e))})},n)},u.reveal=E,c.Defer=u,c.addEventListener('on'+e in c?e:d,function(){for(n();f[0];o=1)t(f[p](),f[p]())})}(this,document,setTimeout); \ No newline at end of file +!function(r,i,t){var u,o=/^data-(.+)/,a='IntersectionObserver',c=/p/.test(i.readyState),s=[],f=s.slice,l='lazied',e='load',n='pageshow',d='forEach',h='hasAttribute',m='shift';function v(e){i.head.appendChild(e)}function p(e){return f.call(e.attributes)}function y(e,n,t,o){return o=(o=n?i.getElementById(n):o)||i.createElement(e),n&&(o.id=n),t&&(o.onload=t),o}function b(e,n){return f.call((n||i).querySelectorAll(e))}function I(t){b('source',t)[d](I),p(t)[d](function(e,n){(n=o.exec(e.name))&&(t[n[1]]=e.value)}),e in t&&t[e]()}function g(e){u(function(o){o=b(e||'[type=deferjs]'),function e(n,t){(n=o[m]())&&(n.parentNode.removeChild(n),(t=y(n.nodeName)).text=n.text,p(n)[d](function(e){'type'!=e.name&&(t[e.name]=e.value)}),t.src&&!t[h]('async')?(t.onload=t.onerror=e,v(t)):(v(t),e()))}()})}(u=function(e,n){c?t(e,n):s.push(e,n)}).all=g,u.js=function(n,t,e,o){u(function(e){(e=y('SCRIPT',t,o)).src=n,v(e)},e)},u.css=function(n,t,e,o){u(function(e){(e=y('LINK',t,o)).rel='stylesheet',e.href=n,v(e)},e)},u.dom=function(e,n,t,o,i){function c(e){o&&!1===o(e)||(I(e),t&&(e.className+=' '+t))}u(function(t){t=a in r&&new r[a](function(e){e[d](function(e,n){e.isIntersecting&&(n=e.target)&&(t.unobserve(n),c(n))})},i),b(e||'[data-src]')[d](function(e){e[h](l)||(e.setAttribute(l,''),t?t.observe(e):c(e))})},n)},u.reveal=I,r.Defer=u,r.addEventListener('on'+n in r?n:e,function(){for(g();s[0];c=1)t(s[m](),s[m]())})}(this,document,setTimeout); \ No newline at end of file diff --git a/dist/defer_plus.min.js b/dist/defer_plus.min.js index d51588f..893280c 100644 --- a/dist/defer_plus.min.js +++ b/dist/defer_plus.min.js @@ -1,2 +1,2 @@ /*@shinsenter/defer.js*/ -!function(c,o,t){var f,i=/^data-(.+)/,s='IntersectionObserver',r=/p/.test(o.readyState),u=[],a=u.slice,d='lazied',l='load',e='pageshow',m='forEach',h='hasAttribute',p='setAttribute',v='shift';function y(e){o.head.appendChild(e)}function b(e){return a.call(e.attributes)}function g(e,n,t,r){return r=(r=n?o.getElementById(n):r)||o.createElement(e),n&&(r.id=n),t&&(r.onload=t),r}function I(e,n){return a.call((n||o).querySelectorAll(e))}function E(e,n,t,r){for(n=b(e);n[0];)t=n[v](),(r=i.exec(t.name))&&e[p](r[1],t.value);I('source',e)[m](E),l in e&&e[l]()}function n(e){f(function(i){i=I(e||'[type=deferjs]'),function e(n,t,r,o){if(n=i[v]()){for(n.parentNode.removeChild(n),(t=g(n.nodeName)).text=n.text,r=b(n);r[0];)'type'!=(o=r[v]()).name&&t[p](o.name,o.value);t.src&&!t[h]('async')?(t.onload=t.onerror=e,y(t)):(y(t),e())}}()})}(f=function(e,n){r?t(e,n):u.push(e,n)}).all=n,f.js=function(n,t,e,r){f(function(e){(e=g('SCRIPT',t,r)).src=n,y(e)},e)},f.css=function(n,t,e,r){f(function(e){(e=g('LINK',t,r)).rel='stylesheet',e.href=n,y(e)},e)},f.dom=function(e,n,t,r,o){function i(e){r&&!1===r(e)||(E(e),t&&(e.className+=' '+t))}f(function(t){t=s in c&&new c[s](function(e){e[m](function(e,n){e.isIntersecting&&(n=e.target)&&(t.unobserve(n),i(n))})},o),I(e||'[data-src]')[m](function(e){e[h](d)||(e[p](d,''),t?t.observe(e):i(e))})},n)},f.reveal=E,c.Defer=f,c.addEventListener('on'+e in c?e:l,function(){for(n();u[0];r=1)t(u[v](),u[v]())})}(this,document,setTimeout),function(e,n){e.defer=n=e.Defer,e.deferscript=n.js,e.deferstyle=n.css,e.deferimg=e.deferiframe=n.dom}(this); \ No newline at end of file +!function(c,i,t){var u,o=/^data-(.+)/,f='IntersectionObserver',r=/p/.test(i.readyState),s=[],a=s.slice,d='lazied',e='load',n='pageshow',l='forEach',m='hasAttribute',h='shift';function p(e){i.head.appendChild(e)}function v(e){return a.call(e.attributes)}function y(e,n,t,o){return o=(o=n?i.getElementById(n):o)||i.createElement(e),n&&(o.id=n),t&&(o.onload=t),o}function b(e,n){return a.call((n||i).querySelectorAll(e))}function g(t){b('source',t)[l](g),v(t)[l](function(e,n){(n=o.exec(e.name))&&(t[n[1]]=e.value)}),e in t&&t[e]()}function I(e){u(function(o){o=b(e||'[type=deferjs]'),function e(n,t){(n=o[h]())&&(n.parentNode.removeChild(n),(t=y(n.nodeName)).text=n.text,v(n)[l](function(e){'type'!=e.name&&(t[e.name]=e.value)}),t.src&&!t[m]('async')?(t.onload=t.onerror=e,p(t)):(p(t),e()))}()})}(u=function(e,n){r?t(e,n):s.push(e,n)}).all=I,u.js=function(n,t,e,o){u(function(e){(e=y('SCRIPT',t,o)).src=n,p(e)},e)},u.css=function(n,t,e,o){u(function(e){(e=y('LINK',t,o)).rel='stylesheet',e.href=n,p(e)},e)},u.dom=function(e,n,t,o,i){function r(e){o&&!1===o(e)||(g(e),t&&(e.className+=' '+t))}u(function(t){t=f in c&&new c[f](function(e){e[l](function(e,n){e.isIntersecting&&(n=e.target)&&(t.unobserve(n),r(n))})},i),b(e||'[data-src]')[l](function(e){e[m](d)||(e.setAttribute(d,''),t?t.observe(e):r(e))})},n)},u.reveal=g,c.Defer=u,c.addEventListener('on'+n in c?n:e,function(){for(I();s[0];r=1)t(s[h](),s[h]())})}(this,document,setTimeout),function(e,n){e.defer=n=e.Defer,e.deferscript=n.js,e.deferstyle=n.css,e.deferimg=e.deferiframe=n.dom}(this); \ No newline at end of file diff --git a/docs/about.md b/docs/about.md index d0b155d..42ba295 100644 --- a/docs/about.md +++ b/docs/about.md @@ -16,7 +16,7 @@ [![NPM](https://nodei.co/npm/@shinsenter/defer.js.png?downloads=true)](https://www.npmjs.com/package/@shinsenter/defer.js) - **Package**: [@shinsenter/defer.js](https://www.npmjs.com/package/@shinsenter/defer.js) -- **Version**: 2.3.0 +- **Version**: 2.4.0 - **Author**: Mai Nhut Tan - **Copyright**: 2021 AppSeeds - **License**: [MIT](https://raw.githubusercontent.com/shinsenter/defer.js/master/LICENSE) @@ -90,7 +90,7 @@ or load it from a CDN like below example. My Awesome Page - + @@ -111,7 +111,7 @@ instead of `defer.min.js`. ```html - + diff --git a/docs/apis.md b/docs/apis.md index e2012d2..4b8bef9 100644 --- a/docs/apis.md +++ b/docs/apis.md @@ -207,7 +207,7 @@ you should load `IntersectionObserver` polyfill library right after the `defer.min.js` script tag as following example: ```html - + diff --git a/docs/index.md b/docs/index.md index 8dd1f40..ef8feee 100644 --- a/docs/index.md +++ b/docs/index.md @@ -16,7 +16,7 @@ [![NPM](https://nodei.co/npm/@shinsenter/defer.js.png?downloads=true)](https://www.npmjs.com/package/@shinsenter/defer.js) - **Package**: [@shinsenter/defer.js](https://www.npmjs.com/package/@shinsenter/defer.js) -- **Version**: 2.3.0 +- **Version**: 2.4.0 - **Author**: Mai Nhut Tan - **Copyright**: 2021 AppSeeds - **License**: [MIT](https://raw.githubusercontent.com/shinsenter/defer.js/master/LICENSE) @@ -90,7 +90,7 @@ or load it from a CDN like below example. My Awesome Page - + @@ -111,7 +111,7 @@ instead of `defer.min.js`. ```html - + @@ -345,7 +345,7 @@ you should load `IntersectionObserver` polyfill library right after the `defer.min.js` script tag as following example: ```html - + diff --git a/package-lock.json b/package-lock.json index 5592e57..29c7fd1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@shinsenter/defer.js", - "version": "2.3.0", + "version": "2.4.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@shinsenter/defer.js", - "version": "2.3.0", + "version": "2.4.0", "funding": [ { "type": "github", diff --git a/package.json b/package.json index 0c1ee76..bc52662 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@shinsenter/defer.js", "title": "defer.js", - "version": "2.3.0", + "version": "2.4.0", "description": "🥇 A super small, super efficient library that helps you lazy load almost everything like images, video, audio, iframes as well as stylesheets, and JavaScript.", "homepage": "https://shinsenter.github.io/defer.js/", "license": "MIT", diff --git a/src/defer.js b/src/defer.js index 544ed1e..28f967f 100644 --- a/src/defer.js +++ b/src/defer.js @@ -117,17 +117,15 @@ return _toArray.call((parent || document).querySelectorAll(selector)); } - function _reveal(node, _attributes, _property, _found) { - for (_attributes = _propArray(node); _attributes[0];) { - _property = _attributes[_shift](); - _found = _dataRegExp.exec(_property.name); + function _reveal(node) { + _query('source', node)[_forEach](_reveal); + _propArray(node)[_forEach](function (_property, _found) { + _found = _dataRegExp.exec(_property.name); if (_found) { - node[_setAttribute](_found[1], _property.value); + node[_found[1]] = _property.value; } - } - - _query('source', node)[_forEach](_reveal); + }); if (_load in node) { node[_load](); @@ -138,7 +136,7 @@ defer(function (_found) { _found = _query(selector || _selectorDeferJs); - function _next(_node, _clone, _attributes, _property) { + function _next(_node, _clone) { _node = _found[_shift](); if (_node) { @@ -148,13 +146,11 @@ // Clone the node _clone = _newNode(_node.nodeName); _clone.text = _node.text; - for (_attributes = _propArray(_node); _attributes[0];) { - _property = _attributes[_shift](); - + _propArray(_node)[_forEach](function (_property) { if (_property.name != 'type') { - _clone[_setAttribute](_property.name, _property.value); + _clone[_property.name] = _property.value; } - } + }); // Execute the node if (_clone.src && !_clone[_hasAttribute]('async')) { @@ -390,7 +386,7 @@ * ```html * - * + * * * *