Skip to content

Scroll on mac #214

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
wants to merge 10 commits into from
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-ui-scroll",
"description": "AngularJS infinite scrolling module",
"version": "1.7.2",
"version": "1.8.0-rc",
"main": "./dist/ui-scroll.js",
"homepage": "https://github.com/angular-ui/ui-scroll.git",
"license": "MIT",
Expand Down
8 changes: 6 additions & 2 deletions demo/serviceDatasource/serviceDatasource.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ <h1 class="page-header page-header-exapmle">Datasource as service</h1>
</div>

<div class="viewport" id="viewport-serviceDatasource" ui-scroll-viewport>
<div class="item" ui-scroll="item in datasource">{{item}}</div>
<div class="item" ui-scroll="item in datasource">
<div ng-if="$index%10 === 0 && $index%20 !== 0">{{item}} ************ {{$index}}</div>
<div ng-if="$index%10 === 0 && $index%20 === 0">{{item}} ************ {{$index}} OOOOOOOOOOOO </div>
<div ng-if="$index%10 !== 0">{{item}}</div>
</div>
</div>

</div>

</body>
</html>
</html>
2 changes: 1 addition & 1 deletion demo/serviceDatasource/serviceDatasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ angular.module('application', ['ui.scroll'])
result.push("item #" + i);
}
success(result);
}, 100);
}, 700);
};

return {
Expand Down
2 changes: 1 addition & 1 deletion dist/ui-scroll-grid.js

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

2 changes: 1 addition & 1 deletion dist/ui-scroll-grid.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ui-scroll-grid.min.js

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

2 changes: 1 addition & 1 deletion dist/ui-scroll-grid.min.js.map

Large diffs are not rendered by default.

64 changes: 52 additions & 12 deletions dist/ui-scroll.js

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

2 changes: 1 addition & 1 deletion dist/ui-scroll.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/ui-scroll.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ui-scroll.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-ui-scroll",
"description": "AngularJS infinite scrolling module",
"version": "1.7.2",
"version": "1.8.0-rc",
"src": "./src/",
"public": "./dist/",
"main": "./dist/ui-scroll.js",
Expand Down
7 changes: 6 additions & 1 deletion src/modules/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Adapter {

generatePublicContext() {
// these methods will be accessible out of ui-scroll via user defined adapter
const publicMethods = ['reload', 'applyUpdates', 'append', 'prepend', 'isBOF', 'isEOF', 'isEmpty'];
const publicMethods = ['reload', 'applyUpdates', 'append', 'prepend', 'isBOF', 'isEOF', 'isEmpty', 'resetScrollTopCorrection'];
for (let i = publicMethods.length - 1; i >= 0; i--) {
this.publicContext[publicMethods[i]] = this[publicMethods[i]].bind(this);
}
Expand Down Expand Up @@ -87,6 +87,11 @@ class Adapter {
return !this.buffer.length;
}

resetScrollTopCorrection() {
// is needed to scroll at negative area programmatically (e.g. tests)
this.viewport.scrollTopValue = null;
}

append(newItems) {
this.buffer.append(newItems);
this.doAdjust();
Expand Down
15 changes: 14 additions & 1 deletion src/modules/viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export default function Viewport(elementRoutines, buffer, element, viewportContr
'display': 'block'
});

viewport.scrollTopOriginal = viewport.scrollTopOriginal || viewport.scrollTop;
viewport.scrollTopBeforeSet = null;
viewport.scrollTopValue = null;

function bufferPadding() {
return viewport.outerHeight() * padding; // some extra space to initiate preload
}
Expand All @@ -22,6 +26,14 @@ export default function Viewport(elementRoutines, buffer, element, viewportContr
return scope;
},

scrollTop() {
if (typeof arguments[0] !== 'undefined') {
viewport.scrollTopBeforeSet = viewport.scrollTop();
viewport.scrollTopValue = arguments[0];
}
return viewport.scrollTopOriginal.apply(viewport, arguments);
},

createPaddingElements(template) {
topPadding = new Padding(template);
bottomPadding = new Padding(template);
Expand Down Expand Up @@ -97,7 +109,7 @@ export default function Viewport(elementRoutines, buffer, element, viewportContr
},

shouldLoadTop() {
return !buffer.bof && (viewport.topDataPos() > viewport.topVisiblePos() - bufferPadding());
return !buffer.bof && !viewport.scrollTopSetFailed && viewport.topDataPos() > viewport.topVisiblePos() - bufferPadding();
},

clipTop() {
Expand Down Expand Up @@ -187,6 +199,7 @@ export default function Viewport(elementRoutines, buffer, element, viewportContr
}
else {
topPadding.height(0);
viewport.scrollTopAdjust = paddingHeight;
viewport.scrollTop(viewport.scrollTop() - paddingHeight);
}
},
Expand Down
40 changes: 31 additions & 9 deletions src/ui-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ angular.module('ui.scroll', [])

const BUFFER_MIN = 3;
const BUFFER_DEFAULT = 10;
const PADDING_MIN = 0.3;
const PADDING_MIN = 0.01;
const PADDING_DEFAULT = 0.5;
const MAX_VIEWPORT_DELAY = 500;
const VIEWPORT_POLLING_INTERVAL = 50;
Expand Down Expand Up @@ -475,18 +475,40 @@ angular.module('ui.scroll', [])
}
}

function resizeAndScrollHandler() {
if (!$rootScope.$$phase && !adapter.isLoading && !adapter.disabled) {
function resizeAndScrollHandler(ev) {
if ($rootScope.$$phase || adapter.isLoading || adapter.disabled) {
return;
}

enqueueFetch(ridActual);
if (ev.type === 'scroll') {
// Don't process scroll event if it was triggered by us setting scrollTop.
if (viewport[0].scrollTop === viewport.scrollTopValue) {
return false;
}

if (pending.length) {
unbindEvents();
} else {
adapter.calculateProperties();
!$scope.$$phase && $scope.$digest();
// Check if we tried to set scrollTop and it failed. If that happens, don't prepend more items based on the stale value
// of scrollTop that will be used by shouldLoadTop(). Also, try to set it again.
viewport.scrollTopSetFailed = false;
if (viewport.scrollTopValue != null) {
const curScrollTop = viewport[0].scrollTop;
if (Math.abs(curScrollTop - viewport.scrollTopValue) > Math.abs(curScrollTop - viewport.scrollTopBeforeSet)) {
viewport.scrollTopSetFailed = true;
viewport.scrollTop(curScrollTop - viewport.scrollTopAdjust);
}
}
}

enqueueFetch(ridActual);

// we got a real scroll event, so browser is now in charge of scrollTop
viewport.scrollTopValue = null;

if (pending.length) {
unbindEvents();
} else {
adapter.calculateProperties();
!$scope.$$phase && $scope.$digest();
}
}

function wheelHandler(event) {
Expand Down
Loading