From 565fbe3f785d64e7b4102593a4d5c25cb9bcfdfb Mon Sep 17 00:00:00 2001 From: Shin <2082119+shinsenter@users.noreply.github.com> Date: Tue, 26 Apr 2022 09:17:43 +0900 Subject: [PATCH] Save more bytes (#105) --- .github/dependabot.yml | 25 ----------- .github/workflows/codeql-analysis.yml | 52 ++--------------------- .vscode/settings.json | 6 +++ CONTRIBUTING.md | 16 +++---- README.md | 28 ++++++------ dist/defer.min.js | 4 +- dist/defer_plus.min.js | 4 +- dist/polyfill.min.js | 2 +- docs/about.md | 14 +++--- docs/apis.md | 2 +- docs/index.md | 28 ++++++------ docs/links.md | 12 +++--- package-lock.json | 6 +-- package.json | 6 +-- src/defer.js | 61 +++++++++++++-------------- src/fallback.js | 2 +- 16 files changed, 101 insertions(+), 167 deletions(-) delete mode 100644 .github/dependabot.yml create mode 100644 .vscode/settings.json diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 6696737..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,25 +0,0 @@ -version: 2 -updates: -- package-ecosystem: npm - directory: "/" - schedule: - interval: daily - time: "20:00" - open-pull-requests-limit: 10 - ignore: - - dependency-name: uglify-js - versions: - - 3.12.6 - - 3.12.7 - - dependency-name: clean-css - versions: - - 5.0.1 - - dependency-name: eslint - versions: - - 7.19.0 - - dependency-name: intersection-observer - versions: - - 0.12.0 - - dependency-name: js-beautify - versions: - - 1.13.5 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index c99eb45..ab5a2ad 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -1,67 +1,23 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# name: "CodeQL" - on: push: branches: [ master ] pull_request: - # The branches below must be a subset of the branches above branches: [ master ] schedule: - cron: '27 22 * * 3' - jobs: analyze: name: Analyze runs-on: ubuntu-latest - strategy: fail-fast: false matrix: language: [ 'javascript' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] - # Learn more: - # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + - uses: actions/checkout@v2 + - uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + - uses: github/codeql-action/autobuild@v2 + - uses: github/codeql-action/analyze@v2 \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..045ff46 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "editor.rulers": [80, 100, 120], + "editor.trimAutoWhitespace": true, + "files.encoding": "utf8", + "files.eol": "\n" +} \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 23fe424..d2ff759 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,7 +33,7 @@ The [Project Team](#join-the-project-team) looks forward to your contributions. If you have a question about this project, how to use it, or just need clarification about something: -* Open an Issue at https://github.com/shinsenter/defer.js/issues +* Open an Issue at https://code.shin.company/defer.js/issues * Provide as much context as you can about what you're running into. * Provide project and platform versions (nodejs, npm, etc), depending on what seems relevant. If not, please be ready to provide that information if maintainers ask for it. @@ -47,7 +47,7 @@ Once it's filed: If you run into an error or bug with the project: -* Open an Issue at https://github.com/shinsenter/defer.js/issues +* Open an Issue at https://code.shin.company/defer.js/issues * Include *reproduction steps* that someone else can follow to recreate the bug or error on their own. * Provide project and platform versions (nodejs, npm, etc), depending on what seems relevant. If not, please be ready to provide that information if maintainers ask for it. @@ -63,7 +63,7 @@ Once it's filed: If the project doesn't do something you need or want it to do: -* Open an Issue at https://github.com/shinsenter/defer.js/issues +* Open an Issue at https://code.shin.company/defer.js/issues * Provide as much context as you can about what you're running into. * Please try and be clear about why existing features and alternatives would not work for you. @@ -106,7 +106,7 @@ To contribute documentation: * Make sure your changes are formatted correctly and consistently with the rest of the documentation. * Re-read what you wrote, and run a spellchecker on it to make sure you didn't miss anything. * Write clear, concise commit message(s) using [conventional-changelog format](https://github.com/conventional-changelog/conventional-changelog-angular/blob/master/convention.md). Documentation commits should use `docs(): `. -* Go to https://github.com/shinsenter/defer.js/pulls and open a new pull request with your changes. +* Go to https://code.shin.company/defer.js/pulls and open a new pull request with your changes. * If your PR is connected to an open issue, add a line in your PR's description that says `Fixes: #123`, where `#123` is the number of the issue you're fixing. Once you've filed the PR: @@ -132,7 +132,7 @@ To contribute code: * Write tests that verify that your contribution works as expected. * Write clear, concise commit message(s) using [conventional-changelog format](https://github.com/conventional-changelog/conventional-changelog-angular/blob/master/convention.md). * Dependency updates, additions, or removals must be in individual commits, and the message must use the format: `(deps): PKG@VERSION`, where `` is any of the usual `conventional-changelog` prefixes, at your discretion. -* Go to https://github.com/shinsenter/defer.js/pulls and open a new pull request with your changes. +* Go to https://code.shin.company/defer.js/pulls and open a new pull request with your changes. * If your PR is connected to an open issue, add a line in your PR's description that says `Fixes: #123`, where `#123` is the number of the issue you're fixing. Once you've filed the PR: @@ -153,7 +153,7 @@ Sometimes, the `support` label will be added to things that turn out to actually In order to help other folks out with their questions: -* Go to the issue tracker and [filter open issues by the `support` label](https://github.com/shinsenter/defer.js/issues?q=is%3Aopen+is%3Aissue+label%3Asupport). +* Go to the issue tracker and [filter open issues by the `support` label](https://code.shin.company/defer.js/issues?q=is%3Aopen+is%3Aissue+label%3Asupport). * Read through the list until you find something that you're familiar enough with to give an answer to. * Respond to the issue with whatever details are needed to clarify the question, or get more details about what's going on. * Once the discussion wraps up and things are clarified, either close the issue, or ask the original issue filer (or a maintainer) to close it for you. @@ -170,7 +170,7 @@ Some notes on picking up support issues: One of the most important tasks in handling issues is labeling them usefully and accurately. All other tasks involving issues ultimately rely on the issue being classified in such a way that relevant parties looking to do their own tasks can find them quickly and easily. -In order to label issues, [open up the list of unlabeled issues](https://github.com/shinsenter/defer.js/issues?q=is%3Aopen+is%3Aissue+no%3Alabel) and, **from newest to oldest**, read through each one and apply issue labels according to the table below. If you're unsure about what label to apply, skip the issue and try the next one: don't feel obligated to label each and every issue yourself! +In order to label issues, [open up the list of unlabeled issues](https://code.shin.company/defer.js/issues?q=is%3Aopen+is%3Aissue+no%3Alabel) and, **from newest to oldest**, read through each one and apply issue labels according to the table below. If you're unsure about what label to apply, skip the issue and try the next one: don't feel obligated to label each and every issue yourself! Label | Apply When | Notes --- | --- | --- @@ -205,7 +205,7 @@ To clean up issues and PRs: * not marked as `starter` or `help wanted` (these might stick around for a while, in general, as they're intended to be available) * no explicit messages in the comments asking for it to be left open * does not belong to a milestone -* Leave a message when closing saying "Cleaning up stale issue. Please reopen or ping us if and when you're ready to resume this. See https://github.com/shinsenter/defer.js/blob/latest/CONTRIBUTING.md#clean-up-issues-and-prs for more details." +* Leave a message when closing saying "Cleaning up stale issue. Please reopen or ping us if and when you're ready to resume this. See https://code.shin.company/defer.js/blob/latest/CONTRIBUTING.md#clean-up-issues-and-prs for more details." ## Review Pull Requests diff --git a/README.md b/README.md index 5c15c60..2e3f925 100644 --- a/README.md +++ b/README.md @@ -2,24 +2,24 @@ đŸĨ‡ A super small, super efficient library that helps you lazy load almost everything like images, video, audio, iframes as well as stylesheets, and JavaScript. -[![NPM](https://img.shields.io/npm/l/@shinsenter/defer.js)](https://raw.githubusercontent.com/shinsenter/defer.js/master/LICENSE) +[![NPM](https://img.shields.io/npm/l/@shinsenter/defer.js)](https://code.shin.company/defer.js/blob/master/LICENSE) [![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/@shinsenter/defer.js)](https://snyk.io/advisor/npm-package/@shinsenter/defer.js) [![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/shinsenter/defer.js)](https://www.codefactor.io/repository/github/shinsenter/defer.js) * * * -[![GitHub Release Date](https://img.shields.io/github/release-date/shinsenter/defer.js)](https://github.com/shinsenter/defer.js/releases) -[![GitHub package.json version](https://img.shields.io/github/package-json/v/shinsenter/defer.js)](https://github.com/shinsenter/defer.js/releases) +[![GitHub Release Date](https://img.shields.io/github/release-date/shinsenter/defer.js)](https://code.shin.company/defer.js/releases) +[![GitHub package.json version](https://img.shields.io/github/package-json/v/shinsenter/defer.js)](https://code.shin.company/defer.js/releases) [![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@shinsenter/defer.js)](https://www.npmjs.com/package/@shinsenter/defer.js) [![jsDelivr hits (npm)](https://img.shields.io/jsdelivr/npm/hm/@shinsenter/defer.js)](https://www.jsdelivr.com/package/npm/@shinsenter/defer.js) [![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.5.0 +- **Version**: 2.6.0 - **Author**: Mai Nhut Tan - **Copyright**: 2021 AppSeeds -- **License**: [MIT](https://raw.githubusercontent.com/shinsenter/defer.js/master/LICENSE) +- **License**: [MIT](https://code.shin.company/defer.js/blob/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`. My Awesome Page - + @@ -602,7 +602,7 @@ Defer.js(base + '/highlight.pack.min.js', 'hljs-js', 1000, function () { ### Defer.reveal(element, [revealedClass]) ⇒ void -Reveal an element which is lazyloaded by the library +Reveals an element which is lazyloaded by the library **Kind**: static method of [Defer](#Defer) **Since**: 2.1 @@ -781,21 +781,21 @@ In this library, a closure is a [Function](#Function) that gives you access to a ### PHP library -[https://github.com/shinsenter/defer.php/](https://github.com/shinsenter/defer.php/) +[https://code.shin.company/defer.php/](https://code.shin.company/defer.php/) 🚀 A PHP library that focuses on minimizing payload size of HTML document and optimizing processing on the browser when rendering the web page. ### Wordpress plugin -[https://github.com/shinsenter/defer-wordpress/](https://github.com/shinsenter/defer-wordpress/) +[https://code.shin.company/defer-wordpress/](https://code.shin.company/defer-wordpress/) ⚡ī¸ A native, blazing fast lazy loader. ✅ Legacy browsers support (IE9+). đŸ’¯ SEO friendly. 🧩 Lazy load almost anything. ### Laravel package -[https://github.com/shinsenter/defer-laravel/](https://github.com/shinsenter/defer-laravel/) +[https://code.shin.company/defer-laravel/](https://code.shin.company/defer-laravel/) 🚀 A Laravel package that focuses on minimizing payload size of HTML document and optimizing processing on the browser when rendering the web page. @@ -804,9 +804,9 @@ In this library, a closure is a [Function](#Function) that gives you access to a [![Donate via Paypal](https://img.shields.io/badge/Donate-Paypal-blue)](https://www.paypal.me/shinsenter) [![Become a sponsor](https://img.shields.io/badge/Donate-Patreon-orange)](https://www.patreon.com/appseeds) -[![Become a stargazer](https://img.shields.io/badge/Support-Stargazer-yellow)](https://github.com/shinsenter/defer.js/stargazers) -[![Report an issue](https://img.shields.io/badge/Support-Issues-green)](https://github.com/shinsenter/defer.js/issues/new) [![Join the chat at https://gitter.im/shinsenter/defer.js](https://badges.gitter.im/shinsenter/defer.js.svg)](https://gitter.im/shinsenter/defer.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - +[![Become a stargazer](https://img.shields.io/badge/Support-Stargazer-yellow)](https://code.shin.company/defer.js/stargazers) +[![Report an issue](https://img.shields.io/badge/Support-Issues-green)](https://code.shin.company/defer.js/issues/new) +[![Join the chat at https://gitter.im/shinsenter/defer.js](https://badges.gitter.im/shinsenter/defer.js.svg)](https://gitter.im/shinsenter/defer.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) * * * diff --git a/dist/defer.min.js b/dist/defer.min.js index e6ba898..3dff61e 100644 --- a/dist/defer.min.js +++ b/dist/defer.min.js @@ -1,2 +1,2 @@ -/*@shinsenter/defer.js@2.5.0*/ -!function(r,i,t){var u,o=/^data-(.+)/,a='IntersectionObserver',c=/p/.test(i.readyState),s=[],f=s.slice,l='deferjs',n='load',e='pageshow',d='forEach',h='shift';function m(e){i.head.appendChild(e)}function v(e,n){f.call(e.attributes)[d](n)}function p(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 y(e,n){return f.call((n||i).querySelectorAll(e))}function b(t,e){y('source',t)[d](b),v(t,function(e,n){(n=o.exec(e.name))&&(t[n[1]]=e.value)}),e&&(t.className+=' '+e),n in t&&t[n]()}function I(e){u(function(o){o=y(e||'[type=deferjs]'),function e(n,t){(n=o[h]())&&(n.parentNode.removeChild(n),(t=p(n.nodeName)).text=n.text,v(n,function(e){'type'!=e.name&&t.setAttribute(e.name,e.value)}),t.src&&!t.hasAttribute('async')?(t.onload=t.onerror=e,m(t)):(m(t),e()))}()})}(u=function(e,n){c?t(e,n):s.push(e,n)}).all=I,u.js=function(n,t,e,o){u(function(e){(e=p('SCRIPT',t,o)).src=n,m(e)},e)},u.css=function(n,t,e,o){u(function(e){(e=p('LINK',t,o)).rel='stylesheet',e.href=n,m(e)},e)},u.dom=function(e,n,t,o,i){function c(e){o&&!1===o(e)||b(e,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),y(e||'[data-src]')[d](function(e){l in e||(e[l]=1,t?t.observe(e):c(e))})},n)},u.reveal=b,r.Defer=u,r.addEventListener('on'+e in r?e:n,function(){for(I();s[0];t(s[h](),s[h]()))c=1})}(this,document,setTimeout); \ No newline at end of file +/*@shinsenter/defer.js@2.6.0*/ +!function(r,i,t){var u,o=/^data-(.+)/,a='IntersectionObserver',s='deferjs',n='load',e='pageshow',f='forEach',c='shift',l=/p/.test(i.readyState),d=[],h=d.slice;function m(e){i.head.appendChild(e)}function v(e,n){h.call(e.attributes)[f](n)}function p(e,n,t,o){return o=(n?i.getElementById(n):o)||i.createElement(e),n&&(o.id=n),t&&(o.onload=t),o}function y(e,n){return h.call((n||i).querySelectorAll(e))}function b(t,e){y('source',t)[f](b),v(t,function(e,n){(n=o.exec(e.name))&&(t[n[1]]=e.value)}),e&&(t.className+=' '+e),n in t&&t[n]()}function I(e){u(function(o){o=y(e||'[type=deferjs]'),function e(n,t){(n=o[c]())&&(n.parentNode.removeChild(n),(t=p(n.nodeName)).text=n.text,v(n,function(e){'type'!=e.name&&t.setAttribute(e.name,e.value)}),t.src&&!t.hasAttribute('async')?(t.onload=t.onerror=e,m(t)):(m(t),e()))}()})}(u=function(e,n){l?t(e,n):d.push(e,n)}).all=I,u.js=function(n,t,e,o){u(function(e){(e=p('SCRIPT',t,o)).src=n,m(e)},e)},u.css=function(n,t,e,o){u(function(e){(e=p('LINK',t,o)).rel='stylesheet',e.href=n,m(e)},e)},u.dom=function(e,n,t,o,i){function c(e){o&&!1===o(e)||b(e,t)}u(function(t){t=a in r&&new r[a](function(e){e[f](function(e,n){e.isIntersecting&&(n=e.target)&&(t.unobserve(n),c(n))})},i),y(e||'[data-src]')[f](function(e){s in e||(e[s]=1,t?t.observe(e):c(e))})},n)},u.reveal=b,r.Defer=u,r.addEventListener('on'+e in r?e:n,function(){for(I();d[0];t(d[c](),d[c]()))l=1})}(this,document,setTimeout); \ No newline at end of file diff --git a/dist/defer_plus.min.js b/dist/defer_plus.min.js index 001b977..51da95a 100644 --- a/dist/defer_plus.min.js +++ b/dist/defer_plus.min.js @@ -1,2 +1,2 @@ -/*@shinsenter/defer.js@2.5.0*/ -!function(c,i,t){var f,o=/^data-(.+)/,s='IntersectionObserver',r=/p/.test(i.readyState),u=[],a=u.slice,d='deferjs',n='load',e='pageshow',l='forEach',m='shift';function h(e){i.head.appendChild(e)}function p(e,n){a.call(e.attributes)[l](n)}function v(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 y(e,n){return a.call((n||i).querySelectorAll(e))}function b(t,e){y('source',t)[l](b),p(t,function(e,n){(n=o.exec(e.name))&&(t[n[1]]=e.value)}),e&&(t.className+=' '+e),n in t&&t[n]()}function g(e){f(function(o){o=y(e||'[type=deferjs]'),function e(n,t){(n=o[m]())&&(n.parentNode.removeChild(n),(t=v(n.nodeName)).text=n.text,p(n,function(e){'type'!=e.name&&t.setAttribute(e.name,e.value)}),t.src&&!t.hasAttribute('async')?(t.onload=t.onerror=e,h(t)):(h(t),e()))}()})}(f=function(e,n){r?t(e,n):u.push(e,n)}).all=g,f.js=function(n,t,e,o){f(function(e){(e=v('SCRIPT',t,o)).src=n,h(e)},e)},f.css=function(n,t,e,o){f(function(e){(e=v('LINK',t,o)).rel='stylesheet',e.href=n,h(e)},e)},f.dom=function(e,n,t,o,i){function r(e){o&&!1===o(e)||b(e,t)}f(function(t){t=s in c&&new c[s](function(e){e[l](function(e,n){e.isIntersecting&&(n=e.target)&&(t.unobserve(n),r(n))})},i),y(e||'[data-src]')[l](function(e){d in e||(e[d]=1,t?t.observe(e):r(e))})},n)},f.reveal=b,c.Defer=f,c.addEventListener('on'+e in c?e:n,function(){for(g();u[0];t(u[m](),u[m]()))r=1})}(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 +/*@shinsenter/defer.js@2.6.0*/ +!function(c,i,t){var f,o=/^data-(.+)/,s='IntersectionObserver',u='deferjs',n='load',e='pageshow',a='forEach',r='shift',d=/p/.test(i.readyState),l=[],m=l.slice;function h(e){i.head.appendChild(e)}function p(e,n){m.call(e.attributes)[a](n)}function v(e,n,t,o){return o=(n?i.getElementById(n):o)||i.createElement(e),n&&(o.id=n),t&&(o.onload=t),o}function y(e,n){return m.call((n||i).querySelectorAll(e))}function b(t,e){y('source',t)[a](b),p(t,function(e,n){(n=o.exec(e.name))&&(t[n[1]]=e.value)}),e&&(t.className+=' '+e),n in t&&t[n]()}function g(e){f(function(o){o=y(e||'[type=deferjs]'),function e(n,t){(n=o[r]())&&(n.parentNode.removeChild(n),(t=v(n.nodeName)).text=n.text,p(n,function(e){'type'!=e.name&&t.setAttribute(e.name,e.value)}),t.src&&!t.hasAttribute('async')?(t.onload=t.onerror=e,h(t)):(h(t),e()))}()})}(f=function(e,n){d?t(e,n):l.push(e,n)}).all=g,f.js=function(n,t,e,o){f(function(e){(e=v('SCRIPT',t,o)).src=n,h(e)},e)},f.css=function(n,t,e,o){f(function(e){(e=v('LINK',t,o)).rel='stylesheet',e.href=n,h(e)},e)},f.dom=function(e,n,t,o,i){function r(e){o&&!1===o(e)||b(e,t)}f(function(t){t=s in c&&new c[s](function(e){e[a](function(e,n){e.isIntersecting&&(n=e.target)&&(t.unobserve(n),r(n))})},i),y(e||'[data-src]')[a](function(e){u in e||(e[u]=1,t?t.observe(e):r(e))})},n)},f.reveal=b,c.Defer=f,c.addEventListener('on'+e in c?e:n,function(){for(g();l[0];t(l[r](),l[r]()))d=1})}(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/dist/polyfill.min.js b/dist/polyfill.min.js index 0f5e9dc..e60d89f 100644 --- a/dist/polyfill.min.js +++ b/dist/polyfill.min.js @@ -1 +1 @@ -!function(){'use strict';var p,n,f,d;function r(t){try{return t.defaultView&&t.defaultView.frameElement||null}catch(t){return null}}function u(t){this.time=t.time,this.target=t.target,this.rootBounds=o(t.rootBounds),this.boundingClientRect=o(t.boundingClientRect),this.intersectionRect=o(t.intersectionRect||a()),this.isIntersecting=!!t.intersectionRect;var e=this.boundingClientRect,t=e.width*e.height,e=this.intersectionRect,e=e.width*e.height;this.intersectionRatio=t?Number((e/t).toFixed(4)):this.isIntersecting?1:0}function t(t,e){var n,o,i,e=e||{};if('function'!=typeof t)throw new Error('callback must be a function');if(e.root&&1!=e.root.nodeType&&9!=e.root.nodeType)throw new Error('root must be a Document or Element');this._checkForIntersections=(n=this._checkForIntersections.bind(this),o=this.THROTTLE_TIMEOUT,i=null,function(){i=i||setTimeout(function(){n(),i=null},o)}),this._callback=t,this._observationTargets=[],this._queuedEntries=[],this._rootMarginValues=this._parseRootMargin(e.rootMargin),this.thresholds=this._initThresholds(e.threshold),this.root=e.root||null,this.rootMargin=this._rootMarginValues.map(function(t){return t.value+t.unit}).join(' '),this._monitoringDocuments=[],this._monitoringUnsubscribes=[]}function s(t,e,n,o){'function'==typeof t.addEventListener?t.addEventListener(e,n,o||!1):'function'==typeof t.attachEvent&&t.attachEvent('on'+e,n)}function h(t,e,n,o){'function'==typeof t.removeEventListener?t.removeEventListener(e,n,o||!1):'function'==typeof t.detatchEvent&&t.detatchEvent('on'+e,n)}function g(t){var e;try{e=t.getBoundingClientRect()}catch(t){}return e?e.width&&e.height?e:{top:e.top,right:e.right,bottom:e.bottom,left:e.left,width:e.right-e.left,height:e.bottom-e.top}:a()}function a(){return{top:0,bottom:0,left:0,right:0,width:0,height:0}}function o(t){return!t||'x'in t?t:{top:t.top,y:t.top,bottom:t.bottom,left:t.left,x:t.left,right:t.right,width:t.width,height:t.height}}function m(t,e){var n=e.top-t.top,t=e.left-t.left;return{top:n,left:t,height:e.height,width:e.width,bottom:n+e.height,right:t+e.width}}function i(t,e){for(var n=e;n;){if(n==t)return!0;n=_(n)}return!1}function _(t){var e=t.parentNode;return 9==t.nodeType&&t!=p?r(t):(e=e&&e.assignedSlot?e.assignedSlot.parentNode:e)&&11==e.nodeType&&e.host?e.host:e}function c(t){return t&&9===t.nodeType}'object'==typeof window&&('IntersectionObserver'in window&&'IntersectionObserverEntry'in window&&'intersectionRatio'in window.IntersectionObserverEntry.prototype?'isIntersecting'in window.IntersectionObserverEntry.prototype||Object.defineProperty(window.IntersectionObserverEntry.prototype,'isIntersecting',{get:function(){return 0 - **Copyright**: 2021 AppSeeds -- **License**: [MIT](https://raw.githubusercontent.com/shinsenter/defer.js/master/LICENSE) +- **License**: [MIT](https://code.shin.company/defer.js/blob/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`. My Awesome Page - + diff --git a/docs/apis.md b/docs/apis.md index 27ee890..fb05ff2 100644 --- a/docs/apis.md +++ b/docs/apis.md @@ -450,7 +450,7 @@ Defer.js(base + '/highlight.pack.min.js', 'hljs-js', 1000, function () { ### Defer.reveal(element, [revealedClass]) ⇒ void -Reveal an element which is lazyloaded by the library +Reveals an element which is lazyloaded by the library **Kind**: static method of [Defer](#Defer) **Since**: 2.1 diff --git a/docs/index.md b/docs/index.md index b1eee27..2e3f925 100644 --- a/docs/index.md +++ b/docs/index.md @@ -2,24 +2,24 @@ đŸĨ‡ A super small, super efficient library that helps you lazy load almost everything like images, video, audio, iframes as well as stylesheets, and JavaScript. -[![NPM](https://img.shields.io/npm/l/@shinsenter/defer.js)](https://raw.githubusercontent.com/shinsenter/defer.js/master/LICENSE) +[![NPM](https://img.shields.io/npm/l/@shinsenter/defer.js)](https://code.shin.company/defer.js/blob/master/LICENSE) [![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/@shinsenter/defer.js)](https://snyk.io/advisor/npm-package/@shinsenter/defer.js) [![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/shinsenter/defer.js)](https://www.codefactor.io/repository/github/shinsenter/defer.js) * * * -[![GitHub Release Date](https://img.shields.io/github/release-date/shinsenter/defer.js)](https://github.com/shinsenter/defer.js/releases) -[![GitHub package.json version](https://img.shields.io/github/package-json/v/shinsenter/defer.js)](https://github.com/shinsenter/defer.js/releases) +[![GitHub Release Date](https://img.shields.io/github/release-date/shinsenter/defer.js)](https://code.shin.company/defer.js/releases) +[![GitHub package.json version](https://img.shields.io/github/package-json/v/shinsenter/defer.js)](https://code.shin.company/defer.js/releases) [![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@shinsenter/defer.js)](https://www.npmjs.com/package/@shinsenter/defer.js) [![jsDelivr hits (npm)](https://img.shields.io/jsdelivr/npm/hm/@shinsenter/defer.js)](https://www.jsdelivr.com/package/npm/@shinsenter/defer.js) [![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.5.0 +- **Version**: 2.6.0 - **Author**: Mai Nhut Tan - **Copyright**: 2021 AppSeeds -- **License**: [MIT](https://raw.githubusercontent.com/shinsenter/defer.js/master/LICENSE) +- **License**: [MIT](https://code.shin.company/defer.js/blob/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`. My Awesome Page - + @@ -602,7 +602,7 @@ Defer.js(base + '/highlight.pack.min.js', 'hljs-js', 1000, function () { ### Defer.reveal(element, [revealedClass]) ⇒ void -Reveal an element which is lazyloaded by the library +Reveals an element which is lazyloaded by the library **Kind**: static method of [Defer](#Defer) **Since**: 2.1 @@ -781,21 +781,21 @@ In this library, a closure is a [Function](#Function) that gives you access to a ### PHP library -[https://github.com/shinsenter/defer.php/](https://github.com/shinsenter/defer.php/) +[https://code.shin.company/defer.php/](https://code.shin.company/defer.php/) 🚀 A PHP library that focuses on minimizing payload size of HTML document and optimizing processing on the browser when rendering the web page. ### Wordpress plugin -[https://github.com/shinsenter/defer-wordpress/](https://github.com/shinsenter/defer-wordpress/) +[https://code.shin.company/defer-wordpress/](https://code.shin.company/defer-wordpress/) ⚡ī¸ A native, blazing fast lazy loader. ✅ Legacy browsers support (IE9+). đŸ’¯ SEO friendly. 🧩 Lazy load almost anything. ### Laravel package -[https://github.com/shinsenter/defer-laravel/](https://github.com/shinsenter/defer-laravel/) +[https://code.shin.company/defer-laravel/](https://code.shin.company/defer-laravel/) 🚀 A Laravel package that focuses on minimizing payload size of HTML document and optimizing processing on the browser when rendering the web page. @@ -804,9 +804,9 @@ In this library, a closure is a [Function](#Function) that gives you access to a [![Donate via Paypal](https://img.shields.io/badge/Donate-Paypal-blue)](https://www.paypal.me/shinsenter) [![Become a sponsor](https://img.shields.io/badge/Donate-Patreon-orange)](https://www.patreon.com/appseeds) -[![Become a stargazer](https://img.shields.io/badge/Support-Stargazer-yellow)](https://github.com/shinsenter/defer.js/stargazers) -[![Report an issue](https://img.shields.io/badge/Support-Issues-green)](https://github.com/shinsenter/defer.js/issues/new) - +[![Become a stargazer](https://img.shields.io/badge/Support-Stargazer-yellow)](https://code.shin.company/defer.js/stargazers) +[![Report an issue](https://img.shields.io/badge/Support-Issues-green)](https://code.shin.company/defer.js/issues/new) +[![Join the chat at https://gitter.im/shinsenter/defer.js](https://badges.gitter.im/shinsenter/defer.js.svg)](https://gitter.im/shinsenter/defer.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) * * * diff --git a/docs/links.md b/docs/links.md index c2dc1e0..30d6c48 100644 --- a/docs/links.md +++ b/docs/links.md @@ -2,21 +2,21 @@ ### PHP library -[https://github.com/shinsenter/defer.php/](https://github.com/shinsenter/defer.php/) +[https://code.shin.company/defer.php/](https://code.shin.company/defer.php/) 🚀 A PHP library that focuses on minimizing payload size of HTML document and optimizing processing on the browser when rendering the web page. ### Wordpress plugin -[https://github.com/shinsenter/defer-wordpress/](https://github.com/shinsenter/defer-wordpress/) +[https://code.shin.company/defer-wordpress/](https://code.shin.company/defer-wordpress/) ⚡ī¸ A native, blazing fast lazy loader. ✅ Legacy browsers support (IE9+). đŸ’¯ SEO friendly. 🧩 Lazy load almost anything. ### Laravel package -[https://github.com/shinsenter/defer-laravel/](https://github.com/shinsenter/defer-laravel/) +[https://code.shin.company/defer-laravel/](https://code.shin.company/defer-laravel/) 🚀 A Laravel package that focuses on minimizing payload size of HTML document and optimizing processing on the browser when rendering the web page. @@ -25,9 +25,9 @@ [![Donate via Paypal](https://img.shields.io/badge/Donate-Paypal-blue)](https://www.paypal.me/shinsenter) [![Become a sponsor](https://img.shields.io/badge/Donate-Patreon-orange)](https://www.patreon.com/appseeds) -[![Become a stargazer](https://img.shields.io/badge/Support-Stargazer-yellow)](https://github.com/shinsenter/defer.js/stargazers) -[![Report an issue](https://img.shields.io/badge/Support-Issues-green)](https://github.com/shinsenter/defer.js/issues/new) - +[![Become a stargazer](https://img.shields.io/badge/Support-Stargazer-yellow)](https://code.shin.company/defer.js/stargazers) +[![Report an issue](https://img.shields.io/badge/Support-Issues-green)](https://code.shin.company/defer.js/issues/new) +[![Join the chat at https://gitter.im/shinsenter/defer.js](https://badges.gitter.im/shinsenter/defer.js.svg)](https://gitter.im/shinsenter/defer.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) * * * diff --git a/package-lock.json b/package-lock.json index 0975c27..e12bbec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,16 @@ { "name": "@shinsenter/defer.js", - "version": "2.5.0", + "version": "2.6.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@shinsenter/defer.js", - "version": "2.5.0", + "version": "2.6.0", "funding": [ { "type": "github", - "url": "https://github.com/shinsenter/defer.js/stargazers" + "url": "https://code.shin.company/defer.js/stargazers" }, { "type": "paypal", diff --git a/package.json b/package.json index 434549c..e929738 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@shinsenter/defer.js", "title": "defer.js", - "version": "2.5.0", + "version": "2.6.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", @@ -15,12 +15,12 @@ "url": "git+https://github.com/shinsenter/defer.js.git" }, "bugs": { - "url": "https://github.com/shinsenter/defer.js/issues" + "url": "https://code.shin.company/defer.js/issues" }, "funding": [ { "type": "github", - "url": "https://github.com/shinsenter/defer.js/stargazers" + "url": "https://code.shin.company/defer.js/stargazers" }, { "type": "paypal", diff --git a/src/defer.js b/src/defer.js index 3dd6192..6d9c504 100644 --- a/src/defer.js +++ b/src/defer.js @@ -3,7 +3,7 @@ * https://www.npmjs.com/package/@shinsenter/defer.js * * Released under the MIT license - * https://raw.githubusercontent.com/shinsenter/defer.js/master/LICENSE + * https://code.shin.company/defer.js/blob/master/LICENSE * * MIT License * @@ -36,12 +36,12 @@ * * @author Mai Nhut Tan * @copyright 2021 AppSeeds - * @version 2.0 - * @license {@link https://raw.githubusercontent.com/shinsenter/defer.js/master/LICENSE|MIT} + * @version 2.6.0 + * @license {@link https://code.shin.company/defer.js/blob/master/LICENSE|MIT} */ -/*@shinsenter/defer.js@2.5.0*/ -(function (window, document, handler) { +/*@shinsenter/defer.js@2.6.0*/ +(function (window, document, worker) { /* |-------------------------------------------------------------------------- @@ -53,18 +53,13 @@ var defer; // Constant values - var _dataRegExp = /^data-(.+)/; - var _IO = 'IntersectionObserver'; - - // State holders - var _domReady = (/p/).test(document.readyState); - var _queue = []; - var _toArray = _queue.slice; + var _dataRegExp = /^data-(.+)/; + var _IO = 'IntersectionObserver'; // Common attributes - var _lazied = 'deferjs'; - var _load = 'load'; - var _pageshow = 'pageshow'; + var _lazied = 'deferjs'; + var _load = 'load'; + var _pageshow = 'pageshow'; // Method aliases var _forEach = 'forEach'; @@ -74,8 +69,13 @@ var _shift = 'shift'; // CSS Selectors - var _defaultScripts = '[type=deferjs]'; - var _defaultTargets = '[data-src]'; + var _selectorJS = '[type=deferjs]'; + var _selectorDOM = '[data-src]'; + + // State holders + var _booted = (/p/).test(document.readyState); + var _queue = []; + var _slice = _queue.slice; /* |-------------------------------------------------------------------------- @@ -88,15 +88,12 @@ } function _attrLoop(node, callback) { - _toArray.call(node.attributes)[_forEach](callback); + _slice.call(node.attributes)[_forEach](callback); } function _newNode(nodeName, id, callback, _node) { - _node = id ? document.getElementById(id) : _node; - - if (!_node) { - _node = document.createElement(nodeName); - } + _node = (id ? document.getElementById(id) : _node) || + document.createElement(nodeName); if (id) { _node.id = id; @@ -110,7 +107,7 @@ } function _query(selector, parent) { - return _toArray.call((parent || document).querySelectorAll(selector)); + return _slice.call((parent || document).querySelectorAll(selector)); } function _reveal(node, revealedClass) { @@ -139,7 +136,7 @@ function _scripts(selector) { // Defer action until page loaded defer(function (_found) { - _found = _query(selector || _defaultScripts); + _found = _query(selector || _selectorJS); function _next(_node, _clone) { _node = _found[_shift](); @@ -253,8 +250,8 @@ * ``` */ defer = function (func, delay) { - if (_domReady) { - handler(func, delay); + if (_booted) { + worker(func, delay); } else { _queue.push(func, delay); } @@ -666,7 +663,7 @@ _observer = false; } - _query(selector || _defaultTargets)[_forEach](function (node) { + _query(selector || _selectorDOM)[_forEach](function (node) { if (!(_lazied in node)) { node[_lazied] = 1; @@ -683,7 +680,7 @@ }; /** - * Reveal an element which is lazyloaded by the library + * Reveals an element which is lazyloaded by the library * * @function Defer.reveal * @since 2.1 @@ -721,7 +718,7 @@ |-------------------------------------------------------------------------- */ - // Expose Defer instance + // Exposes a Defer instance window.Defer = defer; // Listens for the load event of the global context @@ -732,9 +729,9 @@ for ( _scripts(); _queue[0]; - handler(_queue[_shift](), _queue[_shift]()) + worker(_queue[_shift](), _queue[_shift]()) ) { - _domReady = 1; + _booted = 1; } } ); diff --git a/src/fallback.js b/src/fallback.js index 7cf4d20..cb48819 100644 --- a/src/fallback.js +++ b/src/fallback.js @@ -4,7 +4,7 @@ * https://www.npmjs.com/package/@shinsenter/defer.js * * Released under the MIT license - * https://raw.githubusercontent.com/shinsenter/defer.js/master/LICENSE + * https://code.shin.company/defer.js/blob/master/LICENSE * * MIT License *