|
132 | 132 | } |
133 | 133 | $document.on("mousedown", mousedownOnDoc); |
134 | 134 | $document.on("keydown", keydownOnOnDoc); |
| 135 | + $document.on("scroll", invalidSizes); |
135 | 136 | } |
136 | 137 | function removeEventListeners() { |
137 | 138 | ctrl.ngelt.off('wheel', wheelOnElt); |
|
144 | 145 | ng.element($window).off("resize", updateSize); |
145 | 146 | $document.off("mousedown", mousedownOnDoc); |
146 | 147 | $document.off("keydown", keydownOnOnDoc); |
| 148 | + $document.off("scroll", invalidSizes); |
| 149 | + } |
| 150 | + function invalidSizes(event) { |
| 151 | + ctrl.getScrollbarArea().invalid = true; |
| 152 | + ctrl.getEltArea().invalid = true; |
147 | 153 | } |
148 | 154 | function keydownOnOnDoc(event) { |
149 | 155 | if (!$scope.allowKeynav || !hasFocus || event.which < 33 || event.which > 40) |
|
492 | 498 | if ($scope.max) { |
493 | 499 | $scope.ngLimit = $scope.max; |
494 | 500 | } else if ($scope.total) { |
495 | | - if (items.length) { |
496 | | - var size = ctrl.horizontal ? |
497 | | - getArea(items[items.length - 1]).right - getArea(items[0]).left : |
498 | | - getArea(items[items.length - 1]).bottom - getArea(items[0]).top; |
499 | | - var offset = getOffsetPixelContainerBeforeItem(items[0]); // on ignore les éléments avant |
500 | | - var empty = getHeightArea() - offset - size; |
| 501 | + var nbItems = items.length; |
| 502 | + if (nbItems) { |
| 503 | + var firstItem = items[0]; |
| 504 | + var lastItem = items[nbItems - 1]; |
| 505 | + var containerSize = ctrl.horizontal ? |
| 506 | + getArea(lastItem).right - getArea(firstItem).left : |
| 507 | + getArea(lastItem).bottom - getArea(firstItem).top; |
| 508 | + var offset = getOffsetPixelContainerBeforeItem(firstItem); // on ignore les éléments avant |
| 509 | + var empty = getHeightArea() - offset - containerSize; // zone non remplie |
501 | 510 | var inc = 0; |
502 | | - var average = size / items.length; |
| 511 | + var average = containerSize / nbItems; |
503 | 512 | if (average) { // protect div par 0 |
504 | 513 | var floatValue = empty / average; |
505 | 514 | inc = floatValue < 0 ? Math.ceil(floatValue) : Math.ceil(floatValue); // on veut en voir une de plus |
|
769 | 778 | ngelt.append(ctrl.ngsb); |
770 | 779 | ctrl.sb = getHtmlElement(ctrl.ngsb); |
771 | 780 | var watcherClears = []; |
772 | | - if (ngelt.css('display') === 'none') { // si c'est une popup, on surveille le display via un $interval global |
| 781 | + if (ngelt.css('display') === 'none') { // si c'est une popup, on surveille le display |
773 | 782 | var watcherClear = scope.$watch(function (scope) { |
774 | 783 | return scope.ctrl.ngelt.css('display'); |
775 | 784 | }, function (v1, v2, s) { |
|
807 | 816 | } |
808 | 817 | })); |
809 | 818 | } |
| 819 | + var totalTimer; |
810 | 820 | watcherClears.push(scope.$watch('total', function (v1, v2, s) { |
811 | 821 | if (v1 !== v2) { |
812 | | - $timeout(s.ctrl.updateTotal, s.debounce || DEBOUNCE, true); |
| 822 | + if(totalTimer) $timeout.cancel(totalTimer); |
| 823 | + totalTimer = $timeout(s.ctrl.updateTotal, s.debounce || DEBOUNCE, true); |
813 | 824 | } |
814 | 825 | })); |
| 826 | + var limitTimer; |
815 | 827 | watcherClears.push(scope.$watch('ngLimit', function (v1, v2, s) { |
816 | 828 | if (v1 !== v2) { |
817 | | - $timeout(s.ctrl.updateLimit, s.debounce || DEBOUNCE, true); |
| 829 | + if(limitTimer) $timeout.cancel(limitTimer); |
| 830 | + limitTimer = $timeout(s.ctrl.updateLimit, s.debounce || DEBOUNCE, true); |
818 | 831 | } |
819 | 832 | })); |
820 | 833 | watcherClears.push(scope.$watch('ngBegin', function (v1, v2, s) { |
821 | 834 | if (v1 >= 0 && v1 <= s.total - s.ctrl.getInnerLimit()) { |
822 | | - $timeout(s.ctrl.updateBegin, s.debounce || DEBOUNCE, true); |
| 835 | + s.ctrl.updateBegin(); |
823 | 836 | } else if (v1 < 0) { |
824 | 837 | s.ngBegin = 0; |
825 | 838 | } else { |
|
0 commit comments