Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Move init to top of file #761

Benjamin King0d13b4e15d8e
diff --git a/web/js/date/timeline-input.js b/web/js/date/timeline-input.js
index 78fa43ffb..0704fff86 100644
--- a/web/js/date/timeline-input.js
+++ b/web/js/date/timeline-input.js
@@ -23,6 +23,226 @@ export function timelineInput(models, config, ui) {
var $incrementBtn = $('#right-arrow-group');
var $decrementBtn = $('#left-arrow-group');
+
+ var init = function () {
+ $incrementBtn
+ .mousedown(function (e) {
+ e.preventDefault();
+ switch (ui.timeline.config.currentZoom) {
+ case 1:
+ animateByIncrement(1, 'year');
+ break;
+ case 2:
+ animateByIncrement(1, 'month');
+ break;
+ case 3:
+ animateByIncrement(1, 'day');
+ break;
+ case 4:
+ animateByIncrement(10, 'minute');
+ break;
+ default:
+ animateByIncrement(1, 'day');
+ }
+ })
+ .mouseup(stopper);
+
+ $decrementBtn
+ .mousedown(function (e) {
+ e.preventDefault();
+ switch (ui.timeline.config.currentZoom) {
+ case 1:
+ animateByIncrement(-1, 'year');
+ break;
+ case 2:
+ animateByIncrement(-1, 'month');
+ break;
+ case 3:
+ animateByIncrement(-1, 'day');
+ break;
+ case 4:
+ animateByIncrement(-10, 'minute');
+ break;
+ default:
+ animateByIncrement(-1, 'day');
+ }
+ })
+ .mouseup(stopper);
+
+ $(document)
+ .mouseout(stopper)
+ .keydown(function (event) {
+ if (event.target.nodeName === 'INPUT' || keyDown === event.keyCode) return;
+ switch (event.keyCode) {
+ case util.key.LEFT:
+ if (models.date.selectedZoom === 4) {
+ animateByIncrement(-1, 'hour');
+ } else {
+ animateByIncrement(-1, 'day');
+ }
+ event.preventDefault();
+ break;
+ case util.key.RIGHT:
+ if (models.date.selectedZoom === 4) {
+ animateByIncrement(1, 'hour');
+ } else {
+ animateByIncrement(1, 'day');
+ }
+ event.preventDefault();
+ break;
+ }
+ keyDown = event.keyCode;
+ })
+ .keyup(function (event) {
+ switch (event.keyCode) {
+ case util.key.LEFT:
+ case util.key.RIGHT:
+ stopper();
+ event.preventDefault();
+ break;
+ }
+ keyDown = null;
+ });
+ // bind click action to interval radio buttons
+ var $buttons = $('.button-input-group');
+ var $oneIntervalButtons = $('.1-interval-group');
+ var $tenIntervalButtons = $('.10-interval-group');
+ $buttons.unbind();
+ $oneIntervalButtons.unbind();
+ $tenIntervalButtons.unbind();
+
+ // FIXME: Quick fix for fixing the propagation
+ // of events with arrow keys and input field
+ $oneIntervalButtons.keydown(function (event) {
+ var interval = $(this)
+ .attr('id')
+ .split('-')[0];
+ event.stopPropagation();
+ if (event.keyCode === (util.key.LEFT || util.key.RIGHT)) {
+ event.preventDefault();
+ $(this)
+ .select()
+ .focus();
+ } else if (event.keyCode === (util.key.UP)) {
+ event.preventDefault();
+ roll(interval, 1);
+ $(this)
+ .select()
+ .focus();
+ } else if (event.keyCode === (util.key.DOWN)) {
+ event.preventDefault();
+ roll(interval, -1);
+ $(this)
+ .select()
+ .focus();
+ }
+ });
+
+ // FIXME: Quick fix for fixing the propagation
+ // of events with arrow keys and input field
+ $tenIntervalButtons.keydown(function (event) {
+ var interval = $(this)
+ .attr('id')
+ .split('-')[0];
+ event.stopPropagation();
+ if (event.keyCode === (util.key.LEFT || util.key.RIGHT)) {
+ event.preventDefault();
+ $(this)
+ .select()
+ .focus();
+ } else if (event.keyCode === (util.key.UP)) {
+ event.preventDefault();
+ roll(interval, 10);
+ $(this)
+ .select()
+ .focus();
+ } else if (event.keyCode === (util.key.DOWN)) {
+ event.preventDefault();
+ roll(interval, -10);
+ $(this)
+ .select()
+ .focus();
+ }
+ });
+
+ $buttons.on('focus', function (e) {
+ e.preventDefault();
+ $buttons.siblings('.date-arrows')
+ .css('visibility', '');
+ $buttons.parent()
+ .removeClass('selected');
+ $(this)
+ .parent()
+ .addClass('selected');
+ $(this)
+ .siblings('.date-arrows')
+ .css('visibility', 'visible');
+ });
+
+ $buttons.focusout(function (e) {
+ $buttons.siblings('.date-arrows')
+ .css('visibility', '');
+ $buttons.parent()
+ .removeClass('selected');
+ });
+
+ var $incrementIntDate = $('.date-arrow-up');
+ $incrementIntDate.click(roll);
+ $incrementIntDate.mousedown(function (e) {
+ e.preventDefault();
+ });
+
+ var $decrementIntDate = $('.date-arrow-down');
+ $decrementIntDate.click(roll);
+ $decrementIntDate.mousedown(function (e) {
+ e.preventDefault();
+ });
+
+ // select all input on focus
+ $('input')
+ .focus(function (e) {
+ $(this)
+ .select();
+ })
+ .mouseup(function (e) {
+ e.preventDefault();
+ });
+
+ $('.button-input-group')
+ .keydown(validateInput)
+ .focusout(function (event) {
+ if ($(this)
+ .hasClass('focus')) {
+ $(this)
+ .removeClass('focus');
+ validateInput.call(this, event);
+ }
+ })
+ .focus(function () {
+ $(this)
+ .addClass('focus');
+ });
+
+ $('#focus-guard-1')
+ .on('focus', function () {
+ $('#minute-input-group')
+ .focus()
+ .select();
+ });
+ $('#focus-guard-2')
+ .on('focus', function () {
+ $('#year-input-group')
+ .focus()
+ .select();
+ });
+
+ if (util.browser.tests.touchDevice()) {
+ $('.button-input-group')
+ .prop('disabled', true);
+ }
+
+ self.update();
+ };
/**
* Add timeout to date change when buttons are being held so that
* date changes don't happen too quickly
@@ -304,226 +524,6 @@ export function timelineInput(models, config, ui) {
tl.pick.update();
};
- var init = function () {
- $incrementBtn
- .mousedown(function (e) {
- e.preventDefault();
- switch (ui.timeline.config.currentZoom) {
- case 1:
- animateByIncrement(1, 'year');
- break;
- case 2:
- animateByIncrement(1, 'month');
- break;
- case 3:
- animateByIncrement(1, 'day');
- break;
- case 4:
- animateByIncrement(10, 'minute');
- break;
- default:
- animateByIncrement(1, 'day');
- }
- })
- .mouseup(stopper);
-
- $decrementBtn
- .mousedown(function (e) {
- e.preventDefault();
- switch (ui.timeline.config.currentZoom) {
- case 1:
- animateByIncrement(-1, 'year');
- break;
- case 2:
- animateByIncrement(-1, 'month');
- break;
- case 3:
- animateByIncrement(-1, 'day');
- break;
- case 4:
- animateByIncrement(-10, 'minute');
- break;
- default:
- animateByIncrement(-1, 'day');
- }
- })
- .mouseup(stopper);
-
- $(document)
- .mouseout(stopper)
- .keydown(function (event) {
- if (event.target.nodeName === 'INPUT' || keyDown === event.keyCode) return;
- switch (event.keyCode) {
- case util.key.LEFT:
- if (models.date.selectedZoom === 4) {
- animateByIncrement(-1, 'hour');
- } else {
- animateByIncrement(-1, 'day');
- }
- event.preventDefault();
- break;
- case util.key.RIGHT:
- if (models.date.selectedZoom === 4) {
- animateByIncrement(1, 'hour');
- } else {
- animateByIncrement(1, 'day');
- }
- event.preventDefault();
- break;
- }
- keyDown = event.keyCode;
- })
- .keyup(function (event) {
- switch (event.keyCode) {
- case util.key.LEFT:
- case util.key.RIGHT:
- stopper();
- event.preventDefault();
- break;
- }
- keyDown = null;
- });
- // bind click action to interval radio buttons
- var $buttons = $('.button-input-group');
- var $oneIntervalButtons = $('.1-interval-group');
- var $tenIntervalButtons = $('.10-interval-group');
- $buttons.unbind();
- $oneIntervalButtons.unbind();
- $tenIntervalButtons.unbind();
-
- // FIXME: Quick fix for fixing the propagation
- // of events with arrow keys and input field
- $oneIntervalButtons.keydown(function (event) {
- var interval = $(this)
- .attr('id')
- .split('-')[0];
- event.stopPropagation();
- if (event.keyCode === (util.key.LEFT || util.key.RIGHT)) {
- event.preventDefault();
- $(this)
- .select()
- .focus();
- } else if (event.keyCode === (util.key.UP)) {
- event.preventDefault();
- roll(interval, 1);
- $(this)
- .select()
- .focus();
- } else if (event.keyCode === (util.key.DOWN)) {
- event.preventDefault();
- roll(interval, -1);
- $(this)
- .select()
- .focus();
- }
- });
-
- // FIXME: Quick fix for fixing the propagation
- // of events with arrow keys and input field
- $tenIntervalButtons.keydown(function (event) {
- var interval = $(this)
- .attr('id')
- .split('-')[0];
- event.stopPropagation();
- if (event.keyCode === (util.key.LEFT || util.key.RIGHT)) {
- event.preventDefault();
- $(this)
- .select()
- .focus();
- } else if (event.keyCode === (util.key.UP)) {
- event.preventDefault();
- roll(interval, 10);
- $(this)
- .select()
- .focus();
- } else if (event.keyCode === (util.key.DOWN)) {
- event.preventDefault();
- roll(interval, -10);
- $(this)
- .select()
- .focus();
- }
- });
-
- $buttons.on('focus', function (e) {
- e.preventDefault();
- $buttons.siblings('.date-arrows')
- .css('visibility', '');
- $buttons.parent()
- .removeClass('selected');
- $(this)
- .parent()
- .addClass('selected');
- $(this)
- .siblings('.date-arrows')
- .css('visibility', 'visible');
- });
-
- $buttons.focusout(function (e) {
- $buttons.siblings('.date-arrows')
- .css('visibility', '');
- $buttons.parent()
- .removeClass('selected');
- });
-
- var $incrementIntDate = $('.date-arrow-up');
- $incrementIntDate.click(roll);
- $incrementIntDate.mousedown(function (e) {
- e.preventDefault();
- });
-
- var $decrementIntDate = $('.date-arrow-down');
- $decrementIntDate.click(roll);
- $decrementIntDate.mousedown(function (e) {
- e.preventDefault();
- });
-
- // select all input on focus
- $('input')
- .focus(function (e) {
- $(this)
- .select();
- })
- .mouseup(function (e) {
- e.preventDefault();
- });
-
- $('.button-input-group')
- .keydown(validateInput)
- .focusout(function (event) {
- if ($(this)
- .hasClass('focus')) {
- $(this)
- .removeClass('focus');
- validateInput.call(this, event);
- }
- })
- .focus(function () {
- $(this)
- .addClass('focus');
- });
-
- $('#focus-guard-1')
- .on('focus', function () {
- $('#minute-input-group')
- .focus()
- .select();
- });
- $('#focus-guard-2')
- .on('focus', function () {
- $('#year-input-group')
- .focus()
- .select();
- });
-
- if (util.browser.tests.touchDevice()) {
- $('.button-input-group')
- .prop('disabled', true);
- }
-
- self.update();
- };
-
init();
return self;
};