Skip to content

Commit f3ed72d

Browse files
committed
Merge branch 'master' into refactor
2 parents b6d9458 + 688d45c commit f3ed72d

File tree

5 files changed

+74
-58
lines changed

5 files changed

+74
-58
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ File ui-scroll-jqlite.coffee houses implementations of the above methods and als
4747
'ui.scroll.jqlite' and this name should also be included in the dependency list of the main module. The implementation currently supports missing methods
4848
only as necessary for the directive. It is tested on IE8 and up as well as on the Chrome 28 and Firefox 20.
4949

50-
This module is only necessary if you plan to use ui-scroll without jQuery. If jQuery implementation is present it will not override them.
50+
This module is only necessary if you plan to use ui-scroll without jQuery. If full jQuery is loaded, uiScroll will use the jQuery implementatin of the above methods, the ui.scroll.jqlite implementation of them will be ignored.
5151
If you plan to use ui-scroll over jQuery feel free to skip ui-scroll-jqlite.
5252

5353
###Usage

dist/ui-scroll-jqlite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-ui-scroll
33
* https://github.com/angular-ui/ui-scroll.git
4-
* Version: 1.3.2 -- 2015-10-09T10:33:17.514Z
4+
* Version: 1.3.2 -- 2015-10-27T14:48:21.672Z
55
* License: MIT
66
*/
77

dist/ui-scroll-jqlite.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ui-scroll.js

Lines changed: 69 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-ui-scroll
33
* https://github.com/angular-ui/ui-scroll.git
4-
* Version: 1.3.2 -- 2015-10-09T10:33:17.514Z
4+
* Version: 1.3.2 -- 2015-10-27T14:48:21.672Z
55
* License: MIT
66
*/
77

