PageSourceSearch

https://infortech.net.cn/assets/static/site/np_template/js/lazy.js

js infortech.net.cn collected 2026-10-08 19:23:16 UTC 6,489 bytes, 123 lines download raw bytes

1// yall.min.js
2var yall=function(){"use strict";return function(e){var n=(e=e||{}).lazyClass||"lazy",t=e.lazyBackgroundClass||"lazy-bg",o="idleLoadTimeout"in e?e.idleLoadTimeout:200,i=e.observeChanges||!1,r=e.events||{},a=e.noPolyfill||!1,s=window,c="requestIdleCallback",u="IntersectionObserver",l=u in s&&u+"Entry"in s,d=/baidu|(?:google|bing|yandex|duckduck)bot/i.test(navigator.userAgent),v=["srcset","src","poster"],f=[],queryDOM=function(e,o){return f.slice.call((o||document).querySelectorAll(e||"img."+n+",video."+n+",iframe."+n+",."+t))},yallLoad=function(n){var o=n.parentNode;"PICTURE"==o.nodeName&&yallApplyFn(queryDOM("source",o),yallFlipDataAttrs),"VIDEO"==n.nodeName&&yallApplyFn(queryDOM("source",n),yallFlipDataAttrs),yallFlipDataAttrs(n);var i=n.classList;i.contains(t)&&(i.remove(t),i.add(e.lazyBackgroundLoaded||"lazy-bg-loaded"))},yallBindEvents=function(e){for(var n in r)e.addEventListener(n,r[n].listener||r[n],r[n].options||void 0)},yallFlipDataAttrs=function(e){for(var t in v)if(v[t]in e.dataset){e.setAttribute(v[t],e.dataset[v[t]]);var o=e.parentNode;"SOURCE"===e.nodeName&&o.autoplay&&(o.load(),/Trident/.test(navigator.userAgent)&&o.play(),o.classList.remove(n)),e.classList.remove(n)}},yallApplyFn=function(e,n){for(var t=0;t<e.length;t++)s[u]&&n instanceof s[u]?n.observe(e[t]):n(e[t])},b=queryDOM();if(yallApplyFn(b,yallBindEvents),l&&!d){var g=new s[u]((function(e){yallApplyFn(e,(function(e){if(e.isIntersecting||e.intersectionRatio){var n=e.target;c in s&&o?s[c]((function(){yallLoad(n)}),{timeout:o}):yallLoad(n),g.unobserve(n),(b=b.filter((function(e){return e!=n}))).length||i||g.disconnect()}}))}),{rootMargin:("threshold"in e?e.threshold:200)+"px 0%"});yallApplyFn(b,g),i&&yallApplyFn(queryDOM(e.observeRootSelector||"body"),(function(n){new MutationObserver((function(){yallApplyFn(queryDOM(),(function(e){b.indexOf(e)<0&&(b.push(e),yallBindEvents(e),l&&!d?g.observe(e):(a||d)&&yallApplyFn(b,yallLoad))}))})).observe(n,e.mutationObserverOptions||{childList:!0,subtree:!0})}))}else(a||d)&&yallApplyFn(b,yallLoad)}}();
3
4//
5var lazyYall = function () {
6  document.addEventListener("DOMContentLoaded", function () {
7    yall({
8      observeChanges: true,
9      events: {
10        load: function (event) {
11          if (!event.target.classList.contains("lazy") && event.target.nodeName == "IMG") {
12            event.target.classList.add("img-loaded");
13            if ($(event.target.closest('.img-count')).length > 0) {
14              let that = $(event.target.closest('.img-count'));
15              var setTimeoutX = setTimeout(function () {
16                commonjs.imgCount(that);
17                clearTimeout(setTimeoutX);
18              }, 100);
19            }
20          }
21        },
22        play: function (event) {
23          if (event.target.nodeName == "VIDEO") {
24          }
25        }
26      }
27    });
28  });
29}
30var lazyload = function (imgs) {
31  let clientHeight = window.innerHeight;
32  for (let i = 0; i < imgs.length; i++) {
33    if (imgs[i].getBoundingClientRect().top <= clientHeight*1.5 && imgs[i].style.display != 'none') {
34      (function (i) {
35        let temp = new Image();
36        temp.onload = function () {
37        imgs[i].src = imgs[i].getAttribute('data-src');
38          let classX = imgs[i].getAttribute("class");
39          classX = classX.replace("lazy", "img-loaded");
40          imgs[i].setAttribute("class", classX);
41          if ($(imgs[i]).closest('.img-count').length > 0) {
42            let that = $(imgs[i]).closest('.img-count');
43            let setTimeoutX = setTimeout(function () {
44              commonjs.imgCount(that);
45              clearTimeout(setTimeoutX);
46            }, 100);
47          }
48        }
49        temp.src = imgs[i].getAttribute('data-src');
50      })(i)
51    }
52  }
53}
54var lazybgload = function (imgs) {
55  let clientHeight = window.innerHeight;
56  for (let i = 0; i < imgs.length; i++) {
57    if (imgs[i].getBoundingClientRect().top <= clientHeight*1.5 && imgs[i].style.display != 'none') {
58      (function (i) {
59        let temp = new Image();
60        temp.onload = function () {
61          imgs[i].style['background-image'] ="url('"+ imgs[i].getAttribute("data-bgsrc") +"')";
62          let classX = imgs[i].getAttribute("class");
63          classX = classX.replace("lazy-bgimg", "bgimg-loaded");
64          imgs[i].setAttribute("class", classX);
65        }
66        temp.src = imgs[i].getAttribute('data-bgsrc');
67      })(i)
68    }
69  }
70}
71var lazyVideoload = function (lazyVideos) {
72  var clientHeight = window.innerHeight;
73  lazyVideos.forEach(function (video) {
74    if (video.getBoundingClientRect().top <= clientHeight*1.5) {
75      for (var source in video.children) {
76        var videoSource = video.children[source];
77        if (typeof videoSource.tagName === "string" && videoSource.tagName === "SOURCE") {
78          videoSource.src = videoSource.getAttribute('data-src');
79        }
80      }
81      video.load();
82      var classVideo = video.getAttribute("class");
83      classVideo = classVideo.replace("lazy", "video-loaded");
84      video.setAttribute("class", classVideo);
85    }
86  });
87}
88var userAgent = navigator.userAgent;
89var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
90var isEdge = userAgent.indexOf("Edge") > -1 && !isIE;
91var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
92if (isIE || isIE11) {
93  let imgs =[].slice.call( document.querySelectorAll('img.lazy'));
94  lazyload(imgs)
95  let lazyVideos = [].slice.call(document.querySelectorAll("video.lazy"));
96  lazyVideoload(lazyVideos);
97  let bgimgs =[].slice.call( document.querySelectorAll('div.lazy-bgimg'));
98  lazybgload(bgimgs)
99  $(window).on('scroll', function () {
100    imgs =[].slice.call( document.querySelectorAll('img.lazy'));
101    if (imgs.length > 0) {
102      lazyload(imgs)
103    }
104    lazyVideos = [].slice.call(document.querySelectorAll("video.lazy"));
105    if (lazyVideos.length > 0) {
106      lazyVideoload(lazyVideos);
107    }
108    bgimgs =[].slice.call( document.querySelectorAll('div.lazy-bgimg'));
109    if (bgimgs.length > 0) {
110      lazybgload(bgimgs)
111    }
112  })
113} else {
114  lazyYall()
115  let bgimgs =[].slice.call( document.querySelectorAll('div.lazy-bgimg'));
116  lazybgload(bgimgs)
117  $(window).on('scroll', function () {
118    bgimgs =[].slice.call( document.querySelectorAll('div.lazy-bgimg'));
119    if (bgimgs.length > 0) {
120      lazybgload(bgimgs)
121    }
122  })
123}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.