angular-ui-scroll
Advanced tools
Comparing version 1.3.1 to 1.3.2
{ | ||
"name": "angular-ui-scroll", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"homepage": "https://github.com/angular-ui/ui-scroll.git", | ||
@@ -25,9 +25,7 @@ "description": "AngularJS infinite scrolling module", | ||
"test", | ||
"src/examples", | ||
"src/index.html", | ||
"demo", | ||
"**/.*", | ||
"Gruntfile.coffee", | ||
"package.json", | ||
"test.dat" | ||
"package.json" | ||
] | ||
} |
/*! | ||
* angular-ui-scroll | ||
* https://github.com/angular-ui/ui-scroll.git | ||
* Version: 1.3.1 -- 2015-08-05T13:39:04.079Z | ||
* Version: 1.3.2 -- 2015-09-03T13:52:16.202Z | ||
* License: MIT | ||
@@ -6,0 +6,0 @@ */ |
/*! | ||
* angular-ui-scroll | ||
* https://github.com/angular-ui/ui-scroll.git | ||
* Version: 1.3.1 -- 2015-08-05T13:39:04.079Z | ||
* Version: 1.3.2 -- 2015-09-03T13:52:16.202Z | ||
* License: MIT | ||
*/ | ||
!function(){"use strict";angular.module("ui.scroll.jqlite",["ui.scroll"]).service("jqLiteExtras",["$log","$window",function(a,b){return{registerFor:function(a){var c,d,e,f,g,h,i;return d=angular.element.prototype.css,a.prototype.css=function(a,b){var c,e;return e=this,c=e[0],c&&3!==c.nodeType&&8!==c.nodeType&&c.style?d.call(e,a,b):void 0},h=function(a){return a&&a.document&&a.location&&a.alert&&a.setInterval},i=function(a,b,c){var d,e,f,g,i;return d=a[0],i={top:["scrollTop","pageYOffset","scrollLeft"],left:["scrollLeft","pageXOffset","scrollTop"]}[b],e=i[0],g=i[1],f=i[2],h(d)?angular.isDefined(c)?d.scrollTo(a[f].call(a),c):g in d?d[g]:d.document.documentElement[e]:angular.isDefined(c)?d[e]=c:d[e]},b.getComputedStyle?(f=function(a){return b.getComputedStyle(a,null)},c=function(a,b){return parseFloat(b)}):(f=function(a){return a.currentStyle},c=function(a,b){var c,d,e,f,g,h,i;return c=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,f=new RegExp("^("+c+")(?!px)[a-z%]+$","i"),f.test(b)?(i=a.style,d=i.left,g=a.runtimeStyle,h=g&&g.left,g&&(g.left=i.left),i.left=b,e=i.pixelLeft,i.left=d,h&&(g.left=h),e):parseFloat(b)}),e=function(a,b){var d,e,g,i,j,k,l,m,n,o,p,q,r;return h(a)?(d=document.documentElement[{height:"clientHeight",width:"clientWidth"}[b]],{base:d,padding:0,border:0,margin:0}):(r={width:[a.offsetWidth,"Left","Right"],height:[a.offsetHeight,"Top","Bottom"]}[b],d=r[0],l=r[1],m=r[2],k=f(a),p=c(a,k["padding"+l])||0,q=c(a,k["padding"+m])||0,e=c(a,k["border"+l+"Width"])||0,g=c(a,k["border"+m+"Width"])||0,i=k["margin"+l],j=k["margin"+m],n=c(a,i)||0,o=c(a,j)||0,{base:d,padding:p+q,border:e+g,margin:n+o})},g=function(a,b,c){var d,g,h;return g=e(a,b),g.base>0?{base:g.base-g.padding-g.border,outer:g.base,outerfull:g.base+g.margin}[c]:(d=f(a),h=d[b],(0>h||null===h)&&(h=a.style[b]||0),h=parseFloat(h)||0,{base:h-g.padding-g.border,outer:h,outerfull:h+g.padding+g.border+g.margin}[c])},angular.forEach({before:function(a){var b,c,d,e,f,g,h;if(h=this,c=h[0],f=h.parent(),b=f.contents(),b[0]===c)return f.prepend(a);for(d=e=1,g=b.length-1;g>=1?g>=e:e>=g;d=g>=1?++e:--e)if(b[d]===c)return void angular.element(b[d-1]).after(a);throw new Error("invalid DOM structure "+c.outerHTML)},height:function(a){var b;return b=this,angular.isDefined(a)?(angular.isNumber(a)&&(a+="px"),d.call(b,"height",a)):g(this[0],"height","base")},outerHeight:function(a){return g(this[0],"height",a?"outerfull":"outer")},offset:function(a){var b,c,d,e,f,g;if(f=this,arguments.length){if(void 0===a)return f;throw new Error("offset setter method is not implemented")}return b={top:0,left:0},e=f[0],(c=e&&e.ownerDocument)?(d=c.documentElement,null!=e.getBoundingClientRect&&(b=e.getBoundingClientRect()),g=c.defaultView||c.parentWindow,{top:b.top+(g.pageYOffset||d.scrollTop)-(d.clientTop||0),left:b.left+(g.pageXOffset||d.scrollLeft)-(d.clientLeft||0)}):void 0},scrollTop:function(a){return i(this,"top",a)},scrollLeft:function(a){return i(this,"left",a)}},function(b,c){return a.prototype[c]?void 0:a.prototype[c]=b})}}}]).run(["$log","$window","jqLiteExtras",function(a,b,c){return b.jQuery?void 0:c.registerFor(angular.element)}])}(); |
/*! | ||
* angular-ui-scroll | ||
* https://github.com/angular-ui/ui-scroll.git | ||
* Version: 1.3.1 -- 2015-08-05T13:39:04.079Z | ||
* Version: 1.3.2 -- 2015-09-03T13:52:16.202Z | ||
* License: MIT | ||
@@ -46,3 +46,3 @@ */ | ||
return function($scope, element, $attr, controllers) { | ||
var adapter, adapterOnScope, adjustBuffer, applyUpdate, bof, bottomVisiblePos, buffer, bufferPadding, bufferSize, builder, clipBottom, clipTop, datasource, datasourceName, dismissPendingRequests, enqueueFetch, eof, eventListener, fetch, finalize, first, insertElement, insertElementAnimated, insertItem, isDatasourceValid, itemName, loading, log, match, next, pending, reload, removeFromBuffer, removeItem, resizeAndScrollHandler, ridActual, scrollHeight, shouldLoadBottom, shouldLoadTop, topVisible, topVisiblePos, unsupportedMethod, viewport, viewportScope, wheelHandler; | ||
var adapter, adapterOnScope, adjustBuffer, adjustBufferAfterFetch, applyUpdate, bof, bottomVisiblePos, buffer, bufferPadding, bufferSize, builder, calculateTopProperties, clipBottom, clipTop, datasource, datasourceName, dismissPendingRequests, enqueueFetch, eof, eventListener, fetch, first, insertElement, insertElementAnimated, insertItem, insertWrapperContent, isAngularVersionLessThen1_3, isDatasourceValid, isElementVisible, itemName, loading, log, match, next, pending, processBufferedItems, reload, removeFromBuffer, removeItem, resizeAndScrollHandler, ridActual, scrollHeight, shouldLoadBottom, shouldLoadTop, topVisible, topVisiblePos, unsupportedMethod, viewport, viewportScope, visibilityWatcher, wheelHandler; | ||
log = console.debug || console.log; | ||
@@ -80,3 +80,4 @@ if (!(match = $attr.uiScroll.match(/^\s*(\w+)\s+in\s+([\w\.]+)\s*$/))) { | ||
bof = false; | ||
removeItem = $animate ? angular.version.minor === 2 ? function(wrapper) { | ||
isAngularVersionLessThen1_3 = angular.version.major === 1 && angular.version.minor < 3; | ||
removeItem = $animate ? isAngularVersionLessThen1_3 ? function(wrapper) { | ||
var deferred; | ||
@@ -104,6 +105,6 @@ buffer.splice(buffer.indexOf(wrapper), 1); | ||
insertElement = function(newElement, previousElement) { | ||
element.after.apply(previousElement, newElement); | ||
element.after.apply(previousElement, [newElement]); | ||
return []; | ||
}; | ||
insertElementAnimated = $animate ? angular.version.minor === 2 ? function(newElement, previousElement) { | ||
insertElementAnimated = $animate ? isAngularVersionLessThen1_3 ? function(newElement, previousElement) { | ||
var deferred; | ||
@@ -118,4 +119,5 @@ deferred = $q.defer(); | ||
} : insertElement; | ||
linker($scope.$new(), function(template) { | ||
linker($scope.$new(), function(template, scope) { | ||
var bottomPadding, padding, repeaterType, topPadding, viewport; | ||
scope.$destroy(); | ||
repeaterType = template[0].localName; | ||
@@ -335,59 +337,114 @@ if (repeaterType === 'dl') { | ||
}; | ||
adjustBuffer = function(rid, finalize) { | ||
var promises, toBePrepended, toBeRemoved; | ||
isElementVisible = function(wrapper) { | ||
return wrapper.element.height() && wrapper.element[0].offsetParent; | ||
}; | ||
visibilityWatcher = function(wrapper) { | ||
var item, j, len; | ||
if (isElementVisible(wrapper)) { | ||
for (j = 0, len = buffer.length; j < len; j++) { | ||
item = buffer[j]; | ||
item.unregisterVisibilityWatcher(); | ||
delete item.unregisterVisibilityWatcher; | ||
} | ||
return adjustBuffer(); | ||
} | ||
}; | ||
insertWrapperContent = function(wrapper, sibling) { | ||
builder.insertElement(wrapper.element, sibling); | ||
if (isElementVisible(wrapper)) { | ||
return true; | ||
} | ||
wrapper.unregisterVisibilityWatcher = wrapper.scope.$watch(function() { | ||
return visibilityWatcher(wrapper); | ||
}); | ||
return false; | ||
}; | ||
processBufferedItems = function(rid) { | ||
var bottomPos, heightIncrement, i, item, j, k, keepFetching, l, len, len1, len2, len3, m, promises, toBePrepended, toBeRemoved, wrapper; | ||
promises = []; | ||
toBePrepended = []; | ||
toBeRemoved = []; | ||
return $timeout(function() { | ||
var bottomPos, heightIncrement, i, item, itemHeight, itemTop, j, k, l, len, len1, len2, len3, len4, m, n, newRow, rowTop, topHeight, wrapper; | ||
bottomPos = builder.bottomDataPos(); | ||
for (i = j = 0, len = buffer.length; j < len; i = ++j) { | ||
wrapper = buffer[i]; | ||
switch (wrapper.op) { | ||
case 'prepend': | ||
toBePrepended.unshift(wrapper); | ||
break; | ||
case 'append': | ||
if (i === 0) { | ||
keepFetching = insertWrapperContent(wrapper) || keepFetching; | ||
} else { | ||
keepFetching = insertWrapperContent(wrapper, buffer[i - 1].element) || keepFetching; | ||
} | ||
wrapper.op = 'none'; | ||
break; | ||
case 'insert': | ||
if (i === 0) { | ||
promises = promises.concat(builder.insertElementAnimated(wrapper.element)); | ||
} else { | ||
promises = promises.concat(builder.insertElementAnimated(wrapper.element, buffer[i - 1].element)); | ||
} | ||
wrapper.op = 'none'; | ||
break; | ||
case 'remove': | ||
toBeRemoved.push(wrapper); | ||
} | ||
} | ||
for (k = 0, len1 = toBeRemoved.length; k < len1; k++) { | ||
wrapper = toBeRemoved[k]; | ||
promises = promises.concat(removeItem(wrapper)); | ||
} | ||
builder.bottomPadding(Math.max(0, builder.bottomPadding() - (builder.bottomDataPos() - bottomPos))); | ||
if (toBePrepended.length) { | ||
bottomPos = builder.bottomDataPos(); | ||
for (i = j = 0, len = buffer.length; j < len; i = ++j) { | ||
wrapper = buffer[i]; | ||
switch (wrapper.op) { | ||
case 'prepend': | ||
toBePrepended.unshift(wrapper); | ||
break; | ||
case 'append': | ||
if (i === 0) { | ||
builder.insertElement(wrapper.element); | ||
} else { | ||
builder.insertElement(wrapper.element, buffer[i - 1].element); | ||
} | ||
wrapper.op = 'none'; | ||
break; | ||
case 'insert': | ||
if (i === 0) { | ||
promises = promises.concat(builder.insertElementAnimated(wrapper.element)); | ||
} else { | ||
promises = promises.concat(builder.insertElementAnimated(wrapper.element, buffer[i - 1].element)); | ||
} | ||
wrapper.op = 'none'; | ||
break; | ||
case 'remove': | ||
toBeRemoved.push(wrapper); | ||
} | ||
for (l = 0, len2 = toBePrepended.length; l < len2; l++) { | ||
wrapper = toBePrepended[l]; | ||
keepFetching = insertWrapperContent(wrapper) || keepFetching; | ||
wrapper.op = 'none'; | ||
} | ||
for (k = 0, len1 = toBeRemoved.length; k < len1; k++) { | ||
wrapper = toBeRemoved[k]; | ||
promises = promises.concat(removeItem(wrapper)); | ||
heightIncrement = builder.bottomDataPos() - bottomPos; | ||
if (builder.topPadding() >= heightIncrement) { | ||
builder.topPadding(builder.topPadding() - heightIncrement); | ||
} else { | ||
viewport.scrollTop(viewport.scrollTop() + heightIncrement); | ||
} | ||
builder.bottomPadding(Math.max(0, builder.bottomPadding() - (builder.bottomDataPos() - bottomPos))); | ||
if (toBePrepended.length) { | ||
bottomPos = builder.bottomDataPos(); | ||
for (l = 0, len2 = toBePrepended.length; l < len2; l++) { | ||
wrapper = toBePrepended[l]; | ||
builder.insertElement(wrapper.element); | ||
wrapper.op = 'none'; | ||
} | ||
for (i = m = 0, len3 = buffer.length; m < len3; i = ++m) { | ||
item = buffer[i]; | ||
item.scope.$index = first + i; | ||
} | ||
if (promises.length) { | ||
$q.all(promises).then(function() { | ||
return adjustBuffer(rid); | ||
}); | ||
} | ||
return keepFetching; | ||
}; | ||
calculateTopProperties = function() { | ||
var item, itemHeight, itemTop, j, len, newRow, results, rowTop, topHeight; | ||
topHeight = 0; | ||
results = []; | ||
for (j = 0, len = buffer.length; j < len; j++) { | ||
item = buffer[j]; | ||
itemTop = item.element.offset().top; | ||
newRow = rowTop !== itemTop; | ||
rowTop = itemTop; | ||
if (newRow) { | ||
itemHeight = item.element.outerHeight(true); | ||
} | ||
if (newRow && (builder.topDataPos() + topHeight + itemHeight < topVisiblePos())) { | ||
results.push(topHeight += itemHeight); | ||
} else { | ||
if (newRow) { | ||
topVisible(item); | ||
} | ||
heightIncrement = builder.bottomDataPos() - bottomPos; | ||
if (builder.topPadding() >= heightIncrement) { | ||
builder.topPadding(builder.topPadding() - heightIncrement); | ||
} else { | ||
viewport.scrollTop(viewport.scrollTop() + heightIncrement); | ||
} | ||
break; | ||
} | ||
for (i = m = 0, len3 = buffer.length; m < len3; i = ++m) { | ||
item = buffer[i]; | ||
item.scope.$index = first + i; | ||
} | ||
} | ||
return results; | ||
}; | ||
adjustBuffer = function(rid) { | ||
return $timeout(function() { | ||
processBufferedItems(rid); | ||
if (shouldLoadBottom()) { | ||
@@ -400,37 +457,26 @@ enqueueFetch(rid, true); | ||
} | ||
if (finalize) { | ||
finalize(rid); | ||
if (pending.length === 0) { | ||
return calculateTopProperties(); | ||
} | ||
if (pending.length === 0) { | ||
topHeight = 0; | ||
for (n = 0, len4 = buffer.length; n < len4; n++) { | ||
item = buffer[n]; | ||
itemTop = item.element.offset().top; | ||
newRow = rowTop !== itemTop; | ||
rowTop = itemTop; | ||
if (newRow) { | ||
itemHeight = item.element.outerHeight(true); | ||
}); | ||
}; | ||
adjustBufferAfterFetch = function(rid) { | ||
return $timeout(function() { | ||
var keepFetching; | ||
keepFetching = processBufferedItems(rid); | ||
if (shouldLoadBottom()) { | ||
if (keepFetching) { | ||
enqueueFetch(rid, true); | ||
} | ||
} else { | ||
if (shouldLoadTop()) { | ||
if (keepFetching || pending[0]) { | ||
enqueueFetch(rid, false); | ||
} | ||
if (newRow && (builder.topDataPos() + topHeight + itemHeight < topVisiblePos())) { | ||
topHeight += itemHeight; | ||
} else { | ||
if (newRow) { | ||
topVisible(item); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
if (promises.length) { | ||
return $q.all(promises).then(function() { | ||
return adjustBuffer(rid); | ||
}); | ||
} | ||
}); | ||
}; | ||
finalize = function(rid) { | ||
return adjustBuffer(rid, function() { | ||
pending.shift(); | ||
if (pending.length === 0) { | ||
return loading(false); | ||
loading(false); | ||
return calculateTopProperties(); | ||
} else { | ||
@@ -444,3 +490,3 @@ return fetch(rid); | ||
if (buffer.length && !shouldLoadBottom()) { | ||
return finalize(rid); | ||
return adjustBufferAfterFetch(rid); | ||
} else { | ||
@@ -464,3 +510,3 @@ return datasource.get(next, bufferSize, function(result) { | ||
} | ||
return finalize(rid); | ||
return adjustBufferAfterFetch(rid); | ||
}); | ||
@@ -470,3 +516,3 @@ } | ||
if (buffer.length && !shouldLoadTop()) { | ||
return finalize(rid); | ||
return adjustBufferAfterFetch(rid); | ||
} else { | ||
@@ -491,3 +537,3 @@ return datasource.get(first - bufferSize, bufferSize, function(result) { | ||
} | ||
return finalize(rid); | ||
return adjustBufferAfterFetch(rid); | ||
}); | ||
@@ -494,0 +540,0 @@ } |
/*! | ||
* angular-ui-scroll | ||
* https://github.com/angular-ui/ui-scroll.git | ||
* Version: 1.3.1 -- 2015-08-05T13:39:04.079Z | ||
* Version: 1.3.2 -- 2015-09-03T13:52:16.202Z | ||
* License: MIT | ||
*/ | ||
!function(){"use strict";angular.module("ui.scroll",[]).directive("uiScrollViewport",function(){return{controller:["$scope","$element",function(a,b){return this.viewport=b,this}]}}).directive("uiScroll",["$log","$injector","$rootScope","$timeout","$q","$parse",function(a,b,c,d,e,f){var g;return b.has&&b.has("$animate")&&(g=b.get("$animate")),{require:["?^uiScrollViewport"],transclude:"element",priority:1e3,terminal:!0,compile:function(h,i,j){return function(h,i,k,l){var m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,_,aa,ba,ca;if(N=a.debug||a.log,!(O=k.uiScroll.match(/^\s*(\w+)\s+in\s+([\w\.]+)\s*$/)))throw new Error("Expected uiScroll in form of '_item_ in _datasource_' but got ' + $attr.uiScroll + '");if(L=O[1],z=O[2],y=f(z)(h),K=function(){return angular.isObject(y)&&angular.isFunction(y.get)},!K()&&(y=b.get(z),!K()))throw new Error(z+" is not a valid datasource");return u=Math.max(3,+k.bufferSize||10),t=function(){return aa.outerHeight()*Math.max(.1,+k.padding||.1)},W=function(a){var b;return null!=(b=a[0].scrollHeight)?b:a[0].document.documentElement.scrollHeight},v=null,V=0,G=1,P=1,s=[],Q=[],C=!1,q=!1,T=g?2===angular.version.minor?function(a){var b;return s.splice(s.indexOf(a),1),b=e.defer(),g.leave(a.element,function(){return a.scope.$destroy(),b.resolve()}),[b.promise]}:function(a){return s.splice(s.indexOf(a),1),[g.leave(a.element).then(function(){return a.scope.$destroy()})]}:function(a){return s.splice(s.indexOf(a),1),a.element.remove(),a.scope.$destroy(),[]},H=function(a,b){return i.after.apply(b,a),[]},I=g?2===angular.version.minor?function(a,b){var c;return c=e.defer(),g.enter(a,i,b,function(){return c.resolve()}),[c.promise]}:function(a,b){return[g.enter(a,i,b)]}:H,j(h.$new(),function(a){var b,c,d,e,f;if(d=a[0].localName,"dl"===d)throw new Error("ui-scroll directive does not support <"+a[0].localName+"> as a repeating tag: "+a[0].outerHTML);return"li"!==d&&"tr"!==d&&(d="div"),f=l[0]&&l[0].viewport?l[0].viewport:angular.element(window),f.css({"overflow-y":"auto",display:"block"}),c=function(a){var b,c,d;switch(a){case"tr":d=angular.element("<table><tr><td><div></div></td></tr></table>"),b=d.find("div"),c=d.find("tr"),c.paddingHeight=function(){return b.height.apply(b,arguments)};break;default:c=angular.element("<"+a+"></"+a+">"),c.paddingHeight=c.height}return c},e=c(d),i.before(e),b=c(d),i.after(b),h.$on("$destroy",function(){return a.remove()}),v={viewport:f,topPadding:function(){return e.paddingHeight.apply(e,arguments)},bottomPadding:function(){return b.paddingHeight.apply(b,arguments)},bottomDataPos:function(){return W(f)-b.paddingHeight()},topDataPos:function(){return e.paddingHeight()},insertElement:function(a,b){return H(a,b||e)},insertElementAnimated:function(a,b){return I(a,b||e)}}}),aa=v.viewport,ba=aa.scope()||c,Z=function(a){return m.topVisible=a.scope[L],m.topVisibleElement=a.element,m.topVisibleScope=a.scope,k.topVisible&&f(k.topVisible).assign(ba,m.topVisible),k.topVisibleElement&&f(k.topVisibleElement).assign(ba,m.topVisibleElement),k.topVisibleScope&&f(k.topVisibleScope).assign(ba,m.topVisibleScope),angular.isFunction(y.topVisible)?y.topVisible(a):void 0},M=function(a){return m.isLoading=a,k.isLoading&&f(k.isLoading).assign(h,a),angular.isFunction(y.loading)?y.loading(a):void 0},S=function(a,b){var c,d,e,f;for(c=d=e=a,f=b;f>=e?f>d:d>f;c=f>=e?++d:--d)s[c].scope.$destroy(),s[c].element.remove();return s.splice(a,b-a)},A=function(){return V++,Q=[]},R=function(){return A(),G=1,P=1,S(0,s.length),v.topPadding(0),v.bottomPadding(0),C=!1,q=!1,o(V)},r=function(){return aa.scrollTop()+aa.outerHeight()},$=function(){return aa.scrollTop()},X=function(){return!C&&v.bottomDataPos()<r()+t()},w=function(){var a,b,c,d,e,f,g,h,i,j;for(a=0,h=0,b=f=i=s.length-1;0>=i?0>=f:f>=0;b=0>=i?++f:--f)if(c=s[b],e=c.element.offset().top,g=j!==e,j=e,g&&(d=c.element.outerHeight(!0)),v.bottomDataPos()-a-d>r()+t())g&&(a+=d),h++,C=!1;else{if(g)break;h++}return h>0?(v.bottomPadding(v.bottomPadding()+a),S(s.length-h,s.length),P-=h):void 0},Y=function(){return!q&&v.topDataPos()>$()-t()},x=function(){var a,b,c,d,e,f,g,h,i;for(i=0,g=0,d=0,e=s.length;e>d;d++)if(a=s[d],c=a.element.offset().top,f=h!==c,h=c,f&&(b=a.element.outerHeight(!0)),v.topDataPos()+i+b<$()-t())f&&(i+=b),g++,q=!1;else{if(f)break;g++}return g>0?(v.topPadding(v.topPadding()+i),S(0,g),G+=g):void 0},B=function(a,b){return m.isLoading||M(!0),1===Q.push(b)?E(a):void 0},J=function(a,b){var c,d;if(c=h.$new(),c[L]=b,d={scope:c},j(c,function(a){return d.element=a}),a%1===0)return d.op="insert",s.splice(a,0,d);switch(d.op=a,a){case"append":return s.push(d);case"prepend":return s.unshift(d)}},o=function(a,b){var c,f,g;return c=[],f=[],g=[],d(function(){var d,h,i,j,k,l,m,n,p,q,r,t,u,w,x,y,z,A,C,D;for(d=v.bottomDataPos(),i=m=0,q=s.length;q>m;i=++m)switch(D=s[i],D.op){case"prepend":f.unshift(D);break;case"append":0===i?v.insertElement(D.element):v.insertElement(D.element,s[i-1].element),D.op="none";break;case"insert":c=0===i?c.concat(v.insertElementAnimated(D.element)):c.concat(v.insertElementAnimated(D.element,s[i-1].element)),D.op="none";break;case"remove":g.push(D)}for(n=0,r=g.length;r>n;n++)D=g[n],c=c.concat(T(D));if(v.bottomPadding(Math.max(0,v.bottomPadding()-(v.bottomDataPos()-d))),f.length){for(d=v.bottomDataPos(),p=0,t=f.length;t>p;p++)D=f[p],v.insertElement(D.element),D.op="none";h=v.bottomDataPos()-d,v.topPadding()>=h?v.topPadding(v.topPadding()-h):aa.scrollTop(aa.scrollTop()+h)}for(i=x=0,u=s.length;u>x;i=++x)j=s[i],j.scope.$index=G+i;if(X()?B(a,!0):Y()&&B(a,!1),b&&b(a),0===Q.length)for(C=0,y=0,w=s.length;w>y;y++){if(j=s[y],l=j.element.offset().top,z=A!==l,A=l,z&&(k=j.element.outerHeight(!0)),!(z&&v.topDataPos()+C+k<$())){z&&Z(j);break}C+=k}return c.length?e.all(c).then(function(){return o(a)}):void 0})},F=function(a){return o(a,function(){return Q.shift(),0===Q.length?M(!1):E(a)})},E=function(a){return Q[0]?s.length&&!X()?F(a):y.get(P,u,function(b){var c,d,e;if(!(a&&a!==V||h.$$destroyed)){if(b.length<u&&(C=!0,v.bottomPadding(0)),b.length>0)for(x(),d=0,e=b.length;e>d;d++)c=b[d],++P,J("append",c);return F(a)}}):s.length&&!Y()?F(a):y.get(G-u,u,function(b){var c,d,e;if(!(a&&a!==V||h.$$destroyed)){if(b.length<u&&(q=!0,v.topPadding(0)),b.length>0)for(s.length&&w(),c=d=e=b.length-1;0>=e?0>=d:d>=0;c=0>=e?++d:--d)--G,J("prepend",b[c]);return F(a)}})},U=function(){return c.$$phase||m.isLoading?void 0:(o(),h.$apply())},ca=function(a){var b,c;return b=aa[0].scrollTop,c=aa[0].scrollHeight-aa[0].clientHeight,0===b&&!q||b===c&&!C?a.preventDefault():void 0},aa.bind("resize",U),aa.bind("scroll",U),aa.bind("mousewheel",ca),h.$watch(y.revision,R),h.$on("$destroy",function(){var a,b,c;for(b=0,c=s.length;c>b;b++)a=s[b],a.scope.$destroy(),a.element.remove();return aa.unbind("resize",U),aa.unbind("scroll",U),aa.unbind("mousewheel",ca)}),m={},m.isLoading=!1,m.reload=R,p=function(a,b){var c,d,e,f,g,h,i;if(angular.isArray(b)){for(h=s.indexOf(a)+1,i=b.reverse(),c=d=0,f=i.length;f>d;c=++d)g=i[c],g===a.scope[L]?(e=!0,h--):J(h,g);if(!e)return a.op="remove"}},m.applyUpdates=function(a,b){var c,d,e,f,g,h;if(A(),angular.isFunction(a))for(c=s.slice(0),d=e=0,f=c.length;f>e;d=++e)h=c[d],p(h,a(h.scope[L],h.scope,h.element));else{if(a%1!==0)throw new Error("applyUpdates - "+a+" is not a valid index");0<=(g=a-G)&&g<s.length&&p(s[a-G],b)}return o(V)},m.append=function(a){var b,c,d;for(A(),c=0,d=a.length;d>c;c++)b=a[c],++P,J("append",b);return o(V)},m.prepend=function(a){var b,c,d,e;for(A(),e=a.reverse(),c=0,d=e.length;d>c;c++)b=e[c],--G,J("prepend",b);return o(V)},k.adapter&&(n=f(k.adapter)(h),n||(f(k.adapter).assign(h,{}),n=f(k.adapter)(h)),angular.extend(n,m),m=n),_=function(a){throw new Error(a+" event is no longer supported - use applyUpdates instead")},D=y.scope?y.scope.$new():h.$new(),D.$on("insert.item",function(){return _("insert")}),D.$on("update.items",function(){return _("update")}),D.$on("delete.items",function(){return _("delete")})}}}}])}(); | ||
!function(){"use strict";angular.module("ui.scroll",[]).directive("uiScrollViewport",function(){return{controller:["$scope","$element",function(a,b){return this.viewport=b,this}]}}).directive("uiScroll",["$log","$injector","$rootScope","$timeout","$q","$parse",function(a,b,c,d,e,f){var g;return b.has&&b.has("$animate")&&(g=b.get("$animate")),{require:["?^uiScrollViewport"],transclude:"element",priority:1e3,terminal:!0,compile:function(h,i,j){return function(h,i,k,l){var m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,_,aa,ba,ca,da,ea,fa,ga,ha,ia;if(R=a.debug||a.log,!(S=k.uiScroll.match(/^\s*(\w+)\s+in\s+([\w\.]+)\s*$/)))throw new Error("Expected uiScroll in form of '_item_ in _datasource_' but got ' + $attr.uiScroll + '");if(P=S[1],B=S[2],A=f(B)(h),N=function(){return angular.isObject(A)&&angular.isFunction(A.get)},!N()&&(A=b.get(B),!N()))throw new Error(B+" is not a valid datasource");return v=Math.max(3,+k.bufferSize||10),u=function(){return fa.outerHeight()*Math.max(.1,+k.padding||.1)},_=function(a){var b;return null!=(b=a[0].scrollHeight)?b:a[0].document.documentElement.scrollHeight},w=null,$=0,H=1,T=1,t=[],U=[],E=!1,r=!1,M=1===angular.version.major&&angular.version.minor<3,Y=g?M?function(a){var b;return t.splice(t.indexOf(a),1),b=e.defer(),g.leave(a.element,function(){return a.scope.$destroy(),b.resolve()}),[b.promise]}:function(a){return t.splice(t.indexOf(a),1),[g.leave(a.element).then(function(){return a.scope.$destroy()})]}:function(a){return t.splice(t.indexOf(a),1),a.element.remove(),a.scope.$destroy(),[]},I=function(a,b){return i.after.apply(b,[a]),[]},J=g?M?function(a,b){var c;return c=e.defer(),g.enter(a,i,b,function(){return c.resolve()}),[c.promise]}:function(a,b){return[g.enter(a,i,b)]}:I,j(h.$new(),function(a,b){var c,d,e,f,g;if(b.$destroy(),e=a[0].localName,"dl"===e)throw new Error("ui-scroll directive does not support <"+a[0].localName+"> as a repeating tag: "+a[0].outerHTML);return"li"!==e&&"tr"!==e&&(e="div"),g=l[0]&&l[0].viewport?l[0].viewport:angular.element(window),g.css({"overflow-y":"auto",display:"block"}),d=function(a){var b,c,d;switch(a){case"tr":d=angular.element("<table><tr><td><div></div></td></tr></table>"),b=d.find("div"),c=d.find("tr"),c.paddingHeight=function(){return b.height.apply(b,arguments)};break;default:c=angular.element("<"+a+"></"+a+">"),c.paddingHeight=c.height}return c},f=d(e),i.before(f),c=d(e),i.after(c),h.$on("$destroy",function(){return a.remove()}),w={viewport:g,topPadding:function(){return f.paddingHeight.apply(f,arguments)},bottomPadding:function(){return c.paddingHeight.apply(c,arguments)},bottomDataPos:function(){return _(g)-c.paddingHeight()},topDataPos:function(){return f.paddingHeight()},insertElement:function(a,b){return I(a,b||f)},insertElementAnimated:function(a,b){return J(a,b||f)}}}),fa=w.viewport,ga=fa.scope()||c,ca=function(a){return m.topVisible=a.scope[P],m.topVisibleElement=a.element,m.topVisibleScope=a.scope,k.topVisible&&f(k.topVisible).assign(ga,m.topVisible),k.topVisibleElement&&f(k.topVisibleElement).assign(ga,m.topVisibleElement),k.topVisibleScope&&f(k.topVisibleScope).assign(ga,m.topVisibleScope),angular.isFunction(A.topVisible)?A.topVisible(a):void 0},Q=function(a){return m.isLoading=a,k.isLoading&&f(k.isLoading).assign(h,a),angular.isFunction(A.loading)?A.loading(a):void 0},X=function(a,b){var c,d,e,f;for(c=d=e=a,f=b;f>=e?f>d:d>f;c=f>=e?++d:--d)t[c].scope.$destroy(),t[c].element.remove();return t.splice(a,b-a)},C=function(){return $++,U=[]},W=function(){return C(),H=1,T=1,X(0,t.length),w.topPadding(0),w.bottomPadding(0),E=!1,r=!1,o($)},s=function(){return fa.scrollTop()+fa.outerHeight()},da=function(){return fa.scrollTop()},aa=function(){return!E&&w.bottomDataPos()<s()+u()},y=function(){var a,b,c,d,e,f,g,h,i,j;for(a=0,h=0,b=f=i=t.length-1;0>=i?0>=f:f>=0;b=0>=i?++f:--f)if(c=t[b],e=c.element.offset().top,g=j!==e,j=e,g&&(d=c.element.outerHeight(!0)),w.bottomDataPos()-a-d>s()+u())g&&(a+=d),h++,E=!1;else{if(g)break;h++}return h>0?(w.bottomPadding(w.bottomPadding()+a),X(t.length-h,t.length),T-=h):void 0},ba=function(){return!r&&w.topDataPos()>da()-u()},z=function(){var a,b,c,d,e,f,g,h,i;for(i=0,g=0,d=0,e=t.length;e>d;d++)if(a=t[d],c=a.element.offset().top,f=h!==c,h=c,f&&(b=a.element.outerHeight(!0)),w.topDataPos()+i+b<da()-u())f&&(i+=b),g++,r=!1;else{if(f)break;g++}return g>0?(w.topPadding(w.topPadding()+i),X(0,g),H+=g):void 0},D=function(a,b){return m.isLoading||Q(!0),1===U.push(b)?G(a):void 0},K=function(a,b){var c,d;if(c=h.$new(),c[P]=b,d={scope:c},j(c,function(a){return d.element=a}),a%1===0)return d.op="insert",t.splice(a,0,d);switch(d.op=a,a){case"append":return t.push(d);case"prepend":return t.unshift(d)}},O=function(a){return a.element.height()&&a.element[0].offsetParent},ha=function(a){var b,c,d;if(O(a)){for(c=0,d=t.length;d>c;c++)b=t[c],b.unregisterVisibilityWatcher(),delete b.unregisterVisibilityWatcher;return o()}},L=function(a,b){return w.insertElement(a.element,b),O(a)?!0:(a.unregisterVisibilityWatcher=a.scope.$watch(function(){return ha(a)}),!1)},V=function(a){var b,c,d,f,g,h,i,j,k,l,m,n,p,q,r,s,u;for(q=[],r=[],s=[],b=w.bottomDataPos(),d=g=0,k=t.length;k>g;d=++g)switch(u=t[d],u.op){case"prepend":r.unshift(u);break;case"append":i=0===d?L(u)||i:L(u,t[d-1].element)||i,u.op="none";break;case"insert":q=0===d?q.concat(w.insertElementAnimated(u.element)):q.concat(w.insertElementAnimated(u.element,t[d-1].element)),u.op="none";break;case"remove":s.push(u)}for(h=0,l=s.length;l>h;h++)u=s[h],q=q.concat(Y(u));if(w.bottomPadding(Math.max(0,w.bottomPadding()-(w.bottomDataPos()-b))),r.length){for(b=w.bottomDataPos(),j=0,m=r.length;m>j;j++)u=r[j],i=L(u)||i,u.op="none";c=w.bottomDataPos()-b,w.topPadding()>=c?w.topPadding(w.topPadding()-c):fa.scrollTop(fa.scrollTop()+c)}for(d=p=0,n=t.length;n>p;d=++p)f=t[d],f.scope.$index=H+d;return q.length&&e.all(q).then(function(){return o(a)}),i},x=function(){var a,b,c,d,e,f,g,h,i;for(i=0,g=[],d=0,e=t.length;e>d;d++){if(a=t[d],c=a.element.offset().top,f=h!==c,h=c,f&&(b=a.element.outerHeight(!0)),!(f&&w.topDataPos()+i+b<da())){f&&ca(a);break}g.push(i+=b)}return g},o=function(a){return d(function(){return V(a),aa()?D(a,!0):ba()&&D(a,!1),0===U.length?x():void 0})},p=function(a){return d(function(){var b;return b=V(a),aa()?b&&D(a,!0):ba()&&(b||U[0])&&D(a,!1),U.shift(),0===U.length?(Q(!1),x()):G(a)})},G=function(a){return U[0]?t.length&&!aa()?p(a):A.get(T,v,function(b){var c,d,e;if(!(a&&a!==$||h.$$destroyed)){if(b.length<v&&(E=!0,w.bottomPadding(0)),b.length>0)for(z(),d=0,e=b.length;e>d;d++)c=b[d],++T,K("append",c);return p(a)}}):t.length&&!ba()?p(a):A.get(H-v,v,function(b){var c,d,e;if(!(a&&a!==$||h.$$destroyed)){if(b.length<v&&(r=!0,w.topPadding(0)),b.length>0)for(t.length&&y(),c=d=e=b.length-1;0>=e?0>=d:d>=0;c=0>=e?++d:--d)--H,K("prepend",b[c]);return p(a)}})},Z=function(){return c.$$phase||m.isLoading?void 0:(o(),h.$apply())},ia=function(a){var b,c;return b=fa[0].scrollTop,c=fa[0].scrollHeight-fa[0].clientHeight,0===b&&!r||b===c&&!E?a.preventDefault():void 0},fa.bind("resize",Z),fa.bind("scroll",Z),fa.bind("mousewheel",ia),h.$watch(A.revision,W),h.$on("$destroy",function(){var a,b,c;for(b=0,c=t.length;c>b;b++)a=t[b],a.scope.$destroy(),a.element.remove();return fa.unbind("resize",Z),fa.unbind("scroll",Z),fa.unbind("mousewheel",ia)}),m={},m.isLoading=!1,m.reload=W,q=function(a,b){var c,d,e,f,g,h,i;if(angular.isArray(b)){for(h=t.indexOf(a)+1,i=b.reverse(),c=d=0,f=i.length;f>d;c=++d)g=i[c],g===a.scope[P]?(e=!0,h--):K(h,g);if(!e)return a.op="remove"}},m.applyUpdates=function(a,b){var c,d,e,f,g,h;if(C(),angular.isFunction(a))for(c=t.slice(0),d=e=0,f=c.length;f>e;d=++e)h=c[d],q(h,a(h.scope[P],h.scope,h.element));else{if(a%1!==0)throw new Error("applyUpdates - "+a+" is not a valid index");0<=(g=a-H)&&g<t.length&&q(t[a-H],b)}return o($)},m.append=function(a){var b,c,d;for(C(),c=0,d=a.length;d>c;c++)b=a[c],++T,K("append",b);return o($)},m.prepend=function(a){var b,c,d,e;for(C(),e=a.reverse(),c=0,d=e.length;d>c;c++)b=e[c],--H,K("prepend",b);return o($)},k.adapter&&(n=f(k.adapter)(h),n||(f(k.adapter).assign(h,{}),n=f(k.adapter)(h)),angular.extend(n,m),m=n),ea=function(a){throw new Error(a+" event is no longer supported - use applyUpdates instead")},F=A.scope?A.scope.$new():h.$new(),F.$on("insert.item",function(){return ea("insert")}),F.$on("update.items",function(){return ea("update")}),F.$on("delete.items",function(){return ea("delete")})}}}}])}(); |
{ | ||
"name": "angular-ui-scroll", | ||
"description": "two way infinite scroll", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"src": "./src/", | ||
@@ -6,0 +6,0 @@ "public": "./public/", |
@@ -218,2 +218,5 @@ The common way to present to the user a list of data elements of undefined length is to start with a small portion at the top of the | ||
###v1.3.2 | ||
* Implemented logic for adjustBuffer triggering during invisible items became visible. | ||
###v1.3.1 | ||
@@ -220,0 +223,0 @@ * Changed the logic of viewport scroll/padding recalculation (to solve the problem [#8](https://github.com/angular-ui/ui-scroll/issues/8)). |
@@ -1,147 +0,8 @@ | ||
/*global describe, beforeEach, module, inject, it, expect */ | ||
/*global describe, beforeEach, module, it, expect, runTest */ | ||
describe('uiScroll', function () { | ||
'use strict'; | ||
angular.module('ui.scroll.test', []) | ||
.factory('myEmptyDatasource', [ | ||
'$log', '$timeout', '$rootScope', function () { | ||
return { | ||
get: function (index, count, success) { | ||
success([]); | ||
} | ||
}; | ||
} | ||
]) | ||
.factory('myOnePageDatasource', [ | ||
'$log', '$timeout', '$rootScope', function () { | ||
return { | ||
get: function (index, count, success) { | ||
if (index === 1) { | ||
success(['one', 'two', 'three']); | ||
} else { | ||
success([]); | ||
} | ||
} | ||
}; | ||
} | ||
]) | ||
.factory('myObjectDatasource', [ | ||
'$log', '$timeout', '$rootScope', function () { | ||
return { | ||
get: function (index, count, success) { | ||
if (index === 1) { | ||
success([{text: 'one'}, {text: 'two'}, {text: 'three'}]); | ||
} else { | ||
success([]); | ||
} | ||
} | ||
}; | ||
} | ||
]) | ||
.factory('myMultipageDatasource', [ | ||
'$log', '$timeout', '$rootScope', function () { | ||
return { | ||
get: function (index, count, success) { | ||
var result = []; | ||
for (var i = index; i < index + count; i++) { | ||
if (i > 0 && i <= 20) | ||
result.push('item' + i); | ||
} | ||
success(result); | ||
} | ||
}; | ||
} | ||
]) | ||
.factory('anotherDatasource', [ | ||
'$log', '$timeout', '$rootScope', function () { | ||
return { | ||
get: function (index, count, success) { | ||
var result = []; | ||
for (var i = index; i < index + count; i++) { | ||
if (i > -3 && i < 1) | ||
result.push('item' + i); | ||
} | ||
success(result); | ||
} | ||
}; | ||
} | ||
]) | ||
.factory('myEdgeDatasource', [ | ||
'$log', '$timeout', '$rootScope', function () { | ||
return { | ||
get: function (index, count, success) { | ||
var result = []; | ||
for (var i = index; i < index + count; i++) { | ||
if (i > -6 && i <= 6) | ||
result.push('item' + i); | ||
} | ||
success(result); | ||
} | ||
}; | ||
} | ||
]) | ||
.factory('myDatasourceToPreventScrollBubbling', [ | ||
'$log', '$timeout', '$rootScope', function () { | ||
return { | ||
get: function (index, count, success) { | ||
var result = []; | ||
for (var i = index; i < index + count; i++) { | ||
if (i < -6 || i > 20) { | ||
break; | ||
} | ||
result.push('item' + i); | ||
} | ||
success(result); | ||
} | ||
}; | ||
} | ||
]); | ||
beforeEach(module('ui.scroll')); | ||
beforeEach(module('ui.scroll.test')); | ||
beforeEach(module('ui.scroll.test.datasources')); | ||
var createHtml = function (settings) { | ||
var viewportStyle = ' style="height:' + (settings.viewportHeight || 200) + 'px"'; | ||
var itemStyle = settings.itemHeight ? ' style="height:' + settings.itemHeight + 'px"' : ''; | ||
var bufferSize = settings.bufferSize ? ' buffer-size="' + settings.bufferSize + '"' : ''; | ||
var isLoading = settings.isLoading ? ' is-loading="' + settings.isLoading + '"' : ''; | ||
var adapter = settings.adapter ? ' adapter="' + settings.adapter + '"' : ''; | ||
var template = settings.template ? settings.template : '{{$index}}: {{item}}'; | ||
return '<div ui-scroll-viewport' + viewportStyle + '>' + | ||
'<div ui-scroll="item in ' + settings.datasource + '"' + | ||
adapter + | ||
itemStyle + bufferSize + isLoading + '>' + | ||
template + | ||
'</div>' + | ||
'</div>'; | ||
}; | ||
var runTest = function (scrollSettings, run, options) { | ||
inject(function ($rootScope, $compile, $window, $timeout) { | ||
var scroller = angular.element(createHtml(scrollSettings)); | ||
var scope = $rootScope.$new(); | ||
angular.element(document).find('body').append(scroller); | ||
$compile(scroller)(scope); | ||
scope.$apply(); | ||
$timeout.flush(); | ||
run(scroller, scope, $timeout); | ||
scroller.remove(); | ||
if (options && typeof options.cleanupTest === 'function') { | ||
options.cleanupTest(scroller, scope, $timeout); | ||
} | ||
} | ||
); | ||
}; | ||
describe('applyUpdates tests\n', function () { | ||
@@ -148,0 +9,0 @@ var scrollSettings = {datasource: 'myOnePageDatasource', adapter: 'adapter'}; |
@@ -1,224 +0,8 @@ | ||
/*global describe, beforeEach, module, inject, it, spyOn, expect, $ */ | ||
/*global describe, beforeEach, module, inject, it, spyOn, expect, runTest */ | ||
describe('uiScroll', function () { | ||
'use strict'; | ||
angular.module('ui.scroll.test', []) | ||
.factory('myEmptyDatasource', [ | ||
'$log', '$timeout', '$rootScope', function () { | ||
return { | ||
get: function (index, count, success) { | ||
success([]); | ||
} | ||
}; | ||
} | ||
]) | ||
.factory('myOnePageDatasource', [ | ||
'$log', '$timeout', '$rootScope', function () { | ||
return { | ||
get: function (index, count, success) { | ||
if (index === 1) { | ||
success(['one', 'two', 'three']); | ||
} else { | ||
success([]); | ||
} | ||
} | ||
}; | ||
} | ||
]) | ||
.factory('myObjectDatasource', [ | ||
'$log', '$timeout', '$rootScope', function () { | ||
return { | ||
get: function (index, count, success) { | ||
if (index === 1) { | ||
success([{text: 'one'}, {text: 'two'}, {text: 'three'}]); | ||
} else { | ||
success([]); | ||
} | ||
} | ||
}; | ||
} | ||
]) | ||
.factory('myMultipageDatasource', [ | ||
'$log', '$timeout', '$rootScope', function () { | ||
return { | ||
get: function (index, count, success) { | ||
var result = []; | ||
for (var i = index; i < index + count; i++) { | ||
if (i > 0 && i <= 20) | ||
result.push('item' + i); | ||
} | ||
success(result); | ||
} | ||
}; | ||
} | ||
]) | ||
.factory('anotherDatasource', [ | ||
'$log', '$timeout', '$rootScope', function () { | ||
return { | ||
get: function (index, count, success) { | ||
var result = []; | ||
for (var i = index; i < index + count; i++) { | ||
if (i > -3 && i < 1) | ||
result.push('item' + i); | ||
} | ||
success(result); | ||
} | ||
}; | ||
} | ||
]) | ||
.factory('myEdgeDatasource', [ | ||
'$log', '$timeout', '$rootScope', function () { | ||
return { | ||
get: function (index, count, success) { | ||
var result = []; | ||
for (var i = index; i < index + count; i++) { | ||
if (i > -6 && i <= 6) | ||
result.push('item' + i); | ||
} | ||
success(result); | ||
} | ||
}; | ||
} | ||
]) | ||
.factory('myDatasourceToPreventScrollBubbling', [ | ||
'$log', '$timeout', '$rootScope', function () { | ||
return { | ||
get: function (index, count, success) { | ||
var result = []; | ||
for (var i = index; i < index + count; i++) { | ||
if (i < -6 || i > 20) { | ||
break; | ||
} | ||
result.push('item' + i); | ||
} | ||
success(result); | ||
} | ||
}; | ||
} | ||
]) | ||
.factory('myInfiniteDatasource', [ | ||
'$log', '$timeout', '$rootScope', function () { | ||
return { | ||
get: function (index, count, success) { | ||
var result = []; | ||
for (var i = index; i < index + count; i++) { | ||
result.push('item' + i); | ||
} | ||
success(result); | ||
} | ||
}; | ||
} | ||
]); | ||
beforeEach(module('ui.scroll')); | ||
beforeEach(module('ui.scroll.test')); | ||
beforeEach(module('ui.scroll.test.datasources')); | ||
var createHtml = function (settings) { | ||
var viewportStyle = ' style="height:' + (settings.viewportHeight || 200) + 'px"'; | ||
var itemStyle = settings.itemHeight ? ' style="height:' + settings.itemHeight + 'px"' : ''; | ||
var bufferSize = settings.bufferSize ? ' buffer-size="' + settings.bufferSize + '"' : ''; | ||
var isLoading = settings.isLoading ? ' is-loading="' + settings.isLoading + '"' : ''; | ||
var adapter = settings.adapter ? ' adapter="' + settings.adapter + '"' : ''; | ||
var template = settings.template ? settings.template : '{{$index}}: {{item}}'; | ||
return '<div ui-scroll-viewport' + viewportStyle + '>' + | ||
'<div ui-scroll="item in ' + settings.datasource + '"' + | ||
adapter + | ||
itemStyle + bufferSize + isLoading + '>' + | ||
template + | ||
'</div>' + | ||
'</div>'; | ||
}; | ||
var runTest = function (scrollSettings, run, options) { | ||
inject(function ($rootScope, $compile, $window, $timeout) { | ||
var scroller = angular.element(createHtml(scrollSettings)); | ||
var scope = $rootScope.$new(); | ||
angular.element(document).find('body').append(scroller); | ||
$compile(scroller)(scope); | ||
scope.$apply(); | ||
$timeout.flush(); | ||
run(scroller, scope, $timeout); | ||
scroller.remove(); | ||
if (options && typeof options.cleanupTest === 'function') { | ||
options.cleanupTest(scroller, scope, $timeout); | ||
} | ||
} | ||
); | ||
}; | ||
describe('basic setup', function () { | ||
var scrollSettings = {datasource: 'myEmptyDatasource'}; | ||
it('should bind to window scroll and resize events and unbind them after the scope is destroyed', function () { | ||
spyOn($.fn, 'bind').and.callThrough(); | ||
spyOn($.fn, 'unbind').and.callThrough(); | ||
runTest(scrollSettings, | ||
function (viewport) { | ||
expect($.fn.bind.calls.all().length).toBe(3); | ||
expect($.fn.bind.calls.all()[0].args[0]).toBe('resize'); | ||
expect($.fn.bind.calls.all()[0].object[0]).toBe(viewport[0]); | ||
expect($.fn.bind.calls.all()[1].args[0]).toBe('scroll'); | ||
expect($.fn.bind.calls.all()[1].object[0]).toBe(viewport[0]); | ||
expect($.fn.bind.calls.all()[2].args[0]).toBe('mousewheel'); | ||
expect($.fn.bind.calls.all()[2].object[0]).toBe(viewport[0]); | ||
}, { | ||
cleanupTest: function (viewport, scope, $timeout) { | ||
$timeout(function () { | ||
expect($.fn.unbind.calls.all().length).toBe(3); | ||
expect($.fn.unbind.calls.all()[0].args[0]).toBe('resize'); | ||
expect($.fn.unbind.calls.all()[0].object[0]).toBe(viewport[0]); | ||
expect($.fn.unbind.calls.all()[1].args[0]).toBe('scroll'); | ||
expect($.fn.unbind.calls.all()[1].object[0]).toBe(viewport[0]); | ||
expect($.fn.unbind.calls.all()[2].args[0]).toBe('mousewheel'); | ||
expect($.fn.unbind.calls.all()[2].object[0]).toBe(viewport[0]); | ||
}); | ||
} | ||
} | ||
); | ||
}); | ||
it('should create 2 divs of 0 height', function () { | ||
runTest(scrollSettings, | ||
function (viewport) { | ||
expect(viewport.children().length).toBe(2); | ||
var topPadding = viewport.children()[0]; | ||
expect(topPadding.tagName.toLowerCase()).toBe('div'); | ||
expect(angular.element(topPadding).css('height')).toBe('0px'); | ||
var bottomPadding = viewport.children()[1]; | ||
expect(bottomPadding.tagName.toLowerCase()).toBe('div'); | ||
expect(angular.element(bottomPadding).css('height')).toBe('0px'); | ||
} | ||
); | ||
}); | ||
it('should call get on the datasource 1 time ', function () { | ||
var spy; | ||
inject(function (myEmptyDatasource) { | ||
spy = spyOn(myEmptyDatasource, 'get').and.callThrough(); | ||
}); | ||
runTest(scrollSettings, | ||
function () { | ||
expect(spy.calls.all().length).toBe(2); | ||
expect(spy.calls.all()[0].args[0]).toBe(1); | ||
expect(spy.calls.all()[1].args[0]).toBe(-9); | ||
} | ||
); | ||
}); | ||
}); | ||
describe('datasource with only 3 elements', function () { | ||
@@ -225,0 +9,0 @@ var scrollSettings = {datasource: 'myOnePageDatasource'}; |
@@ -21,2 +21,4 @@ // Karma configuration | ||
'../src/ui-scroll*.coffee', | ||
'datasources.js', | ||
'scaffolding.js', | ||
'**/*Spec.js' | ||
@@ -23,0 +25,0 @@ ], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
210095
2786
277
2