@@ -41,9 +41,10 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
4141
transclude: 'element',
4242
priority: 1000,
4343
terminal: true,
44-
compile: function(elementTemplate, attr, linker) {
45-
return function($scope, element, $attr, controllers) {
46-
var adapter, adapterOnScope, adjustBuffer, adjustBufferAfterFetch, applyUpdate, bof, bottomVisiblePos, buffer, bufferPadding, bufferSize, builder, calculateTopProperties, clipBottom, clipTop, datasource, datasourceName, dismissPendingRequests, enqueueFetch, eof, eventListener, fetch, first, insertElement, insertElementAnimated, insertItem, insertWrapperContent, isAngularVersionLessThen1_3, isDatasourceValid, isElementVisible, itemName, loading, log, match, next, pending, processBufferedItems, reload, removeFromBuffer, removeItem, resizeAndScrollHandler, ridActual, scrollHeight, shouldLoadBottom, shouldLoadTop, topVisible, topVisiblePos, unsupportedMethod, viewport, viewportScope, visibilityWatcher, wheelHandler;
44+
compile: function(elementTemplate, attr, compileLinker) {
45+
return function($scope, element, $attr, controllers, linker) {
46+
var Buffer, adapter, adapterOnScope, adjustBuffer, adjustBufferAfterFetch, applyUpdate, bof, bottomVisiblePos, buffer, bufferPadding, bufferSize, builder, calculateTopProperties, clipBottom, clipTop, datasource, datasourceName, dismissPendingRequests, enqueueFetch, eof, eventListener, fetch, first, insertElement, insertElementAnimated, insertItem, insertWrapperContent, isAngularVersionLessThen1_3, isDatasourceValid, isElementVisible, itemName, loading, log, match, next, pending, processBufferedItems, reload, resizeAndScrollHandler, ridActual, scrollHeight, shouldLoadBottom, shouldLoadTop, topVisible, topVisiblePos, unsupportedMethod, viewport, viewportScope, visibilityWatcher, wheelHandler;
47+
linker = linker || compileLinker;
4748
log = console.debug || console.log;
4849
if (!(match = $attr.uiScroll.match(/^\s*(\w+)\s+in\s+([\w\.]+)\s*$/))) {
4950
throw new Error('Expected uiScroll in form of \'_item_ in _datasource_\' but got \'' + $attr.uiScroll + '\'');
@@ -68,37 +69,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
6869
var ref;
6970
return (ref = elem[0].scrollHeight) != null ? ref : elem[0].document.documentElement.scrollHeight;
7071
};
71-
builder = null;
72-
ridActual = 0;
73-
first = 1;
74-
next = 1;
75-
buffer = [];
76-
pending = [];
77-
eof = false;
78-
bof = false;
7972
isAngularVersionLessThen1_3 = angular.version.major === 1 && angular.version.minor < 3;
80-
removeItem = $animate ? isAngularVersionLessThen1_3 ? function(wrapper) {
81-
var deferred;
82-
buffer.splice(buffer.indexOf(wrapper), 1);
83-
deferred = $q.defer();
84-
$animate.leave(wrapper.element, function() {
85-
wrapper.scope.$destroy();
86-
return deferred.resolve();
87-
});
88-
return [deferred.promise];
89-
} : function(wrapper) {
90-
buffer.splice(buffer.indexOf(wrapper), 1);
91-
return [
92-
($animate.leave(wrapper.element)).then(function() {
93-
return wrapper.scope.$destroy();
94-
})
95-
];
96-
} : function(wrapper) {
97-
buffer.splice(buffer.indexOf(wrapper), 1);
98-
wrapper.element.remove();
99-
wrapper.scope.$destroy();
100-
return [];
101-
};
10273
insertElement = function(newElement, previousElement) {
10374
element.after.apply(previousElement, [newElement]);
10475
return [];
@@ -113,6 +84,64 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
11384
} : function(newElement, previousElement) {
11485
return [$animate.enter(newElement, element, previousElement)];
11586
} : insertElement;
87+
Buffer = function() {
88+
var buffer, remove;
89+
buffer = Object.create(Array.prototype);
90+
if ($animate) {
91+
if (isAngularVersionLessThen1_3) {
92+
remove = function(wrapper) {
93+
var deferred;
94+
buffer.splice(buffer.indexOf(wrapper), 1);
95+
deferred = $q.defer();
96+
$animate.leave(wrapper.element, function() {
97+
wrapper.scope.$destroy();
98+
return deferred.resolve();
99+
});
100+
return [deferred.promise];
101+
};
102+
} else {
103+
remove = function(wrapper) {
104+
buffer.splice(buffer.indexOf(wrapper), 1);
105+
return [
106+
($animate.leave(wrapper.element)).then(function() {
107+
return wrapper.scope.$destroy();
108+
})
109+
];
110+
};
111+
}
112+
} else {
113+
remove = function(wrapper) {
114+
buffer.splice(buffer.indexOf(wrapper), 1);
115+
wrapper.element.remove();
116+
wrapper.scope.$destroy();
117+
return [];
118+
};
119+
}
120+
buffer.remove = function(arg1, arg2) {
121+
var i, j, ref, ref1;
122+
if (angular.isNumber(arg1)) {
123+
for (i = j = ref = arg1, ref1 = arg2; ref <= ref1 ? j < ref1 : j > ref1; i = ref <= ref1 ? ++j : --j) {
124+
buffer[i].scope.$destroy();
125+
buffer[i].element.remove();
126+
}
127+
return buffer.splice(arg1, arg2 - arg1);
128+
} else {
129+
return remove(arg1);
130+
}
131+
};
132+
buffer.clear = function() {
133+
return buffer.remove(0, buffer.length);
134+
};
135+
return buffer;
136+
};
137+
builder = null;
138+
ridActual = 0;
139+
first = 1;
140+
next = 1;
141+
buffer = new Buffer();
142+
pending = [];
143+
eof = false;
144+
bof = false;
116145
linker($scope.$new(), function(template, scope) {
117146
var bottomPadding, padding, repeaterType, topPadding, viewport;
118147
scope.$destroy();
@@ -202,14 +231,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
202231
return datasource.loading(value);
203232
}
204233
};
205-
removeFromBuffer = function(start, stop) {
206-
var i, j, ref, ref1;
207-
for (i = j = ref = start, ref1 = stop; ref <= ref1 ? j < ref1 : j > ref1; i = ref <= ref1 ? ++j : --j) {
208-
buffer[i].scope.$destroy();
209-
buffer[i].element.remove();
210-
}
211-
return buffer.splice(start, stop - start);
212-
};
213234
dismissPendingRequests = function() {
214235
ridActual++;
215236
return pending = [];
@@ -218,7 +239,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
218239
dismissPendingRequests();
219240
first = 1;
220241
next = 1;
221-
removeFromBuffer(0, buffer.length);
242+
buffer.clear();
222243
builder.topPadding(0);
223244
builder.bottomPadding(0);
224245
eof = false;
@@ -261,7 +282,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
261282
}
262283
if (overage > 0) {
263284
builder.bottomPadding(builder.bottomPadding() + bottomHeight);
264-
removeFromBuffer(buffer.length - overage, buffer.length);
285+
buffer.remove(buffer.length - overage, buffer.length);
265286
return next -= overage;
266287
}
267288
};
@@ -295,7 +316,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
295316
}
296317
if (overage > 0) {
297318
builder.topPadding(builder.topPadding() + topHeight);
298-
removeFromBuffer(0, overage);
319+
buffer.remove(0, overage);
299320
return first += overage;
300321
}
301322
};
@@ -390,7 +411,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
390411
}
391412
for (k = 0, len1 = toBeRemoved.length; k < len1; k++) {
392413
wrapper = toBeRemoved[k];
393-
promises = promises.concat(removeItem(wrapper));
414+
promises = promises.concat(buffer.remove(wrapper));
394415
}
395416
builder.bottomPadding(Math.max(0, builder.bottomPadding() - (builder.bottomDataPos() - bottomPos)));
396417
if (toBePrepended.length) {
@@ -551,12 +572,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
551572
viewport.bind('mousewheel', wheelHandler);
552573
$scope.$watch(datasource.revision, reload);
553574
$scope.$on('$destroy', function() {
554-
var item, j, len;
555-
for (j = 0, len = buffer.length; j < len; j++) {
556-
item = buffer[j];
557-
item.scope.$destroy();
558-
item.element.remove();
559-
}
575+
buffer.clear();
560576
viewport.unbind('resize', resizeAndScrollHandler);
561577
viewport.unbind('scroll', resizeAndScrollHandler);
562578
return viewport.unbind('mousewheel', wheelHandler);
@@ -626,7 +642,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function() {
626642
};
627643
if ($attr.adapter) {
628644
adapterOnScope = $parse($attr.adapter)($scope);
629-
if (!adapterOnScope) {
645+
if (!angular.isObject(adapterOnScope)) {
630646
$parse($attr.adapter).assign($scope, {});
631647
adapterOnScope = $parse($attr.adapter)($scope);
632648
}

0 commit comments

Comments
 (0)