(function(){ "use strict"; angular.module('shared') .directive('scrollToFolder', ['$timeout', '$window', function ($timeout, $window) { return { restrict: 'A', scope: { folderIndex: '=', folderListItemHeight: '=' }, link: function(scope, elem, attrs) { $timeout(function() { scrollTo(); }); function scrollTo () { var chooseFolder = $window.document.getElementById('chooseFolder'); if (scope.folderIndex > -1) { var newFolderHeight = $window.document.getElementById('newFolder').clientHeight; chooseFolder.scrollTop = (scope.folderIndex * scope.folderListItemHeight) + newFolderHeight; } } } } } ]) })();