Created
October 15, 2014 19:29
-
-
Save carbonrobot/162255ca69e6d61f00bf to your computer and use it in GitHub Desktop.
Angular Right Click Directive
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
(function () { | |
/* | |
* @name ngRightClick | |
* @type Directive | |
* @desc Binds the right click to a javascript function by using the ng-right-click attribute | |
*/ | |
function ngRightClick($parse) { | |
return function (scope, element, attrs) { | |
var fn = $parse(attrs.ngRightClick); | |
element.bind('contextmenu', function (event) { | |
scope.$apply(function () { | |
event.preventDefault(); | |
fn(scope, { $event: event }); | |
}); | |
}); | |
}; | |
} | |
ngRightClick.$inject = ['$parse']; | |
angular.module('app').directive('ngRightClick', ngRightClick); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment