Skip to content

Commit 6df8a3d

Browse files
committed
2 parents 8865a71 + be09ec0 commit 6df8a3d

9 files changed

+202
-165
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ If you plan to use ui-scroll over jQuery feel free to skip ui-scroll-jqlite.
5353
###Usage
5454

5555
```html
56-
<ANY ui-scroll="{scroll_expression}" buffer-size="value" padding="value">
56+
<ANY ui-scroll="{scroll_expression}" buffer-size="value" padding="value" adapter="name">
5757
...
5858
</ANY>
5959
```
@@ -88,7 +88,7 @@ Data source is an object to be used by the uiScroll directive to access the data
8888
The directive will locate the object using the provided data source name. It will first look for a property with the given name on its $scope.
8989
If none found it will try to get an angular service with the provided name.
9090

91-
The datasource object implements methods and properties to be used by the directive to access the data:
91+
The data source object implements methods and properties to be used by the directive to access the data:
9292

9393
* Method `get`
9494

@@ -103,7 +103,7 @@ The datasource object implements methods and properties to be used by the direct
103103
* **descriptor** is an object defining the portion of the dataset requested. The object will have 3 properties. Two of them named `index` and `count`. They have the same meaning as in the alternative signature when the parameters passed explicitly (see below). The third one will be named either `append` if the items will be appended to the last item in the buffer, or `prepend` if they are to be prepended to the first item in the buffer. The value of the property in either case will be the item the new items will be appended/prepended to. This is useful if it is easier to identify the items to be added based on the previously requested items rather than on the index. Keep in mind that in certain use cases (i.e. on initial load) the value of the append/prepend property can be undefined.
104104
* **index** indicates the first data row requested
105105
* **count** indicates number of data rows requested
106-
* **success** function to call when the data are retrieved. The implementation of the datsource has to call this function when the data are retrieved and pass it an array of the items retrieved. If no items are retrieved, an empty array has to be passed.
106+
* **success** function to call when the data are retrieved. The implementation of the data source has to call this function when the data are retrieved and pass it an array of the items retrieved. If no items are retrieved, an empty array has to be passed.
107107

108108
**Important:** Make sure to respect the `index` and `count` parameters of the request. The array passed to the success method should have
109109
exactly `count` elements unless it hit eof/bof

demo/examples/positionedList.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ angular.module('application', [
88
'$rootScope',
99
'$location',
1010
function (console, $timeout, $rootScope, $location) {
11-
var current, data, get, i, j, k, l, len, len1, letter1, letter2, position, ref, ref1, revision;
11+
var current, data, get, i, j, k, l, len, len1, letter1, letter2, position, ref, ref1;
1212
$rootScope.key = "";
1313
position = 0;
1414
data = [];
@@ -50,12 +50,9 @@ angular.module('application', [
5050
}
5151
return current++;
5252
});
53-
revision = function () {
54-
return current;
55-
};
53+
5654
return {
57-
get: get,
58-
revision: revision
55+
get: get
5956
};
6057
}
6158
]);

dist/ui-scroll-jqlite.js

+1-1
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.3 -- 2016-03-15T20:00:58.115Z
4+
* Version: 1.3.3 -- 2016-03-16T09:12:39.242Z
55
* License: MIT
66
*/
77

dist/ui-scroll-jqlite.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ui-scroll.js

+60-49
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.3 -- 2016-03-15T20:00:58.115Z
4+
* Version: 1.3.3 -- 2016-03-16T09:12:39.242Z
55
* License: MIT
66
*/
77

@@ -115,7 +115,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
115115
buffer.first = origin;
116116
buffer.next = origin;
117117
buffer.minIndex = Number.MAX_VALUE;
118-
return buffer.maxIndex = Number.MIN_VALUE;
118+
buffer.maxIndex = Number.MIN_VALUE;
119119
}
120120

