lib/public/js/keyboard.js in parade-0.8.0 vs lib/public/js/keyboard.js in parade-0.8.1

- old
+ new

@@ -6,16 +6,21 @@ * * Copyright 2011, Robert William Hurst * Licenced under the BSD License. * See https://raw.github.com/RobertWHurst/KeyboardJS/master/license.txt */ -(function(context, factory) { + +window.KeyboardCreate = function(name) { + createKeyboard(name,this,keyboardFactory); +} + +createKeyboard = function(name, context, factory) { var namespaces = [], previousValues = {}, library; if(typeof define === 'function' && define.amd) { define(function() { return factory('amd'); }); } else { - library = factory('global'); + library = factory('global',name); library.noConflict = function( ) { var args, nI; newNamespaces = Array.prototype.slice.apply(arguments); for(nI = 0; nI < namespaces.length; nI += 1) { if(typeof previousValues[namespaces[nI]] === 'undefined') { @@ -31,15 +36,17 @@ context[newNamespaces[nI]] = library; } namespaces = newNamespaces; return namespaces; }; - library.noConflict('KeyboardJS', 'k'); + library.noConflict(name); } -})(this, function(env) { - var KeyboardJS = {}, locales, locale, map, macros, activeKeys = [], bindings = [], activeBindings = [], activeMacros = []; +}; +keyboardFactory = function(env) { + var keyboardJS = {}, locales, locale, map, macros, activeKeys = [], bindings = [], activeBindings = [], activeMacros = []; + //INDEXOF POLLYFILL [].indexOf||(Array.prototype.indexOf=function(a,b,c){for(c=this.length,b=(c+~~b)%c;b<c&&(!(b in this)||this[b]!==a);b++);return b^c?b:-1;}); //BUNDLED LOCALES locales = { @@ -216,11 +223,11 @@ [[[["shift", "z"]]], ["Z"]] ] } //If you create a new locale please submit it as a pull request or post it in the issue tracker at - // http://github.com/RobertWhurst/KeyboardJS/issues/ + // http://github.com/RobertWhurst/keyboardJS/issues/ }; locale = 'us'; map = locales[locale].map; macros = locales[locale].macros; if(document.addEventListener) { @@ -233,43 +240,43 @@ document.attachEvent('onblur', blur); } else { throw new Error('Cannot bind to keydown event. Both addEventListener and attachEvent are unsupported by your browser.'); } - KeyboardJS.enable = function() { - KeyboardJS.enabled = true; + keyboardJS.enable = function() { + keyboardJS.enabled = true; }; - KeyboardJS.disable = function() { - KeyboardJS.enabled = false; + keyboardJS.disable = function() { + keyboardJS.enabled = false; }; - KeyboardJS.toggle = function() { - KeyboardJS.enabled = !KeyboardJS.enabled; + keyboardJS.toggle = function() { + keyboardJS.enabled = !keyboardJS.enabled; }; - KeyboardJS.enabled = true; - KeyboardJS.activeKeys = getActiveKeys; - KeyboardJS.on = createBinding; - KeyboardJS.clear = removeBindingByKeyCombo; - KeyboardJS.clear.key = removeBindingByKeyName; - KeyboardJS.locale = getSetLocale; - KeyboardJS.locale.register = registerLocale; - KeyboardJS.macro = createMacro; - KeyboardJS.macro.remove = removeMacro; - KeyboardJS.getKey = getKeyName; - KeyboardJS.combo = {}; - KeyboardJS.combo.parse = parseKeyCombo; - KeyboardJS.combo.stringify = stringifyKeyCombo; + keyboardJS.enabled = true; + keyboardJS.activeKeys = getActiveKeys; + keyboardJS.on = createBinding; + keyboardJS.clear = removeBindingByKeyCombo; + keyboardJS.clear.key = removeBindingByKeyName; + keyboardJS.locale = getSetLocale; + keyboardJS.locale.register = registerLocale; + keyboardJS.macro = createMacro; + keyboardJS.macro.remove = removeMacro; + keyboardJS.getKey = getKeyName; + keyboardJS.combo = {}; + keyboardJS.combo.parse = parseKeyCombo; + keyboardJS.combo.stringify = stringifyKeyCombo; window.map = map; window.macros = macros; - return KeyboardJS; + return keyboardJS; function keydown(event) { - if (!KeyboardJS.enabled) { return; } + if (!keyboardJS.enabled) { return; } var keyNames, kI; keyNames = getKeyName(event.keyCode); if(keyNames.length < 1) { return; } for(kI = 0; kI < keyNames.length; kI += 1) { @@ -277,25 +284,24 @@ } executeMacros(); executeBindings(event); } function keyup(event) { - if (!KeyboardJS.enabled) { return; } var keyNames, kI; keyNames = getKeyName(event.keyCode); if(keyNames.length < 1) { return; } for(kI = 0; kI < keyNames.length; kI += 1) { removeActiveKey(keyNames[kI]); } + if (!keyboardJS.enabled) { return; } pruneMacros(); pruneBindings(event); } function blur(event) { - if (!KeyboardJS.enabled) { return; } - activeKeys = []; + if (!keyboardJS.enabled) { return; } pruneMacros(); pruneBindings(event); } function getKeyName(keyCode) { return map[keyCode] || []; @@ -421,11 +427,11 @@ } } function removeBindingByKeyCombo(keyCombo) { var bI, binding, keyName; for(bI = 0; bI < bindings.length; bI += 1) { - binding = bindings[bi]; + binding = bindings[bI]; if(compareCombos(keyCombo, binding.keyCombo)) { bindings.splice(bI, 1); bI -= 1; } } } @@ -721,13 +727,13 @@ * @return {Object} */ function getSetLocale(localeName) { if(!localeName) { if(typeof localeName !== 'string') { throw new Error('Cannot set locale. The locale name must be a string.'); } - if(!locales[localeName]) { throw new Error('Cannot set locale to ' + localeName + ' because it does not exist. If you would like to submit a ' + localeName + ' locale map for KeyboardJS please submit it at https://github.com/RobertWHurst/KeyboardJS/issues.'); } + if(!locales[localeName]) { throw new Error('Cannot set locale to ' + localeName + ' because it does not exist. If you would like to submit a ' + localeName + ' locale map for keyboardJS please submit it at https://github.com/RobertWHurst/keyboardJS/issues.'); } locale = localeName; map = locales[locale].map; macros = locales[locale].macros; } return locale; } -}); +}; \ No newline at end of file