Skip to content

Fix for multiple reloads in the same instance causes skipping #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions dist/ui-scroll-jqlite.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*!
* angular-ui-scroll
* https://github.com/angular-ui/ui-scroll.git
* Version: 1.3.3 -- 2016-03-04T12:15:03.597Z
* License: MIT
*/
(function () {
/*!
* angular-ui-scroll
* https://github.com/angular-ui/ui-scroll.git
* Version: 1.3.3 -- 2016-03-11T21:07:06.923Z
* License: MIT
*/


(function () {
'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; }();
Expand Down
2 changes: 1 addition & 1 deletion dist/ui-scroll-jqlite.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 70 additions & 61 deletions dist/ui-scroll.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*!
* angular-ui-scroll
* https://github.com/angular-ui/ui-scroll.git
* Version: 1.3.3 -- 2016-03-04T12:15:03.597Z
* License: MIT
*/
(function () {
/*!
* angular-ui-scroll
* https://github.com/angular-ui/ui-scroll.git
* Version: 1.3.3 -- 2016-03-11T21:07:06.923Z
* License: MIT
*/


(function () {
'use strict';

var _typeof = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === 'function' && obj.constructor === Symbol ? 'symbol' : typeof obj; };
Expand Down Expand Up @@ -115,7 +115,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
buffer.first = origin;
buffer.next = origin;
buffer.minIndex = Number.MAX_VALUE;
return buffer.maxIndex = Number.MIN_VALUE;
buffer.maxIndex = Number.MIN_VALUE;
}

angular.extend(buffer, {
Expand Down Expand Up @@ -215,28 +215,9 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
return buffer;
}

function Padding(template) {
var result = undefined;
var tagName = template.localName;

switch (tagName) {
case 'dl':
throw new Error('ui-scroll directive does not support <' + tagName + '> as a repeating tag: ' + template.outerHTML);
case 'tr':
var table = angular.element('<table><tr><td><div></div></td></tr></table>');
result = table.find('tr');
break;
case 'li':
result = angular.element('<li></li>');
break;
default:
result = angular.element('<div></div>');
}

return result;
}

function Viewport(buffer, element, controllers, attrs) {
var PADDING_MIN = 0.3;
var PADDING_DEFAULT = 0.5;
var topPadding = null;
var bottomPadding = null;
var averageItemHeight = 0;
Expand All @@ -254,7 +235,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
};

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

angular.extend(viewport, {
Expand All @@ -263,6 +244,27 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
bottomPadding = new Padding(template);
element.before(topPadding);
element.after(bottomPadding);

function Padding(template) {
var result = undefined;
var tagName = template.localName;

switch (tagName) {
case 'dl':
throw new Error('ui-scroll directive does not support <' + tagName + '> as a repeating tag: ' + template.outerHTML);
case 'tr':
var table = angular.element('<table><tr><td><div></div></td></tr></table>');
result = table.find('tr');
break;
case 'li':
result = angular.element('<li></li>');
break;
default:
result = angular.element('<div></div>');
}

return result;
}
},
bottomDataPos: function bottomDataPos() {
var scrollHeight = viewport[0].scrollHeight;
Expand Down Expand Up @@ -366,6 +368,12 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
topPadding.height(0);
viewport.scrollTop(viewport.scrollTop() - paddingHeight);
}
},
resetTopPaddingHeight: function resetTopPaddingHeight() {
topPadding.height(0);
},
resetBottomPaddingHeight: function resetBottomPaddingHeight() {
bottomPadding.height(0);
}
});

Expand Down Expand Up @@ -572,10 +580,8 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
viewport.createPaddingElements(template[0]);
// Destroy template's scope to remove any watchers on it.
scope.$destroy();
// also remove the template when the directive scope is destroyed
$scope.$on('$destroy', function () {
return template.remove();
});
// We don't need template anymore.
template.remove();
});

adapter.reload = reload;
Expand All @@ -585,10 +591,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
viewport.bind('scroll', resizeAndScrollHandler);
viewport.bind('mousewheel', wheelHandler);

$scope.$watch(datasource.revision, function () {
return reload();
});

$scope.$on('$destroy', function () {
// clear the buffer. It is necessary to remove the elements and $destroy the scopes
buffer.clear();
Expand All @@ -597,6 +599,31 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
viewport.unbind('mousewheel', wheelHandler);
});

// update events (deprecated since v1.1.0, unsupported since 1.2.0)
(function () {
var eventListener = datasource.scope ? datasource.scope.$new() : $scope.$new();

eventListener.$on('insert.item', function () {
return unsupportedMethod('insert');
});

eventListener.$on('update.items', function () {
return unsupportedMethod('update');
});

eventListener.$on('delete.items', function () {
return unsupportedMethod('delete');
});

function unsupportedMethod(token) {
throw new Error(token + ' event is no longer supported - use applyUpdates instead');
}
})();

reload();

/* Functions definitions */

function dismissPendingRequests() {
ridActual++;
pending = [];
Expand All @@ -605,6 +632,9 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
function reload() {
dismissPendingRequests();

viewport.resetTopPaddingHeight();
viewport.resetBottomPaddingHeight();

if (arguments.length) {
buffer.clear(arguments[0]);
} else {
Expand Down Expand Up @@ -835,27 +865,6 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
event.preventDefault();
}
}

// update events (deprecated since v1.1.0, unsupported since 1.2.0)
(function () {
var eventListener = datasource.scope ? datasource.scope.$new() : $scope.$new();

eventListener.$on('insert.item', function () {
return unsupportedMethod('insert');
});

eventListener.$on('update.items', function () {
return unsupportedMethod('update');
});

eventListener.$on('delete.items', function () {
return unsupportedMethod('delete');
});

function unsupportedMethod(token) {
throw new Error(token + ' event is no longer supported - use applyUpdates instead');
}
})();
};
}
}]);
Expand Down
Loading