From 9c596531e281128c5c5fbb1e41837a6217ce768b Mon Sep 17 00:00:00 2001 From: Xaver Maierhofer Date: Fri, 3 Aug 2018 20:08:08 +0200 Subject: [PATCH] [TASK] Optimize code --- lib/datadistributor.js | 3 +-- lib/map.js | 28 ++++++++++++---------------- lib/utils/language.js | 2 +- lib/utils/version.js | 5 +---- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/lib/datadistributor.js b/lib/datadistributor.js index ea0bf75..385f65a 100644 --- a/lib/datadistributor.js +++ b/lib/datadistributor.js @@ -97,8 +97,7 @@ define(['filters/nodefilter'], function (NodeFilter) { setData: setData, addFilter: addFilter, removeFilter: removeFilter, - watchFilters: watchFilters, - refresh: refresh + watchFilters: watchFilters }; }; }); diff --git a/lib/map.js b/lib/map.js index f0698ea..c00669e 100644 --- a/lib/map.js +++ b/lib/map.js @@ -27,29 +27,25 @@ define(['map/clientlayer', 'map/labellayer', 'map/button', 'leaflet', 'map/activ document.querySelector('.leaflet-control-layers').classList.add('leaflet-control-layers-expanded'); } + function mapActiveArea() { + map.setActiveArea({ + position: 'absolute', + left: sidebar.getWidth() + 'px', + right: 0, + top: 0, + bottom: 0 + }); + } + function setActiveArea() { - setTimeout(function () { - map.setActiveArea({ - position: 'absolute', - left: sidebar.getWidth() + 'px', - right: 0, - top: 0, - bottom: 0 - }); - }, 300); + setTimeout(mapActiveArea, 300); } var el = document.createElement('div'); el.classList.add('map'); map = L.map(el, options); - map.setActiveArea({ - position: 'absolute', - left: sidebar.getWidth() + 'px', - right: 0, - top: 0, - bottom: 0 - }); + mapActiveArea(); var now = new Date(); config.mapLayers.forEach(function (item, i) { diff --git a/lib/utils/language.js b/lib/utils/language.js index b9e88a6..3e72b1a 100644 --- a/lib/utils/language.js +++ b/lib/utils/language.js @@ -22,7 +22,7 @@ define(['polyglot', 'moment', 'helper'], function (Polyglot, moment, helper) { } function getLocale(input) { - var language = input || navigator.languages && navigator.languages[0] || navigator.language || navigator.userLanguage; + var language = input || navigator.languages && navigator.languages[0] || navigator.language; var locale = config.supportedLocale[0]; config.supportedLocale.some(function (item) { if (language.indexOf(item) !== -1) { diff --git a/lib/utils/version.js b/lib/utils/version.js index 6a8cf86..32fe792 100644 --- a/lib/utils/version.js +++ b/lib/utils/version.js @@ -50,10 +50,7 @@ define(function () { var ca = a.split(''); var cb = b.split(''); var diff = this.findIndex(ca, function (c, index) { - if (cb[index] && c === cb[index]) { - return false; - } - return true; + return !(cb[index] && c === cb[index]); }); if (diff === -1) { if (cb.length > ca.length) {