Skip to content

Commit

Permalink
timoxley#24 making the library UMD - support for AMD and global
Browse files Browse the repository at this point in the history
  • Loading branch information
bigomega committed Aug 18, 2016
1 parent 99053f0 commit aca6b22
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@
* @api public
*/

exports = module.exports = function(searchInput) {
(function (root, factory) {
if(typeof define === "function" && define.amd) {
// the AMD environment.
root.keycode = factory()
} else if(typeof module === "object" && module.exports) {
// CommonJS environment
exports = module.exports = (root.keycode = factory());
} else {
root.keycode = factory();
}
}(this, function() {

var keycode = function(searchInput) {
// Keyboard Events
if (searchInput && 'object' === typeof searchInput) {
var hasKeyCode = searchInput.which || searchInput.keyCode || searchInput.charCode
Expand Down Expand Up @@ -39,10 +51,10 @@ exports = module.exports = function(searchInput) {
/**
* Get by name
*
* exports.code['enter'] // => 13
* keycode.code['enter'] // => 13
*/

var codes = exports.code = exports.codes = {
var codes = keycode.code = keycode.codes = {
'backspace': 8,
'tab': 9,
'enter': 13,
Expand Down Expand Up @@ -90,7 +102,7 @@ var codes = exports.code = exports.codes = {

// Helper aliases

var aliases = exports.aliases = {
var aliases = keycode.aliases = {
'windows': 91,
'⇧': 16,
'⌥': 18,
Expand Down Expand Up @@ -132,10 +144,10 @@ for (i = 0; i < 10; i++) codes['numpad '+i] = i + 96
/**
* Get by code
*
* exports.name[13] // => 'Enter'
* keycode.name[13] // => 'Enter'
*/

var names = exports.names = exports.title = {} // title for backward compat
var names = keycode.names = keycode.title = {} // title for backward compat

// Create reverse mapping
for (i in codes) names[codes[i]] = i
Expand All @@ -144,3 +156,7 @@ for (i in codes) names[codes[i]] = i
for (var alias in aliases) {
codes[alias] = aliases[alias]
}

return keycode;

}));

0 comments on commit aca6b22

Please sign in to comment.