-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathangular-virtual-scroll.min.js
1 lines (1 loc) · 5.1 KB
/
angular-virtual-scroll.min.js
1
/* angular-virtual-scroll - v0.6.0 - 2014-01-30 */ (function(){"use strict";angular.module("sf.virtualScroll",[])})(),function(){"use strict";var t=angular.module("sf.virtualScroll");t.filter("sublist",function(){return function(t,e,r){return t.slice(r,r+e)}})}(),function(){"use strict";var t=angular.module("sf.virtualScroll");t.directive("sfScroller",function(){function t(t){var e=t.match(/^(x|y)\s*(=|in)\s*(.+) to (.+)$/);if(!e)throw Error("Expected sfScroller in form of '_axis_ in _lower_ to _upper_' but got '"+t+"'.");return{axis:e[1],lower:e[3],upper:e[4]}}var e=18;return function(r,i,n){var o=t(n.sfScroller),l=r.$eval(o.lower),a=r.$eval(o.upper),c="x"===o.axis;i.css({height:c?"1em":"100%",width:c?"100%":"1em","overflow-x":c?"scroll":"hidden","overflow-y":c?"hidden":"scroll",position:"absolute",top:c?"100%":0,right:0}).parent().css({position:"relative"});var s=angular.element("<div></div>");i.append(s),i.bind("scroll",function(){var t=i.prop("scrollTop");n.ngModel&&r.$apply(n.ngModel+" = "+t/e)}),r.$watch(o.lower,function(t){l=t,s.css("height",(a-l)*e+"px")}),r.$watch(o.upper,function(t){a=t,s.css("height",(a-l)*e+"px")}),r.$watch(n.ngModel,function(t){var r=t*e;i.prop("scrollTop")!==r&&i.prop("scrollTop".scrollTop)})}})}(),function(){"use strict";function t(e,r,i){return angular.isArray(e)?angular.forEach(e,function(e){return t(e,r,i)}):Math.max(r,Math.min(e,i))}var e=angular.module("sf.virtualScroll"),r=["TABLE","TBODY","THEAD","TR","TFOOT"],i=["TABLE","TBODY","THEAD","TR","TFOOT"],n=["TABLE","TBODY","THEAD","TR","TFOOT"];e.directive("sfVirtualRepeat",["$log","$rootElement",function(e,o){function l(t){var e=t.match(/^\s*([\$\w]+)\s+in\s+([\S\s]*)$/);if(!e)throw Error("Expected sfVirtualRepeat in form of '_item_ in _collection_' but got '"+t+"'.");return{value:e[1],collection:e[2]}}function a(t,e){var r,i=t.tagName.toUpperCase();for(r=0;e.length>r;r++)if(e[r]===i)return!0;return!1}function c(t){var e,n,l=o[0];for(e=t.parent().parent()[0];e!==l&&1==e.nodeType;e=e.parentNode)if(!a(e,r)&&1==e.childElementCount&&!a(e.firstElementChild,i)){for(n=e.firstChild;n&&(3!=n.nodeType||!/\S/g.test(n.textContent));n=n.nextSibling);if(null==n)return{viewport:angular.element(e),content:angular.element(e.firstElementChild)}}throw Error("No suitable viewport element")}function s(t){var e={overflow:"auto"},r=window.getComputedStyle?window.getComputedStyle(t[0]):t[0].currentStyle,i=r&&r.getPropertyValue("max-height"),n=r&&r.getPropertyValue("height");i&&"0px"!==i?e.maxHeight=i:e.height=n&&"0px"!==n?n:window.innerHeight,t.css(e)}function u(t){var e={margin:0,padding:0,border:0,"box-sizing":"border-box"};t.css(e)}function f(t){var e=window.getComputedStyle?window.getComputedStyle(t):t.currentStyle,r=e&&e.getPropertyValue("max-height"),i=e&&e.getPropertyValue("height");if(i&&"0px"!==i&&"auto"!==i);else if(r&&"0px"!==r&&"none"!==r)i=r;else{if(!t.clientHeight)throw Error("Unable to compute height of row");i=t.clientHeight+"px"}return angular.element(t).css("height",i),parseInt(i,10)}function p(e,r,i){function o(e,r,o){function l(t){var e={margin:"0"};a(t[0],n)||(e.display="block"),$&&(e.height=$+"px"),t.css(e)}function h(t,e,r){var i=r.$new(),n=r.$eval(e);return i[p.value]=n[t],i.$index=t,i.$first=0===t,i.$last=t===n.length-1,i.$middle=!(i.$first||i.$last),i.$watch(function(){n=r.$eval(e),i[p.value]=n[t]}),i}function g(t,e,r,n,o){var a,c,s,u=document.createDocumentFragment(),f=[];for(c=t;c!==e;c++)s=h(c,r,n),a=i(s,angular.noop),l(a),f.push(a),u.appendChild(a[0]);return o.after(u),f}function v(){var e=t(E.firstActive,E.firstVisible-E.lowWater,E.firstVisible-E.highWater),r=t(E.firstActive+E.active,E.firstVisible+E.visible+E.lowWater,E.firstVisible+E.visible+E.highWater);E.firstActive=t(e,0,E.total-E.visible-E.lowWater),E.active=Math.min(r,E.total)-E.firstActive}function d(t){$&&e.$apply(function(){E.firstVisible=Math.floor(t.target.scrollTop/$),E.visible=Math.ceil(y.viewport[0].clientHeight/$),b=t.target.scrollTop+t.target.clientHeight>=t.target.scrollHeight,v()})}function m(t){var e=t.$eval(p.collection);return e.length!==E.total&&(E.total=e.length,v()),{start:E.firstActive,active:E.active,len:e.length}}function w(t,e){var r,i,n=Array.prototype[t];for(i=0;e>i;i++)r=n.call(T),r.scope().$destroy(),r.remove()}function x(t,e,i){var n,o=e.start+e.active;if(t===e)n=g(t.start,o,p.collection,i,r),T=n,T.length&&($=f(n[0][0]));else{var l=t.start+t.active,a=t.start>=e.start,c=a?t.start-e.start:e.start-t.start,s=l>=o?l-o:o-l,u=(a?e.active:t.active)>c;if(u){if(a?w("shift",c):c&&(n=g(t.start,e.start,p.collection,i,r),T=n.concat(T)),o>l)w("pop",o-l);else if(s){var h=T[T.length-1];n=g(o,l,p.collection,i,h),T=T.concat(n)}}else w("pop",T.length),T=g(t.start,l,p.collection,i,r);!$&&T.length&&($=f(T[0][0])),y.content.css({"padding-top":t.start*$+"px"})}y.content.css({height:t.len*$+"px"})}var T=[],$=0,b=!1,y=c(r),E="ngModel"in o?e.$eval(o.ngModel):{};E.firstActive=0,E.firstVisible=0,E.visible=0,E.active=0,E.total=0,E.lowWater=E.lowWater||100,E.highWater=E.highWater||300,u(y.content),s(y.viewport),y.viewport.bind("scroll",d),e.$watch(m,x,!0)}var p=l(r.sfVirtualRepeat);return{post:o}}return{require:"?ngModel",transclude:"element",priority:1e3,terminal:!0,compile:p}}])}();