Add js libs lozad (lazy load images) and list (sort and filter any HTML).
This commit is contained in:
parent
d4deb91f58
commit
a1e7e3f79b
4 changed files with 44 additions and 0 deletions
2
assets/js/lib/list.min.js
vendored
Normal file
2
assets/js/lib/list.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
15
assets/js/lib/lozad.min.js
vendored
Normal file
15
assets/js/lib/lozad.min.js
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/*! lozad.js - v1.16.0 - 2020-09-10
|
||||
* https://github.com/ApoorvSaxena/lozad.js
|
||||
* Copyright (c) 2020 Apoorv Saxena; Licensed MIT */
|
||||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.lozad=e()}(this,function(){"use strict";
|
||||
/**
|
||||
* Detect IE browser
|
||||
* @const {boolean}
|
||||
* @private
|
||||
*/var g="undefined"!=typeof document&&document.documentMode,v=function(t){return window&&window[t]},h=["data-iesrc","data-alt","data-src","data-srcset","data-background-image","data-toggle-class"],p={rootMargin:"0px",threshold:0,enableAutoReload:!1,load:function(t){if("picture"===t.nodeName.toLowerCase()){var e=t.querySelector("img"),r=!1;null===e&&(e=document.createElement("img"),r=!0),g&&t.getAttribute("data-iesrc")&&(e.src=t.getAttribute("data-iesrc")),t.getAttribute("data-alt")&&(e.alt=t.getAttribute("data-alt")),r&&t.append(e)}if("video"===t.nodeName.toLowerCase()&&!t.getAttribute("data-src")&&t.children){for(var a=t.children,o=void 0,i=0;i<=a.length-1;i++)(o=a[i].getAttribute("data-src"))&&(a[i].src=o);t.load()}t.getAttribute("data-poster")&&(t.poster=t.getAttribute("data-poster")),t.getAttribute("data-src")&&(t.src=t.getAttribute("data-src")),t.getAttribute("data-srcset")&&t.setAttribute("srcset",t.getAttribute("data-srcset"));var n=",";if(t.getAttribute("data-background-delimiter")&&(n=t.getAttribute("data-background-delimiter")),t.getAttribute("data-background-image"))t.style.backgroundImage="url('"+t.getAttribute("data-background-image").split(n).join("'),url('")+"')";else if(t.getAttribute("data-background-image-set")){var d=t.getAttribute("data-background-image-set").split(n),u=d[0].substr(0,d[0].indexOf(" "))||d[0];// Substring before ... 1x
|
||||
u=-1===u.indexOf("url(")?"url("+u+")":u,1===d.length?t.style.backgroundImage=u:t.setAttribute("style",(t.getAttribute("style")||"")+"background-image: "+u+"; background-image: -webkit-image-set("+d+"); background-image: image-set("+d+")")}t.getAttribute("data-toggle-class")&&t.classList.toggle(t.getAttribute("data-toggle-class"))},loaded:function(){}};
|
||||
/**
|
||||
*
|
||||
* @param {string} type
|
||||
*
|
||||
*/function k(t){t.setAttribute("data-loaded",!0)}var y=function(t){return"true"===t.getAttribute("data-loaded")},w=function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document;return t instanceof Element?[t]:t instanceof NodeList?t:e.querySelectorAll(t)};return function(){var r,a,e,o=0<arguments.length&&void 0!==arguments[0]?arguments[0]:".lozad",t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},i=Object.assign({},p,t),n=i.root,d=i.rootMargin,u=i.threshold,g=i.enableAutoReload,s=i.load,c=i.loaded,l=void 0,b=void 0;v("IntersectionObserver")&&(l=new IntersectionObserver((r=s,a=c,function(t,e){t.forEach(function(t){(0<t.intersectionRatio||t.isIntersecting)&&(e.unobserve(t.target),y(t.target)||(r(t.target),k(t.target),a(t.target)))})}),{root:n,rootMargin:d,threshold:u})),v("MutationObserver")&&g&&(b=new MutationObserver((e=s,function(t){t.forEach(function(t){y(t.target)&&"attributes"===t.type&&-1<h.indexOf(t.attributeName)&&e(t.target)})})));for(var f,m=w(o,n),A=0;A<m.length;A++)(f=m[A]).getAttribute("data-placeholder-background")&&(f.style.background=f.getAttribute("data-placeholder-background"));return{observe:function(){for(var t=w(o,n),e=0;e<t.length;e++)y(t[e])||(l?(b&&g&&b.observe(t[e],{subtree:!0,attributes:!0,attributeFilter:h}),l.observe(t[e])):(s(t[e]),k(t[e]),c(t[e])))},triggerLoad:function(t){y(t)||(s(t),k(t),c(t))},observer:l,mutationObserver:b}}});
|
||||
10
assets/js/lozadinit.js
Normal file
10
assets/js/lozadinit.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
// Lazy load images with lozad.js.
|
||||
const observer = window.lozad(); //
|
||||
observer.observe();
|
||||
|
||||
|
||||
})();
|
||||
|
|
@ -16,6 +16,18 @@
|
|||
{{ $cookieconsent := resources.Get "js/cookieconsent.js" | minify | fingerprint -}}
|
||||
<script defer src="{{ $cookieconsent.RelPermalink }}"></script>
|
||||
{{ end -}}
|
||||
{{ if $.Param "lazyload" -}}
|
||||
{{ $lozadmin := resources.Get "js/lib/lozad.min.js" | fingerprint -}}
|
||||
<script defer src="{{ $lozadmin.RelPermalink }}"></script>
|
||||
{{ $lozad := resources.Get "js/lozadinit.js" | fingerprint -}}
|
||||
<script defer src="{{ $lozad.RelPermalink }}"></script>
|
||||
{{ end -}}
|
||||
{{ if $.Param "listsort" -}}
|
||||
{{ $listmin := resources.Get "js/lib/list.min.js" | fingerprint -}}
|
||||
<script defer src="{{ $listmin.RelPermalink }}"></script>
|
||||
{{ $listsort := resources.Get "js/listsort.js" | fingerprint -}}
|
||||
<script defer src="{{ $listsort.RelPermalink }}"></script>
|
||||
{{ end -}}
|
||||
{{ if .HasShortcode "contact" -}}
|
||||
{{ $contact := resources.Get "js/contact.js" | minify | fingerprint -}}
|
||||
<script defer src="{{ $contact.RelPermalink }}"></script>
|
||||
|
|
@ -28,3 +40,8 @@
|
|||
{{ end -}}
|
||||
{{ $script := resources.Get "js/script.js" | minify | fingerprint -}}
|
||||
<script defer src="{{ $script.RelPermalink }}"></script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue