trackad.js 1.5 KB

1
  1. !function(t,n,e){var a=!0,r={isVisible:function(t){var n=t.getBoundingClientRect(),e=n.width||n.right||0-n.left||0,a=n.height||n.bottom||0-n.top||0;return e>0&&a>0},isInSight:function(e){const a=e.parentNode,r=this.getDataset(a).pid,i=this.getDataset(e).src;if(-1!=n.cookie.indexOf("c_adb=")&&-1===i.indexOf("adBottom"))return!1;const c=t.innerWidth,s=["476","479","480"];if(c<1720&&-1!=s.indexOf(r))return!1;if("indexSuperise_"+r in localStorage)return!1;var o=e.getBoundingClientRect();if(this.isVisible(e)){var d=t.innerHeight;return o.top<=d+100}return!1},loadImg:function(t){var n=this;if(!t.src){var e=n.getDataset(t).src;t.src=e}},getDataset:function(t){if(t.dataset)return t.dataset;var n=t.attributes,e={};name,matchStr;for(var a=0;a<n.length;a++)matchStr=n[a].name.match(/^data-(.+)/),matchStr=n[a].name.match(/^data-(.+)/),matchStr&&(name=matchStr[1].replace(/-([\da-z])/gi,function(t,n){return n.toUpperCase()}),e[name]=n[a].value);return e},throttle:function(t){var n=null;return function(){var e=new Date,a=this,r=arguments;n||(n=e),e-n>=500&&(t.apply(a,r),n=e)}},checkImgs:function(){for(var t=this,n=e(".pre-img-lasy"),r=0;r<n.length;r++)t.isInSight(n[r])&&t.loadImg(n[r]);a=!0}};void 0===t.csdn&&(t.csdn={}),t.csdn.trackad=r,e(function(){csdn.trackad.checkImgs(),e(t).on("scroll",function(){a&&(a=!1,csdn.trackad.throttle(csdn.trackad.checkImgs()))}),e(t).on("resize",function(){e(this).width(),e(this).height();a&&(a=!1,csdn.trackad.throttle(csdn.trackad.checkImgs()))})})}(window,document,jQuery);