MediaWiki:Gadget-jQueryLazyload.js
外观
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
/**
* -------------------------------------------------------------------------
* !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
* -------------------------------------------------------------------------
*/
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/jQueryLazyload/Gadget-jQueryLazyload.js|user=[[U:AnnAngela]]|co-authors=GH:github-actions[bot]|longId=103d1a563ea4ccc8ff29fb55c9bcd88329a56eb5|shortId=103d1a56|summary=feat: rename (#594)|body=<nowiki>Co-authored-by: github-actions[bot] <41898282+github-actions[bot]📧users.noreply.github.com></nowiki>}}';
/* <pre> */
"use strict";(()=>{const t={src:"data-src",srcset:"data-srcset",selector:".lazyload",root:null,rootMargin:"0px",threshold:0},extend=(t,...s)=>{const o={},r="boolean"==typeof t&&t,i=[..."boolean"!=typeof t?[t]:[],...s],merge=t=>{for(const s in t)Object.prototype.hasOwnProperty.bind(t)(s)&&(r&&"[object Object]"===Object.prototype.toString.bind(t[s])()?o[s]=extend(!0,o[s],t[s]):o[s]=t[s])};for(const t of i)merge(t);return o};class LazyLoad{constructor(s,o){this.settings=extend(t,o||{}),this.images=s||document.querySelectorAll(this.settings.selector),this.observer=null,this.init()}init(){if(!window.IntersectionObserver)return void this.loadImages();const t=this,s={root:this.settings.root,rootMargin:this.settings.rootMargin,threshold:[this.settings.threshold]};this.observer=new IntersectionObserver(s=>{Array.prototype.forEach.bind(s)(s=>{if(s.isIntersecting){t.observer.unobserve(s.target);const o=s.target.getAttribute(t.settings.src),r=s.target.getAttribute(t.settings.srcset);"img"===s.target.tagName.toLowerCase()?(o&&(s.target.src=o),r&&(s.target.srcset=r)):s.target.style.backgroundImage=`url(${o})`}})},s),Array.prototype.forEach.bind(this.images)(s=>{t.observer.observe(s)})}loadAndDestroy(){this.settings&&(this.loadImages(),this.destroy())}loadImages(){if(!this.settings)return;const t=this;Array.prototype.forEach.bind(this.images)(s=>{const o=s.getAttribute(t.settings.src),r=s.getAttribute(t.settings.srcset);"img"===s.tagName.toLowerCase()?(o&&(s.src=o),r&&(s.srcset=r)):s.style.backgroundImage=`url('${o}')`})}destroy(){this.settings&&(this.observer.disconnect(),this.settings=null)}}window.lazyload=(t,s)=>new LazyLoad(t,s),window.jQuery&&(jQuery.fn.lazyload=function(t){const s=t||{};return s.attribute||(s.attribute="data-src"),new LazyLoad(this.toArray(),s),this})})();
/* </pre> */