121121
angular.extend(buffer, {
@@ -215,28 +215,9 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
215215
return buffer;
216216
}
217217

218-
function Padding(template) {
219-
var result = undefined;
220-
var tagName = template.localName;
221-
222-
switch (tagName) {
223-
case 'dl':
224-
throw new Error('ui-scroll directive does not support <' + tagName + '> as a repeating tag: ' + template.outerHTML);
225-
case 'tr':
226-
var table = angular.element('<table><tr><td><div></div></td></tr></table>');
227-
result = table.find('tr');
228-
break;
229-
case 'li':
230-
result = angular.element('<li></li>');
231-
break;
232-
default:
233-
result = angular.element('<div></div>');
234-
}
235-
236-
return result;
237-
}
238-
239218
function Viewport(buffer, element, controllers, attrs) {
219+
var PADDING_MIN = 0.3;
220+
var PADDING_DEFAULT = 0.5;
240221
var topPadding = null;
241222
var bottomPadding = null;
242223
var averageItemHeight = 0;
@@ -254,7 +235,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
254235
};
255236

256237
function bufferPadding() {
257-
return viewport.outerHeight() * Math.max(0.1, +attrs.padding || 0.1); // some extra space to initiate preload
238+
return viewport.outerHeight() * Math.max(PADDING_MIN, +attrs.padding || PADDING_DEFAULT); // some extra space to initiate preload
258239
}
259240

260241
angular.extend(viewport, {
@@ -263,6 +244,27 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
263244
bottomPadding = new Padding(template);
264245
element.before(topPadding);
265246
element.after(bottomPadding);
247+
248+
function Padding(template) {
249+
var result = undefined;
250+
var tagName = template.localName;
251+
252+
switch (tagName) {
253+
case 'dl':
254+
throw new Error('ui-scroll directive does not support <' + tagName + '> as a repeating tag: ' + template.outerHTML);
255+
case 'tr':
256+
var table = angular.element('<table><tr><td><div></div></td></tr></table>');
257+
result = table.find('tr');
258+
break;
259+
case 'li':
260+
result = angular.element('<li></li>');
261+
break;
262+
default:
263+
result = angular.element('<div></div>');
264+
}
265+
266+
return result;
267+
}
266268
},
267269
bottomDataPos: function bottomDataPos() {
268270
var scrollHeight = viewport[0].scrollHeight;
@@ -365,6 +367,12 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
365367
topPadding.height(0);
366368
viewport.scrollTop(viewport.scrollTop() - paddingHeight);
367369
}
370+
},
371+
resetTopPaddingHeight: function resetTopPaddingHeight() {
372+
topPadding.height(0);
373+
},
374+
resetBottomPaddingHeight: function resetBottomPaddingHeight() {
375+
bottomPadding.height(0);
368376
}
369377
});
370378

@@ -582,10 +590,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
582590
viewport.bind('scroll', resizeAndScrollHandler);
583591
viewport.bind('mousewheel', wheelHandler);
584592

585-
$scope.$watch(datasource.revision, function () {
586-
return reload();
587-
});
588-
589593
$scope.$on('$destroy', function () {
590594
// clear the buffer. It is necessary to remove the elements and $destroy the scopes
591595
buffer.clear();
@@ -594,6 +598,31 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
594598
viewport.unbind('mousewheel', wheelHandler);
595599
});
596600

601+
// update events (deprecated since v1.1.0, unsupported since 1.2.0)
602+
(function () {
603+
var eventListener = datasource.scope ? datasource.scope.$new() : $scope.$new();
604+
605+
eventListener.$on('insert.item', function () {
606+
return unsupportedMethod('insert');
607+
});
608+
609+
eventListener.$on('update.items', function () {
610+
return unsupportedMethod('update');
611+
});
612+
613+
eventListener.$on('delete.items', function () {
614+
return unsupportedMethod('delete');
615+
});
616+
617+
function unsupportedMethod(token) {
618+
throw new Error(token + ' event is no longer supported - use applyUpdates instead');
619+
}
620+
})();
621+
622+
reload();
623+
624+
/* Functions definitions */
625+
597626
function dismissPendingRequests() {
598627
ridActual++;
599628
pending = [];
@@ -602,6 +631,9 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
602631
function reload() {
603632
dismissPendingRequests();
604633

634+
viewport.resetTopPaddingHeight();
635+
viewport.resetBottomPaddingHeight();
636+
605637
if (arguments.length) {
606638
buffer.clear(arguments[0]);
607639
} else {
@@ -832,27 +864,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
832864
event.preventDefault();
833865
}
834866
}
835-
836-
// update events (deprecated since v1.1.0, unsupported since 1.2.0)
837-
(function () {
838-
var eventListener = datasource.scope ? datasource.scope.$new() : $scope.$new();
839-
840-
eventListener.$on('insert.item', function () {
841-
return unsupportedMethod('insert');
842-
});
843-
844-
eventListener.$on('update.items', function () {
845-
return unsupportedMethod('update');
846-
});
847-
848-
eventListener.$on('delete.items', function () {
849-
return unsupportedMethod('delete');
850-
});
851-
852-
function unsupportedMethod(token) {
853-
throw new Error(token + ' event is no longer supported - use applyUpdates instead');
854-
}
855-
})();
856867
};
857868
}
858869
}]);

0 commit comments

Comments
 (0)