From 938329fd84dc1b1b63bb55782fb3bb38a19ca7f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20P=C3=A4ssler?= Date: Thu, 25 Feb 2016 21:03:33 +0100 Subject: [PATCH] infobox/location: show uci in one box --- lib/infobox/location.js | 74 +++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/lib/infobox/location.js b/lib/infobox/location.js index 216a6e5..1080f44 100644 --- a/lib/infobox/location.js +++ b/lib/infobox/location.js @@ -9,42 +9,48 @@ define(function () { h2.textContent = result.display_name }) + var latDiv = document.createElement("div") var h3lat = document.createElement("h3") h3lat.textContent = "Breitengrad" - el.appendChild(h3lat) + h3lat.id = "h3-latitude" + latDiv.appendChild(h3lat) var txt1 = document.createElement("textarea") txt1.id = "location-latitude" txt1.value = d.lat.toFixed(9) var p = document.createElement("p") p.appendChild(txt1) p.appendChild(createCopyButton(txt1.id)) - el.appendChild(p) + latDiv.appendChild(p) + el.appendChild(latDiv) + var longDiv = document.createElement("div") var h3lng = document.createElement("h3") h3lng.textContent = "Längengrad" - el.appendChild(h3lng) + longDiv.appendChild(h3lng) var txt2 = document.createElement("textarea") txt2.id = "location-longitude" txt2.value = d.lng.toFixed(9) var p2 = document.createElement("p") p2.appendChild(txt2) p2.appendChild(createCopyButton(txt2.id)) - el.appendChild(p2) + longDiv.appendChild(p2) + longDiv.id = "div-longitude" + el.appendChild(longDiv) var a1 = document.createElement("a") a1.textContent = "plain" a1.onclick = function() { - switch2plain() - return false + switch2plain() + return false } a1.href = config.siteURL var a2 = document.createElement("a") a2.textContent = "uci" a2.onclick = function() { - switch2uci() - return false + switch2uci() + return false } - a2.href = config.siteURL + a2.href = "#" var p3 = document.createElement("p") p3.textContent = "Du kannst zwischen " @@ -57,36 +63,38 @@ define(function () { el.appendChild(p3) function createCopyButton(id) { - var btn = document.createElement("button") - btn.className = "ion-ios-copy" - btn.title = "Kopiere" - btn.onclick = function() { - copy2clip(id) - } - return btn + var btn = document.createElement("button") + btn.className = "ion-ios-copy" + btn.title = "Kopieren" + btn.onclick = function() { + copy2clip(id) + } + return btn } + function copy2clip(id) { - var copyTextarea = document.querySelector("#" + id) - copyTextarea.select() - try { - var successful = document.execCommand("copy") - var msg = successful ? "successful" : "unsuccessful" - console.log("Copying text command was " + msg) - } catch (err) { - console.log("Oops, unable to copy") - } + var copyTextarea = document.querySelector("#" + id) + copyTextarea.select() + try { + document.execCommand("copy") + } catch (err) { + console.log(err) + } } + function switch2plain() { - var box1 = document.getElementById("location-latitude") - box1.value = d.lat.toFixed(9) - var box2 = document.getElementById("location-longitude") - box2.value = d.lng.toFixed(9) + var box1 = document.getElementById("location-latitude") + box1.value = d.lat.toFixed(9) + var box2 = document.getElementById("location-longitude") + box2.value = d.lng.toFixed(9) + document.getElementById("h3-latitude").textContent = "Breitengrad" + document.getElementById("div-longitude").style.display = "block" } + function switch2uci() { - var box1 = document.getElementById("location-latitude") - box1.value = "uci set gluon-node-info.@location[0].latitude='" + d.lat.toFixed(9) + "'" - var box2 = document.getElementById("location-longitude") - box2.value = "uci set gluon-node-info.@location[0].longitude='" + d.lng.toFixed(9) + "'" + document.getElementById("location-latitude").value = "uci set gluon-node-info.@location[0].latitude='" + d.lat.toFixed(9) + "'; uci set gluon-node-info.@location[0].longitude='" + d.lng.toFixed(9) + "'" + document.getElementById("h3-latitude").textContent = "Befehl" + document.getElementById("div-longitude").style.display = "none" } } })