Skip to content

Instantly share code, notes, and snippets.

@schottra
schottra / 0_reuse_code.js
Last active August 29, 2015 14:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@schottra
schottra / escapeHandlerMixin.js
Last active August 29, 2015 14:19
A reusable escape handler mixin that will call a function of your choice when escape is pressed and automatically detach when the scope is destroyed
angular.module('myModule').factory('escapeHandler', function($document){
var ESCAPE_KEY = 27;
return function(scope, handler){
var eventHandler = function(keyEvent){
if(keyEvent.keyCode === ESCAPE_KEY){ // use `keyCode`, not `which`
scope.$apply(handler);
}
};
$document[0].addEventListener('keydown', eventHandler, true); // using capture mode