-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathui-scroll.js
1594 lines (1558 loc) · 61.3 KB
/
ui-scroll.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* angular-ui-scroll
* https://github.com/angular-ui/ui-scroll
* Version: 1.9.1 -- 2023-05-17T15:38:46.936Z
* License: MIT
*/
/******/ (function() { // webpackBootstrap
/******/ "use strict";
var __webpack_exports__ = {};
;// CONCATENATED MODULE: ./src/modules/jqLiteExtras.js
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
/*!
globals: angular, window
List of used element methods available in JQuery but not in JQuery Lite
element.before(elem)
element.height()
element.outerHeight(true)
element.height(value) = only for Top/Bottom padding elements
element.scrollTop()
element.scrollTop(value)
*/
var JQLiteExtras = /*#__PURE__*/function () {
function JQLiteExtras() {
_classCallCheck(this, JQLiteExtras);
}
_createClass(JQLiteExtras, [{
key: "registerFor",
value: function registerFor(element) {
var convertToPx, css, getStyle, isWindow;
// angular implementation blows up if elem is the window
css = angular.element.prototype.css;
element.prototype.css = function (name, value) {
var self = this;
var elem = self[0];
if (!(!elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style)) {
return css.call(self, name, value);
}
};
// as defined in angularjs v1.0.5
isWindow = function isWindow(obj) {
return obj && obj.document && obj.location && obj.alert && obj.setInterval;
};
function scrollTo(self, direction, value) {
var elem = self[0];
var _top$left$direction = _slicedToArray({
top: ['scrollTop', 'pageYOffset', 'scrollLeft'],
left: ['scrollLeft', 'pageXOffset', 'scrollTop']
}[direction], 3),
method = _top$left$direction[0],
prop = _top$left$direction[1],
preserve = _top$left$direction[2];
var isValueDefined = typeof value !== 'undefined';
if (isWindow(elem)) {
if (isValueDefined) {
return elem.scrollTo(self[preserve].call(self), value);
}
return prop in elem ? elem[prop] : elem.document.documentElement[method];
} else {
if (isValueDefined) {
elem[method] = value;
}
return elem[method];
}
}
if (window.getComputedStyle) {
getStyle = function getStyle(elem) {
return window.getComputedStyle(elem, null);
};
convertToPx = function convertToPx(elem, value) {
return parseFloat(value);
};
} else {
getStyle = function getStyle(elem) {
return elem.currentStyle;
};
convertToPx = function convertToPx(elem, value) {
var left, result, rs, rsLeft, style;
var core_pnum = /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source;
var rnumnonpx = new RegExp('^(' + core_pnum + ')(?!px)[a-z%]+$', 'i');
if (!rnumnonpx.test(value)) {
return parseFloat(value);
}
// ported from JQuery
style = elem.style;
left = style.left;
rs = elem.runtimeStyle;
rsLeft = rs && rs.left;
if (rs) {
rs.left = style.left;
}
// put in the new values to get a computed style out
style.left = value;
result = style.pixelLeft;
style.left = left;
if (rsLeft) {
rs.left = rsLeft;
}
return result;
};
}
function getMeasurements(elem, measure) {
var base, borderA, borderB, computedMarginA, computedMarginB, computedStyle, dirA, dirB, marginA, marginB, paddingA, paddingB;
if (isWindow(elem)) {
base = document.documentElement[{
height: 'clientHeight',
width: 'clientWidth'
}[measure]];
return {
base: base,
padding: 0,
border: 0,
margin: 0
};
}
// Start with offset property
var _width$height$measure = _slicedToArray({
width: [elem.offsetWidth, 'Left', 'Right'],
height: [elem.offsetHeight, 'Top', 'Bottom']
}[measure], 3);
base = _width$height$measure[0];
dirA = _width$height$measure[1];
dirB = _width$height$measure[2];
computedStyle = getStyle(elem);
paddingA = convertToPx(elem, computedStyle['padding' + dirA]) || 0;
paddingB = convertToPx(elem, computedStyle['padding' + dirB]) || 0;
borderA = convertToPx(elem, computedStyle['border' + dirA + 'Width']) || 0;
borderB = convertToPx(elem, computedStyle['border' + dirB + 'Width']) || 0;
computedMarginA = computedStyle['margin' + dirA];
computedMarginB = computedStyle['margin' + dirB];
// I do not care for width for now, so this hack is irrelevant
// if ( !supportsPercentMargin )
// computedMarginA = hackPercentMargin( elem, computedStyle, computedMarginA )
// computedMarginB = hackPercentMargin( elem, computedStyle, computedMarginB )
marginA = convertToPx(elem, computedMarginA) || 0;
marginB = convertToPx(elem, computedMarginB) || 0;
return {
base: base,
padding: paddingA + paddingB,
border: borderA + borderB,
margin: marginA + marginB
};
}
function getWidthHeight(elem, direction, measure) {
var computedStyle, result;
var measurements = getMeasurements(elem, direction);
if (measurements.base > 0) {
return {
base: measurements.base - measurements.padding - measurements.border,
outer: measurements.base,
outerfull: measurements.base + measurements.margin
}[measure];
}
// Fall back to computed then uncomputed css if necessary
computedStyle = getStyle(elem);
result = computedStyle[direction];
if (result < 0 || result === null) {
result = elem.style[direction] || 0;
}
// Normalize "", auto, and prepare for extra
result = parseFloat(result) || 0;
return {
base: result - measurements.padding - measurements.border,
outer: result,
outerfull: result + measurements.padding + measurements.border + measurements.margin
}[measure];
}
// define missing methods
return angular.forEach({
before: function before(newElem) {
var children, elem, i, j, parent, ref, self;
self = this;
elem = self[0];
parent = self.parent();
children = parent.contents();
if (children[0] === elem) {
return parent.prepend(newElem);
} else {
for (i = j = 1, ref = children.length - 1; 1 <= ref ? j <= ref : j >= ref; i = 1 <= ref ? ++j : --j) {
if (children[i] === elem) {
angular.element(children[i - 1]).after(newElem);
return;
}
}
throw new Error('invalid DOM structure ' + elem.outerHTML);
}
},
height: function height(value) {
var self;
self = this;
if (typeof value !== 'undefined') {
if (angular.isNumber(value)) {
value = value + 'px';
}
return css.call(self, 'height', value);
} else {
return getWidthHeight(this[0], 'height', 'base');
}
},
outerHeight: function outerHeight(option) {
return getWidthHeight(this[0], 'height', option ? 'outerfull' : 'outer');
},
outerWidth: function outerWidth(option) {
return getWidthHeight(this[0], 'width', option ? 'outerfull' : 'outer');
},
/*
The offset setter method is not implemented
*/
offset: function offset(value) {
var docElem, win;
var self = this;
var box = {
top: 0,
left: 0
};
var elem = self[0];
var doc = elem && elem.ownerDocument;
if (arguments.length) {
if (value === undefined) {
return self;
}
// TODO: implement setter
throw new Error('offset setter method is not implemented');
}
if (!doc) {
return;
}
docElem = doc.documentElement;
// TODO: Make sure it's not a disconnected DOM node
if (elem.getBoundingClientRect != null) {
box = elem.getBoundingClientRect();
}
win = doc.defaultView || doc.parentWindow;
return {
top: box.top + (win.pageYOffset || docElem.scrollTop) - (docElem.clientTop || 0),
left: box.left + (win.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || 0)
};
},
scrollTop: function scrollTop(value) {
return scrollTo(this, 'top', value);
},
scrollLeft: function scrollLeft(value) {
return scrollTo(this, 'left', value);
}
}, function (value, key) {
if (!element.prototype[key]) {
return element.prototype[key] = value;
}
});
}
}]);
return JQLiteExtras;
}();
;// CONCATENATED MODULE: ./src/modules/elementRoutines.js
function elementRoutines_typeof(obj) { "@babel/helpers - typeof"; return elementRoutines_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, elementRoutines_typeof(obj); }
function elementRoutines_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function elementRoutines_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, elementRoutines_toPropertyKey(descriptor.key), descriptor); } }
function elementRoutines_createClass(Constructor, protoProps, staticProps) { if (protoProps) elementRoutines_defineProperties(Constructor.prototype, protoProps); if (staticProps) elementRoutines_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function elementRoutines_toPropertyKey(arg) { var key = elementRoutines_toPrimitive(arg, "string"); return elementRoutines_typeof(key) === "symbol" ? key : String(key); }
function elementRoutines_toPrimitive(input, hint) { if (elementRoutines_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (elementRoutines_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
var hideClassToken = 'ng-ui-scroll-hide';
var ElementRoutines = /*#__PURE__*/function () {
function ElementRoutines($injector, $q) {
elementRoutines_classCallCheck(this, ElementRoutines);
this.$animate = $injector.has && $injector.has('$animate') ? $injector.get('$animate') : null;
this.isAngularVersionLessThen1_3 = angular.version.major === 1 && angular.version.minor < 3;
this.$q = $q;
}
elementRoutines_createClass(ElementRoutines, [{
key: "hideElement",
value: function hideElement(wrapper) {
wrapper.element.addClass(hideClassToken);
}
}, {
key: "showElement",
value: function showElement(wrapper) {
wrapper.element.removeClass(hideClassToken);
}
}, {
key: "insertElement",
value: function insertElement(newElement, previousElement) {
previousElement.after(newElement);
return [];
}
}, {
key: "removeElement",
value: function removeElement(wrapper) {
wrapper.element.remove();
wrapper.scope.$destroy();
return [];
}
}, {
key: "insertElementAnimated",
value: function insertElementAnimated(newElement, previousElement) {
if (!this.$animate) {
return this.insertElement(newElement, previousElement);
}
if (this.isAngularVersionLessThen1_3) {
var deferred = this.$q.defer();
// no need for parent - previous element is never null
this.$animate.enter(newElement, null, previousElement, function () {
return deferred.resolve();
});
return [deferred.promise];
}
// no need for parent - previous element is never null
return [this.$animate.enter(newElement, null, previousElement)];
}
}, {
key: "removeElementAnimated",
value: function removeElementAnimated(wrapper) {
if (!this.$animate) {
return this.removeElement(wrapper);
}
if (this.isAngularVersionLessThen1_3) {
var deferred = this.$q.defer();
this.$animate.leave(wrapper.element, function () {
wrapper.scope.$destroy();
return deferred.resolve();
});
return [deferred.promise];
}
return [this.$animate.leave(wrapper.element).then(function () {
return wrapper.scope.$destroy();
})];
}
}], [{
key: "addCSSRules",
value: function addCSSRules() {
var selector = '.' + hideClassToken;
var rules = 'display: none';
var sheet = document.styleSheets[0];
var index;
try {
index = sheet.cssRules.length;
} catch (err) {
index = 0;
}
if ('insertRule' in sheet) {
sheet.insertRule(selector + '{' + rules + '}', index);
} else if ('addRule' in sheet) {
sheet.addRule(selector, rules, index);
}
}
}]);
return ElementRoutines;
}();
;// CONCATENATED MODULE: ./src/modules/utils.js
var OPERATIONS = {
PREPEND: 'prepend',
APPEND: 'append',
INSERT: 'insert',
REMOVE: 'remove',
NONE: 'none'
};
;// CONCATENATED MODULE: ./src/modules/buffer.js
function ScrollBuffer(elementRoutines, bufferSize, startIndex) {
var buffer = Object.create(Array.prototype);
angular.extend(buffer, {
size: bufferSize,
reset: function reset(startIndex) {
buffer.remove(0, buffer.length);
buffer.eof = false;
buffer.bof = false;
buffer.first = startIndex;
buffer.next = startIndex;
buffer.minIndex = startIndex;
buffer.maxIndex = startIndex;
buffer.minIndexUser = null;
buffer.maxIndexUser = null;
},
append: function append(items) {
items.forEach(function (item) {
++buffer.next;
buffer.insert(OPERATIONS.APPEND, item);
});
buffer.maxIndex = buffer.eof ? buffer.next - 1 : Math.max(buffer.next - 1, buffer.maxIndex);
},
prepend: function prepend(items, immutableTop) {
items.reverse().forEach(function (item) {
if (immutableTop) {
++buffer.next;
} else {
--buffer.first;
}
buffer.insert(OPERATIONS.PREPEND, item);
});
buffer.minIndex = buffer.bof ? buffer.minIndex = buffer.first : Math.min(buffer.first, buffer.minIndex);
},
/**
* inserts wrapped element in the buffer
* the first argument is either operation keyword (see below) or a number for operation 'insert'
* for insert the number is the index for the buffer element the new one have to be inserted after
* operations: 'append', 'prepend', 'insert', 'remove', 'none'
*/
insert: function insert(operation, item, shiftTop) {
var wrapper = {
item: item
};
if (operation % 1 === 0) {
// it is an insert
wrapper.op = OPERATIONS.INSERT;
buffer.splice(operation, 0, wrapper);
if (shiftTop) {
buffer.first--;
} else {
buffer.next++;
}
} else {
wrapper.op = operation;
switch (operation) {
case OPERATIONS.APPEND:
buffer.push(wrapper);
break;
case OPERATIONS.PREPEND:
buffer.unshift(wrapper);
break;
}
}
},
// removes elements from buffer
remove: function remove(arg1, arg2) {
if (angular.isNumber(arg1)) {
// removes items from arg1 (including) through arg2 (excluding)
for (var i = arg1; i < arg2; i++) {
elementRoutines.removeElement(buffer[i]);
}
return buffer.splice(arg1, arg2 - arg1);
}
// removes single item (wrapper) from the buffer
buffer.splice(buffer.indexOf(arg1), 1);
if (arg1.shiftTop && buffer.first === this.getAbsMinIndex()) {
this.incrementMinIndex();
} else {
this.decrementMaxIndex();
}
if (arg1.shiftTop) {
buffer.first++;
} else {
buffer.next--;
}
if (!buffer.length) {
buffer.minIndex = Math.min(buffer.maxIndex, buffer.minIndex);
}
return elementRoutines.removeElementAnimated(arg1);
},
incrementMinIndex: function incrementMinIndex() {
if (buffer.minIndexUser !== null) {
if (buffer.minIndex > buffer.minIndexUser) {
buffer.minIndexUser++;
return;
}
if (buffer.minIndex === buffer.minIndexUser) {
buffer.minIndexUser++;
}
}
buffer.minIndex++;
},
decrementMaxIndex: function decrementMaxIndex() {
if (buffer.maxIndexUser !== null && buffer.maxIndex <= buffer.maxIndexUser) {
buffer.maxIndexUser--;
}
buffer.maxIndex--;
},
getAbsMinIndex: function getAbsMinIndex() {
if (buffer.minIndexUser !== null) {
return Math.min(buffer.minIndexUser, buffer.minIndex);
}
return buffer.minIndex;
},
getAbsMaxIndex: function getAbsMaxIndex() {
if (buffer.maxIndexUser !== null) {
return Math.max(buffer.maxIndexUser, buffer.maxIndex);
}
return buffer.maxIndex;
},
effectiveHeight: function effectiveHeight(elements) {
if (!elements.length) {
return 0;
}
var top = Number.MAX_VALUE;
var bottom = Number.NEGATIVE_INFINITY;
elements.forEach(function (wrapper) {
if (wrapper.element[0].offsetParent) {
// element style is not display:none
top = Math.min(top, wrapper.element.offset().top);
bottom = Math.max(bottom, wrapper.element.offset().top + wrapper.element.outerHeight(true));
}
});
return Math.max(0, bottom - top);
},
getItems: function getItems() {
return buffer.filter(function (item) {
return item.op === OPERATIONS.NONE;
});
},
getFirstItem: function getFirstItem() {
var list = buffer.getItems();
if (!list.length) {
return null;
}
return list[0].item;
},
getLastItem: function getLastItem() {
var list = buffer.getItems();
if (!list.length) {
return null;
}
return list[list.length - 1].item;
}
});
buffer.reset(startIndex);
return buffer;
}
;// CONCATENATED MODULE: ./src/modules/padding.js
function padding_typeof(obj) { "@babel/helpers - typeof"; return padding_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, padding_typeof(obj); }
function padding_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function padding_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, padding_toPropertyKey(descriptor.key), descriptor); } }
function padding_createClass(Constructor, protoProps, staticProps) { if (protoProps) padding_defineProperties(Constructor.prototype, protoProps); if (staticProps) padding_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function padding_toPropertyKey(arg) { var key = padding_toPrimitive(arg, "string"); return padding_typeof(key) === "symbol" ? key : String(key); }
function padding_toPrimitive(input, hint) { if (padding_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (padding_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
// Can't just extend the Array, due to Babel does not support built-in classes extending
// This solution was taken from https://stackoverflow.com/questions/46897414/es6-class-extends-array-workaround-for-es5-babel-transpile
var CacheProto = /*#__PURE__*/function () {
function CacheProto() {
padding_classCallCheck(this, CacheProto);
}
padding_createClass(CacheProto, [{
key: "add",
value: function add(item) {
for (var i = this.length - 1; i >= 0; i--) {
if (this[i].index === item.scope.$index) {
this[i].height = item.element.outerHeight();
return;
}
}
this.push({
index: item.scope.$index,
height: item.element.outerHeight()
});
this.sort(function (a, b) {
return a.index < b.index ? -1 : a.index > b.index ? 1 : 0;
});
}
}, {
key: "remove",
value: function remove(argument, _shiftTop) {
var index = argument % 1 === 0 ? argument : argument.scope.$index;
var shiftTop = argument % 1 === 0 ? _shiftTop : argument.shiftTop;
for (var i = this.length - 1; i >= 0; i--) {
if (this[i].index === index) {
this.splice(i, 1);
break;
}
}
if (!shiftTop) {
for (var _i = this.length - 1; _i >= 0; _i--) {
if (this[_i].index > index) {
this[_i].index--;
}
}
}
}
}, {
key: "clear",
value: function clear() {
this.length = 0;
}
}]);
return CacheProto;
}();
function Cache() {
var instance = [];
instance.push.apply(instance, arguments);
Object.setPrototypeOf(instance, Cache.prototype);
return instance;
}
Cache.prototype = Object.create(Array.prototype);
Object.getOwnPropertyNames(CacheProto.prototype).forEach(function (methodName) {
return Cache.prototype[methodName] = CacheProto.prototype[methodName];
});
function generateElement(template) {
if (template.nodeType !== Node.ELEMENT_NODE) {
throw new Error('ui-scroll directive requires an Element node for templating the view');
}
var element;
switch (template.tagName.toLowerCase()) {
case 'dl':
throw new Error("ui-scroll directive does not support <".concat(template.tagName, "> as a repeating tag: ").concat(template.outerHTML));
case 'tr':
var table = angular.element('<table><tr><td><div></div></td></tr></table>');
element = table.find('tr');
break;
case 'li':
element = angular.element('<li></li>');
break;
default:
element = angular.element('<div></div>');
}
return element;
}
var Padding = /*#__PURE__*/function () {
function Padding(template) {
padding_classCallCheck(this, Padding);
this.element = generateElement(template);
this.cache = new Cache();
}
padding_createClass(Padding, [{
key: "height",
value: function height() {
return this.element.height.apply(this.element, arguments);
}
}]);
return Padding;
}();
/* harmony default export */ var modules_padding = (Padding);
;// CONCATENATED MODULE: ./src/modules/viewport.js
function Viewport(elementRoutines, buffer, element, viewportController, $rootScope, padding) {
var topPadding = null;
var bottomPadding = null;
var viewport = viewportController && viewportController.viewport ? viewportController.viewport : angular.element(window);
var container = viewportController && viewportController.container ? viewportController.container : undefined;
var scope = viewportController && viewportController.scope ? viewportController.scope : $rootScope;
viewport.css({
'overflow-anchor': 'none',
'overflow-y': 'auto',
'display': 'block'
});
function bufferPadding() {
return viewport.outerHeight() * padding; // some extra space to initiate preload
}
angular.extend(viewport, {
getScope: function getScope() {
return scope;
},
createPaddingElements: function createPaddingElements(template) {
topPadding = new modules_padding(template);
bottomPadding = new modules_padding(template);
element.before(topPadding.element);
element.after(bottomPadding.element);
topPadding.height(0);
bottomPadding.height(0);
},
applyContainerStyle: function applyContainerStyle() {
if (!container) {
return true;
}
if (container !== viewport) {
viewport.css('height', window.getComputedStyle(container[0]).height);
}
return viewport.height() > 0;
},
bottomDataPos: function bottomDataPos() {
var scrollHeight = viewport[0].scrollHeight;
scrollHeight = scrollHeight != null ? scrollHeight : viewport[0].document.documentElement.scrollHeight;
return scrollHeight - bottomPadding.height();
},
topDataPos: function topDataPos() {
return topPadding.height();
},
bottomVisiblePos: function bottomVisiblePos() {
return viewport.scrollTop() + viewport.outerHeight();
},
topVisiblePos: function topVisiblePos() {
return viewport.scrollTop();
},
insertElement: function insertElement(e, sibling) {
return elementRoutines.insertElement(e, sibling || topPadding.element);
},
insertElementAnimated: function insertElementAnimated(e, sibling) {
return elementRoutines.insertElementAnimated(e, sibling || topPadding.element);
},
shouldLoadBottom: function shouldLoadBottom() {
return !buffer.eof && viewport.bottomDataPos() < viewport.bottomVisiblePos() + bufferPadding();
},
clipBottom: function clipBottom() {
// clip the invisible items off the bottom
var overage = 0;
var overageHeight = 0;
var itemHeight = 0;
var emptySpaceHeight = viewport.bottomDataPos() - viewport.bottomVisiblePos() - bufferPadding();
for (var i = buffer.length - 1; i >= 0; i--) {
itemHeight = buffer[i].element.outerHeight(true);
if (overageHeight + itemHeight > emptySpaceHeight) {
break;
}
bottomPadding.cache.add(buffer[i]);
overageHeight += itemHeight;
overage++;
}
if (overage > 0) {
buffer.eof = false;
buffer.remove(buffer.length - overage, buffer.length);
buffer.next -= overage;
viewport.adjustPaddings();
}
},
shouldLoadTop: function shouldLoadTop() {
return !buffer.bof && viewport.topDataPos() > viewport.topVisiblePos() - bufferPadding();
},
clipTop: function clipTop() {
// clip the invisible items off the top
var overage = 0;
var overageHeight = 0;
var itemHeight = 0;
var emptySpaceHeight = viewport.topVisiblePos() - viewport.topDataPos() - bufferPadding();
for (var i = 0; i < buffer.length; i++) {
itemHeight = buffer[i].element.outerHeight(true);
if (overageHeight + itemHeight > emptySpaceHeight) {
break;
}
topPadding.cache.add(buffer[i]);
overageHeight += itemHeight;
overage++;
}
if (overage > 0) {
// we need to adjust top padding element before items are removed from top
// to avoid strange behaviour of scroll bar during remove top items when we are at the very bottom
topPadding.height(topPadding.height() + overageHeight);
buffer.bof = false;
buffer.remove(0, overage);
buffer.first += overage;
}
},
adjustPaddings: function adjustPaddings() {
if (!buffer.length) {
return;
}
// precise heights calculation based on items that are in buffer or that were in buffer once
var visibleItemsHeight = buffer.reduce(function (summ, item) {
return summ + item.element.outerHeight(true);
}, 0);
var topPaddingHeight = 0,
topCount = 0;
topPadding.cache.forEach(function (item) {
if (item.index < buffer.first) {
topPaddingHeight += item.height;
topCount++;
}
});
var bottomPaddingHeight = 0,
bottomCount = 0;
bottomPadding.cache.forEach(function (item) {
if (item.index >= buffer.next) {
bottomPaddingHeight += item.height;
bottomCount++;
}
});
var totalHeight = visibleItemsHeight + topPaddingHeight + bottomPaddingHeight;
var averageItemHeight = totalHeight / (topCount + bottomCount + buffer.length);
// average heights calculation, items that have never been reached
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;
var bottomPaddingHeightAdd = adjustBottomPadding ? (buffer.maxIndexUser - buffer.maxIndex) * averageItemHeight : 0;
// paddings combine adjustment
topPadding.height(topPaddingHeight + topPaddingHeightAdd);
bottomPadding.height(bottomPaddingHeight + bottomPaddingHeightAdd);
},
onAfterMinIndexSet: function onAfterMinIndexSet(topPaddingHeightOld) {
// additional scrollTop adjustment in case of datasource.minIndex external set
if (buffer.minIndexUser !== null && buffer.minIndex > buffer.minIndexUser) {
var diff = topPadding.height() - topPaddingHeightOld;
viewport.scrollTop(viewport.scrollTop() + diff);
while ((diff -= viewport.scrollTop()) > 0) {
bottomPadding.height(bottomPadding.height() + diff);
viewport.scrollTop(viewport.scrollTop() + diff);
}
}
},
onAfterPrepend: function onAfterPrepend(updates) {
if (!updates.prepended.length) {
return;
}
var height = buffer.effectiveHeight(updates.prepended);
var paddingHeight = topPadding.height() - height;
if (paddingHeight >= 0) {
topPadding.height(paddingHeight);
return;
}
var position = viewport.scrollTop();
var newPosition = position - paddingHeight;
viewport.synthetic = {
previous: position,
next: newPosition
};
topPadding.height(0);
viewport.scrollTop(newPosition);
},
resetTopPadding: function resetTopPadding() {
topPadding.height(0);
topPadding.cache.clear();
},
resetBottomPadding: function resetBottomPadding() {
bottomPadding.height(0);
bottomPadding.cache.clear();
},
removeCacheItem: function removeCacheItem(item, shiftTop) {
topPadding.cache.remove(item, shiftTop);
bottomPadding.cache.remove(item, shiftTop);
},
removeItem: function removeItem(item) {
this.removeCacheItem(item);
return buffer.remove(item);
}
});
return viewport;
}
;// CONCATENATED MODULE: ./src/modules/adapter.js
function adapter_typeof(obj) { "@babel/helpers - typeof"; return adapter_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, adapter_typeof(obj); }
function adapter_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function adapter_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, adapter_toPropertyKey(descriptor.key), descriptor); } }
function adapter_createClass(Constructor, protoProps, staticProps) { if (protoProps) adapter_defineProperties(Constructor.prototype, protoProps); if (staticProps) adapter_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function adapter_toPropertyKey(arg) { var key = adapter_toPrimitive(arg, "string"); return adapter_typeof(key) === "symbol" ? key : String(key); }
function adapter_toPrimitive(input, hint) { if (adapter_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (adapter_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
var Adapter = /*#__PURE__*/function () {
function Adapter($scope, $parse, $attr, viewport, buffer, doAdjust, reload) {
adapter_classCallCheck(this, Adapter);
this.$parse = $parse;
this.$attr = $attr;
this.viewport = viewport;
this.buffer = buffer;
this.doAdjust = doAdjust;
this.reload = reload;
this.isLoading = false;
this.disabled = false;
var viewportScope = viewport.getScope();
this.startScope = viewportScope.$parent ? viewportScope : $scope;
this.publicContext = {};
this.assignAdapter($attr.adapter);
this.generatePublicContext();
}
adapter_createClass(Adapter, [{
key: "assignAdapter",
value: function assignAdapter(adapterAttr) {
if (!adapterAttr || !(adapterAttr = adapterAttr.replace(/^\s+|\s+$/gm, ''))) {
return;
}
var adapterOnScope;
try {
this.$parse(adapterAttr).assign(this.startScope, {});
adapterOnScope = this.$parse(adapterAttr)(this.startScope);
} catch (error) {
error.message = "Angular ui-scroll Adapter assignment exception.\n" + "Can't parse \"".concat(adapterAttr, "\" expression.\n") + error.message;
throw error;
}
angular.extend(adapterOnScope, this.publicContext);
this.publicContext = adapterOnScope;
}
}, {
key: "generatePublicContext",
value: function generatePublicContext() {
var _this = this;
// these methods will be accessible out of ui-scroll via user defined adapter
var publicMethods = ['reload', 'applyUpdates', 'append', 'prepend', 'isBOF', 'isEOF', 'isEmpty'];
for (var i = publicMethods.length - 1; i >= 0; i--) {
this.publicContext[publicMethods[i]] = this[publicMethods[i]].bind(this);
}
// these read-only props will be accessible out of ui-scroll via user defined adapter
var publicProps = ['isLoading', 'topVisible', 'topVisibleElement', 'topVisibleScope', 'bottomVisible', 'bottomVisibleElement', 'bottomVisibleScope'];
var _loop = function _loop(_i) {
var property,
attr = _this.$attr[publicProps[_i]];
Object.defineProperty(_this, publicProps[_i], {
get: function get() {
return property;
},
set: function set(value) {
property = value;
_this.publicContext[publicProps[_i]] = value;
if (attr) {
_this.$parse(attr).assign(_this.startScope, value);
}
}
});
};
for (var _i = publicProps.length - 1; _i >= 0; _i--) {
_loop(_i);
}
// read-only immediately calculated public properties
var publicPropsImmediate = ['bufferFirst', 'bufferLast', 'bufferLength'];
var _loop2 = function _loop2(_i2) {
Object.defineProperty(_this.publicContext, publicPropsImmediate[_i2], {
get: function get() {
return _this[publicPropsImmediate[_i2]];
}
});
};
for (var _i2 = publicPropsImmediate.length - 1; _i2 >= 0; _i2--) {
_loop2(_i2);
}
// non-read-only public property
Object.defineProperty(this.publicContext, 'disabled', {
get: function get() {
return _this.disabled;
},
set: function set(value) {
return !(_this.disabled = value) ? _this.doAdjust() : null;
}
});
}
}, {
key: "loading",
value: function loading(value) {
this.isLoading = value;
}
}, {
key: "isBOF",
value: function isBOF() {
return this.buffer.bof;
}
}, {
key: "isEOF",
value: function isEOF() {
return this.buffer.eof;
}
}, {
key: "isEmpty",
value: function isEmpty() {
return !this.buffer.length;
}
}, {
key: "bufferLength",
get: function get() {
return this.buffer.getItems().length;
}
}, {
key: "bufferFirst",
get: function get() {
return this.buffer.getFirstItem();
}
}, {
key: "bufferLast",
get: function get() {
return this.buffer.getLastItem();
}
}, {
key: "append",
value: function append(newItems) {
this.buffer.append(newItems);
this.doAdjust();
this.viewport.clipTop();
this.viewport.clipBottom();
}
}, {
key: "prepend",
value: function prepend(newItems) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this.buffer.prepend(newItems, options.immutableTop);
this.doAdjust();
this.viewport.clipTop();
this.viewport.clipBottom();
}
}, {
key: "applyUpdates",
value: function applyUpdates(arg1, arg2, arg3) {
if (typeof arg1 === 'function') {
this.applyUpdatesFunc(arg1, arg2);
} else {
this.applyUpdatesIndex(arg1, arg2, arg3);
}
this.doAdjust();
}
}, {
key: "applyUpdatesFunc",
value: function applyUpdatesFunc(cb) {
var _this2 = this;