Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added export and destroy function #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions egg.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function Egg(/* keySequence, fn, metadata */) {
// attempt to call passed function bound to Egg object instance
Egg.prototype.__execute = function(fn) {
return typeof fn === 'function' && fn.call(this);
}
};

// converts literal character values to keyCodes
Egg.prototype.__toCharCodes = function(keys) {
Expand Down Expand Up @@ -67,20 +67,20 @@ Egg.prototype.__toCharCodes = function(keys) {
});

return characterKeyCodes.join(',');
}
};

// Keycode lookup: http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
Egg.prototype.AddCode = function(keys, fn, metadata) {
this.eggs.push({keys: this.__toCharCodes(keys), fn: fn, metadata: metadata});

return this;
}
};

Egg.prototype.AddHook = function(fn) {
this.hooks.push(fn);

return this;
}
};

Egg.prototype.handleEvent = function(e) {
var keyCode = e.which;
Expand Down Expand Up @@ -142,9 +142,21 @@ Egg.prototype.Listen = function() {
return this;
};

Egg.prototype.Destroy = function() {
if ( document.removeEventListener !== void 0 ) {
document.removeEventListener( "keydown", this, false );
document.removeEventListener( "keyup", this, false );
}

return this;
};

Egg.prototype.listen = Egg.prototype.Listen;
Egg.prototype.addCode = Egg.prototype.AddCode;
Egg.prototype.addHook = Egg.prototype.AddHook;
Egg.prototype.destroy = Egg.prototype.Destroy;

module.exports = Egg;

// EGGSAMPLE
// var egg = new Egg();
Expand Down
2 changes: 1 addition & 1 deletion egg.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.