MCPcopy
hub / github.com/pcottle/learnGitBranching / initRootEvents

Function initRootEvents

src/js/app/index.js:126–171  ·  view source on GitHub ↗
(eventBaton)

Source from the content-addressed store, hash-verified

124};
125
126var 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
173var initDemo = function(sandbox) {
174 var params = util.parseQueryString(window.location.href);

Callers 1

initFunction · 0.85

Calls 7

focusTextAreaFunction · 0.85
makeKeyListenerFunction · 0.85
focusMethod · 0.80
triggerMethod · 0.45
clickMethod · 0.45
bindMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected