diff options
author | Kristian Lyngstol <kristian@bohemians.org> | 2016-05-25 21:27:37 +0200 |
---|---|---|
committer | Kristian Lyngstol <kristian@bohemians.org> | 2016-05-25 21:27:37 +0200 |
commit | 78e32778d51f9aa8c98e48e472b6b5a31031a7b7 (patch) | |
tree | 61bbf2946e5a1ffa74cdc9a4c01c24c3636e4dff /web | |
parent | 4a7a96996f2366c0b598ede597b6ebaddde1188e (diff) |
front: Remove nms.views and improve #anchor logic
Fixes #82
nms.views is gone, and if the anchor (http://.../#anchor) is a
comma-separated list, "tvmode" will be used.
Also ensures that the anchor already contains the updater tag, it wont be
changed. This means that for tvmode the anchor wont change constantly.
Diffstat (limited to 'web')
-rw-r--r-- | web/js/nms.js | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/web/js/nms.js b/web/js/nms.js index c617c77..d4c3488 100644 --- a/web/js/nms.js +++ b/web/js/nms.js @@ -54,7 +54,6 @@ var nms = { }, interval: 10, - views: "ping", /* * This is a list of nms[x] variables that we store in our * settings-cookie when altered and restore on load. @@ -63,7 +62,6 @@ var nms = { 'nightMode', 'menuShowing', 'vertical', - 'views', 'interval' ], keyBindings:{ @@ -397,21 +395,32 @@ nms.tvmode.tick = function() { if(nms.tvmode.currentIndex > nms.tvmode.handlers.length - 1) { nms.tvmode.currentIndex = 0; } - setUpdater(nms.tvmode.handlers[nms.tvmode.currentIndex]); + setUpdater(nms.tvmode.handlers[nms.tvmode.currentIndex],false); nms.tvmode.currentIndex++; } nms.tvmode.stop = function() { nms.timers.tvmode.stop(); - document.body.classList.remove("tvmode"); - document.body.classList.remove("vertical"); nms.tvmode.active = false; } +function ensureAnchorHas(view) { + try { + var views = document.location.hash.slice(1); + views = views.split(","); + if (views.includes(view)) { + return true; + } + } catch(e) { } + document.location.hash = view; + return false; +} /* * Change map handler (e.g., change from uplink map to ping map) */ -function setUpdater(fo) +function setUpdater(fo, stopTv = true) { + if (stopTv) + nms.tvmode.stop(); nmsMap.reset(); nmsData.unregisterHandlerWildcard("mapHandler"); try { @@ -427,7 +436,7 @@ function setUpdater(fo) } var foo = document.getElementById("map-mode-title"); foo.innerHTML = fo.name; - document.location.hash = fo.tag; + ensureAnchorHas(fo.tag); } function toggleLayer(layer) { @@ -567,24 +576,20 @@ function initNMS() { } function detectHandler() { - var views = nms.views; + var views = document.location.hash.slice(1); var interval = nms.interval; + if (views == undefined || views == "") + views = "ping"; views = views.split(","); if (views.length > 1) { nms.tvmode.start(views,interval); + return; } else { - var anchorviews = document.location.hash.slice(1); - views = anchorviews.split(","); - if (views.length > 1) { - nms.tvmode.start(views,interval); - return; - } else { - for (var i in handlers) { - if (('#' + handlers[i].tag) == anchorviews) { - setUpdater(handlers[i]); - return; - } + for (var i in handlers) { + if (handlers[i].tag == views[0]) { + setUpdater(handlers[i]); + return; } } } |