-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
1 lines (1 loc) · 1.02 KB
/
index.js
1
!function(){"use strict";angular.module("angular-lazy-loader",[]).directive("angularLazyLoad",["$window","$timeout","$rootScope",function(e,t,n){return{restrict:"EA",scope:!0,link:function(r,o,a){function i(){s=Array.prototype.slice.call(o[0].querySelectorAll("img[data-src], iframe[data-src], div[data-src]")),console.log(s),s.length>0&&l()}function c(e){var t=e.getBoundingClientRect();return t.bottom+g>=0&&t.left>=0&&t.top-g<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)}function l(){s=s.reduce(function(e,t){var n=t.getAttribute("data-src");if(!c(t))return e.push(t),e;switch(t.tagName){case"IMG":case"IFRAME":t.src=n;break;case"DIV":t.style.backgroundImage="url("+n+")";break;default:e.push(t)}return e},[])}function u(){t(i,0)}function d(){t(l,0)}var s=[],g=Number(a.threshold)||0;i(),r.$on("$includeContentLoaded",u),n.$on("selectiveLoad",u),angular.element(e).bind("scroll",d),angular.element(e).bind("resize",d),angular.element(o).bind("scroll",d)}}}])}();