(eventBaton)
| 124 | }; |
| 125 | |
| 126 | var initRootEvents = function(eventBaton) { |
| 127 | // we always want to focus the text area to collect input |
| 128 | var focusTextArea = function() { |
| 129 | $('#commandTextField').focus(); |
| 130 | }; |
| 131 | focusTextArea(); |
| 132 | |
| 133 | $(window).focus(function(e) { |
| 134 | eventBaton.trigger('windowFocus', e); |
| 135 | }); |
| 136 | $(document).click(function(e) { |
| 137 | eventBaton.trigger('documentClick', e); |
| 138 | }); |
| 139 | $(document).bind('keydown', function(e) { |
| 140 | eventBaton.trigger('docKeydown', e); |
| 141 | }); |
| 142 | $(document).bind('keyup', function(e) { |
| 143 | eventBaton.trigger('docKeyup', e); |
| 144 | }); |
| 145 | $(window).on('resize', function(e) { |
| 146 | events.trigger('resize', e); |
| 147 | }); |
| 148 | |
| 149 | eventBaton.stealBaton('docKeydown', function() { }); |
| 150 | eventBaton.stealBaton('docKeyup', function() { }); |
| 151 | |
| 152 | // the default action on window focus and document click is to just focus the text area |
| 153 | eventBaton.stealBaton('windowFocus', focusTextArea); |
| 154 | eventBaton.stealBaton('documentClick', focusTextArea); |
| 155 | |
| 156 | // but when the input is fired in the text area, we pipe that to whoever is |
| 157 | // listenining |
| 158 | var makeKeyListener = function(name) { |
| 159 | return function() { |
| 160 | var args = [name]; |
| 161 | Array.prototype.slice.apply(arguments).forEach(function(arg) { |
| 162 | args.push(arg); |
| 163 | }); |
| 164 | eventBaton.trigger.apply(eventBaton, args); |
| 165 | }; |
| 166 | }; |
| 167 | |
| 168 | $('#commandTextField').on('keydown', makeKeyListener('keydown')); |
| 169 | $('#commandTextField').on('keyup', makeKeyListener('keyup')); |
| 170 | $(window).trigger('resize'); |
| 171 | }; |
| 172 | |
| 173 | var initDemo = function(sandbox) { |
| 174 | var params = util.parseQueryString(window.location.href); |
no test coverage detected