Skip to content

Instantly share code, notes, and snippets.

@andresmatasuarez
Last active August 29, 2015 14:11
Show Gist options
  • Save andresmatasuarez/1870bb8fd9048c2ce68e to your computer and use it in GitHub Desktop.
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.
'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
'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