Created
November 16, 2012 10:37
-
-
Save drphrozen/4086297 to your computer and use it in GitHub Desktop.
AngularJS directives for the document element. Usage doc-click, doc-*. Check ng-click and ng-* for documentation :-)
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
var dem = angular.module('DocumentEventsModule', []); | |
angular.forEach(['click', 'dblclick', 'mousedown', 'mouseup', 'mouseover', 'mouseout', 'mousemove', 'mouseenter', 'mouseleave'], function(name) { | |
var capitalizedName = name.charAt(0).toUpperCase() + name.slice(1); | |
var directiveName = 'doc' + capitalizedName; | |
dem.directive(directiveName, ['$parse', '$document', function(parse, document) { | |
return function(scope, element, attr) { | |
var fn = parse(attr[directiveName]); | |
document.bind(name, function(event) { | |
scope.$apply(function() { | |
fn(scope, {$event:event}); | |
}); | |
}); | |
}; | |
}]); | |
}); | |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example http://jsfiddle.net/bxUMV/15/