Skip to content
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

Adding initial page feature #8

Closed
wants to merge 8 commits into from
10 changes: 10 additions & 0 deletions src/angular-vs-repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@
$scope.offsetAfter = 0;
$scope.excess = 2;

$scope.$watch($attrs.vsInitialElement, function(elementIndex){
$scope.goTo(elementIndex);
});

$scope.goTo = function(index){
setTimeout(function() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is setTimeout needed here? maybe $scope.$$postDigest would be enough if any delay of execution at all. What happens if the setTimeout is removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, $$postDigest might solve the problem, it was just a hacky setTimeout Zero just to run scrollTop after content loaded, waiting all DOM negotiation finishes before scrollTop, or parent height would be 0px.
I'll note this as many others under the hood and not documented useful angular features found.

$scrollParent[0].scrollTop = $scope.elementSize * index + $scope.offsetBefore;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't check whether the siezes property has been provided

vs-size-property="propertyName" - a property name of the items in collection that is a number denoting the element size (in pixels)

}, 0);
};

Object.keys(attributesDictionary).forEach(function(key){
if($attrs[key]){
$attrs.$observe(key, function(value){
Expand Down