angular-ui-scroll
Advanced tools
Comparing version 1.5.0 to 1.5.1
{ | ||
"name": "angular-ui-scroll", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"homepage": "https://github.com/angular-ui/ui-scroll.git", | ||
@@ -5,0 +5,0 @@ "description": "AngularJS infinite scrolling module", |
@@ -54,5 +54,3 @@ var app = angular.module('application', ['ui.scroll', 'ui.scroll.jqlite']); | ||
var item, result = { | ||
items: [], | ||
bof: false, | ||
eof: false | ||
items: [] | ||
}; | ||
@@ -64,10 +62,2 @@ if (start <= end) { | ||
} | ||
else { // if no item then begin or end of file is reached | ||
if (start <= self.first - self.prependedData.length) { | ||
result.bof = true; | ||
} | ||
if (end > self.max + self.appendedData.length) { | ||
result.eof = true; | ||
} | ||
} | ||
} | ||
@@ -109,20 +99,2 @@ } | ||
var bof = false, eof = false; | ||
function mySuccess(result, success) { | ||
bof = eof = false; | ||
if (result.bof) { | ||
bof = true; | ||
console.log('begin of file is reached'); | ||
} | ||
if (result.eof) { | ||
eof = true; | ||
console.log('end of file is reached'); | ||
} | ||
if (result.items.length) { | ||
console.log('resolved ' + result.items.length + ' items'); | ||
} | ||
success(result.items); | ||
} | ||
$scope.datasource = { | ||
@@ -132,3 +104,6 @@ get: function (index, count, success) { | ||
Server.request(index, count).then(function (result) { | ||
mySuccess(result, success); | ||
if (result.items.length) { | ||
console.log('resolved ' + result.items.length + ' items'); | ||
} | ||
success(result.items); | ||
}); | ||
@@ -140,3 +115,3 @@ } | ||
var newItem = Server.prependItem(' (new)*'); | ||
if (bof) { | ||
if ($scope.adapter.isBOF()) { | ||
$scope.adapter.prepend([newItem]); | ||
@@ -148,3 +123,3 @@ } | ||
var newItem = Server.appendItem(' (new)*'); | ||
if (eof) { | ||
if ($scope.adapter.isEOF()) { | ||
$scope.adapter.append([newItem]); | ||
@@ -151,0 +126,0 @@ } |
/*! | ||
* angular-ui-scroll | ||
* https://github.com/angular-ui/ui-scroll.git | ||
* Version: 1.4.1 -- 2016-06-02T19:39:46.238Z | ||
* Version: 1.5.1 -- 2016-06-27T18:18:39.277Z | ||
* License: MIT | ||
@@ -99,3 +99,3 @@ */ | ||
if (insidePoint(header, x, y)) return this; | ||
var result = void 0; | ||
var result = undefined; | ||
controller.forEachRow(function (row) { | ||
@@ -227,3 +227,3 @@ if (insidePoint(row[_this2.id], x, y)) result = _this2; | ||
var mapTo = selected.mapTo, | ||
next = void 0; | ||
next = undefined; | ||
index -= mapTo < index ? 1 : 0; | ||
@@ -230,0 +230,0 @@ |
/*! | ||
* angular-ui-scroll | ||
* https://github.com/angular-ui/ui-scroll.git | ||
* Version: 1.4.1 -- 2016-05-26T23:58:09.875Z | ||
* Version: 1.5.1 -- 2016-06-27T18:18:39.277Z | ||
* License: MIT | ||
*/ | ||
!function(){"use strict";angular.module("ui.scroll.grid",[]).directive("uiScrollTh",["$log","$timeout",function(a,b){function c(a){this.getLayout=function(){return a.getLayout()},this.applyLayout=function(b){return a.applyLayout(b)},this.columnFromPoint=function(b,c){return a.columnFromPoint(b,c)},Object.defineProperty(this,"columns",{get:function(){return a.getColumns()}})}function d(a,b){this.css=function(){var c=arguments[0],d=arguments[1];return 1==arguments.length?b.header.css(c):void(2==arguments.length&&(b.header.css(c,d),a.forEachRow(function(a){return a[b.id].css(c,d)}),b.css[c]=d))},this.moveBefore=function(c){a.moveBefore(b,c)},this.exchangeWith=function(c){a.exchangeWith(b,c)},Object.defineProperty(this,"columnId",{get:function(){return b.id}})}function e(a,b,c){function d(a,b,c){var d=a.offset();return b<d.left||d.left+a.outerWidth(!0)<b?!1:!(c<d.top||d.top+a.outerHeight(!0)<c)}function e(a,b){a.detach(),b.before(a)}function f(a,b){var c=a.parent();a.detach(),c.append(a)}function g(a,b){a.removeAttr("style");for(var c in b)b.hasOwnProperty(c)&&a.css(c,b[c])}this.header=c,this.cells=[],this.css={},this.mapTo=b.length,this.id=b.length,this.applyLayout=function(a){this.css=angular.extend({},a.css),this.mapTo=a.mapTo,g(this.header,this.css)},this.moveBefore=function(b){var d=this;b?(e(c,b.header),a.forEachRow(function(a){return e(a[d.id],a[b.id])})):(f(c),a.forEachRow(function(a){return f(a[d.id])}))},this.columnFromPoint=function(b,e){var f=this;if(d(c,b,e))return this;var g=void 0;return a.forEachRow(function(a){d(a[f.id],b,e)&&(g=f)}),g},this.applyCss=function(a){g(a,this.css)}}function f(a,f){function g(a){var b=a[0].parent(),c=[];a.forEach(function(b,d){i[d].applyCss(b),c[i[d].mapTo]=a[d],a[d].detach()}),c.forEach(function(a){return b.append(a)})}var h=this,i=[],j=new Map;b(function(){f.adapter.gridAdapter=new c(h),f.adapter.transform=function(a,b){return g(j.get(a),b)}}),this.registerColumn=function(a){i.push(new e(this,i,a))},this.registerCell=function(a,b){var c=j.get(a);return c||(c=[],j.set(a,c)),c.length>=i.length?!1:(c.push(b),!0)},this.unregisterCell=function(a,b){var c=j.get(a),d=c.indexOf(b);c.splice(d,1),c.length||j["delete"](a)},this.forEachRow=function(a){j.forEach(a)},this.getColumns=function(){var a=this,b=[];return i.slice().sort(function(a,b){return a.mapTo-b.mapTo}).forEach(function(c){return b.push(new d(a,c))}),b},this.getLayout=function(){var a=[];return i.forEach(function(b,c){return a.push({index:c,css:angular.extend({},b.css),mapTo:b.mapTo})}),a},this.applyLayout=function(a){if(!a||a.length!=i.length)throw new Error("Failed to apply layout - number of layouts should match number of columns");a.forEach(function(a,b){i[b].applyLayout(a)}),g(i.map(function(a){return a.header})),j.forEach(function(a){g(a)})},this.moveBefore=function(a,b){var c=b;if(b%1!==0&&(c=b?i[b.columnId].mapTo:i.length),!(0>c||c>i.length)){var d=a.mapTo,e=void 0;c-=c>d?1:0,i.forEach(function(a){a.mapTo-=a.mapTo>d?1:0,a.mapTo+=a.mapTo>=c?1:0,e=a.mapTo===c+1?a:e}),a.mapTo=c,a.moveBefore(e)}},this.exchangeWith=function(a,b){0>b||b>=i.length||(i.find(function(a){return a.mapTo===b}).mapTo=a.mapTo,a.mapTo=b)},this.columnFromPoint=function(a,b){for(var c=0;c<i.length;c++){var e=i[c].columnFromPoint(a,b);if(e)break}return e?new d(this,e):void 0}}return{require:["^^uiScrollViewport"],restrict:"A",link:function(a,b,c,d,e){d[0].gridController=d[0].gridController||new f(a,d[0]),d[0].gridController.registerColumn(b)}}}]).directive("uiScrollTd",["$log",function(a){return{require:["?^^uiScrollViewport"],restrict:"A",link:function(a,b,c,d,e){d[0]&&!function(){var c=d[0].gridController;c.registerCell(a,b)&&a.$on("$destroy",function(){return c.unregisterCell(a,b)})}()}}}])}(); |
/*! | ||
* angular-ui-scroll | ||
* https://github.com/angular-ui/ui-scroll.git | ||
* Version: 1.4.1 -- 2016-06-02T19:39:46.238Z | ||
* Version: 1.5.1 -- 2016-06-27T18:18:39.277Z | ||
* License: MIT | ||
@@ -74,7 +74,7 @@ */ | ||
convertToPx = function convertToPx(elem, value) { | ||
var left = void 0, | ||
result = void 0, | ||
rs = void 0, | ||
rsLeft = void 0, | ||
style = void 0; | ||
var left = undefined, | ||
result = undefined, | ||
rs = undefined, | ||
rsLeft = undefined, | ||
style = undefined; | ||
var core_pnum = /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source; | ||
@@ -107,14 +107,14 @@ var rnumnonpx = new RegExp('^(' + core_pnum + ')(?!px)[a-z%]+$', 'i'); | ||
function getMeasurements(elem, measure) { | ||
var base = void 0, | ||
borderA = void 0, | ||
borderB = void 0, | ||
computedMarginA = void 0, | ||
computedMarginB = void 0, | ||
computedStyle = void 0, | ||
dirA = void 0, | ||
dirB = void 0, | ||
marginA = void 0, | ||
marginB = void 0, | ||
paddingA = void 0, | ||
paddingB = void 0; | ||
var base = undefined, | ||
borderA = undefined, | ||
borderB = undefined, | ||
computedMarginA = undefined, | ||
computedMarginB = undefined, | ||
computedStyle = undefined, | ||
dirA = undefined, | ||
dirB = undefined, | ||
marginA = undefined, | ||
marginB = undefined, | ||
paddingA = undefined, | ||
paddingB = undefined; | ||
@@ -168,4 +168,4 @@ if (isWindow(elem)) { | ||
function getWidthHeight(elem, direction, measure) { | ||
var computedStyle = void 0, | ||
result = void 0; | ||
var computedStyle = undefined, | ||
result = undefined; | ||
@@ -244,4 +244,4 @@ var measurements = getMeasurements(elem, direction); | ||
offset: function offset(value) { | ||
var docElem = void 0, | ||
win = void 0; | ||
var docElem = undefined, | ||
win = undefined; | ||
var self = this; | ||
@@ -248,0 +248,0 @@ var box = { |
/*! | ||
* angular-ui-scroll | ||
* https://github.com/angular-ui/ui-scroll.git | ||
* Version: 1.4.1 -- 2016-05-09T16:49:23.122Z | ||
* Version: 1.5.1 -- 2016-06-27T18:18:39.277Z | ||
* License: MIT | ||
*/ | ||
!function(){"use strict";var a=function(){function a(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!b||c.length!==b);d=!0);}catch(i){e=!0,f=i}finally{try{!d&&h["return"]&&h["return"]()}finally{if(e)throw f}}return c}return function(b,c){if(Array.isArray(b))return b;if(Symbol.iterator in Object(b))return a(b,c);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();angular.module("ui.scroll.jqlite",["ui.scroll"]).service("jqLiteExtras",["$log","$window",function(b,c){return{registerFor:function(b){function d(b,c,d){var e=b[0],f=a({top:["scrollTop","pageYOffset","scrollLeft"],left:["scrollLeft","pageXOffset","scrollTop"]}[c],3),g=f[0],h=f[1],i=f[2];return j(e)?angular.isDefined(d)?e.scrollTo(b[i].call(b),d):h in e?e[h]:e.document.documentElement[g]:(angular.isDefined(d)&&(e[g]=d),e[g])}function e(b,c){var d=void 0,e=void 0,f=void 0,h=void 0,k=void 0,l=void 0,m=void 0,n=void 0,o=void 0,p=void 0,q=void 0,r=void 0;if(j(b))return d=document.documentElement[{height:"clientHeight",width:"clientWidth"}[c]],{base:d,padding:0,border:0,margin:0};var s=a({width:[b.offsetWidth,"Left","Right"],height:[b.offsetHeight,"Top","Bottom"]}[c],3);return d=s[0],m=s[1],n=s[2],l=i(b),q=g(b,l["padding"+m])||0,r=g(b,l["padding"+n])||0,e=g(b,l["border"+m+"Width"])||0,f=g(b,l["border"+n+"Width"])||0,h=l["margin"+m],k=l["margin"+n],o=g(b,h)||0,p=g(b,k)||0,{base:d,padding:q+r,border:e+f,margin:o+p}}function f(a,b,c){var d=void 0,f=void 0,g=e(a,b);return g.base>0?{base:g.base-g.padding-g.border,outer:g.base,outerfull:g.base+g.margin}[c]:(d=i(a),f=d[b],(0>f||null===f)&&(f=a.style[b]||0),f=parseFloat(f)||0,{base:f-g.padding-g.border,outer:f,outerfull:f+g.padding+g.border+g.margin}[c])}var g,h,i,j;return h=angular.element.prototype.css,b.prototype.css=function(a,b){var c=this,d=c[0];return d&&3!==d.nodeType&&8!==d.nodeType&&d.style?h.call(c,a,b):void 0},j=function(a){return a&&a.document&&a.location&&a.alert&&a.setInterval},c.getComputedStyle?(i=function(a){return c.getComputedStyle(a,null)},g=function(a,b){return parseFloat(b)}):(i=function(a){return a.currentStyle},g=function(a,b){var c=void 0,d=void 0,e=void 0,f=void 0,g=void 0,h=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,i=new RegExp("^("+h+")(?!px)[a-z%]+$","i");return i.test(b)?(g=a.style,c=g.left,e=a.runtimeStyle,f=e&&e.left,e&&(e.left=g.left),g.left=b,d=g.pixelLeft,g.left=c,f&&(e.left=f),d):parseFloat(b)}),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"),h.call(b,"height",a)):f(this[0],"height","base")},outerHeight:function(a){return f(this[0],"height",a?"outerfull":"outer")},offset:function(a){var b=void 0,c=void 0,d=this,e={top:0,left:0},f=d[0],g=f&&f.ownerDocument;if(arguments.length){if(void 0===a)return d;throw new Error("offset setter method is not implemented")}return g?(b=g.documentElement,null!=f.getBoundingClientRect&&(e=f.getBoundingClientRect()),c=g.defaultView||g.parentWindow,{top:e.top+(c.pageYOffset||b.scrollTop)-(b.clientTop||0),left:e.left+(c.pageXOffset||b.scrollLeft)-(b.clientLeft||0)}):void 0},scrollTop:function(a){return d(this,"top",a)},scrollLeft:function(a){return d(this,"left",a)}},function(a,c){return b.prototype[c]?void 0:b.prototype[c]=a})}}}]).run(["$log","$window","jqLiteExtras",function(a,b,c){return b.jQuery?void 0:c.registerFor(angular.element)}])}(); | ||
!function(){"use strict";var a=function(){function a(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!b||c.length!==b);d=!0);}catch(i){e=!0,f=i}finally{try{!d&&h["return"]&&h["return"]()}finally{if(e)throw f}}return c}return function(b,c){if(Array.isArray(b))return b;if(Symbol.iterator in Object(b))return a(b,c);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();angular.module("ui.scroll.jqlite",["ui.scroll"]).service("jqLiteExtras",["$log","$window",function(b,c){return{registerFor:function(b){function d(b,c,d){var e=b[0],f=a({top:["scrollTop","pageYOffset","scrollLeft"],left:["scrollLeft","pageXOffset","scrollTop"]}[c],3),g=f[0],h=f[1],i=f[2];return j(e)?angular.isDefined(d)?e.scrollTo(b[i].call(b),d):h in e?e[h]:e.document.documentElement[g]:(angular.isDefined(d)&&(e[g]=d),e[g])}function e(b,c){var d=void 0,e=void 0,f=void 0,h=void 0,k=void 0,l=void 0,m=void 0,n=void 0,o=void 0,p=void 0,q=void 0,r=void 0;if(j(b))return d=document.documentElement[{height:"clientHeight",width:"clientWidth"}[c]],{base:d,padding:0,border:0,margin:0};var s=a({width:[b.offsetWidth,"Left","Right"],height:[b.offsetHeight,"Top","Bottom"]}[c],3);return d=s[0],m=s[1],n=s[2],l=i(b),q=g(b,l["padding"+m])||0,r=g(b,l["padding"+n])||0,e=g(b,l["border"+m+"Width"])||0,f=g(b,l["border"+n+"Width"])||0,h=l["margin"+m],k=l["margin"+n],o=g(b,h)||0,p=g(b,k)||0,{base:d,padding:q+r,border:e+f,margin:o+p}}function f(a,b,c){var d=void 0,f=void 0,g=e(a,b);return g.base>0?{base:g.base-g.padding-g.border,outer:g.base,outerfull:g.base+g.margin}[c]:(d=i(a),f=d[b],(0>f||null===f)&&(f=a.style[b]||0),f=parseFloat(f)||0,{base:f-g.padding-g.border,outer:f,outerfull:f+g.padding+g.border+g.margin}[c])}var g,h,i,j;return h=angular.element.prototype.css,b.prototype.css=function(a,b){var c=this,d=c[0];return d&&3!==d.nodeType&&8!==d.nodeType&&d.style?h.call(c,a,b):void 0},j=function(a){return a&&a.document&&a.location&&a.alert&&a.setInterval},c.getComputedStyle?(i=function(a){return c.getComputedStyle(a,null)},g=function(a,b){return parseFloat(b)}):(i=function(a){return a.currentStyle},g=function(a,b){var c=void 0,d=void 0,e=void 0,f=void 0,g=void 0,h=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,i=new RegExp("^("+h+")(?!px)[a-z%]+$","i");return i.test(b)?(g=a.style,c=g.left,e=a.runtimeStyle,f=e&&e.left,e&&(e.left=g.left),g.left=b,d=g.pixelLeft,g.left=c,f&&(e.left=f),d):parseFloat(b)}),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"),h.call(b,"height",a)):f(this[0],"height","base")},outerHeight:function(a){return f(this[0],"height",a?"outerfull":"outer")},outerWidth:function(a){return f(this[0],"width",a?"outerfull":"outer")},offset:function(a){var b=void 0,c=void 0,d=this,e={top:0,left:0},f=d[0],g=f&&f.ownerDocument;if(arguments.length){if(void 0===a)return d;throw new Error("offset setter method is not implemented")}return g?(b=g.documentElement,null!=f.getBoundingClientRect&&(e=f.getBoundingClientRect()),c=g.defaultView||g.parentWindow,{top:e.top+(c.pageYOffset||b.scrollTop)-(b.clientTop||0),left:e.left+(c.pageXOffset||b.scrollLeft)-(b.clientLeft||0)}):void 0},scrollTop:function(a){return d(this,"top",a)},scrollLeft:function(a){return d(this,"left",a)}},function(a,c){return b.prototype[c]?void 0:b.prototype[c]=a})}}}]).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.4.1 -- 2016-06-02T19:39:46.238Z | ||
* Version: 1.5.1 -- 2016-06-27T18:18:39.277Z | ||
* License: MIT | ||
@@ -139,2 +139,3 @@ */ | ||
}); | ||
buffer.maxIndex = buffer.eof ? buffer.next - 1 : Math.max(buffer.next - 1, buffer.maxIndex); | ||
}, | ||
@@ -146,2 +147,3 @@ prepend: function prepend(items) { | ||
}); | ||
buffer.minIndex = buffer.bof ? buffer.minIndex = buffer.first : Math.min(buffer.first, buffer.minIndex); | ||
}, | ||
@@ -194,8 +196,2 @@ | ||
}, | ||
setUpper: function setUpper() { | ||
buffer.maxIndex = buffer.eof ? buffer.next - 1 : Math.max(buffer.next - 1, buffer.maxIndex); | ||
}, | ||
setLower: function setLower() { | ||
buffer.minIndex = buffer.bof ? buffer.minIndex = buffer.first : Math.min(buffer.first, buffer.minIndex); | ||
}, | ||
effectiveHeight: function effectiveHeight(elements) { | ||
@@ -222,4 +218,4 @@ if (!elements.length) return 0; | ||
var PADDING_DEFAULT = 0.5; | ||
var topPadding = void 0; | ||
var bottomPadding = void 0; | ||
var topPadding = undefined; | ||
var bottomPadding = undefined; | ||
var viewport = viewportController && viewportController.viewport ? viewportController.viewport : angular.element(window); | ||
@@ -259,3 +255,3 @@ var container = viewportController && viewportController.container ? viewportController.container : undefined; | ||
function Padding(template) { | ||
var result = void 0; | ||
var result = undefined; | ||
@@ -389,4 +385,4 @@ switch (template.tagName) { | ||
// average heights calculation, items that have never been reached | ||
var adjustTopPadding = buffer.minIndexUser && buffer.minIndex > buffer.minIndexUser; | ||
var adjustBottomPadding = buffer.maxIndexUser && buffer.maxIndex < buffer.maxIndexUser; | ||
var adjustTopPadding = buffer.minIndexUser !== null && buffer.minIndex > buffer.minIndexUser; | ||
var adjustBottomPadding = buffer.maxIndexUser !== null && buffer.maxIndex < buffer.maxIndexUser; | ||
var topPaddingHeightAdd = adjustTopPadding ? (buffer.minIndex - buffer.minIndexUser) * averageItemHeight : 0; | ||
@@ -401,3 +397,3 @@ var bottomPaddingHeightAdd = adjustBottomPadding ? (buffer.maxIndexUser - buffer.maxIndex) * averageItemHeight : 0; | ||
// additional scrollTop adjustment in case of datasource.minIndex external set | ||
if (buffer.minIndexUser && buffer.minIndex > buffer.minIndexUser) { | ||
if (buffer.minIndexUser !== null && buffer.minIndex > buffer.minIndexUser) { | ||
var diff = topPadding.height() - topPaddingHeightOld; | ||
@@ -407,3 +403,5 @@ viewport.scrollTop(viewport.scrollTop() + diff); | ||
}, | ||
adjustScrollTopAfterPrepend: function adjustScrollTopAfterPrepend(height) { | ||
adjustScrollTopAfterPrepend: function adjustScrollTopAfterPrepend(updates) { | ||
if (!updates.prepended.length) return; | ||
var height = buffer.effectiveHeight(updates.prepended); | ||
var paddingHeight = topPadding.height() - height; | ||
@@ -431,10 +429,13 @@ if (paddingHeight >= 0) { | ||
function Adapter($attr, viewport, buffer, adjustBuffer) { | ||
var _this = this; | ||
var viewportScope = viewport.scope() || $rootScope; | ||
var disabled = false; | ||
var self = this; | ||
injectValue($attr.adapter, this); | ||
createValueInjector('adapter')(self); | ||
var topVisibleInjector = createValueInjector('topVisible'); | ||
var topVisibleElementInjector = createValueInjector('topVisibleElement'); | ||
var topVisibleScopeInjector = createValueInjector('topVisibleScope'); | ||
var isLoadingInjector = createValueInjector('isLoading'); | ||
// Adapter API definition | ||
// Adapter API definition | ||
@@ -451,2 +452,8 @@ Object.defineProperty(this, 'disabled', { | ||
this.isLoading = false; | ||
this.isBOF = function () { | ||
return buffer.bof; | ||
}; | ||
this.isEOF = function () { | ||
return buffer.eof; | ||
}; | ||
@@ -488,12 +495,11 @@ this.applyUpdates = function (arg1, arg2) { | ||
this.loading = function (value) { | ||
_this.isLoading = value; | ||
injectValue($attr.isLoading, value); | ||
isLoadingInjector(value); | ||
}; | ||
this.calculateProperties = function () { | ||
var item = void 0, | ||
itemHeight = void 0, | ||
itemTop = void 0, | ||
isNewRow = void 0, | ||
rowTop = void 0; | ||
var item = undefined, | ||
itemHeight = undefined, | ||
itemTop = undefined, | ||
isNewRow = undefined, | ||
rowTop = undefined; | ||
var topHeight = 0; | ||
@@ -512,8 +518,5 @@ for (var i = 0; i < buffer.length; i++) { | ||
if (isNewRow) { | ||
_this.topVisible = item.item; | ||
_this.topVisibleElement = item.element; | ||
_this.topVisibleScope = item.scope; | ||
injectValue($attr.topVisible, item.item); | ||
injectValue($attr.topVisibleElement, item.element); | ||
injectValue($attr.topVisibleScope, item.scope); | ||
topVisibleInjector(item.item); | ||
topVisibleElementInjector(item.element); | ||
topVisibleScopeInjector(item.scope); | ||
} | ||
@@ -527,3 +530,6 @@ break; | ||
function injectValue(expression, value) { | ||
function createValueInjector(attribute) { | ||
var expression = $attr[attribute]; | ||
var scope = viewportScope; | ||
var assign = undefined; | ||
if (expression) { | ||
@@ -534,3 +540,2 @@ var match = expression.match(/^(\S+)(?:\s+on\s+(\w(?:\w|\d)*))?$/); | ||
var controllerName = match[2]; | ||
var scope = viewportScope; | ||
if (controllerName) { | ||
@@ -549,21 +554,9 @@ var candidate = viewport; | ||
} | ||
$parse(target).assign(scope, value); | ||
/* | ||
let scope = viewportScope; | ||
let s = viewportScope; | ||
let i = expression.indexOf('.'); | ||
if (i>0) { | ||
let ctrlName = expression.slice(0, i); | ||
while (s !== $rootScope) { | ||
if (s.hasOwnProperty(ctrlName) && angular.isFunction(s[ctrlName])) { | ||
scope = s; | ||
expression = expression.slice(i+1); | ||
break; | ||
} | ||
s = s.$parent; | ||
} | ||
} | ||
$parse(expression).assign(scope, value); | ||
*/ | ||
assign = $parse(target).assign; | ||
} | ||
return function (value) { | ||
if (self !== value) // just to avoid injecting adapter reference in the adapter itself. Kludgy, I know. | ||
self[attribute] = value; | ||
if (assign) assign(scope, value); | ||
}; | ||
} | ||
@@ -576,3 +569,3 @@ | ||
var keepIt = void 0; | ||
var keepIt = undefined; | ||
var pos = buffer.indexOf(wrapper) + 1; | ||
@@ -597,3 +590,3 @@ | ||
var match = $attr.uiScroll.match(/^\s*(\w+)\s+in\s+([\w\.]+)\s*$/); | ||
var match = $attr.uiScroll.match(/^\s*(\w+)\s+in\s+([(\w|\$)\.]+)\s*$/); | ||
@@ -749,14 +742,13 @@ if (!match) throw new Error('Expected uiScroll in form of \'_item_ in _datasource_\' but got \'' + $attr.uiScroll + '\''); | ||
function insertWrapperContent(wrapper, insertAfter) { | ||
createElement(wrapper, insertAfter, viewport.insertElement); | ||
if (isElementVisible(wrapper)) return true; | ||
wrapper.unregisterVisibilityWatcher = wrapper.scope.$watch(function () { | ||
return visibilityWatcher(wrapper); | ||
}); | ||
return false; | ||
if (!isElementVisible(wrapper)) { | ||
wrapper.unregisterVisibilityWatcher = wrapper.scope.$watch(function () { | ||
return visibilityWatcher(wrapper); | ||
}); | ||
} | ||
wrapper.element.addClass('ng-hide'); // hide inserted elements before data binding | ||
} | ||
function createElement(wrapper, insertAfter, insertElement) { | ||
var promises = void 0; | ||
var promises = undefined; | ||
var sibling = insertAfter > 0 ? buffer[insertAfter - 1].element : undefined; | ||
@@ -813,8 +805,3 @@ linker(function (clone, scope) { | ||
var estimatedPaddingIncrement = buffer.effectiveHeight(toBePrepended); | ||
viewport.adjustScrollTopAfterPrepend(estimatedPaddingIncrement); | ||
return { | ||
estimatedPaddingIncrement: estimatedPaddingIncrement, | ||
prepended: toBePrepended, | ||
@@ -828,7 +815,2 @@ removed: toBeRemoved, | ||
function updatePaddings(rid, updates) { | ||
var adjustedPaddingHeight = buffer.effectiveHeight(updates.prepended) - updates.estimatedPaddingIncrement; | ||
viewport.adjustScrollTopAfterPrepend(adjustedPaddingHeight); | ||
// schedule another adjustBuffer after animation completion | ||
@@ -843,20 +825,22 @@ if (updates.animated.length) { | ||
} | ||
// return true if inserted elements have height > 0 | ||
return adjustedPaddingHeight + updates.estimatedPaddingIncrement > 0 || buffer.effectiveHeight(updates.inserted) > 0; | ||
} | ||
function enqueueFetch(rid, keepFetching) { | ||
if (viewport.shouldLoadBottom() && keepFetching) { | ||
// keepFetching = true means that at least one item app/prepended in the last batch had height > 0 | ||
if (pending.push(true) === 1) { | ||
fetch(rid); | ||
adapter.loading(true); | ||
function enqueueFetch(rid, updates) { | ||
if (viewport.shouldLoadBottom()) { | ||
if (!updates || buffer.effectiveHeight(updates.inserted) > 0) { | ||
// this means that at least one item appended in the last batch has height > 0 | ||
if (pending.push(true) === 1) { | ||
fetch(rid); | ||
adapter.loading(true); | ||
} | ||
} | ||
} else if (viewport.shouldLoadTop() && (keepFetching || pending[0])) { | ||
// pending[0] = true means that previous fetch was appending. We need to force at least one prepend | ||
// BTW there will always be at least 1 element in the pending array because bottom is fetched first | ||
if (pending.push(false) === 1) { | ||
fetch(rid); | ||
adapter.loading(true); | ||
} else if (viewport.shouldLoadTop()) { | ||
if (!updates || buffer.effectiveHeight(updates.prepended) > 0 || pending[0]) { | ||
// this means that at least one item appended in the last batch has height > 0 | ||
// pending[0] = true means that previous fetch was appending. We need to force at least one prepend | ||
// BTW there will always be at least 1 element in the pending array because bottom is fetched first | ||
if (pending.push(false) === 1) { | ||
fetch(rid); | ||
adapter.loading(true); | ||
} | ||
} | ||
@@ -877,2 +861,11 @@ } | ||
$timeout(function () { | ||
// show elements after data binging has been done | ||
updates.inserted.forEach(function (w) { | ||
return w.element.removeClass('ng-hide'); | ||
}); | ||
updates.prepended.forEach(function (w) { | ||
return w.element.removeClass('ng-hide'); | ||
}); | ||
if (isInvalid(rid)) { | ||
@@ -883,3 +876,3 @@ return; | ||
updatePaddings(rid, updates); | ||
enqueueFetch(rid, true); | ||
enqueueFetch(rid); | ||
@@ -895,6 +888,15 @@ if (!pending.length) { | ||
viewport.adjustPadding(); | ||
// We need the item bindings to be processed before we can do adjustment | ||
$timeout(function () { | ||
// show elements after data binging has been done | ||
updates.inserted.forEach(function (w) { | ||
return w.element.removeClass('ng-hide'); | ||
}); | ||
updates.prepended.forEach(function (w) { | ||
return w.element.removeClass('ng-hide'); | ||
}); | ||
viewport.adjustScrollTopAfterPrepend(updates); | ||
if (isInvalid(rid)) { | ||
@@ -904,3 +906,4 @@ return; | ||
enqueueFetch(rid, updatePaddings(rid, updates)); | ||
updatePaddings(rid, updates); | ||
enqueueFetch(rid, updates); | ||
pending.shift(); | ||
@@ -934,3 +937,2 @@ | ||
buffer.append(result); | ||
buffer.setUpper(); | ||
} | ||
@@ -961,3 +963,2 @@ | ||
buffer.prepend(result); | ||
buffer.setLower(); | ||
} | ||
@@ -974,3 +975,3 @@ | ||
enqueueFetch(ridActual, true); | ||
enqueueFetch(ridActual); | ||
@@ -977,0 +978,0 @@ if (pending.length) { |
/*! | ||
* angular-ui-scroll | ||
* https://github.com/angular-ui/ui-scroll.git | ||
* Version: 1.4.1 -- 2016-05-17T15:02:37.211Z | ||
* Version: 1.5.1 -- 2016-06-27T18:18:39.277Z | ||
* License: MIT | ||
*/ | ||
!function(){"use strict";var a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol?"symbol":typeof a};angular.module("ui.scroll",[]).directive("uiScrollViewport",function(){return{controller:["$log","$scope","$element",function(a,b,c){var d=this;d.container=c,d.viewport=c,angular.forEach(c.children(),function(a){"tbody"===a.tagName.toLowerCase()&&(d.viewport=angular.element(a))})}]}}).directive("uiScroll",["$log","$injector","$rootScope","$timeout","$q","$parse",function(b,c,d,e,f,g){function h(a,b){return b.after(a),[]}function i(a){return a.element.remove(),a.scope.$destroy(),[]}function j(b,c){if(!p)return h(b,c);if(q){var d=function(){var a=f.defer();return p.enter(b,null,c,function(){return a.resolve()}),{v:[a.promise]}}();if("object"===("undefined"==typeof d?"undefined":a(d)))return d.v}return[p.enter(b,null,c)]}function k(b){if(!p)return i(b);if(q){var c=function(){var a=f.defer();return p.leave(b.element,function(){return b.scope.$destroy(),a.resolve()}),{v:[a.promise]}}();if("object"===("undefined"==typeof c?"undefined":a(c)))return c.v}return[p.leave(b.element).then(function(){return b.scope.$destroy()})]}function l(a){var b=Object.create(Array.prototype);return angular.extend(b,{size:a,reset:function(a){b.remove(0,b.length),b.eof=!1,b.bof=!1,b.first=a,b.next=a,b.minIndex=a,b.maxIndex=a,b.minIndexUser=null,b.maxIndexUser=null},append:function(a){a.forEach(function(a){++b.next,b.insert("append",a)})},prepend:function(a){a.reverse().forEach(function(a){--b.first,b.insert("prepend",a)})},insert:function(a,c){var d={item:c};if(a%1===0)d.op="insert",b.splice(a,0,d);else switch(d.op=a,a){case"append":b.push(d);break;case"prepend":b.unshift(d)}},remove:function(a,c){if(angular.isNumber(a)){for(var d=a;c>d;d++)i(b[d]);return b.splice(a,c-a)}return b.splice(b.indexOf(a),1),k(a)},setUpper:function(){b.maxIndex=b.eof?b.next-1:Math.max(b.next-1,b.maxIndex)},setLower:function(){b.minIndex=b.bof?b.minIndex=b.first:Math.min(b.first,b.minIndex)},effectiveHeight:function(a){if(!a.length)return 0;var b=Number.MAX_VALUE,c=Number.MIN_VALUE;return a.forEach(function(a){a.element[0].offsetParent&&(b=Math.min(b,a.element.offset().top),c=Math.max(c,a.element.offset().top+a.element.outerHeight(!0)))}),Math.max(0,c-b)}}),b}function m(a,b,c,d){function e(){var a=Object.create(Array.prototype);return angular.extend(a,{add:function(b){var c=a.find(function(a){return a.index===b.scope.$index});return c?void(c.height=b.element.outerHeight()):void a.push({index:b.scope.$index,height:b.element.outerHeight()})},clear:function(){a.length=0}}),a}function f(a){var b=void 0;switch(a.tagName){case"dl":throw new Error("ui-scroll directive does not support <"+a.tagName+"> as a repeating tag: "+a.outerHTML);case"tr":var c=angular.element("<table><tr><td><div></div></td></tr></table>");b=c.find("tr");break;case"li":b=angular.element("<li></li>");break;default:b=angular.element("<div></div>")}return b.cache=new e,b}function g(){return n.outerHeight()*Math.max(i,+d.padding||k)}var i=.3,k=.5,l=void 0,m=void 0,n=c&&c.viewport?c.viewport:angular.element(window),o=c&&c.container?c.container:void 0;return n.css({"overflow-y":"auto",display:"block"}),angular.extend(n,{createPaddingElements:function(a){l=new f(a),m=new f(a),b.before(l),b.after(m)},applyContainerStyle:function(){o&&o!==n&&n.css("height",window.getComputedStyle(o[0]).height)},bottomDataPos:function(){var a=n[0].scrollHeight;return a=null!=a?a:n[0].document.documentElement.scrollHeight,a-m.height()},topDataPos:function(){return l.height()},bottomVisiblePos:function(){return n.scrollTop()+n.outerHeight()},topVisiblePos:function(){return n.scrollTop()},insertElement:function(a,b){return h(a,b||l)},insertElementAnimated:function(a,b){return j(a,b||l)},shouldLoadBottom:function(){return!a.eof&&n.bottomDataPos()<n.bottomVisiblePos()+g()},clipBottom:function(){for(var b=0,c=0,d=0,e=n.bottomDataPos()-n.bottomVisiblePos()-g(),f=a.length-1;f>=0&&(d=a[f].element.outerHeight(!0),!(c+d>e));f--)m.cache.add(a[f]),c+=d,b++;b>0&&(a.eof=!1,a.remove(a.length-b,a.length),a.next-=b,n.adjustPadding())},shouldLoadTop:function(){return!a.bof&&n.topDataPos()>n.topVisiblePos()-g()},clipTop:function(){for(var b=0,c=0,d=0,e=n.topVisiblePos()-n.topDataPos()-g(),f=0;f<a.length&&(d=a[f].element.outerHeight(!0),!(c+d>e));f++)l.cache.add(a[f]),c+=d,b++;b>0&&(l.height(l.height()+c),a.bof=!1,a.remove(0,b),a.first+=b)},adjustPadding:function(){if(a.length){var b=l.cache.reduce(function(b,c){return b+(c.index<a.first?c.height:0)},0),c=m.cache.reduce(function(b,c){return b+(c.index>=a.next?c.height:0)},0),d=a.reduce(function(a,b){return a+b.element.outerHeight(!0)},0),e=(d+b+c)/(a.maxIndex-a.minIndex+1),f=a.minIndexUser&&a.minIndex>a.minIndexUser,g=a.maxIndexUser&&a.maxIndex<a.maxIndexUser,h=f?(a.minIndex-a.minIndexUser)*e:0,i=g?(a.maxIndexUser-a.maxIndex)*e:0;l.height(b+h),m.height(c+i)}},adjustScrollTopAfterMinIndexSet:function(b){if(a.minIndexUser&&a.minIndex>a.minIndexUser){var c=l.height()-b;n.scrollTop(n.scrollTop()+c)}},adjustScrollTopAfterPrepend:function(a){var b=l.height()-a;b>=0?l.height(b):(l.height(0),n.scrollTop(n.scrollTop()-b))},resetTopPadding:function(){l.height(0),l.cache.clear()},resetBottomPadding:function(){m.height(0),m.cache.clear()}}),n}function n(a,b,c,e){function f(a,b){if(angular.isArray(b)){var d=void 0,e=c.indexOf(a)+1;b.reverse().forEach(function(b){b===a.item?(d=!0,e--):c.insert(e,b)}),d||(a.op="remove")}}var h=this,i=b.scope()||d,j=a.topVisible?g(a.topVisible).assign:angular.noop,k=a.topVisibleElement?g(a.topVisibleElement).assign:angular.noop,l=a.topVisibleScope?g(a.topVisibleScope).assign:angular.noop,m=a.isLoading?g(a.isLoading).assign:angular.noop,n=!1;Object.defineProperty(this,"disabled",{get:function(){return n},set:function(a){return(n=a)?null:e()}}),this.isLoading=!1,this.applyUpdates=function(a,b){if(angular.isFunction(a))c.slice(0).forEach(function(b){f(b,a(b.item,b.scope,b.element))});else{if(a%1!==0)throw new Error("applyUpdates - "+a+" is not a valid index");var d=a-c.first;d>=0&&d<c.length&&f(c[d],b)}e()},this.append=function(a){c.append(a),e()},this.prepend=function(a){c.prepend(a),e()},this.loading=function(a){h.isLoading=a,m(i,a)},this.calculateProperties=function(){for(var a=void 0,d=void 0,e=void 0,f=void 0,g=void 0,m=0,n=0;n<c.length;n++){if(a=c[n],e=a.element.offset().top,f=g!==e,g=e,f&&(d=a.element.outerHeight(!0)),!(f&&b.topDataPos()+m+d<=b.topVisiblePos())){f&&(h.topVisible=a.item,h.topVisibleElement=a.element,h.topVisibleScope=a.scope,j(i,a.item),k(i,a.element),l(i,a.scope));break}m+=d}}}function o(a,b,h,i,j){function k(a,b,c){var d=Object.getOwnPropertyDescriptor(a,b);d&&(d.set||d.get)||Object.defineProperty(a,b,{set:function(a){R[b]=a,e(function(){if(N[c]=a,!M.length){var d=O.topDataPos();O.adjustPadding(),"minIndex"===b&&O.adjustScrollTopAfterMinIndexSet(d)}})},get:function(){return R[b]}})}function o(b){return b&&b!==L||a.$$destroyed}function p(){O.bind("resize",C),O.bind("scroll",C)}function q(){O.unbind("resize",C),O.unbind("scroll",C)}function r(){O.resetTopPadding(),O.resetBottomPadding(),arguments.length&&(K=arguments[0]),N.reset(K),z()}function s(a){return a.element.height()&&a.element[0].offsetParent}function t(a){s(a)&&(N.forEach(function(a){angular.isFunction(a.unregisterVisibilityWatcher)&&(a.unregisterVisibilityWatcher(),delete a.unregisterVisibilityWatcher)}),z())}function u(a,b){return v(a,b,O.insertElement),s(a)?!0:(a.unregisterVisibilityWatcher=a.scope.$watch(function(){return t(a)}),!1)}function v(a,b,c){var d=void 0,e=b>0?N[b-1].element:void 0;return j(function(b,f){d=c(b,e),a.element=b,a.scope=f,f[G]=a.item}),d}function w(){var a=[],b=[],c=[],d=[];N.forEach(function(e,f){switch(e.op){case"prepend":b.unshift(e);break;case"append":u(e,f),e.op="none",d.push(e);break;case"insert":a=a.concat(v(e,f,O.insertElementAnimated)),e.op="none",d.push(e);break;case"remove":c.push(e)}}),c.forEach(function(b){return a=a.concat(N.remove(b))}),b.length&&b.forEach(function(a){u(a),a.op="none"}),N.forEach(function(a,b){return a.scope.$index=N.first+b});var e=N.effectiveHeight(b);return O.adjustScrollTopAfterPrepend(e),{estimatedPaddingIncrement:e,prepended:b,removed:c,inserted:d,animated:a}}function x(a,b){var c=N.effectiveHeight(b.prepended)-b.estimatedPaddingIncrement;return O.adjustScrollTopAfterPrepend(c),b.animated.length?f.all(b.animated).then(function(){O.adjustPadding(),z(a)}):O.adjustPadding(),c+b.estimatedPaddingIncrement>0||N.effectiveHeight(b.inserted)>0}function y(a,b){O.shouldLoadBottom()&&b?1===M.push(!0)&&(B(a),P.loading(!0)):O.shouldLoadTop()&&(b||M[0])&&1===M.push(!1)&&(B(a),P.loading(!0))}function z(a){a||(M=[],a=++L);var b=w();e(function(){o(a)||(x(a,b),y(a,!0),M.length||P.calculateProperties())})}function A(a){var b=w();O.adjustPadding(),e(function(){o(a)||(y(a,x(a,b)),M.shift(),M.length?B(a):(P.loading(!1),p(),P.calculateProperties()))})}function B(a){M[0]?N.length&&!O.shouldLoadBottom()?A(a):S(function(b){o(a)||(b.length<I&&(N.eof=!0),b.length>0&&(O.clipTop(),N.append(b),N.setUpper()),A(a))}):N.length&&!O.shouldLoadTop()?A(a):T(function(b){o(a)||(b.length<I&&(N.bof=!0),b.length>0&&(N.length&&O.clipBottom(),N.prepend(b),N.setLower()),A(a))})}function C(){d.$$phase||P.isLoading||P.disabled||(y(L,!0),M.length?q():(P.calculateProperties(),a.$apply()))}function D(a){if(!P.disabled){var b=O[0].scrollTop,c=O[0].scrollHeight-O[0].clientHeight;(0===b&&!N.bof||b===c&&!N.eof)&&a.preventDefault()}}var E=h.uiScroll.match(/^\s*(\w+)\s+in\s+([\w\.]+)\s*$/);if(!E)throw new Error("Expected uiScroll in form of '_item_ in _datasource_' but got '"+h.uiScroll+"'");var F=null,G=E[1],H=E[2],I=Math.max(3,+h.bufferSize||10),J=i[0],K=parseInt(h.startIndex,10);K=isNaN(K)?1:K;var L=0,M=[],N=new l(I),O=new m(N,b,J,h),P=new n(h,O,N,z);J&&(J.adapter=P);var Q=function(){return angular.isObject(F)&&angular.isFunction(F.get)};if(F=g(H)(a),!Q()&&(F=c.get(H),!Q()))throw new Error(H+" is not a valid datasource");var R={};k(F,"minIndex","minIndexUser"),k(F,"maxIndex","maxIndexUser");var S=2!==F.get.length?function(a){return F.get(N.next,I,a)}:function(a){F.get({index:N.next,append:N.length?N[N.length-1].item:void 0,count:I},a)},T=2!==F.get.length?function(a){return F.get(N.first-I,I,a)}:function(a){F.get({index:N.first-I,prepend:N.length?N[0].item:void 0,count:I},a)};P.reload=r,h.adapter&&g(h.adapter).assign(a,P),j(function(a,b){O.createPaddingElements(a[0]),b.$destroy(),a.remove()}),a.$on("$destroy",function(){q(),O.unbind("mousewheel",D)}),O.bind("mousewheel",D),e(function(){O.applyContainerStyle(),r()})}var p=c.has&&c.has("$animate")?c.get("$animate"):null,q=1===angular.version.major&&angular.version.minor<3;return{require:["?^uiScrollViewport"],transclude:"element",priority:1e3,terminal:!0,link:o}}])}(); | ||
!function(){"use strict";var a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol?"symbol":typeof a};angular.module("ui.scroll",[]).directive("uiScrollViewport",function(){return{restrict:"A",controller:["$log","$scope","$element",function(a,b,c){var d=this;d.container=c,d.viewport=c,angular.forEach(c.children(),function(a){"tbody"===a.tagName.toLowerCase()&&(d.viewport=angular.element(a))})}]}}).directive("uiScroll",["$log","$injector","$rootScope","$timeout","$q","$parse",function(b,c,d,e,f,g){function h(a,b){return b.after(a),[]}function i(a){return a.element.remove(),a.scope.$destroy(),[]}function j(b,c){if(!p)return h(b,c);if(q){var d=function(){var a=f.defer();return p.enter(b,null,c,function(){return a.resolve()}),{v:[a.promise]}}();if("object"===("undefined"==typeof d?"undefined":a(d)))return d.v}return[p.enter(b,null,c)]}function k(b){if(!p)return i(b);if(q){var c=function(){var a=f.defer();return p.leave(b.element,function(){return b.scope.$destroy(),a.resolve()}),{v:[a.promise]}}();if("object"===("undefined"==typeof c?"undefined":a(c)))return c.v}return[p.leave(b.element).then(function(){return b.scope.$destroy()})]}function l(a){var b=Object.create(Array.prototype);return angular.extend(b,{size:a,reset:function(a){b.remove(0,b.length),b.eof=!1,b.bof=!1,b.first=a,b.next=a,b.minIndex=a,b.maxIndex=a,b.minIndexUser=null,b.maxIndexUser=null},append:function(a){a.forEach(function(a){++b.next,b.insert("append",a)}),b.maxIndex=b.eof?b.next-1:Math.max(b.next-1,b.maxIndex)},prepend:function(a){a.reverse().forEach(function(a){--b.first,b.insert("prepend",a)}),b.minIndex=b.bof?b.minIndex=b.first:Math.min(b.first,b.minIndex)},insert:function(a,c){var d={item:c};if(a%1===0)d.op="insert",b.splice(a,0,d);else switch(d.op=a,a){case"append":b.push(d);break;case"prepend":b.unshift(d)}},remove:function(a,c){if(angular.isNumber(a)){for(var d=a;c>d;d++)i(b[d]);return b.splice(a,c-a)}return b.splice(b.indexOf(a),1),k(a)},effectiveHeight:function(a){if(!a.length)return 0;var b=Number.MAX_VALUE,c=Number.MIN_VALUE;return a.forEach(function(a){a.element[0].offsetParent&&(b=Math.min(b,a.element.offset().top),c=Math.max(c,a.element.offset().top+a.element.outerHeight(!0)))}),Math.max(0,c-b)}}),b}function m(a,b,c,d){function e(){var a=Object.create(Array.prototype);return angular.extend(a,{add:function(b){var c=a.find(function(a){return a.index===b.scope.$index});return c?void(c.height=b.element.outerHeight()):void a.push({index:b.scope.$index,height:b.element.outerHeight()})},clear:function(){a.length=0}}),a}function f(a){var b=void 0;switch(a.tagName){case"dl":throw new Error("ui-scroll directive does not support <"+a.tagName+"> as a repeating tag: "+a.outerHTML);case"tr":var c=angular.element("<table><tr><td><div></div></td></tr></table>");b=c.find("tr");break;case"li":b=angular.element("<li></li>");break;default:b=angular.element("<div></div>")}return b.cache=new e,b}function g(){return n.outerHeight()*Math.max(i,+d.padding||k)}var i=.3,k=.5,l=void 0,m=void 0,n=c&&c.viewport?c.viewport:angular.element(window),o=c&&c.container?c.container:void 0;return n.css({"overflow-y":"auto",display:"block"}),angular.extend(n,{createPaddingElements:function(a){l=new f(a),m=new f(a),b.before(l),b.after(m)},applyContainerStyle:function(){o&&o!==n&&n.css("height",window.getComputedStyle(o[0]).height)},bottomDataPos:function(){var a=n[0].scrollHeight;return a=null!=a?a:n[0].document.documentElement.scrollHeight,a-m.height()},topDataPos:function(){return l.height()},bottomVisiblePos:function(){return n.scrollTop()+n.outerHeight()},topVisiblePos:function(){return n.scrollTop()},insertElement:function(a,b){return h(a,b||l)},insertElementAnimated:function(a,b){return j(a,b||l)},shouldLoadBottom:function(){return!a.eof&&n.bottomDataPos()<n.bottomVisiblePos()+g()},clipBottom:function(){for(var b=0,c=0,d=0,e=n.bottomDataPos()-n.bottomVisiblePos()-g(),f=a.length-1;f>=0&&(d=a[f].element.outerHeight(!0),!(c+d>e));f--)m.cache.add(a[f]),c+=d,b++;b>0&&(a.eof=!1,a.remove(a.length-b,a.length),a.next-=b,n.adjustPadding())},shouldLoadTop:function(){return!a.bof&&n.topDataPos()>n.topVisiblePos()-g()},clipTop:function(){for(var b=0,c=0,d=0,e=n.topVisiblePos()-n.topDataPos()-g(),f=0;f<a.length&&(d=a[f].element.outerHeight(!0),!(c+d>e));f++)l.cache.add(a[f]),c+=d,b++;b>0&&(l.height(l.height()+c),a.bof=!1,a.remove(0,b),a.first+=b)},adjustPadding:function(){if(a.length){var b=l.cache.reduce(function(b,c){return b+(c.index<a.first?c.height:0)},0),c=m.cache.reduce(function(b,c){return b+(c.index>=a.next?c.height:0)},0),d=a.reduce(function(a,b){return a+b.element.outerHeight(!0)},0),e=(d+b+c)/(a.maxIndex-a.minIndex+1),f=null!==a.minIndexUser&&a.minIndex>a.minIndexUser,g=null!==a.maxIndexUser&&a.maxIndex<a.maxIndexUser,h=f?(a.minIndex-a.minIndexUser)*e:0,i=g?(a.maxIndexUser-a.maxIndex)*e:0;l.height(b+h),m.height(c+i)}},adjustScrollTopAfterMinIndexSet:function(b){if(null!==a.minIndexUser&&a.minIndex>a.minIndexUser){var c=l.height()-b;n.scrollTop(n.scrollTop()+c)}},adjustScrollTopAfterPrepend:function(b){if(b.prepended.length){var c=a.effectiveHeight(b.prepended),d=l.height()-c;d>=0?l.height(d):(l.height(0),n.scrollTop(n.scrollTop()-d))}},resetTopPadding:function(){l.height(0),l.cache.clear()},resetBottomPadding:function(){m.height(0),m.cache.clear()}}),n}function n(a,b,c,e){function f(c){var d=a[c],e=i,f=void 0;if(d){var h=d.match(/^(\S+)(?:\s+on\s+(\w(?:\w|\d)*))?$/);if(!h)throw new Error("Expected injection expression in form of 'target' or 'target on controller' but got '"+d+"'");var j=h[1],l=h[2];if(l){var m=b;for(e=void 0;m.length;){var n=m.attr("ng-controller");if(n===l){e=m.scope();break}m=m.parent()}if(!e)throw new Error("Failed to locate target controller '"+l+"' to inject '"+j+"'")}f=g(j).assign}return function(a){k!==a&&(k[c]=a),f&&f(e,a)}}function h(a,b){if(angular.isArray(b)){var d=void 0,e=c.indexOf(a)+1;b.reverse().forEach(function(b){b===a.item?(d=!0,e--):c.insert(e,b)}),d||(a.op="remove")}}var i=b.scope()||d,j=!1,k=this;f("adapter")(k);var l=f("topVisible"),m=f("topVisibleElement"),n=f("topVisibleScope"),o=f("isLoading");Object.defineProperty(this,"disabled",{get:function(){return j},set:function(a){return(j=a)?null:e()}}),this.isLoading=!1,this.isBOF=function(){return c.bof},this.isEOF=function(){return c.eof},this.applyUpdates=function(a,b){if(angular.isFunction(a))c.slice(0).forEach(function(b){h(b,a(b.item,b.scope,b.element))});else{if(a%1!==0)throw new Error("applyUpdates - "+a+" is not a valid index");var d=a-c.first;d>=0&&d<c.length&&h(c[d],b)}e()},this.append=function(a){c.append(a),e()},this.prepend=function(a){c.prepend(a),e()},this.loading=function(a){o(a)},this.calculateProperties=function(){for(var a=void 0,d=void 0,e=void 0,f=void 0,g=void 0,h=0,i=0;i<c.length;i++){if(a=c[i],e=a.element.offset().top,f=g!==e,g=e,f&&(d=a.element.outerHeight(!0)),!(f&&b.topDataPos()+h+d<=b.topVisiblePos())){f&&(l(a.item),m(a.element),n(a.scope));break}h+=d}}}function o(a,b,h,i,j){function k(a,b,c){var d=Object.getOwnPropertyDescriptor(a,b);d&&(d.set||d.get)||Object.defineProperty(a,b,{set:function(a){R[b]=a,e(function(){if(N[c]=a,!M.length){var d=O.topDataPos();O.adjustPadding(),"minIndex"===b&&O.adjustScrollTopAfterMinIndexSet(d)}})},get:function(){return R[b]}})}function o(b){return b&&b!==L||a.$$destroyed}function p(){O.bind("resize",C),O.bind("scroll",C)}function q(){O.unbind("resize",C),O.unbind("scroll",C)}function r(){O.resetTopPadding(),O.resetBottomPadding(),arguments.length&&(K=arguments[0]),N.reset(K),z()}function s(a){return a.element.height()&&a.element[0].offsetParent}function t(a){s(a)&&(N.forEach(function(a){angular.isFunction(a.unregisterVisibilityWatcher)&&(a.unregisterVisibilityWatcher(),delete a.unregisterVisibilityWatcher)}),z())}function u(a,b){v(a,b,O.insertElement),s(a)||(a.unregisterVisibilityWatcher=a.scope.$watch(function(){return t(a)})),a.element.addClass("ng-hide")}function v(a,b,c){var d=void 0,e=b>0?N[b-1].element:void 0;return j(function(b,f){d=c(b,e),a.element=b,a.scope=f,f[G]=a.item}),P.transform&&P.transform(a.scope,a.element),d}function w(){var a=[],b=[],c=[],d=[];return N.forEach(function(e,f){switch(e.op){case"prepend":b.unshift(e);break;case"append":u(e,f),e.op="none",d.push(e);break;case"insert":a=a.concat(v(e,f,O.insertElementAnimated)),e.op="none",d.push(e);break;case"remove":c.push(e)}}),c.forEach(function(b){return a=a.concat(N.remove(b))}),b.length&&b.forEach(function(a){u(a),a.op="none"}),N.forEach(function(a,b){return a.scope.$index=N.first+b}),{prepended:b,removed:c,inserted:d,animated:a}}function x(a,b){b.animated.length?f.all(b.animated).then(function(){O.adjustPadding(),z(a)}):O.adjustPadding()}function y(a,b){O.shouldLoadBottom()?(!b||N.effectiveHeight(b.inserted)>0)&&1===M.push(!0)&&(B(a),P.loading(!0)):O.shouldLoadTop()&&(!b||N.effectiveHeight(b.prepended)>0||M[0])&&1===M.push(!1)&&(B(a),P.loading(!0))}function z(a){a||(M=[],a=++L);var b=w();e(function(){b.inserted.forEach(function(a){return a.element.removeClass("ng-hide")}),b.prepended.forEach(function(a){return a.element.removeClass("ng-hide")}),o(a)||(x(a,b),y(a),M.length||P.calculateProperties())})}function A(a){var b=w();e(function(){b.inserted.forEach(function(a){return a.element.removeClass("ng-hide")}),b.prepended.forEach(function(a){return a.element.removeClass("ng-hide")}),O.adjustScrollTopAfterPrepend(b),o(a)||(x(a,b),y(a,b),M.shift(),M.length?B(a):(P.loading(!1),p(),P.calculateProperties()))})}function B(a){M[0]?N.length&&!O.shouldLoadBottom()?A(a):S(function(b){o(a)||(b.length<I&&(N.eof=!0),b.length>0&&(O.clipTop(),N.append(b)),A(a))}):N.length&&!O.shouldLoadTop()?A(a):T(function(b){o(a)||(b.length<I&&(N.bof=!0),b.length>0&&(N.length&&O.clipBottom(),N.prepend(b)),A(a))})}function C(){d.$$phase||P.isLoading||P.disabled||(y(L),M.length?q():(P.calculateProperties(),a.$apply()))}function D(a){if(!P.disabled){var b=O[0].scrollTop,c=O[0].scrollHeight-O[0].clientHeight;(0===b&&!N.bof||b===c&&!N.eof)&&a.preventDefault()}}var E=h.uiScroll.match(/^\s*(\w+)\s+in\s+([(\w|\$)\.]+)\s*$/);if(!E)throw new Error("Expected uiScroll in form of '_item_ in _datasource_' but got '"+h.uiScroll+"'");var F=null,G=E[1],H=E[2],I=Math.max(3,+h.bufferSize||10),J=i[0],K=parseInt(h.startIndex,10);K=isNaN(K)?1:K;var L=0,M=[],N=new l(I),O=new m(N,b,J,h),P=new n(h,O,N,z);J&&(J.adapter=P);var Q=function(){return angular.isObject(F)&&angular.isFunction(F.get)};if(F=g(H)(a),!Q()&&(F=c.get(H),!Q()))throw new Error(H+" is not a valid datasource");var R={};k(F,"minIndex","minIndexUser"),k(F,"maxIndex","maxIndexUser");var S=2!==F.get.length?function(a){return F.get(N.next,I,a)}:function(a){F.get({index:N.next,append:N.length?N[N.length-1].item:void 0,count:I},a)},T=2!==F.get.length?function(a){return F.get(N.first-I,I,a)}:function(a){F.get({index:N.first-I,prepend:N.length?N[0].item:void 0,count:I},a)};P.reload=r,j(function(a,b){O.createPaddingElements(a[0]),b.$destroy(),a.remove()}),a.$on("$destroy",function(){q(),O.unbind("mousewheel",D)}),O.bind("mousewheel",D),e(function(){O.applyContainerStyle(),r()})}var p=c.has&&c.has("$animate")?c.get("$animate"):null,q=1===angular.version.major&&angular.version.minor<3;return{require:["?^^uiScrollViewport"],restrict:"A",transclude:"element",priority:1e3,terminal:!0,link:o}}])}(); |
{ | ||
"name": "angular-ui-scroll", | ||
"description": "two way infinite scroll", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"src": "./src/", | ||
@@ -6,0 +6,0 @@ "public": "./public/", |
@@ -163,3 +163,3 @@ 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 | ||
* Metod `append` | ||
* Method `append` | ||
@@ -272,2 +272,6 @@ append(newItems) | ||
###v1.5.1 | ||
* Refactored adjustments during elements append/prepend. | ||
* Bof/eof information is accessible out of the scroller. | ||
###v1.5.0 | ||
@@ -274,0 +278,0 @@ * Implemented uiScrollTh and uiScrollTd directives; uiScroll major refactoring. |
@@ -26,3 +26,3 @@ /*! | ||
angular.forEach(element.children(), | ||
angular.forEach(element.children(), | ||
(child => { | ||
@@ -127,2 +127,3 @@ if (child.tagName.toLowerCase() === 'tbody') { | ||
}); | ||
buffer.maxIndex = buffer.eof ? buffer.next - 1 : Math.max(buffer.next - 1, buffer.maxIndex); | ||
}, | ||
@@ -135,2 +136,3 @@ | ||
}); | ||
buffer.minIndex = buffer.bof ? buffer.minIndex = buffer.first : Math.min(buffer.first, buffer.minIndex); | ||
}, | ||
@@ -181,10 +183,2 @@ | ||
setUpper() { | ||
buffer.maxIndex = buffer.eof ? buffer.next - 1 : Math.max(buffer.next - 1, buffer.maxIndex); | ||
}, | ||
setLower() { | ||
buffer.minIndex = buffer.bof ? buffer.minIndex = buffer.first : Math.min(buffer.first, buffer.minIndex); | ||
}, | ||
effectiveHeight(elements) { | ||
@@ -384,4 +378,4 @@ if (!elements.length) | ||
// average heights calculation, items that have never been reached | ||
let adjustTopPadding = buffer.minIndexUser && buffer.minIndex > buffer.minIndexUser; | ||
let adjustBottomPadding = buffer.maxIndexUser && buffer.maxIndex < buffer.maxIndexUser; | ||
let adjustTopPadding = buffer.minIndexUser !== null && buffer.minIndex > buffer.minIndexUser; | ||
let adjustBottomPadding = buffer.maxIndexUser !== null && buffer.maxIndex < buffer.maxIndexUser; | ||
let topPaddingHeightAdd = adjustTopPadding ? (buffer.minIndex - buffer.minIndexUser) * averageItemHeight : 0; | ||
@@ -397,3 +391,3 @@ let bottomPaddingHeightAdd = adjustBottomPadding ? (buffer.maxIndexUser - buffer.maxIndex) * averageItemHeight : 0; | ||
// additional scrollTop adjustment in case of datasource.minIndex external set | ||
if(buffer.minIndexUser && buffer.minIndex > buffer.minIndexUser) { | ||
if (buffer.minIndexUser !== null && buffer.minIndex > buffer.minIndexUser) { | ||
let diff = topPadding.height() - topPaddingHeightOld; | ||
@@ -404,7 +398,11 @@ viewport.scrollTop(viewport.scrollTop() + diff); | ||
adjustScrollTopAfterPrepend(height) { | ||
adjustScrollTopAfterPrepend(updates) { | ||
if(!updates.prepended.length) | ||
return; | ||
const height = buffer.effectiveHeight(updates.prepended); | ||
const paddingHeight = topPadding.height() - height; | ||
if (paddingHeight >= 0) { | ||
topPadding.height(paddingHeight); | ||
} else { | ||
} | ||
else { | ||
topPadding.height(0); | ||
@@ -432,6 +430,11 @@ viewport.scrollTop(viewport.scrollTop() - paddingHeight); | ||
let disabled = false; | ||
let self = this; | ||
injectValue($attr.adapter, this); | ||
createValueInjector('adapter')(self); | ||
let topVisibleInjector = createValueInjector('topVisible'); | ||
let topVisibleElementInjector = createValueInjector('topVisibleElement'); | ||
let topVisibleScopeInjector = createValueInjector('topVisibleScope'); | ||
let isLoadingInjector = createValueInjector('isLoading'); | ||
// Adapter API definition | ||
// Adapter API definition | ||
@@ -444,2 +447,4 @@ Object.defineProperty(this, 'disabled', { | ||
this.isLoading = false; | ||
this.isBOF = () => buffer.bof; | ||
this.isEOF = () => buffer.eof; | ||
@@ -480,4 +485,3 @@ this.applyUpdates = (arg1, arg2) => { | ||
this.loading = (value) => { | ||
this.isLoading = value; | ||
injectValue($attr.isLoading, value); | ||
isLoadingInjector(value); | ||
}; | ||
@@ -500,8 +504,5 @@ | ||
if (isNewRow) { | ||
this.topVisible = item.item; | ||
this.topVisibleElement = item.element; | ||
this.topVisibleScope = item.scope; | ||
injectValue($attr.topVisible, item.item); | ||
injectValue($attr.topVisibleElement, item.element); | ||
injectValue($attr.topVisibleScope, item.scope); | ||
topVisibleInjector(item.item); | ||
topVisibleElementInjector(item.element); | ||
topVisibleScopeInjector(item.scope); | ||
} | ||
@@ -515,3 +516,6 @@ break; | ||
function injectValue(expression, value) { | ||
function createValueInjector(attribute) { | ||
let expression = $attr[attribute]; | ||
let scope = viewportScope; | ||
let assign; | ||
if (expression) { | ||
@@ -523,3 +527,2 @@ let match = expression.match(/^(\S+)(?:\s+on\s+(\w(?:\w|\d)*))?$/); | ||
let controllerName = match[2]; | ||
let scope = viewportScope; | ||
if (controllerName) { | ||
@@ -539,21 +542,10 @@ let candidate = viewport; | ||
} | ||
$parse(target).assign(scope, value); | ||
/* | ||
let scope = viewportScope; | ||
let s = viewportScope; | ||
let i = expression.indexOf('.'); | ||
if (i>0) { | ||
let ctrlName = expression.slice(0, i); | ||
while (s !== $rootScope) { | ||
if (s.hasOwnProperty(ctrlName) && angular.isFunction(s[ctrlName])) { | ||
scope = s; | ||
expression = expression.slice(i+1); | ||
break; | ||
} | ||
s = s.$parent; | ||
} | ||
} | ||
$parse(expression).assign(scope, value); | ||
*/ | ||
assign = $parse(target).assign; | ||
} | ||
return (value) => { | ||
if (self !== value) // just to avoid injecting adapter reference in the adapter itself. Kludgy, I know. | ||
self[attribute] = value; | ||
if (assign) | ||
assign(scope, value); | ||
}; | ||
} | ||
@@ -587,3 +579,3 @@ | ||
const match = $attr.uiScroll.match(/^\s*(\w+)\s+in\s+([\w\.]+)\s*$/); | ||
const match = $attr.uiScroll.match(/^\s*(\w+)\s+in\s+([(\w|\$)\.]+)\s*$/); | ||
@@ -673,4 +665,4 @@ if (!(match)) | ||
viewport.createPaddingElements(clone[0]); | ||
// we do not include the clone in the DOM. It means that the nested directives will not | ||
// be able to reach the parent directives, but in this case it is intentional because we | ||
// we do not include the clone in the DOM. It means that the nested directives will not | ||
// be able to reach the parent directives, but in this case it is intentional because we | ||
// created the clone to access the template tag name | ||
@@ -737,9 +729,7 @@ scope.$destroy(); | ||
function insertWrapperContent(wrapper, insertAfter) { | ||
createElement(wrapper, insertAfter, viewport.insertElement); | ||
if (isElementVisible(wrapper)) | ||
return true; | ||
wrapper.unregisterVisibilityWatcher = wrapper.scope.$watch(() => visibilityWatcher(wrapper)); | ||
return false; | ||
if (!isElementVisible(wrapper)) { | ||
wrapper.unregisterVisibilityWatcher = wrapper.scope.$watch(() => visibilityWatcher(wrapper)); | ||
} | ||
wrapper.element.addClass('ng-hide'); // hide inserted elements before data binding | ||
} | ||
@@ -787,3 +777,3 @@ | ||
}); | ||
toBeRemoved.forEach((wrapper) => promises = promises.concat(buffer.remove(wrapper))); | ||
@@ -799,8 +789,3 @@ | ||
let estimatedPaddingIncrement = buffer.effectiveHeight(toBePrepended); | ||
viewport.adjustScrollTopAfterPrepend(estimatedPaddingIncrement); | ||
return { | ||
estimatedPaddingIncrement: estimatedPaddingIncrement, | ||
prepended: toBePrepended, | ||
@@ -815,7 +800,2 @@ removed: toBeRemoved, | ||
function updatePaddings(rid, updates) { | ||
let adjustedPaddingHeight = buffer.effectiveHeight(updates.prepended) - updates.estimatedPaddingIncrement; | ||
viewport.adjustScrollTopAfterPrepend(adjustedPaddingHeight); | ||
// schedule another adjustBuffer after animation completion | ||
@@ -830,23 +810,25 @@ if (updates.animated.length) { | ||
} | ||
// return true if inserted elements have height > 0 | ||
return adjustedPaddingHeight + updates.estimatedPaddingIncrement > 0 || buffer.effectiveHeight(updates.inserted) > 0; | ||
} | ||
function enqueueFetch(rid, keepFetching) { | ||
if (viewport.shouldLoadBottom() && keepFetching) { | ||
// keepFetching = true means that at least one item app/prepended in the last batch had height > 0 | ||
if (pending.push(true) === 1) { | ||
fetch(rid); | ||
adapter.loading(true); | ||
function enqueueFetch(rid, updates) { | ||
if (viewport.shouldLoadBottom()) { | ||
if(!updates || buffer.effectiveHeight(updates.inserted) > 0) { | ||
// this means that at least one item appended in the last batch has height > 0 | ||
if (pending.push(true) === 1) { | ||
fetch(rid); | ||
adapter.loading(true); | ||
} | ||
} | ||
} else if (viewport.shouldLoadTop() && (keepFetching || pending[0])) { | ||
} else if (viewport.shouldLoadTop()) { | ||
if ((!updates || buffer.effectiveHeight(updates.prepended) > 0) || pending[0]) { | ||
// this means that at least one item appended in the last batch has height > 0 | ||
// pending[0] = true means that previous fetch was appending. We need to force at least one prepend | ||
// BTW there will always be at least 1 element in the pending array because bottom is fetched first | ||
if (pending.push(false) === 1) { | ||
fetch(rid); | ||
adapter.loading(true); | ||
if (pending.push(false) === 1) { | ||
fetch(rid); | ||
adapter.loading(true); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
@@ -863,2 +845,7 @@ function adjustBuffer(rid) { | ||
$timeout(() => { | ||
// show elements after data binging has been done | ||
updates.inserted.forEach(w => w.element.removeClass('ng-hide')); | ||
updates.prepended.forEach(w => w.element.removeClass('ng-hide')); | ||
if (isInvalid(rid)) { | ||
@@ -869,3 +856,3 @@ return; | ||
updatePaddings(rid, updates); | ||
enqueueFetch(rid, true); | ||
enqueueFetch(rid); | ||
@@ -881,11 +868,17 @@ if (!pending.length) { | ||
viewport.adjustPadding(); | ||
// We need the item bindings to be processed before we can do adjustment | ||
$timeout(() => { | ||
// show elements after data binging has been done | ||
updates.inserted.forEach(w => w.element.removeClass('ng-hide')); | ||
updates.prepended.forEach(w => w.element.removeClass('ng-hide')); | ||
viewport.adjustScrollTopAfterPrepend(updates); | ||
if (isInvalid(rid)) { | ||
return; | ||
} | ||
enqueueFetch(rid, updatePaddings(rid, updates)); | ||
updatePaddings(rid, updates); | ||
enqueueFetch(rid, updates); | ||
pending.shift(); | ||
@@ -920,3 +913,2 @@ | ||
buffer.append(result); | ||
buffer.setUpper(); | ||
} | ||
@@ -946,3 +938,2 @@ | ||
buffer.prepend(result); | ||
buffer.setLower(); | ||
} | ||
@@ -959,3 +950,3 @@ | ||
enqueueFetch(ridActual, true); | ||
enqueueFetch(ridActual); | ||
@@ -962,0 +953,0 @@ if (pending.length) { |
@@ -130,2 +130,3 @@ 'use strict'; | ||
}); | ||
buffer.maxIndex = buffer.eof ? buffer.next - 1 : Math.max(buffer.next - 1, buffer.maxIndex); | ||
}, | ||
@@ -137,2 +138,3 @@ prepend: function prepend(items) { | ||
}); | ||
buffer.minIndex = buffer.bof ? buffer.minIndex = buffer.first : Math.min(buffer.first, buffer.minIndex); | ||
}, | ||
@@ -185,8 +187,2 @@ | ||
}, | ||
setUpper: function setUpper() { | ||
buffer.maxIndex = buffer.eof ? buffer.next - 1 : Math.max(buffer.next - 1, buffer.maxIndex); | ||
}, | ||
setLower: function setLower() { | ||
buffer.minIndex = buffer.bof ? buffer.minIndex = buffer.first : Math.min(buffer.first, buffer.minIndex); | ||
}, | ||
effectiveHeight: function effectiveHeight(elements) { | ||
@@ -378,4 +374,4 @@ if (!elements.length) return 0; | ||
// average heights calculation, items that have never been reached | ||
var adjustTopPadding = buffer.minIndexUser && buffer.minIndex > buffer.minIndexUser; | ||
var adjustBottomPadding = buffer.maxIndexUser && buffer.maxIndex < buffer.maxIndexUser; | ||
var adjustTopPadding = buffer.minIndexUser !== null && buffer.minIndex > buffer.minIndexUser; | ||
var adjustBottomPadding = buffer.maxIndexUser !== null && buffer.maxIndex < buffer.maxIndexUser; | ||
var topPaddingHeightAdd = adjustTopPadding ? (buffer.minIndex - buffer.minIndexUser) * averageItemHeight : 0; | ||
@@ -390,3 +386,3 @@ var bottomPaddingHeightAdd = adjustBottomPadding ? (buffer.maxIndexUser - buffer.maxIndex) * averageItemHeight : 0; | ||
// additional scrollTop adjustment in case of datasource.minIndex external set | ||
if (buffer.minIndexUser && buffer.minIndex > buffer.minIndexUser) { | ||
if (buffer.minIndexUser !== null && buffer.minIndex > buffer.minIndexUser) { | ||
var diff = topPadding.height() - topPaddingHeightOld; | ||
@@ -396,3 +392,5 @@ viewport.scrollTop(viewport.scrollTop() + diff); | ||
}, | ||
adjustScrollTopAfterPrepend: function adjustScrollTopAfterPrepend(height) { | ||
adjustScrollTopAfterPrepend: function adjustScrollTopAfterPrepend(updates) { | ||
if (!updates.prepended.length) return; | ||
var height = buffer.effectiveHeight(updates.prepended); | ||
var paddingHeight = topPadding.height() - height; | ||
@@ -420,10 +418,13 @@ if (paddingHeight >= 0) { | ||
function Adapter($attr, viewport, buffer, adjustBuffer) { | ||
var _this = this; | ||
var viewportScope = viewport.scope() || $rootScope; | ||
var disabled = false; | ||
var self = this; | ||
injectValue($attr.adapter, this); | ||
createValueInjector('adapter')(self); | ||
var topVisibleInjector = createValueInjector('topVisible'); | ||
var topVisibleElementInjector = createValueInjector('topVisibleElement'); | ||
var topVisibleScopeInjector = createValueInjector('topVisibleScope'); | ||
var isLoadingInjector = createValueInjector('isLoading'); | ||
// Adapter API definition | ||
// Adapter API definition | ||
@@ -440,2 +441,8 @@ Object.defineProperty(this, 'disabled', { | ||
this.isLoading = false; | ||
this.isBOF = function () { | ||
return buffer.bof; | ||
}; | ||
this.isEOF = function () { | ||
return buffer.eof; | ||
}; | ||
@@ -477,4 +484,3 @@ this.applyUpdates = function (arg1, arg2) { | ||
this.loading = function (value) { | ||
_this.isLoading = value; | ||
injectValue($attr.isLoading, value); | ||
isLoadingInjector(value); | ||
}; | ||
@@ -501,8 +507,5 @@ | ||
if (isNewRow) { | ||
_this.topVisible = item.item; | ||
_this.topVisibleElement = item.element; | ||
_this.topVisibleScope = item.scope; | ||
injectValue($attr.topVisible, item.item); | ||
injectValue($attr.topVisibleElement, item.element); | ||
injectValue($attr.topVisibleScope, item.scope); | ||
topVisibleInjector(item.item); | ||
topVisibleElementInjector(item.element); | ||
topVisibleScopeInjector(item.scope); | ||
} | ||
@@ -516,3 +519,6 @@ break; | ||
function injectValue(expression, value) { | ||
function createValueInjector(attribute) { | ||
var expression = $attr[attribute]; | ||
var scope = viewportScope; | ||
var assign = void 0; | ||
if (expression) { | ||
@@ -523,3 +529,2 @@ var match = expression.match(/^(\S+)(?:\s+on\s+(\w(?:\w|\d)*))?$/); | ||
var controllerName = match[2]; | ||
var scope = viewportScope; | ||
if (controllerName) { | ||
@@ -538,21 +543,9 @@ var candidate = viewport; | ||
} | ||
$parse(target).assign(scope, value); | ||
/* | ||
let scope = viewportScope; | ||
let s = viewportScope; | ||
let i = expression.indexOf('.'); | ||
if (i>0) { | ||
let ctrlName = expression.slice(0, i); | ||
while (s !== $rootScope) { | ||
if (s.hasOwnProperty(ctrlName) && angular.isFunction(s[ctrlName])) { | ||
scope = s; | ||
expression = expression.slice(i+1); | ||
break; | ||
} | ||
s = s.$parent; | ||
} | ||
} | ||
$parse(expression).assign(scope, value); | ||
*/ | ||
assign = $parse(target).assign; | ||
} | ||
return function (value) { | ||
if (self !== value) // just to avoid injecting adapter reference in the adapter itself. Kludgy, I know. | ||
self[attribute] = value; | ||
if (assign) assign(scope, value); | ||
}; | ||
} | ||
@@ -585,3 +578,3 @@ | ||
var match = $attr.uiScroll.match(/^\s*(\w+)\s+in\s+([\w\.]+)\s*$/); | ||
var match = $attr.uiScroll.match(/^\s*(\w+)\s+in\s+([(\w|\$)\.]+)\s*$/); | ||
@@ -737,10 +730,9 @@ if (!match) throw new Error('Expected uiScroll in form of \'_item_ in _datasource_\' but got \'' + $attr.uiScroll + '\''); | ||
function insertWrapperContent(wrapper, insertAfter) { | ||
createElement(wrapper, insertAfter, viewport.insertElement); | ||
if (isElementVisible(wrapper)) return true; | ||
wrapper.unregisterVisibilityWatcher = wrapper.scope.$watch(function () { | ||
return visibilityWatcher(wrapper); | ||
}); | ||
return false; | ||
if (!isElementVisible(wrapper)) { | ||
wrapper.unregisterVisibilityWatcher = wrapper.scope.$watch(function () { | ||
return visibilityWatcher(wrapper); | ||
}); | ||
} | ||
wrapper.element.addClass('ng-hide'); // hide inserted elements before data binding | ||
} | ||
@@ -801,8 +793,3 @@ | ||
var estimatedPaddingIncrement = buffer.effectiveHeight(toBePrepended); | ||
viewport.adjustScrollTopAfterPrepend(estimatedPaddingIncrement); | ||
return { | ||
estimatedPaddingIncrement: estimatedPaddingIncrement, | ||
prepended: toBePrepended, | ||
@@ -816,7 +803,2 @@ removed: toBeRemoved, | ||
function updatePaddings(rid, updates) { | ||
var adjustedPaddingHeight = buffer.effectiveHeight(updates.prepended) - updates.estimatedPaddingIncrement; | ||
viewport.adjustScrollTopAfterPrepend(adjustedPaddingHeight); | ||
// schedule another adjustBuffer after animation completion | ||
@@ -831,20 +813,22 @@ if (updates.animated.length) { | ||
} | ||
// return true if inserted elements have height > 0 | ||
return adjustedPaddingHeight + updates.estimatedPaddingIncrement > 0 || buffer.effectiveHeight(updates.inserted) > 0; | ||
} | ||
function enqueueFetch(rid, keepFetching) { | ||
if (viewport.shouldLoadBottom() && keepFetching) { | ||
// keepFetching = true means that at least one item app/prepended in the last batch had height > 0 | ||
if (pending.push(true) === 1) { | ||
fetch(rid); | ||
adapter.loading(true); | ||
function enqueueFetch(rid, updates) { | ||
if (viewport.shouldLoadBottom()) { | ||
if (!updates || buffer.effectiveHeight(updates.inserted) > 0) { | ||
// this means that at least one item appended in the last batch has height > 0 | ||
if (pending.push(true) === 1) { | ||
fetch(rid); | ||
adapter.loading(true); | ||
} | ||
} | ||
} else if (viewport.shouldLoadTop() && (keepFetching || pending[0])) { | ||
// pending[0] = true means that previous fetch was appending. We need to force at least one prepend | ||
// BTW there will always be at least 1 element in the pending array because bottom is fetched first | ||
if (pending.push(false) === 1) { | ||
fetch(rid); | ||
adapter.loading(true); | ||
} else if (viewport.shouldLoadTop()) { | ||
if (!updates || buffer.effectiveHeight(updates.prepended) > 0 || pending[0]) { | ||
// this means that at least one item appended in the last batch has height > 0 | ||
// pending[0] = true means that previous fetch was appending. We need to force at least one prepend | ||
// BTW there will always be at least 1 element in the pending array because bottom is fetched first | ||
if (pending.push(false) === 1) { | ||
fetch(rid); | ||
adapter.loading(true); | ||
} | ||
} | ||
@@ -865,2 +849,11 @@ } | ||
$timeout(function () { | ||
// show elements after data binging has been done | ||
updates.inserted.forEach(function (w) { | ||
return w.element.removeClass('ng-hide'); | ||
}); | ||
updates.prepended.forEach(function (w) { | ||
return w.element.removeClass('ng-hide'); | ||
}); | ||
if (isInvalid(rid)) { | ||
@@ -871,3 +864,3 @@ return; | ||
updatePaddings(rid, updates); | ||
enqueueFetch(rid, true); | ||
enqueueFetch(rid); | ||
@@ -883,6 +876,15 @@ if (!pending.length) { | ||
viewport.adjustPadding(); | ||
// We need the item bindings to be processed before we can do adjustment | ||
$timeout(function () { | ||
// show elements after data binging has been done | ||
updates.inserted.forEach(function (w) { | ||
return w.element.removeClass('ng-hide'); | ||
}); | ||
updates.prepended.forEach(function (w) { | ||
return w.element.removeClass('ng-hide'); | ||
}); | ||
viewport.adjustScrollTopAfterPrepend(updates); | ||
if (isInvalid(rid)) { | ||
@@ -892,3 +894,4 @@ return; | ||
enqueueFetch(rid, updatePaddings(rid, updates)); | ||
updatePaddings(rid, updates); | ||
enqueueFetch(rid, updates); | ||
pending.shift(); | ||
@@ -922,3 +925,2 @@ | ||
buffer.append(result); | ||
buffer.setUpper(); | ||
} | ||
@@ -949,3 +951,2 @@ | ||
buffer.prepend(result); | ||
buffer.setLower(); | ||
} | ||
@@ -962,3 +963,3 @@ | ||
enqueueFetch(ridActual, true); | ||
enqueueFetch(ridActual); | ||
@@ -965,0 +966,0 @@ if (pending.length) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
327
675151
137
18206