Last active
December 15, 2015 17:59
-
-
Save oaleynik/5300231 to your computer and use it in GitHub Desktop.
Problem - defer function invokation till the full browser render and till the end of view-model synchronization cycle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Ctrl = function ($scope, initAnchorScrolling) { | |
initAnchorScrolling($scope); | |
}; | |
Ctrl.$inject = ['$scope', "initAnchorScrolling"]; | |
applicationServices.factory("initAnchorScrolling", | |
['scroll', '$location', '$timeout', function(scrollUtils, $location, $timeout) { | |
return function(scope) { | |
/** Some stuff here */ | |
function scroll() { | |
var hash = $location.hash(), elm; | |
if (!hash) { | |
scrollUtils.scrollTo(0, 0); | |
} else if ((elm = getAnchorElement(hash))) { | |
scrollUtils.scrollToElement(elm); | |
} else { | |
scrollUtils.scrollTo(0, 0); | |
} | |
} | |
scope.$watch(function scrollWatch() { return $location.hash(); }, | |
function scrollWatchAction() { | |
$timeout(function () { | |
scroll(); | |
}, 0, true); | |
}); | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment