1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
|
(function() {
var RELOAD_INTERVAL = 600000;//60000;
var last_tab_view_at = new Date();
var reload_interval_obj;
chrome.extension.onMessage.addListener(
function(request, sender, send_response) {
if (request.scrumdo_loaded) {
reload_page();
set_reload_interval();
send_response({ success: true });
}
}
);
chrome.extension.onMessage.addListener(
function(request, sender, send_response) {
if (request.scrumdo_unloaded) {
clear_reload_interval();
send_response({success: true});
}
}
);
// Set reload interval to user-defined interval
chrome.extension.sendMessage({ get_option: 'refresh_interval' }, function(response) {
if (response.refresh_interval) {
clear_reload_interval();
RELOAD_INTERVAL = response.refresh_interval * 1000;
set_reload_interval();
}
});
var set_reload_interval = function() {
reload_interval_obj = window.setInterval(reload_page, RELOAD_INTERVAL);
};
var clear_reload_interval = function() {
window.clearInterval(reload_interval_obj);
};
var reload_page = function() {
now = new Date();
if (now - last_tab_view_at > RELOAD_INTERVAL) {
window.location.reload();
last_tab_view_at = new Date();
}
};
// Set initial reload interval
reload_interval_obj = window.setInterval(reload_page, RELOAD_INTERVAL);
// Conceptual Notes
// If tab is focused, setInterval
// If tab un-focuses, clearInterval();
// When tab is selected, if it has been longer than a minute since the last
// reload, do a reload
})();
var StoryClass;
var Story;
$(function() {
StoryClass = function() {
// Current story
this.el = '.scrum_board_story_block';
this.$el = $('.scrum_board_story_block');
this.column_el = '.scrum_board_column';
this.$column_el = $('.scrum_board_column');
this.total_columns = this.$column_el.length;
this.project_panel_open = false;
this.current = null;
this.set_current = function($el) {
this.unset_current();
this.current = $el;
this.current.addClass('active');
};
this.unset_current = function() {
if (this.current) {
this.current.removeClass('active');
this.current = null;
}
};
// Move to story
this.move = function(opts) {
if (this.current) {
if (opts.direction === 'left') { this.move_left() }
else if (opts.direction === 'right') { this.move_right() }
else if (opts.direction === 'up') { this.move_up() }
else if (opts.direction === 'down') { this.move_down() }
}
else {
this.set_current(this.$el.first());
}
};
this.move_left = function() {
this.set_current(this.current_left_element());
};
this.move_right = function() {
this.set_current(this.current_right_element());
};
this.move_up = function() {
this.set_current(this.$el.eq(this.current_previous_element_index()));
};
this.move_down = function() {
this.set_current(this.$el.eq(this.current_next_element_index()));
};
// Move - supporting methods
// Vertical
this.current_vertical_element_index = function(num) {
return this.$el.index(this.current) + num;
};
this.current_next_element_index = function() {
return this.current_vertical_element_index(1);
};
this.current_previous_element_index = function() {
return this.current_vertical_element_index(-1);
};
// Horizontal
this.current_left_element = function() {
return this.previous_column().find(this.el).first();
};
this.current_right_element = function() {
return this.next_column().find(this.el).first();
};
// Column methods
this.current_column = function() {
return this.current.parent().parent();
};
this.current_column_index = function() {
console.log('CURRENTCOLUMNINDEX');
console.log(this.current_column().index());
return this.current_column().index();
};
this.column_has_stories = function(column_index) {
var that = this;
var query = function(index) {
return (that.$column_el.eq(index).find(that.el).length > 0) ? true : false;
};
if (column_index) {
return query(column_index);
}
else {
return query(this.current_column_index());
}
};
this.sibling_column = function(column_index, offset) {
// Don't let people move outside the edge columns
var new_column_index = column_index + offset;
if (new_column_index >= this.total_columns
|| new_column_index < 0) {
return this.current_column();
}
return this.$column_el.eq(column_index + offset);
};
this.next_column = function() {
return this.sibling_column(this.current_column_index(), 1);
};
this.previous_column = function() {
return this.sibling_column(this.current_column_index(), -1);
};
// Edit story
this.wait_for_edit_modal_to_load = function(func) {
return setTimeout(func, 500);
};
this.open_edit_modal = function() {
this.current.find('.storyIcons').children('a').eq(1).trigger('click');
};
this.close_edit_modal = function() {
$('.overlay_close').trigger('click');
};
this.edit = function() {
if (this.current) {
this.open_edit_modal();
this.wait_for_edit_modal_to_load(function() {
$('textarea#id_summary').focus();
});
}
};
// Go to assignees
this.assign = function() {
if (this.current) {
this.open_edit_modal();
this.wait_for_edit_modal_to_load(function() {
$('.tag_holder').eq(1).children('ul').children('.tagit-new').children('input').focus();
});
}
};
// Point story
// Can't use left and right arrows to change points so doesn't work
this.point = function() {
if (this.current) {
this.open_edit_modal();
this.wait_for_edit_modal_to_load(function() {
$('#points_section').find('input[name="points"]:checked').focus();
});
}
};
// Toggle tasks section
this.tasks = function() {
if (this.current) {
this.current.find('.show_tasks_link').trigger('click');
// Focus task summary field
that = this;
setTimeout(function() {
that.current.find('.tasks_area input[name="summary"]').focus();
}, 500);
}
};
// Open project drop-down
this.enable_project_panel_tabbing = function() {
$('.project-menu-iteration-list-item').attr('tabindex', '0');
$('.project-menu-iteration-list-item').eq(1).focus()
// Enter redirects that iteration
$('.project-menu-iteration-list-item').on('keydown', function(e) {
var key = (e.which || e.keyCode);
if (key === KeyCodes.enter) {
window.location.href = $(this).children('a').attr('href');
}
});
};
this.disable_project_panel_tabbing = function() {
$('.project-menu-iteration-list-item').removeAttr('tabindex');
$('.project-menu-iteration-list-item').off('keydown')
};
this.toggle_project_panel = function() {
if (!this.project_panel_open) {
$('.project-dropdown-menu').parent().trigger('click');
this.project_panel_open = true;
this.enable_project_panel_tabbing();
}
else {
this.disable_project_panel_tabbing();
$('body').trigger('click')
this.project_panel_open = false;
}
};
return this;
};
Story = new StoryClass();
});
var KeyCodes = {
arrows: {
left: 37,
right: 39,
up: 38,
down: 40
},
numbers: {
0: 48,
1: 49,
2: 50,
3: 51,
4: 52,
5: 53,
6: 54,
7: 55,
8: 56,
9: 57
},
a: 65,
b: 66,
i: 73,
l: 76,
p: 80,
t: 84,
enter: 13,
esc: 27
};
// Set the current story
$(function() {
var $story_el = $('.scrum_board_story_block');
// Mouseover
$story_el.on('mouseenter', function() {
Story.set_current($(this));
})
.on('mouseleave', function() {
Story.unset_current();
});
// Arrow keys
$(document).on('keydown', function(e) {
var key = (e.which || e.keyCode);
// Collect arrow key codes into an array
var arrow_keycodes = [];
for (var k in KeyCodes.arrows) {
arrow_keycodes.push(KeyCodes.arrows[k])
}
// Prevent key behavior of arrow keys
if (arrow_keycodes.indexOf(key) !== -1) {
e.preventDefault();
}
switch (key) {
case KeyCodes.arrows.left:
Story.move({ direction: 'left'});
break;
case KeyCodes.arrows.right:
Story.move({ direction: 'right' });
break;
case KeyCodes.arrows.up:
Story.move({ direction: 'up' });
break;
case KeyCodes.arrows.down:
Story.move({ direction: 'down' });
break;
}
});
});
// Story actions - keyboard shortcuts
$(function() {
// Disable keyboard shortcuts when an input element is focused
$('input[type="text"], textarea').on('focus', function() {
// Disable
disable_keyboard_shortcuts();
}).on('blur', function() {
// Enable
enable_keyboard_shortcuts();
});
var bind_keyboard_commands = function(e) {
var key = (e.which || e.keyCode);
// console.log(e);
var responds_to = [];
// for (var k in KeyCodes){}
switch (key) {
case KeyCodes.i:
Story.edit();
break;
case KeyCodes.a:
Story.assign();
break;
case KeyCodes.p:
Story.point();
break;
case KeyCodes.t:
Story.tasks();
break;
case KeyCodes.b:
Story.toggle_project_panel();
break;
case KeyCodes.esc:
Story.close_edit_modal();
break;
case KeyCodes.l:
if (e.shiftKey) {
Story.list_view();
}
break;
}
};
var disable_keyboard_shortcuts = function() {
console.log('DISABLED');
$(document).off('keydown', bind_keyboard_commands);
};
var enable_keyboard_shortcuts = function() {
console.log('ENABLED');
$(document).on('keydown', bind_keyboard_commands);
};
enable_keyboard_shortcuts();
});
|