Skip to content

Instantly share code, notes, and snippets.

@DrMartiner
Created November 12, 2013 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrMartiner/7425844 to your computer and use it in GitHub Desktop.
Save DrMartiner/7425844 to your computer and use it in GitHub Desktop.
Directive, who set\unset toggle class at the element, when the function-condition changed
toggleClass = angular.module('jobMapApp')
.directive 'ngToggleClass', () ->
return {
restrict: 'A'
scope:
condition: '&ngToggleCondition'
link: (scope, element, attrs) ->
scope.timerId = null
scope.$watch () ->
return scope.condition()
, (newValue) ->
if newValue
scope.timerId = setInterval () ->
element.toggleClass attrs.ngToggleClass
, attrs.ngToggleDelay
else
if scope.timerId
clearInterval scope.timerId
}
<!-- ... -->
<button ng-toggle-class="animate" ng-toggle-condition="isBtnShow()" ng-toggle-delay="1000">Attention!</button>
<!-- ... -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment