Last active
August 29, 2015 14:11
-
-
Save andresmatasuarez/1870bb8fd9048c2ce68e to your computer and use it in GitHub Desktop.
AngularJS | Directive | Binds event.stopPropagation and/or event.preventDefault to click. All browsers supported.
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
'use strict' | |
app = angular.module 'app' | |
app.directive 'preventDefault', ($state) -> | |
restrict : 'A' | |
link : ($scope, element, attrs) -> | |
element.bind 'click', (event) -> | |
if event.preventDefault | |
event.preventDefault() | |
else | |
# For IE < 9 | |
event.returnValue = false |
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
'use strict' | |
app = angular.module 'app' | |
app.directive 'stopPropagation', ($state) -> | |
restrict : 'A' | |
link : ($scope, element, attrs) -> | |
element.bind 'click', (event) -> | |
if event.stopPropagation | |
event.stopPropagation() | |
else | |
# For IE < 9 | |
event.cancelBubble = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment