Created
November 12, 2013 05:15
-
-
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
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 characters
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 | |
} |
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 characters
<!-- ... --> | |
<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