From adfca9c4703c03995d138dbc22b563fe7f380476 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Fri, 15 Sep 2017 08:59:38 -0700 Subject: [PATCH] Fixed a divide-by-zero error - Updated package.json to allow for testing and building immediately after an `npm install` - Updated everything to v1.1.8 --- CHANGELOG.md | 5 +++++ Gruntfile.js | 4 ++-- README.md | 2 +- bower.json | 2 +- package.json | 9 ++++++--- src/angular-vs-repeat.js | 10 ++++++++-- src/angular-vs-repeat.min.js | 4 ++-- 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7a73a8..8f182a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +Version 1.1.8 (2017/09/15) +================= + + * Fixed a divide-by-zero issue that could prevent items from rendering + Version 1.1.7 (2016/03/08) ================= diff --git a/Gruntfile.js b/Gruntfile.js index 8c457a2..fe7d3d1 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -13,7 +13,7 @@ module.exports = function(grunt){ banner: [ '//', '// Copyright Kamil Pękala http://github.com/kamilkp', - '// Angular Virtual Scroll Repeat v1.1.7 2016/03/08', + '// Angular Virtual Scroll Repeat v1.1.8 2017/09/15', '//', '' ].join('\n') @@ -47,4 +47,4 @@ module.exports = function(grunt){ grunt.registerTask('test', 'Run unit tests', ['jshint', 'min', 'karma:unit']); grunt.registerTask('default', ['test']); grunt.registerTask('travis', ['jshint', 'min', 'karma:travis']); -}; \ No newline at end of file +}; diff --git a/README.md b/README.md index 8c28130..39fe897 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -angular-vs-repeat v1.1.7 +angular-vs-repeat v1.1.8 ================= Looking for a version for Angular 2? diff --git a/bower.json b/bower.json index b33e7f6..64e398e 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-vs-repeat", - "version": "1.1.7", + "version": "1.1.8", "description": "Virtual Scroll for AngularJS ngRepeat directive", "homepage": "http://kamilkp.github.io/angular-vs-repeat", "main": "src/angular-vs-repeat.js", diff --git a/package.json b/package.json index 4653c63..d086358 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-vs-repeat", - "version": "1.1.7", + "version": "1.1.8", "description": "Virtual Scroll for AngularJS ngRepeat directive", "homepage": "http://kamilkp.github.io/angular-vs-repeat", "author": { @@ -26,7 +26,10 @@ "karma-firefox-launcher": "~0.1.3" }, "scripts": { - "test": "grunt travis" + "test": "grunt travis --force" }, - "dependencies": {} + "dependencies": { + "grunt-cli": "^1.2.0", + "travis": "^0.1.1" + } } diff --git a/src/angular-vs-repeat.js b/src/angular-vs-repeat.js index f65da69..7807d3b 100644 --- a/src/angular-vs-repeat.js +++ b/src/angular-vs-repeat.js @@ -1,6 +1,6 @@ // // Copyright Kamil Pękala http://github.com/kamilkp -// Angular Virtual Scroll Repeat v1.1.7 2016/03/08 +// Angular Virtual Scroll Repeat v1.1.8 2017/09/15 // (function(window, angular) { @@ -512,7 +512,7 @@ originalLength ); } - else { + else if ($scope.elementSize > 0) { __startIndex = Math.max( Math.floor( ($scrollPosition - $scope.offsetBefore - scrollOffset) / $scope.elementSize @@ -527,6 +527,12 @@ originalLength ); } + else { + // Don't try to divide by zero, just default to the size of the + // array + __startIndex = 0; + __endIndex = originalLength; + } _minStartIndex = Math.min(__startIndex, _minStartIndex); _maxEndIndex = Math.max(__endIndex, _maxEndIndex); diff --git a/src/angular-vs-repeat.min.js b/src/angular-vs-repeat.min.js index b76ce4b..d83eecb 100644 --- a/src/angular-vs-repeat.min.js +++ b/src/angular-vs-repeat.min.js @@ -1,5 +1,5 @@ // // Copyright Kamil Pękala http://github.com/kamilkp -// Angular Virtual Scroll Repeat v1.1.7 2016/03/08 +// Angular Virtual Scroll Repeat v1.1.8 2017/09/15 // -!function(a,b){"use strict";function c(){if("pageYOffset"in a)return{scrollTop:pageYOffset,scrollLeft:pageXOffset};var b,c,d=document,e=d.documentElement,f=d.body;return b=e.scrollLeft||f.scrollLeft||0,c=e.scrollTop||f.scrollTop||0,{scrollTop:c,scrollLeft:b}}function d(b,c){return b===a?"clientWidth"===c?a.innerWidth:a.innerHeight:b[c]}function e(b,d){return b===a?c()[d]:b[d]}function f(b,d,e){return b.getBoundingClientRect()[e?"left":"top"]-(d===a?0:d.getBoundingClientRect()[e?"left":"top"])+(d===a?c():d)[e?"scrollLeft":"scrollTop"]}var g=document.documentElement,h=g.matches?"matches":g.matchesSelector?"matchesSelector":g.webkitMatches?"webkitMatches":g.webkitMatchesSelector?"webkitMatchesSelector":g.msMatches?"msMatches":g.msMatchesSelector?"msMatchesSelector":g.mozMatches?"mozMatches":g.mozMatchesSelector?"mozMatchesSelector":null,i=b.element.prototype.closest||function(a){for(var c=this[0].parentNode;c!==document.documentElement&&null!=c&&!c[h](a);)c=c.parentNode;return c&&c[h](a)?b.element(c):b.element()},j=b.module("vs-repeat",[]).directive("vsRepeat",["$compile","$parse",function(c,g){return{restrict:"A",scope:!0,compile:function(h,j){var k,l,m,n,o,p,q=b.isDefined(j.vsRepeatContainer)?b.element(h[0].querySelector(j.vsRepeatContainer)):h,r=q.children().eq(0),s=r[0].outerHTML,t="$vs_collection",u=!1,v={vsRepeat:"elementSize",vsOffsetBefore:"offsetBefore",vsOffsetAfter:"offsetAfter",vsScrolledToEndOffset:"scrolledToEndOffset",vsScrolledToBeginningOffset:"scrolledToBeginningOffset",vsExcess:"excess"};if(r.attr("ng-repeat"))p="ng-repeat",k=r.attr("ng-repeat");else if(r.attr("data-ng-repeat"))p="data-ng-repeat",k=r.attr("data-ng-repeat");else if(r.attr("ng-repeat-start"))u=!0,p="ng-repeat-start",k=r.attr("ng-repeat-start");else{if(!r.attr("data-ng-repeat-start"))throw new Error("angular-vs-repeat: no ng-repeat directive on a child element");u=!0,p="data-ng-repeat-start",k=r.attr("data-ng-repeat-start")}if(l=/^\s*(\S+)\s+in\s+([\S\s]+?)(track\s+by\s+\S+)?$/.exec(k),m=l[1],n=l[2],o=l[3],u)for(var w=0,x=q.children().eq(0);null==x.attr("ng-repeat-end")&&null==x.attr("data-ng-repeat-end");)w++,x=q.children().eq(w),s+=x[0].outerHTML;return q.empty(),{pre:function(h,j,k){function l(){if(!G||G.length<1)h[t]=[],C=0,h.sizesCumulative=[0];else if(C=G.length,L){h.sizes=G.map(function(a){var c=h.$new(!1);b.extend(c,a),c[m]=a;var d=k.vsSize||k.vsSizeProperty?c.$eval(k.vsSize||k.vsSizeProperty):h.elementSize;return c.$destroy(),d});var a=0;h.sizesCumulative=h.sizes.map(function(b){var c=a;return a+=b,c}),h.sizesCumulative.push(a)}else q();y()}function q(){K&&h.$$postDigest(function(){if(D[0].offsetHeight||D[0].offsetWidth){for(var a=D.children(),b=0,c=!1,d=!1;b0&&i--,i=Math.max(Math.floor(i-h.excess/2),0),j=i;h.sizesCumulative[j]=h.excess/2||0===h.startIndex&&0!==R?l=!0:(Math.abs(h.endIndex-S)>=h.excess/2||h.endIndex===C&&S!==C)&&(l=!0):l=h.startIndex!==R||h.endIndex!==S),l){h[t]=G.slice(h.startIndex,h.endIndex),h.$emit("vsRepeatInnerCollectionUpdated",h.startIndex,h.endIndex,R,S);var m;k.vsScrolledToEnd&&(m=G.length-(h.scrolledToEndOffset||0),(h.endIndex>=m&&Sh.startIndex&&h.$eval(k.vsScrolledToBeginning)),R=h.startIndex,S=h.endIndex;var n=L?"(sizesCumulative[$index + startIndex] + offsetBefore)":"(($index + startIndex) * elementSize + offsetBefore)",o=g(n),p=o(h,{$index:0}),q=o(h,{$index:h[t].length}),s=h.totalSize;I.css(r(),p+"px"),J.css(r(),s-q+"px")}return l}var C,D=b.isDefined(k.vsRepeatContainer)?b.element(j[0].querySelector(k.vsRepeatContainer)):j,E=b.element(s),F=E[0].tagName.toLowerCase(),G=[],H=void 0!==k.vsHorizontal,I=b.element("<"+F+' class="vs-repeat-before-content">"),J=b.element("<"+F+' class="vs-repeat-after-content">"),K=!k.vsRepeat,L=!!k.vsSize||!!k.vsSizeProperty,M=k.vsScrollParent?"window"===k.vsScrollParent?b.element(a):i.call(D,k.vsScrollParent):D,N="vsOptions"in k?h.$eval(k.vsOptions):{},O=H?"clientWidth":"clientHeight",P=H?"offsetWidth":"offsetHeight",Q=H?"scrollLeft":"scrollTop";if(h.totalSize=0,!("vsSize"in k)&&"vsSizeProperty"in k&&console.warn("vs-size-property attribute is deprecated. Please use vs-size attribute which also accepts angular expressions."),0===M.length)throw"Specified scroll parent selector did not match any element";h.$scrollParent=M,L&&(h.sizesCumulative=[]),h.elementSize=+k.vsRepeat||d(M[0],O)||50,h.offsetBefore=0,h.offsetAfter=0,h.excess=2,H?(I.css("height","100%"),J.css("height","100%")):(I.css("width","100%"),J.css("width","100%")),Object.keys(v).forEach(function(a){k[a]&&k.$observe(a,function(b){h[v[a]]=+b,y()})}),h.$watchCollection(n,function(a){G=a||[],l()}),E.eq(0).attr(p,m+" in "+t+(o?" "+o:"")),E.addClass("vs-repeat-repeated-element"),D.append(I),D.append(E),c(E)(h),D.append(J),h.startIndex=0,h.endIndex=0,M.on("scroll",w),b.element(a).on("resize",x),h.$on("$destroy",function(){b.element(a).off("resize",x),M.off("scroll",w)}),h.$on("vsRepeatTrigger",l),h.$on("vsRepeatResize",function(){K=!0,q()});var R,S,T,U;h.$on("vsRenderAll",function(){N.latch&&setTimeout(function(){var a=C;U=Math.max(a,U),h.endIndex=N.latch?U:a,h[t]=G.slice(h.startIndex,h.endIndex),S=h.endIndex,h.$$postDigest(function(){I.css(r(),0),J.css(r(),0)}),h.$apply(function(){h.$emit("vsRenderAllDone")})})});var V;h.$watch(function(){"function"==typeof a.requestAnimationFrame?a.requestAnimationFrame(A):A()})}}}}}]);"undefined"!=typeof module&&module.exports&&(module.exports=j.name)}(window,window.angular); \ No newline at end of file +!function(a,b){"use strict";function c(){if("pageYOffset"in a)return{scrollTop:pageYOffset,scrollLeft:pageXOffset};var b,c,d=document,e=d.documentElement,f=d.body;return b=e.scrollLeft||f.scrollLeft||0,c=e.scrollTop||f.scrollTop||0,{scrollTop:c,scrollLeft:b}}function d(b,c){return b===a?"clientWidth"===c?a.innerWidth:a.innerHeight:b[c]}function e(b,d){return b===a?c()[d]:b[d]}function f(b,d,e){return b.getBoundingClientRect()[e?"left":"top"]-(d===a?0:d.getBoundingClientRect()[e?"left":"top"])+(d===a?c():d)[e?"scrollLeft":"scrollTop"]}var g=document.documentElement,h=g.matches?"matches":g.matchesSelector?"matchesSelector":g.webkitMatches?"webkitMatches":g.webkitMatchesSelector?"webkitMatchesSelector":g.msMatches?"msMatches":g.msMatchesSelector?"msMatchesSelector":g.mozMatches?"mozMatches":g.mozMatchesSelector?"mozMatchesSelector":null,i=b.element.prototype.closest||function(a){for(var c=this[0].parentNode;c!==document.documentElement&&null!=c&&!c[h](a);)c=c.parentNode;return c&&c[h](a)?b.element(c):b.element()},j=b.module("vs-repeat",[]).directive("vsRepeat",["$compile","$parse",function(c,g){return{restrict:"A",scope:!0,compile:function(h,j){var k,l,m,n,o,p,q=b.isDefined(j.vsRepeatContainer)?b.element(h[0].querySelector(j.vsRepeatContainer)):h,r=q.children().eq(0),s=r[0].outerHTML,t="$vs_collection",u=!1,v={vsRepeat:"elementSize",vsOffsetBefore:"offsetBefore",vsOffsetAfter:"offsetAfter",vsScrolledToEndOffset:"scrolledToEndOffset",vsScrolledToBeginningOffset:"scrolledToBeginningOffset",vsExcess:"excess"};if(r.attr("ng-repeat"))p="ng-repeat",k=r.attr("ng-repeat");else if(r.attr("data-ng-repeat"))p="data-ng-repeat",k=r.attr("data-ng-repeat");else if(r.attr("ng-repeat-start"))u=!0,p="ng-repeat-start",k=r.attr("ng-repeat-start");else{if(!r.attr("data-ng-repeat-start"))throw new Error("angular-vs-repeat: no ng-repeat directive on a child element");u=!0,p="data-ng-repeat-start",k=r.attr("data-ng-repeat-start")}if(l=/^\s*(\S+)\s+in\s+([\S\s]+?)(track\s+by\s+\S+)?$/.exec(k),m=l[1],n=l[2],o=l[3],u)for(var w=0,x=q.children().eq(0);null==x.attr("ng-repeat-end")&&null==x.attr("data-ng-repeat-end");)w++,x=q.children().eq(w),s+=x[0].outerHTML;return q.empty(),{pre:function(h,j,k){function l(){if(!G||G.length<1)h[t]=[],C=0,h.sizesCumulative=[0];else if(C=G.length,L){h.sizes=G.map(function(a){var c=h.$new(!1);b.extend(c,a),c[m]=a;var d=k.vsSize||k.vsSizeProperty?c.$eval(k.vsSize||k.vsSizeProperty):h.elementSize;return c.$destroy(),d});var a=0;h.sizesCumulative=h.sizes.map(function(b){var c=a;return a+=b,c}),h.sizesCumulative.push(a)}else q();y()}function q(){K&&h.$$postDigest(function(){if(D[0].offsetHeight||D[0].offsetWidth){for(var a=D.children(),b=0,c=!1,d=!1;b0&&i--,i=Math.max(Math.floor(i-h.excess/2),0),j=i;h.sizesCumulative[j]0?(i=Math.max(Math.floor((a-h.offsetBefore-c)/h.elementSize)-h.excess/2,0),j=Math.min(i+Math.ceil(b/h.elementSize)+h.excess,C)):(i=0,j=C);T=Math.min(i,T),U=Math.max(j,U),h.startIndex=N.latch?T:i,h.endIndex=N.latch?U:j,U=h.excess/2||0===h.startIndex&&0!==R?l=!0:(Math.abs(h.endIndex-S)>=h.excess/2||h.endIndex===C&&S!==C)&&(l=!0):l=h.startIndex!==R||h.endIndex!==S),l){h[t]=G.slice(h.startIndex,h.endIndex),h.$emit("vsRepeatInnerCollectionUpdated",h.startIndex,h.endIndex,R,S);var m;k.vsScrolledToEnd&&(m=G.length-(h.scrolledToEndOffset||0),(h.endIndex>=m&&Sh.startIndex&&h.$eval(k.vsScrolledToBeginning)),R=h.startIndex,S=h.endIndex;var n=L?"(sizesCumulative[$index + startIndex] + offsetBefore)":"(($index + startIndex) * elementSize + offsetBefore)",o=g(n),p=o(h,{$index:0}),q=o(h,{$index:h[t].length}),s=h.totalSize;I.css(r(),p+"px"),J.css(r(),s-q+"px")}return l}var C,D=b.isDefined(k.vsRepeatContainer)?b.element(j[0].querySelector(k.vsRepeatContainer)):j,E=b.element(s),F=E[0].tagName.toLowerCase(),G=[],H=void 0!==k.vsHorizontal,I=b.element("<"+F+' class="vs-repeat-before-content">"),J=b.element("<"+F+' class="vs-repeat-after-content">"),K=!k.vsRepeat,L=!!k.vsSize||!!k.vsSizeProperty,M=k.vsScrollParent?"window"===k.vsScrollParent?b.element(a):i.call(D,k.vsScrollParent):D,N="vsOptions"in k?h.$eval(k.vsOptions):{},O=H?"clientWidth":"clientHeight",P=H?"offsetWidth":"offsetHeight",Q=H?"scrollLeft":"scrollTop";if(h.totalSize=0,!("vsSize"in k)&&"vsSizeProperty"in k&&console.warn("vs-size-property attribute is deprecated. Please use vs-size attribute which also accepts angular expressions."),0===M.length)throw"Specified scroll parent selector did not match any element";h.$scrollParent=M,L&&(h.sizesCumulative=[]),h.elementSize=+k.vsRepeat||d(M[0],O)||50,h.offsetBefore=0,h.offsetAfter=0,h.excess=2,H?(I.css("height","100%"),J.css("height","100%")):(I.css("width","100%"),J.css("width","100%")),Object.keys(v).forEach(function(a){k[a]&&k.$observe(a,function(b){h[v[a]]=+b,y()})}),h.$watchCollection(n,function(a){G=a||[],l()}),E.eq(0).attr(p,m+" in "+t+(o?" "+o:"")),E.addClass("vs-repeat-repeated-element"),D.append(I),D.append(E),c(E)(h),D.append(J),h.startIndex=0,h.endIndex=0,M.on("scroll",w),b.element(a).on("resize",x),h.$on("$destroy",function(){b.element(a).off("resize",x),M.off("scroll",w)}),h.$on("vsRepeatTrigger",l),h.$on("vsRepeatResize",function(){K=!0,q()});var R,S,T,U;h.$on("vsRenderAll",function(){N.latch&&setTimeout(function(){var a=C;U=Math.max(a,U),h.endIndex=N.latch?U:a,h[t]=G.slice(h.startIndex,h.endIndex),S=h.endIndex,h.$$postDigest(function(){I.css(r(),0),J.css(r(),0)}),h.$apply(function(){h.$emit("vsRenderAllDone")})})});var V;h.$watch(function(){"function"==typeof a.requestAnimationFrame?a.requestAnimationFrame(A):A()})}}}}}]);"undefined"!=typeof module&&module.exports&&(module.exports=j.name)}(window,window.angular); \ No newline at end of file