diff --git a/build/bundle.js b/build/bundle.js index a85ce0f4..37c3d296 100644 --- a/build/bundle.js +++ b/build/bundle.js @@ -11487,10 +11487,30 @@ var init = function(){ el: $('#canvasWrapper')[0] }); - // set up event baton for certain things - $(window).focus(function() { - eventBaton.trigger('windowFocus'); - }); + // we always want to focus the text area to collect input + var focusTextArea = function() { + console.log('focusing text area'); + $('#commandTextField').focus(); + }; + focusTextArea(); + + $(window).focus(focusTextArea); + $(document).click(focusTextArea); + + // but when the input is fired in the text area, we pipe that to whoever is + // listenining + var makeKeyListener = function(name) { + return function() { + var args = [name]; + _.each(arguments, function(arg) { + args.push(arg); + }); + eventBaton.trigger.apply(eventBaton, args); + }; + }; + + $('#commandTextField').on('keydown', makeKeyListener('keydown')); + $('#commandTextField').on('keyup', makeKeyListener('keyup')); /* hacky demo functionality */ if (/\?demo/.test(window.location.href)) { @@ -11579,6 +11599,7 @@ EventBaton.prototype.trigger = function(name) { var listeners = this.eventMap[name]; if (!listeners) { + console.warn('no listeners for', name); return; } // call the top most listener with context and such @@ -11654,46 +11675,28 @@ var CommandPromptView = Backbone.View.extend({ }); this.index = -1; - this.listening = false; - this.commandSpan = this.$('#prompt span.command')[0]; this.commandCursor = this.$('#prompt span.cursor')[0]; - - // this is evil, but we will refer to HTML outside the view - // and attach a click event listener so we can focus / unfocus - $(document).delegate('#commandLineHistory', 'click', _.bind(function() { - this.focus(); - }, this)); - - - $(document).delegate('#commandTextField', 'blur', _.bind(function() { - this.blur(); - }, this)); + this.focus(); Main.getEvents().on('processCommandFromEvent', this.addToCollection, this); Main.getEvents().on('submitCommandValueFromEvent', this.submitValue, this); Main.getEvents().on('rollupCommands', this.rollupCommands, this); - // hacky timeout focus - setTimeout(_.bind(function() { - this.focus(); - }, this), 100); + Main.getEventBaton().stealBaton('keydown', this.onKeyDown, this); + Main.getEventBaton().stealBaton('keyup', this.onKeyUp, this); }, events: { - 'keydown #commandTextField': 'onKey', - 'keyup #commandTextField': 'onKeyUp', 'blur #commandTextField': 'hideCursor', 'focus #commandTextField': 'showCursor' }, blur: function() { - this.listening = false; this.hideCursor(); }, focus: function() { - this.listening = true; this.$('#commandTextField').focus(); this.showCursor(); }, @@ -11710,21 +11713,13 @@ var CommandPromptView = Backbone.View.extend({ $(this.commandCursor).toggleClass('shown', state); }, - onKey: function(e) { - if (!this.listening) { - return; - } - + onKeyDown: function(e) { var el = e.srcElement; this.updatePrompt(el); }, onKeyUp: function(e) { - if (!this.listening) { - return; - } - - this.onKey(e); + this.onKeyDown(e); // we need to capture some of these events. var keyToFuncMap = { @@ -11743,7 +11738,7 @@ var CommandPromptView = Backbone.View.extend({ if (keyToFuncMap[key] !== undefined) { e.preventDefault(); keyToFuncMap[key](); - this.onKey(e); + this.onKeyDown(e); } }, @@ -12044,7 +12039,6 @@ KeyboardListener.prototype.mute = function() { KeyboardListener.prototype.keydown = function(e) { var which = e.which; - console.log('key which', which); var key = mapKeycodeToKey(which); if (key === undefined) { @@ -12062,6 +12056,7 @@ KeyboardListener.prototype.fireEvent = function(eventName) { exports.KeyboardListener = KeyboardListener; exports.mapKeycodeToKey = mapKeycodeToKey; + }); require.define("/src/js/visuals/index.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore'); @@ -14269,10 +14264,30 @@ var init = function(){ el: $('#canvasWrapper')[0] }); - // set up event baton for certain things - $(window).focus(function() { - eventBaton.trigger('windowFocus'); - }); + // we always want to focus the text area to collect input + var focusTextArea = function() { + console.log('focusing text area'); + $('#commandTextField').focus(); + }; + focusTextArea(); + + $(window).focus(focusTextArea); + $(document).click(focusTextArea); + + // but when the input is fired in the text area, we pipe that to whoever is + // listenining + var makeKeyListener = function(name) { + return function() { + var args = [name]; + _.each(arguments, function(arg) { + args.push(arg); + }); + eventBaton.trigger.apply(eventBaton, args); + }; + }; + + $('#commandTextField').on('keydown', makeKeyListener('keydown')); + $('#commandTextField').on('keyup', makeKeyListener('keyup')); /* hacky demo functionality */ if (/\?demo/.test(window.location.href)) { @@ -17047,6 +17062,7 @@ EventBaton.prototype.trigger = function(name) { var listeners = this.eventMap[name]; if (!listeners) { + console.warn('no listeners for', name); return; } // call the top most listener with context and such @@ -17146,7 +17162,6 @@ KeyboardListener.prototype.mute = function() { KeyboardListener.prototype.keydown = function(e) { var which = e.which; - console.log('key which', which); var key = mapKeycodeToKey(which); if (key === undefined) { @@ -17164,6 +17179,7 @@ KeyboardListener.prototype.fireEvent = function(eventName) { exports.KeyboardListener = KeyboardListener; exports.mapKeycodeToKey = mapKeycodeToKey; + }); require("/src/js/util/keyboard.js"); @@ -17220,46 +17236,28 @@ var CommandPromptView = Backbone.View.extend({ }); this.index = -1; - this.listening = false; - this.commandSpan = this.$('#prompt span.command')[0]; this.commandCursor = this.$('#prompt span.cursor')[0]; - - // this is evil, but we will refer to HTML outside the view - // and attach a click event listener so we can focus / unfocus - $(document).delegate('#commandLineHistory', 'click', _.bind(function() { - this.focus(); - }, this)); - - - $(document).delegate('#commandTextField', 'blur', _.bind(function() { - this.blur(); - }, this)); + this.focus(); Main.getEvents().on('processCommandFromEvent', this.addToCollection, this); Main.getEvents().on('submitCommandValueFromEvent', this.submitValue, this); Main.getEvents().on('rollupCommands', this.rollupCommands, this); - // hacky timeout focus - setTimeout(_.bind(function() { - this.focus(); - }, this), 100); + Main.getEventBaton().stealBaton('keydown', this.onKeyDown, this); + Main.getEventBaton().stealBaton('keyup', this.onKeyUp, this); }, events: { - 'keydown #commandTextField': 'onKey', - 'keyup #commandTextField': 'onKeyUp', 'blur #commandTextField': 'hideCursor', 'focus #commandTextField': 'showCursor' }, blur: function() { - this.listening = false; this.hideCursor(); }, focus: function() { - this.listening = true; this.$('#commandTextField').focus(); this.showCursor(); }, @@ -17276,21 +17274,13 @@ var CommandPromptView = Backbone.View.extend({ $(this.commandCursor).toggleClass('shown', state); }, - onKey: function(e) { - if (!this.listening) { - return; - } - + onKeyDown: function(e) { var el = e.srcElement; this.updatePrompt(el); }, onKeyUp: function(e) { - if (!this.listening) { - return; - } - - this.onKey(e); + this.onKeyDown(e); // we need to capture some of these events. var keyToFuncMap = { @@ -17309,7 +17299,7 @@ var CommandPromptView = Backbone.View.extend({ if (keyToFuncMap[key] !== undefined) { e.preventDefault(); keyToFuncMap[key](); - this.onKey(e); + this.onKeyDown(e); } }, diff --git a/src/js/app/index.js b/src/js/app/index.js index 1789e325..141ef413 100644 --- a/src/js/app/index.js +++ b/src/js/app/index.js @@ -21,10 +21,30 @@ var init = function(){ el: $('#canvasWrapper')[0] }); - // set up event baton for certain things - $(window).focus(function() { - eventBaton.trigger('windowFocus'); - }); + // we always want to focus the text area to collect input + var focusTextArea = function() { + console.log('focusing text area'); + $('#commandTextField').focus(); + }; + focusTextArea(); + + $(window).focus(focusTextArea); + $(document).click(focusTextArea); + + // but when the input is fired in the text area, we pipe that to whoever is + // listenining + var makeKeyListener = function(name) { + return function() { + var args = [name]; + _.each(arguments, function(arg) { + args.push(arg); + }); + eventBaton.trigger.apply(eventBaton, args); + }; + }; + + $('#commandTextField').on('keydown', makeKeyListener('keydown')); + $('#commandTextField').on('keyup', makeKeyListener('keyup')); /* hacky demo functionality */ if (/\?demo/.test(window.location.href)) { diff --git a/src/js/util/eventBaton.js b/src/js/util/eventBaton.js index 22840caa..be720f33 100644 --- a/src/js/util/eventBaton.js +++ b/src/js/util/eventBaton.js @@ -27,6 +27,7 @@ EventBaton.prototype.trigger = function(name) { var listeners = this.eventMap[name]; if (!listeners) { + console.warn('no listeners for', name); return; } // call the top most listener with context and such diff --git a/src/js/util/keyboard.js b/src/js/util/keyboard.js index 0313c72a..5b9a95ea 100644 --- a/src/js/util/keyboard.js +++ b/src/js/util/keyboard.js @@ -32,7 +32,6 @@ KeyboardListener.prototype.mute = function() { KeyboardListener.prototype.keydown = function(e) { var which = e.which; - console.log('key which', which); var key = mapKeycodeToKey(which); if (key === undefined) { @@ -49,3 +48,4 @@ KeyboardListener.prototype.fireEvent = function(eventName) { exports.KeyboardListener = KeyboardListener; exports.mapKeycodeToKey = mapKeycodeToKey; + diff --git a/src/js/views/commandViews.js b/src/js/views/commandViews.js index d34e5b4b..35b03aa3 100644 --- a/src/js/views/commandViews.js +++ b/src/js/views/commandViews.js @@ -37,46 +37,28 @@ var CommandPromptView = Backbone.View.extend({ }); this.index = -1; - this.listening = false; - this.commandSpan = this.$('#prompt span.command')[0]; this.commandCursor = this.$('#prompt span.cursor')[0]; - - // this is evil, but we will refer to HTML outside the view - // and attach a click event listener so we can focus / unfocus - $(document).delegate('#commandLineHistory', 'click', _.bind(function() { - this.focus(); - }, this)); - - - $(document).delegate('#commandTextField', 'blur', _.bind(function() { - this.blur(); - }, this)); + this.focus(); Main.getEvents().on('processCommandFromEvent', this.addToCollection, this); Main.getEvents().on('submitCommandValueFromEvent', this.submitValue, this); Main.getEvents().on('rollupCommands', this.rollupCommands, this); - // hacky timeout focus - setTimeout(_.bind(function() { - this.focus(); - }, this), 100); + Main.getEventBaton().stealBaton('keydown', this.onKeyDown, this); + Main.getEventBaton().stealBaton('keyup', this.onKeyUp, this); }, events: { - 'keydown #commandTextField': 'onKey', - 'keyup #commandTextField': 'onKeyUp', 'blur #commandTextField': 'hideCursor', 'focus #commandTextField': 'showCursor' }, blur: function() { - this.listening = false; this.hideCursor(); }, focus: function() { - this.listening = true; this.$('#commandTextField').focus(); this.showCursor(); }, @@ -93,21 +75,13 @@ var CommandPromptView = Backbone.View.extend({ $(this.commandCursor).toggleClass('shown', state); }, - onKey: function(e) { - if (!this.listening) { - return; - } - + onKeyDown: function(e) { var el = e.srcElement; this.updatePrompt(el); }, onKeyUp: function(e) { - if (!this.listening) { - return; - } - - this.onKey(e); + this.onKeyDown(e); // we need to capture some of these events. var keyToFuncMap = { @@ -126,7 +100,7 @@ var CommandPromptView = Backbone.View.extend({ if (keyToFuncMap[key] !== undefined) { e.preventDefault(); keyToFuncMap[key](); - this.onKey(e); + this.onKeyDown(e); } },