diff --git a/src/main/resources/eu/simstadt/regionchooser/website/script/utils.js b/src/main/resources/eu/simstadt/regionchooser/website/script/utils.js index 6d6702b0c5f5f41eb39511e87266791ae261c6a7..2a4fa6692d7b8496f56d68979430fa49d1f70e11 100644 --- a/src/main/resources/eu/simstadt/regionchooser/website/script/utils.js +++ b/src/main/resources/eu/simstadt/regionchooser/website/script/utils.js @@ -1,64 +1,64 @@ -var utils = { - groupBy : function(xs, key) { - return xs.reduce(function(rv, x) { - (rv[x[key]] = rv[x[key]] || []).push(x); - return rv; - }, {}); - }, +var utils = {}; + +utils.groupBy = function(xs, key) { + return xs.reduce(function(rv, x) { + (rv[x[key]] = rv[x[key]] || []).push(x); + return rv; + }, {}); +} - // Copies a string to the clipboard. Must be called from within an - // event handler such as click. May return false if it failed, but - // this is not always possible. Browser support for Chrome 43+, - // Firefox 42+, Safari 10+, Edge and Internet Explorer 10+. - // Internet Explorer: The clipboard feature may be disabled by - // an administrator. By default a prompt is shown the first - // time the clipboard is used (per session). - // https://stackoverflow.com/a/33928558/6419007 - copyToClipboard : function(text, log) { - if (window.clipboardData && window.clipboardData.setData) { - // Internet Explorer-specific code path to prevent textarea being shown while dialog is visible. - return window.clipboardData.setData("Text", text); +// Copies a string to the clipboard. Must be called from within an +// event handler such as click. May return false if it failed, but +// this is not always possible. Browser support for Chrome 43+, +// Firefox 42+, Safari 10+, Edge and Internet Explorer 10+. +// Internet Explorer: The clipboard feature may be disabled by +// an administrator. By default a prompt is shown the first +// time the clipboard is used (per session). +// https://stackoverflow.com/a/33928558/6419007 +utils.copyToClipboard = function(text, log) { + if (window.clipboardData && window.clipboardData.setData) { + // Internet Explorer-specific code path to prevent textarea being shown while dialog is visible. + return window.clipboardData.setData("Text", text); + } + else if (document.queryCommandSupported && document.queryCommandSupported("copy")) { + var textarea = document.createElement("textarea"); + textarea.textContent = text; + textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in Microsoft Edge. + document.body.appendChild(textarea); + textarea.select(); + try { + document.execCommand("copy"); // Security exception may be thrown by some browsers. + log.append("<h2 class='ok'>Coordinates copied to clipboard!</h2><br/>\n"); + return; + } + catch (ex) { + console.warn("Copy to clipboard failed.", ex); + return prompt("Copy to clipboard: Ctrl+C, Enter", text); } - else if (document.queryCommandSupported && document.queryCommandSupported("copy")) { - var textarea = document.createElement("textarea"); - textarea.textContent = text; - textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in Microsoft Edge. - document.body.appendChild(textarea); - textarea.select(); - try { - document.execCommand("copy"); // Security exception may be thrown by some browsers. - log.append("<h2 class='ok'>Coordinates copied to clipboard!</h2><br/>\n"); - return; - } - catch (ex) { - console.warn("Copy to clipboard failed.", ex); - return prompt("Copy to clipboard: Ctrl+C, Enter", text); - } - finally { - document.body.removeChild(textarea); - } + finally { + document.body.removeChild(textarea); } - }, + } +} - read_kml: function(url){ - return new ol.source.KML({ - projection : ol.proj.get('EPSG:3857'), - url : url, - extractAttributes : false, - extractStyles : false - }); - }, +utils.read_kml = function(url){ + return new ol.source.KML({ + projection : ol.proj.get('EPSG:3857'), + url : url, + extractAttributes : false, + extractStyles : false + }); +} - polygon_style: function(color, alpha) { - return new ol.style.Style({ - fill : new ol.style.Fill({ - color : 'rgba(255, 255, 255,' + alpha + ')' - }), - stroke : new ol.style.Stroke({ - color : color, - width : 2, - lineDash : [ 5, 10 ] - }), - }); - } -}; \ No newline at end of file +utils.polygon_style = function(color, alpha) { + return new ol.style.Style({ + fill : new ol.style.Fill({ + color : 'rgba(255, 255, 255,' + alpha + ')' + }), + stroke : new ol.style.Stroke({ + color : color, + width : 2, + lineDash : [ 5, 10 ] + }), + }); +}