BR.Util = { get(url, cb) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.onload = function () { if ((xhr.status === 200 || xhr.status === 0) && xhr.responseText) { cb(null, xhr.responseText); } else { cb(BR.Util.getError(xhr)); } }; xhr.onerror = function () { cb(BR.Util.getError(xhr)); }; try { xhr.send(); } catch (e) { cb(e); } }, getError(xhr) { var msg = i18next.t('warning.no-response'); if (xhr.responseText) { msg = xhr.responseText; } else if (xhr.status || xhr.statusText) { msg = xhr.status + ': ' + xhr.statusText; } return new Error(msg); }, getJson(url, context, cb) { BR.Util.get(url, function (err, data) { if (err) { BR.message.showError('Error getting ' + context + ': ' + err); return cb(err); } try { var json = JSON.parse(data); cb(null, json); } catch (err) { BR.message.showError('Error parsing ' + context + ': ' + err); console.error(err); cb(err); } }); }, getGeoJson(url, context, cb) { BR.Util.getJson(url, context, function (err, data) { if (err) return cb(err); var geoJson = data; if (data && data.type && data.type === 'Topology') { var key = Object.keys(data.objects)[0]; geoJson = topojson.feature(data, data.objects[key]); } cb(null, geoJson); }); }, // check if localStorage is available, especially for catching SecurityError // when cookie settings are blocking access (Chrome, Pale Moon, older Firefox) // // see also https://github.com/Modernizr/Modernizr/blob/master/feature-detects/storage/localstorage.js // // https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#Testing_for_support_vs_availability // by Mozilla Contributors, with modifications; // Any copyright is dedicated to the Public Domain. https://creativecommons.org/publicdomain/zero/1.0/ localStorageAvailable() { try { var storage = window.localStorage, x = '__storage_test__'; storage.setItem(x, x); storage.removeItem(x); return true; } catch (e) { return false; } }, // see https://stackoverflow.com/a/37141090/1906123 getResponsiveBreakpoint() { var envs = { '1xs': 'd-none', '2sm': 'd-sm-none', '3md': 'd-md-none', '4lg': 'd-lg-none', '5xl': 'd-xl-none' }; var env = ''; var $el = $('