Revisions
-
axelav revised this gist
Jan 27, 2014 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -14,6 +14,8 @@ angular.module('directives.scrollSpy', []) $('html, body').stop().animate scrollTop: target.offset().top + 1 speed easeInOutCubuc = (x, t, b, c, d) -> c * ((t = t / d - 1) * t * t + 1) + b else $('html, body').stop().animate scrollTop: 0, speed @@ -51,7 +53,10 @@ angular.module('directives.scrollSpy', []) spyElems[spy.id] = elem.find('#' + spy.id) if spyElems[spy.id]? and spyElems[spy.id].length isnt 0 # TODO: fix for IE9+ ? # https://gist.github.com/alxhill/6886760#comment-952714 if (pos = spyElems[spy.id].offset().top) - $window.pageYOffset <= topBuffer # if (pos = spyElems[spy.id].offset().top) - $window.scrollY <= topBuffer spy.pos = pos highlightSpy ?=spy if highlightSpy.pos < spy.pos -
axelav revised this gist
Jan 26, 2014 . 1 changed file with 37 additions and 26 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,50 +1,61 @@ angular.module('directives.scrollSpy', []) .directive('spy', ($location) -> restrict: 'A' require: '^scrollSpy' link: (scope, elem, attrs, scrollSpy) -> attrs.spyClass ?= 'active' elem.click (e) -> e.stopPropagation() if attrs.spy target = $('#' + attrs.spy) speed = 750 $('html, body').stop().animate scrollTop: target.offset().top + 1 speed else $('html, body').stop().animate scrollTop: 0, speed scrollSpy.addSpy id: attrs.spy in: -> elem.addClass attrs.spyClass elem.parents('li').addClass attrs.spyClass out: -> elem.removeClass attrs.spyClass ) .directive('scrollSpy', ($window, $timeout) -> restrict: 'A' controller: ($scope) -> $scope.spies = [] @addSpy = (spyObj) -> $scope.spies.push spyObj return scope: true link: (scope, elem, attrs) -> spyElems = [] topBuffer = if attrs.topBuffer then attrs.topBuffer else 0 scope.$watchCollection 'spies', (spies) -> for spy in spies unless spyElems[spy.id]? spyElems[spy.id] = elem.find('#' + spy.id) $($window).scroll -> highlightSpy = null for spy in scope.spies spy.out() if !spyElems[spy.id]? or spyElems.length is 0 spyElems[spy.id] = elem.find('#' + spy.id) if spyElems[spy.id]? and spyElems[spy.id].length isnt 0 if (pos = spyElems[spy.id].offset().top) - $window.scrollY <= topBuffer spy.pos = pos highlightSpy ?=spy if highlightSpy.pos < spy.pos highlightSpy = spy highlightSpy?.in() ) -
alxhill created this gist
Oct 8, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ angular.module('jobFoundryDirectives').directive 'spy', ($location) -> restrict: "A" require: "^scrollSpy" link: (scope, elem, attrs, scrollSpy) -> attrs.spyClass ?= "current" elem.click -> scope.$apply -> $location.hash(attrs.spy) scrollSpy.addSpy id: attrs.spy in: -> elem.addClass attrs.spyClass, out: -> elem.removeClass attrs.spyClass angular.module('jobFoundryDirectives').directive 'scrollSpy', ($window) -> restrict: 'A' controller: ($scope) -> $scope.spies = [] @addSpy = (spyObj) -> $scope.spies.push spyObj link: (scope, elem, attrs) -> spyElems = [] scope.$watch 'spies', (spies) -> for spy in spies unless spyElems[spy.id]? spyElems[spy.id] = elem.find('#'+spy.id) $($window).scroll -> highlightSpy = null for spy in scope.spies spy.out() # the elem might not have been available when it was originally cached, # so we check again to get another element in case this one doesn't exist. spyElems[spy.id] = if spyElems[spy.id].length is 0 elem.find('#'+spy.id) else spyElems[spy.id] # the element could still not exist, so we check first to avoid errors if spyElems[spy.id].length isnt 0 if (pos = spyElems[spy.id].offset().top) - $window.scrollY <= 0 spy.pos = pos highlightSpy ?= spy if highlightSpy.pos < spy.pos highlightSpy = spy highlightSpy?.in()