From 2ed14a26ff08d5e7a619d9f046d9bfc133ffd39b Mon Sep 17 00:00:00 2001 From: Jacek Kowalski <Jacek@jacekk.info> Date: Sun, 14 May 2017 20:39:13 +0000 Subject: [PATCH] Refactor alert pane --- map.js | 38 ++++++++++++++++++++++++-------------- 1 files changed, 24 insertions(+), 14 deletions(-) diff --git a/map.js b/map.js index 2e3614d..b462d46 100644 --- a/map.js +++ b/map.js @@ -23,7 +23,6 @@ var map = null; var map_sphere = null; -var fail_element = document.getElementById('fail'); var ignore_hashchange = false; @@ -63,10 +62,25 @@ }, }; -function fail(msg) { - setText(fail_element, msg); - fail_element.style.top = '0.5em'; -} +var Alert = { + element: document.getElementById('fail'), + action: undefined, + + fail: function(message, action) { + if(this.action) { + this.element.removeEventListener('click', this.action); + this.action = undefined; + } + + setText(this.element, message); + this.element.style.top = '0.5em'; + + if(action) { + this.action = action; + this.element.addEventListener('click', action); + } + }, +}; function fail_ajax_generic(data, fnc) { // abort() is not a failure @@ -82,11 +96,11 @@ } function fail_ajax(data) { - fail_ajax_generic(data, fail); + fail_ajax_generic(data, Alert.fail.bind(Alert)); } function fail_ajax_popup(data) { - fail_ajax_generic(data, Panel.fail); + fail_ajax_generic(data, Panel.fail.bind(Panel)); } function getGeometry(object) { @@ -588,7 +602,7 @@ function init() { if(!window.jQuery) { - fail(lang.jquery_not_loaded); + Alert.fail(lang.jquery_not_loaded); return; } @@ -653,7 +667,7 @@ element: document.getElementById('title'), }), new ol.control.Control({ - element: fail_element, + element: Alert.element, }) ]), loadTilesWhileAnimating: true, @@ -725,10 +739,6 @@ featureClicked(feature); }); - - fail_element.addEventListener('click', function() { - fail_element.style.top = '-10em'; - }); // Change mouse cursor when over marker map.on('pointermove', function(e) { @@ -756,7 +766,7 @@ if(vehicles_xhr) vehicles_xhr.abort(); if(vehicles_timer) clearTimeout(vehicles_timer); - fail(lang.error_refresh); + Alert.fail(lang.error_refresh); }, 1800000); } -- Gitblit v1.9.1