Skip to content

Fix top visible scrolling #71

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

Closed
Closed
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-17T12:18:01.421Z
* License: MIT
*/
(function () {
/*!
* angular-ui-scroll
* https://github.com/angular-ui/ui-scroll.git
* Version: 1.3.3 -- 2016-03-23T04:30:31.917Z
* 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.

51 changes: 35 additions & 16 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-17T12:18:01.421Z
* License: MIT
*/
(function () {
/*!
* angular-ui-scroll
* https://github.com/angular-ui/ui-scroll.git
* Version: 1.3.3 -- 2016-03-23T04:30:31.917Z
* 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 @@ -465,21 +465,38 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
if (isNewRow) {
itemHeight = item.element.outerHeight(true);
}
if (isNewRow && viewport.topDataPos() + topHeight + itemHeight <= viewport.topVisiblePos()) {
if (isNewRow && !isItemTopVisible(topHeight, itemHeight)) {
topHeight += itemHeight;
} else {
if (isNewRow) {
this.topVisible = item.item;
this.topVisibleElement = item.element;
this.topVisibleScope = item.scope;
setTopVisible(viewportScope, item.item);
setTopVisibleElement(viewportScope, item.element);
setTopVisibleScope(viewportScope, item.scope);
this.setTopVisibleItem(item);
}
break;
}
}
};

function isItemTopVisible(topHeight, itemHeight) {
var viewportTopVisible = undefined,
viewportTopData = undefined;
viewportTopVisible = viewport.topVisiblePos();
viewportTopData = viewport.topDataPos();
var startOfEl = viewportTopData + topHeight;
var endOfEl = startOfEl + itemHeight;
return startOfEl <= viewportTopVisible && endOfEl > viewportTopVisible;
}

this.setTopVisibleItem = function (item) {
var parentThis = this;
return $timeout(function () {
parentThis.topVisible = item.item;
parentThis.topVisibleElement = item.element;
parentThis.topVisibleScope = item.scope;
setTopVisible(viewportScope, item.item);
setTopVisibleElement(viewportScope, item.element);
setTopVisibleScope(viewportScope, item.scope);
});
};
}

function compile(elementTemplate, attr, compileLinker) {
Expand Down Expand Up @@ -874,6 +891,8 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {

if (pending.length) {
unbindEvents();
} else {
adapter.calculateProperties();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions dist/ui-scroll.min.js

Large diffs are not rendered by default.

32 changes: 25 additions & 7 deletions src/ui-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,22 +450,38 @@ angular.module('ui.scroll', [])
if (isNewRow) {
itemHeight = item.element.outerHeight(true);
}
if (isNewRow && (viewport.topDataPos() + topHeight + itemHeight <= viewport.topVisiblePos())) {
if (isNewRow && !isItemTopVisible(topHeight, itemHeight)) {
topHeight += itemHeight;
} else {
if (isNewRow) {
this.topVisible = item.item;
this.topVisibleElement = item.element;
this.topVisibleScope = item.scope;
setTopVisible(viewportScope, item.item);
setTopVisibleElement(viewportScope, item.element);
setTopVisibleScope(viewportScope, item.scope);
this.setTopVisibleItem(item);
}
break;

}
}
};

function isItemTopVisible(topHeight, itemHeight) {
let viewportTopVisible, viewportTopData;
viewportTopVisible = viewport.topVisiblePos();
viewportTopData = viewport.topDataPos();
let startOfEl = viewportTopData + topHeight;
let endOfEl = startOfEl + itemHeight;
return startOfEl <= viewportTopVisible && endOfEl > viewportTopVisible;
}

this.setTopVisibleItem = function(item) {
var parentThis = this;
return $timeout(function() {
parentThis.topVisible = item.item;
parentThis.topVisibleElement = item.element;
parentThis.topVisibleScope = item.scope;
setTopVisible(viewportScope, item.item);
setTopVisibleElement(viewportScope, item.element);
setTopVisibleScope(viewportScope, item.scope);
});
};
}

function compile(elementTemplate, attr, compileLinker) {
Expand Down Expand Up @@ -843,6 +859,8 @@ angular.module('ui.scroll', [])

if (pending.length) {
unbindEvents();
} else {
adapter.calculateProperties();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/BasicTestsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,15 +493,15 @@ describe('uiScroll', function () {
wheelEventElement.dispatchEvent(getNewWheelEvent()); //now we are at the top but preventDefault is occurred because of bof will be reached only after next scroll trigger
expect(documentScrollBubblingCount).toBe(2); //here! the only one prevented wheel-event

//flush();
flush();

wheelEventElement.dispatchEvent(getNewWheelEvent()); //preventDefault will not occurred but document will not scroll because of viewport will be scrolled
expect(documentScrollBubblingCount).toBe(3);

viewport.scrollTop(0);
viewport.trigger('scroll'); //bof will be reached right after that

//flush();
flush();

wheelEventElement.dispatchEvent(getNewWheelEvent()); //preventDefault will not occurred because of we are at the top and bof is reached
expect(documentScrollBubblingCount).toBe(4);
Expand Down