Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

remove jquery and use native JS instead

Jason Kent3e33550e318c
diff --git a/.eslintrc b/.eslintrc
index ee9d8ecb5..773a9d932 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -2,8 +2,7 @@
"env": {
"browser": true,
"node": true,
- "jest/globals": true,
- "jquery": true
+ "jest/globals": true
},
"parserOptions": {
"ecmaVersion": 2019,
diff --git a/package-lock.json b/package-lock.json
index e947d797a..faf1579d2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -14819,19 +14819,9 @@
}
},
"jquery": {
- "version": "3.5.0",
- "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.5.0.tgz",
- "integrity": "sha512-Xb7SVYMvygPxbFMpTFQiHh1J7HClEaThguL15N/Gg37Lri/qKyhRGZYzHRyLH8Stq3Aow0LsHO2O2ci86fCrNQ=="
- },
- "jquery-ui-bundle": {
- "version": "1.12.1-migrate",
- "resolved": "https://registry.npmjs.org/jquery-ui-bundle/-/jquery-ui-bundle-1.12.1-migrate.tgz",
- "integrity": "sha1-uTQ+LDEHQ1J2Ms/4vtsMXpYAsUw="
- },
- "jquery-ui-touch-punch": {
- "version": "0.2.3",
- "resolved": "https://registry.npmjs.org/jquery-ui-touch-punch/-/jquery-ui-touch-punch-0.2.3.tgz",
- "integrity": "sha1-7tgiQnM7okP0az6HwYQbMIGR2mg="
+ "version": "3.5.1",
+ "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.5.1.tgz",
+ "integrity": "sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg=="
},
"js-base64": {
"version": "2.5.1",
@@ -21642,12 +21632,6 @@
}
}
},
- "serialize-javascript": {
- "version": "1.9.1",
- "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-1.9.1.tgz",
- "integrity": "sha512-0Vb/54WJ6k5v8sSWN09S0ora+Hnr+cX40r9F170nT+mSkaxltoE/7R3OrIdBSUv1OoiobH1QoWQbCnAO+e8J1A==",
- "dev": true
- },
"serve-index": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/serve-index/-/serve-index-1.9.1.tgz",
@@ -24656,51 +24640,6 @@
"resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.20.tgz",
"integrity": "sha512-8OaIKfzL5cpx8eCMAhhvTlft8GYF8b2eQr6JkCyVdrgjcytyOmPCXrqXFcUnhonRpLlh5yxEZVohm6mzaowUOw=="
},
- "uglify-js": {
- "version": "3.9.1",
- "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.9.1.tgz",
- "integrity": "sha512-JUPoL1jHsc9fOjVFHdQIhqEEJsQvfKDjlubcCilu8U26uZ73qOg8VsN8O1jbuei44ZPlwL7kmbAdM4tzaUvqnA==",
- "dev": true,
- "requires": {
- "commander": "~2.20.3"
- }
- },
- "uglifyjs-webpack-plugin": {
- "version": "2.2.0",
- "resolved": "https://registry.npmjs.org/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-2.2.0.tgz",
- "integrity": "sha512-mHSkufBmBuJ+KHQhv5H0MXijtsoA1lynJt1lXOaotja8/I0pR4L9oGaPIZw+bQBOFittXZg9OC1sXSGO9D9ZYg==",
- "dev": true,
- "requires": {
- "cacache": "^12.0.2",
- "find-cache-dir": "^2.1.0",
- "is-wsl": "^1.1.0",
- "schema-utils": "^1.0.0",
- "serialize-javascript": "^1.7.0",
- "source-map": "^0.6.1",
- "uglify-js": "^3.6.0",
- "webpack-sources": "^1.4.0",
- "worker-farm": "^1.7.0"
- },
- "dependencies": {
- "schema-utils": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-1.0.0.tgz",
- "integrity": "sha512-i27Mic4KovM/lnGsy8whRCHhc7VicJajAjTrYg11K9zfZXnYIt4k5F+kZkwjnrhKzLic/HLU4j11mjsz2G/75g==",
- "dev": true,
- "requires": {
- "ajv": "^6.1.0",
- "ajv-errors": "^1.0.0",
- "ajv-keywords": "^3.1.0"
- }
- },
- "source-map": {
- "version": "0.6.1",
- "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
- "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
- "dev": true
- }
- }
- },
"unherit": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/unherit/-/unherit-1.1.3.tgz",
diff --git a/package.json b/package.json
index 5eb2cb28d..a28e9be62 100644
--- a/package.json
+++ b/package.json
@@ -184,9 +184,6 @@
"geographiclib": "^1.50.0",
"history": "^4.7.2",
"immutability-helper": "^3.0.1",
- "jquery": "^3.5.0",
- "jquery-ui-bundle": "1.12.1-migrate",
- "jquery-ui-touch-punch": "0.2.3",
"lodash": "^4.17.19",
"moment": "^2.19.3",
"moment-locales-webpack-plugin": "^1.1.2",
@@ -230,9 +227,6 @@
"what-input": "^5.2.7",
"whatwg-fetch": "^3.0.0"
},
- "browser": {
- "jquery": "./node_modules/jquery/dist/jquery.js"
- },
"browserslist": [
"last 4 versions",
"not ie < 11",
diff --git a/test-env.js b/test-env.js
index 2c77b4e86..f0b25e288 100644
--- a/test-env.js
+++ b/test-env.js
@@ -1,8 +1,7 @@
/* eslint-disable import/no-extraneous-dependencies */
-import $ from 'jquery';
import fetchMock from 'fetch-mock';
import 'jest-canvas-mock';
// eslint-disable-next-line no-multi-assign
-global.$ = global.jQuery = $;
+
global.fetch = fetchMock;
diff --git a/web/js/app.js b/web/js/app.js
index 2d376920a..204d28a10 100644
--- a/web/js/app.js
+++ b/web/js/app.js
@@ -1,7 +1,6 @@
import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
-import { each as lodashEach } from 'lodash';
// eslint-disable-next-line no-unused-vars
import whatInput from 'what-input';
import googleTagManager from 'googleTagManager';
@@ -36,8 +35,6 @@ import keyPress from './modules/key-press/actions';
// Dependency CSS
import '../../node_modules/bootstrap/dist/css/bootstrap.min.css';
-import '../../node_modules/jquery-ui-bundle/jquery-ui.structure.min.css';
-import '../../node_modules/jquery-ui-bundle/jquery-ui.theme.min.css';
import '../../node_modules/ol/ol.css';
import '../../node_modules/rc-slider/dist/rc-slider.min.css';
import '../../node_modules/simplebar/dist/simplebar.min.css';
@@ -67,7 +64,6 @@ import '../css/image.css';
import '../css/projection.css';
import '../css/tour.css';
import '../css/products.css';
-import '../css/indicator.css';
import '../css/events.css';
import '../css/smart-handoff.css';
import '../css/sidebar.css';
@@ -147,9 +143,7 @@ class App extends React.Component {
const main = function() {
// Load any additional scripts as needed
if (config.scripts) {
- lodashEach(config.scripts, (script) => {
- $.getScript(script);
- });
+ util.loadScipts(config.scripts);
}
if (config.features.googleTagManager) {
googleTagManager.init(config.features.googleTagManager.id); // Insert google tag manager
diff --git a/web/js/combine-ui.js b/web/js/combine-ui.js
index 5b02e542b..00ab45fd4 100644
--- a/web/js/combine-ui.js
+++ b/web/js/combine-ui.js
@@ -38,14 +38,15 @@ export default function combineUi(models, config, store) {
ui.naturalEvents = naturalEventsUI(ui, config, store, models);
}
registerMapMouseHandlers(ui.map.proj);
+
// Sink all focus on inputs if click unhandled
- $(document).click((event) => {
- if (event.target.nodeName !== 'INPUT') {
- $('input').blur();
+ document.addEventListener('click', (e) => {
+ if (e.target.nodeName !== 'INPUT') {
+ document.querySelectorAll('input').forEach((el) => el.blur());
}
});
document.activeElement.blur();
- $('input').blur();
+ document.querySelectorAll('input').forEach((el) => el.blur());
return ui;
}
diff --git a/web/js/containers/sidebar/sidebar.js b/web/js/containers/sidebar/sidebar.js
index 70db25b03..b79571d32 100644
--- a/web/js/containers/sidebar/sidebar.js
+++ b/web/js/containers/sidebar/sidebar.js
@@ -54,14 +54,15 @@ class Sidebar extends React.Component {
constructor(props) {
super(props);
this.state = { subComponentHeight: 700 };
- const customPalettePromise = loadCustomPalette(props.config);
- customPalettePromise.done((customs) => {
- props.loadedCustomPalettes(customs);
- });
this.toggleSidebar = this.toggleSidebar.bind(this);
}
componentDidMount() {
+ const { config, loadedCustomPalettes } = this.props;
+ const customPalettePromise = loadCustomPalette(config);
+ customPalettePromise.then((customs) => {
+ loadedCustomPalettes(customs);
+ });
this.updateDimensions();
// prevent browserzooming in safari
if (util.browser.safari) {
diff --git a/web/js/font-awesome-library.js b/web/js/font-awesome-library.js
index 921982bcf..39c094ef3 100644
--- a/web/js/font-awesome-library.js
+++ b/web/js/font-awesome-library.js
@@ -22,6 +22,7 @@ import {
faArrowCircleUp,
faArrowLeft,
faArrowRight,
+ faArrowsAltH,
faBan,
faBolt,
faCamera,
@@ -63,6 +64,7 @@ import {
faPlay,
faPlus,
faQuestionCircle,
+ faRedo,
faRetweet,
faRuler,
faRulerCombined,
@@ -74,6 +76,7 @@ import {
faTimes,
faTrash,
faTruck,
+ faUndo,
faVideo,
} from '@fortawesome/free-solid-svg-icons';
import { faFacebookF, faTwitter, faRedditAlien } from '@fortawesome/free-brands-svg-icons';
@@ -87,6 +90,7 @@ library.add(
faArrowCircleUp,
faArrowLeft,
faArrowRight,
+ faArrowsAltH,
faBan,
faBolt,
faCamera,
@@ -131,6 +135,7 @@ library.add(
faPlay,
faPlus,
faQuestionCircle,
+ faRedo,
faRetweet,
faRedditAlien,
faRuler,
@@ -144,5 +149,6 @@ library.add(
faTrash,
faTruck,
faTwitter,
+ faUndo,
faVideo,
);
diff --git a/web/js/main.js b/web/js/main.js
index 00d9d4a1c..64965d720 100644
--- a/web/js/main.js
+++ b/web/js/main.js
@@ -27,7 +27,6 @@ import { stateToParams } from './redux-location-state-customs';
import reducers, { getInitialState } from './modules/combine-reducers';
import App from './app';
import util from './util/util';
-import loadingIndicator from './ui/indicator';
import Brand from './brand';
import combineModels from './combine-models';
import parse from './parse';
@@ -120,80 +119,87 @@ window.onload = () => {
elapsed = function() {};
}
elapsed('loading config', startTime, parameters);
- const promise = $.getJSON(configURI);
- loadingIndicator.delayed(promise, 1000);
- promise.done((config) => {
+ const promise = fetch(configURI);
+
+ promise
+ .then((response) => {
+ if (!response.ok) {
+ throw Error('Could not load config');
+ }
+ return response.json();
+ })
+ .then((config) => {
// Perform check to see if app was in the midst of a tour
- const hasTour = lodashGet(config, `stories[${parameters.tr}]`);
- if (hasTour) {
- const isMockTour = parameters.mockTour;
- // Gets the extent of the first tour step and overrides view params
- parameters = util.fromQueryString(hasTour.steps[0].stepLink);
- parameters.mockTour = isMockTour;
- }
+ const hasTour = lodashGet(config, `stories[${parameters.tr}]`);
+ if (hasTour) {
+ const isMockTour = parameters.mockTour;
+ // Gets the extent of the first tour step and overrides view params
+ parameters = util.fromQueryString(hasTour.steps[0].stepLink);
+ parameters.mockTour = isMockTour;
+ }
- config.pageLoadTime = parameters.now
- ? util.parseDateUTC(parameters.now) || new Date()
- : new Date();
+ config.pageLoadTime = parameters.now
+ ? util.parseDateUTC(parameters.now) || new Date()
+ : new Date();
- const pageLoadTime = new Date(config.pageLoadTime);
+ const pageLoadTime = new Date(config.pageLoadTime);
- config.initialDate = config.pageLoadTime.getUTCHours() < 3
- ? new Date(pageLoadTime.setUTCDate(pageLoadTime.getUTCDate() - 1))
- : pageLoadTime;
+ config.initialDate = config.pageLoadTime.getUTCHours() < 3
+ ? new Date(pageLoadTime.setUTCDate(pageLoadTime.getUTCDate() - 1))
+ : pageLoadTime;
- config.palettes = {
- rendered: {},
- custom: {},
- };
+ config.palettes = {
+ rendered: {},
+ custom: {},
+ };
- elapsed('Config loaded', config.now, parameters);
- // Determine which layers need to be preloaded
- let layers = [];
- if (
- (parameters.l && hasCustomTypePalette(parameters.l))
+ elapsed('Config loaded', config.now, parameters);
+ // Determine which layers need to be preloaded
+ let layers = [];
+ if (
+ (parameters.l && hasCustomTypePalette(parameters.l))
|| (parameters.l1 && hasCustomTypePalette(parameters.l1))
- ) {
- if (parameters.l && hasCustomTypePalette(parameters.l)) {
- layers.push(...layersParse12(parameters.l, config));
- }
+ ) {
+ if (parameters.l && hasCustomTypePalette(parameters.l)) {
+ layers.push(...layersParse12(parameters.l, config));
+ }
- if (parameters.l1 && hasCustomTypePalette(parameters.l1)) {
- layers.push(...layersParse12(parameters.l1, config));
+ if (parameters.l1 && hasCustomTypePalette(parameters.l1)) {
+ layers.push(...layersParse12(parameters.l1, config));
+ }
+ layers = uniqBy(layers, (layer) => {
+ let str = '';
+ CUSTOM_PALETTE_TYPE_ARRAY.forEach((element) => {
+ str += layer[element] ? layer[element][0] : '';
+ });
+ return layer.id + str;
+ });
+ }
+ const legacyState = parse(parameters, config, errors);
+ layerValidate(errors, config);
+ adjustStartDates(config.layers);
+ // handle add mock future time to provided layer id
+ if (parameters.mockFutureLayer) {
+ mockFutureTimeLayerOptions(config.layers, parameters.mockFutureLayer);
}
- layers = uniqBy(layers, (layer) => {
- let str = '';
- CUSTOM_PALETTE_TYPE_ARRAY.forEach((element) => {
- str += layer[element] ? layer[element][0] : '';
+ adjustEndDates(config.layers);
+ // Remove any mock stories
+ if (!parameters.mockTour) {
+ Object.keys(config.stories).forEach((storyId) => {
+ if (config.stories[storyId].isMock) {
+ delete config.stories[storyId];
+ config.storyOrder = config.storyOrder.filter((id) => id !== storyId);
+ }
});
- return layer.id + str;
- });
- }
- const legacyState = parse(parameters, config, errors);
- layerValidate(errors, config);
- adjustStartDates(config.layers);
- // handle add mock future time to provided layer id
- if (parameters.mockFutureLayer) {
- mockFutureTimeLayerOptions(config.layers, parameters.mockFutureLayer);
- }
- adjustEndDates(config.layers);
- // Remove any mock stories
- if (!parameters.mockTour) {
- Object.keys(config.stories).forEach((storyId) => {
- if (config.stories[storyId].isMock) {
- delete config.stories[storyId];
- config.storyOrder = config.storyOrder.filter((id) => id !== storyId);
- }
+ }
+ preloadPalettes(layers, {}, false).then((obj) => {
+ config.palettes = {
+ custom: obj.custom,
+ rendered: obj.rendered,
+ };
+ render(config, parameters, legacyState);
});
- }
- preloadPalettes(layers, {}, false).then((obj) => {
- config.palettes = {
- custom: obj.custom,
- rendered: obj.rendered,
- };
- render(config, parameters, legacyState);
- });
- }).fail(util.error);
+ }).catch((error) => console.error(error));
};
export default history;
diff --git a/web/js/map/compare/swipe.js b/web/js/map/compare/swipe.js
index 790f77d28..9edbfd282 100644
--- a/web/js/map/compare/swipe.js
+++ b/web/js/map/compare/swipe.js
@@ -1,9 +1,10 @@
+import React from 'react';
+import ReactDOM from 'react-dom';
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import lodashEach from 'lodash/each';
import lodashRound from 'lodash/round';
import util from '../../util/util';
-import { faIconArrowsAltHSVGDomEl } from '../fa-map-icons';
-
const { events } = util;
let swipeOffset = null;
@@ -27,7 +28,7 @@ export default class Swipe {
this.map = olMap;
percentSwipe = valueOverride / 100;
this.create();
- $(window).resize(() => {
+ window.addEventListener('resize', () => {
if (document.querySelector('.ab-swipe-line')) {
this.destroy();
this.create();
@@ -153,7 +154,7 @@ const addLineOverlay = function(map) {
lineCaseEl.appendChild(firstLabel);
lineCaseEl.appendChild(secondLabel);
draggerEl.appendChild(draggerCircleEl);
- draggerCircleEl.insertAdjacentHTML('beforeend', faIconArrowsAltHSVGDomEl);
+ ReactDOM.render(<FontAwesomeIcon icon="arrows-alt-h" />, draggerCircleEl);
lineCaseEl.appendChild(draggerEl);
mapCase.appendChild(lineCaseEl);
swipeOffset = percentSwipe
diff --git a/web/js/map/fa-map-icons.js b/web/js/map/fa-map-icons.js
deleted file mode 100644
index a3b34d17d..000000000
--- a/web/js/map/fa-map-icons.js
+++ /dev/null
@@ -1,7 +0,0 @@
-// string DOM element SVGs to bridge the gap for non-React FontAwesome icons in the map part of the app
-export const faIconUndoSVGDomEl = '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="undo" class="svg-inline--fa fa-undo fa-w-16 " role="img" xmlns="https://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M212.333 224.333H12c-6.627 0-12-5.373-12-12V12C0 5.373 5.373 0 12 0h48c6.627 0 12 5.373 12 12v78.112C117.773 39.279 184.26 7.47 258.175 8.007c136.906.994 246.448 111.623 246.157 248.532C504.041 393.258 393.12 504 256.333 504c-64.089 0-122.496-24.313-166.51-64.215-5.099-4.622-5.334-12.554-.467-17.42l33.967-33.967c4.474-4.474 11.662-4.717 16.401-.525C170.76 415.336 211.58 432 256.333 432c97.268 0 176-78.716 176-176 0-97.267-78.716-176-176-176-58.496 0-110.28 28.476-142.274 72.333h98.274c6.627 0 12 5.373 12 12v48c0 6.627-5.373 12-12 12z"></path></svg>';
-export const faIconRedoSVGDomEl = '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="redo" class="svg-inline--fa fa-redo fa-w-16 " role="img" xmlns="https://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M500.33 0h-47.41a12 12 0 0 0-12 12.57l4 82.76A247.42 247.42 0 0 0 256 8C119.34 8 7.9 119.53 8 256.19 8.1 393.07 119.1 504 256 504a247.1 247.1 0 0 0 166.18-63.91 12 12 0 0 0 .48-17.43l-34-34a12 12 0 0 0-16.38-.55A176 176 0 1 1 402.1 157.8l-101.53-4.87a12 12 0 0 0-12.57 12v47.41a12 12 0 0 0 12 12h200.33a12 12 0 0 0 12-12V12a12 12 0 0 0-12-12z"></path></svg>';
-export const faIconInfoCircleSVGDomEl = '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle fa-w-16 fa-3x " role="img" xmlns="https://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path></svg>';
-export const faIconPlusSVGDomEl = '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="plus" class="svg-inline--fa fa-plus fa-w-14 fa-1x " role="img" xmlns="https://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M416 208H272V64c0-17.67-14.33-32-32-32h-32c-17.67 0-32 14.33-32 32v144H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h144v144c0 17.67 14.33 32 32 32h32c17.67 0 32-14.33 32-32V304h144c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z"></path></svg>';
-export const faIconMinusSVGDomEl = '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="minus" class="svg-inline--fa fa-minus fa-w-14 fa-1x " role="img" xmlns="https://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M416 208H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h384c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z"></path></svg>';
-export const faIconArrowsAltHSVGDomEl = '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="arrows-alt-h" class="svg-inline--fa fa-arrows-alt-h fa-w-16 " role="img" xmlns="https://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M377.941 169.941V216H134.059v-46.059c0-21.382-25.851-32.09-40.971-16.971L7.029 239.029c-9.373 9.373-9.373 24.568 0 33.941l86.059 86.059c15.119 15.119 40.971 4.411 40.971-16.971V296h243.882v46.059c0 21.382 25.851 32.09 40.971 16.971l86.059-86.059c9.373-9.373 9.373-24.568 0-33.941l-86.059-86.059c-15.119-15.12-40.971-4.412-40.971 16.97z"></path></svg>';
diff --git a/web/js/map/natural-events/request.js b/web/js/map/natural-events/request.js
index c3d640b8e..d2aea15dc 100644
--- a/web/js/map/natural-events/request.js
+++ b/web/js/map/natural-events/request.js
@@ -59,47 +59,50 @@ export default function naturalEventsRequest(models, ui, config) {
}
};
- const queryEvents = function() {
- return new Promise((resolve) => {
- let url = `${self.apiURL}/events`;
- if (config.parameters.mockEvents) {
- console.warn(`Using mock events data: ${config.parameters.mockEvents}`);
- url = `mock/events_data.json-${config.parameters.mockEvents}`;
- }
- $.getJSON(url, (data) => {
- resolve(data);
- });
- });
+ const queryEvents = async () => {
+ let url = `${self.apiURL}/events`;
+ if (config.parameters.mockEvents) {
+ console.warn(`Using mock events data: ${config.parameters.mockEvents}`);
+ url = `mock/events_data.json-${config.parameters.mockEvents}`;
+ }
+ const response = await fetch(url);
+ const json = await response.json();
+ if (!response.ok) {
+ throw Error('Request for events failed.');
+ }
+ return json;
};
- const queryTypes = function() {
- return new Promise((resolve) => {
- let url = `${self.apiURL}/categories`;
- if (config.parameters.mockCategories) {
- console.warn(
- `Using mock categories data: ${config.parameters.mockEvents}`,
- );
- url = `mock/categories_data.json-${config.parameters.mockCategories}`;
- }
- $.getJSON(url, (data) => {
- resolve(data);
- });
- });
+ const queryTypes = async () => {
+ let url = `${self.apiURL}/categories`;
+ if (config.parameters.mockCategories) {
+ console.warn(
+ `Using mock categories data: ${config.parameters.mockEvents}`,
+ );
+ url = `mock/categories_data.json-${config.parameters.mockCategories}`;
+ }
+ const response = await fetch(url);
+ const json = await response.json();
+ if (!response.ok) {
+ throw Error('Request for event types failed.');
+ }
+ return json;
};
- const querySources = function() {
- return new Promise((resolve) => {
- let url = `${self.apiURL}/sources`;
- if (config.parameters.mockSources) {
- console.warn(
- `Using mock sources data: ${config.parameters.mockEvents}`,
- );
- url = `mock/sources_data.json-${config.parameters.mockSources}`;
- }
- $.getJSON(url, (data) => {
- resolve(data);
- });
- });
+ const querySources = async () => {
+ let url = `${self.apiURL}/sources`;
+ if (config.parameters.mockSources) {
+ console.warn(
+ `Using mock sources data: ${config.parameters.mockEvents}`,
+ );
+ url = `mock/sources_data.json-${config.parameters.mockSources}`;
+ }
+ const response = await fetch(url);
+ if (!response.ok) {
+ throw Error('Request for event sources failed.');
+ }
+ const json = await response.json();
+ return json;
};
self.query = function() {
diff --git a/web/js/modules/map/reducers.js b/web/js/modules/map/reducers.js
index 623d1080f..da1234c01 100644
--- a/web/js/modules/map/reducers.js
+++ b/web/js/modules/map/reducers.js
@@ -17,13 +17,14 @@ const INITIAL_STATE = {
rendered: false,
leadingExtent: [],
isClickable: false,
-
};
export default function mapReducer(state = INITIAL_STATE, action) {
switch (action.type) {
case UPDATE_MAP_EXTENT:
- return update(state, { extent: { $set: action.extent } });
+ return update(state, {
+ extent: { $set: action.extent },
+ });
case UPDATE_MAP_UI:
return lodashAssign({}, state, {
ui: action.ui,
@@ -31,7 +32,9 @@ export default function mapReducer(state = INITIAL_STATE, action) {
});
case UPDATE_MAP_ROTATION:
case REFRESH_ROTATE:
- return update(state, { rotation: { $set: action.rotation } });
+ return update(state, {
+ rotation: { $set: action.rotation },
+ });
case RENDERED:
return lodashAssign({}, state, {
rendered: true,
diff --git a/web/js/ui/indicator.js b/web/js/ui/indicator.js
deleted file mode 100644
index cdbbfa881..000000000
--- a/web/js/ui/indicator.js
+++ /dev/null
@@ -1,122 +0,0 @@
-import lodashUniqueId from 'lodash/uniqueId';
-import lodashIsString from 'lodash/isString';
-import lodashEach from 'lodash/each';
-import lodashRemove from 'lodash/remove';
-import lodashIsEmpty from 'lodash/isEmpty';
-import lodashLast from 'lodash/last';
-
-export default (function() {
- const self = {};
-
- let $indicator;
- let $icon;
- let $message;
-
- self.active = [];
-
- const init = function() {
- $indicator = $('<div></div>')
- .attr('id', 'indicator');
- $icon = $('<img />');
- $message = $('<span></span>');
-
- $indicator.append($icon)
- .append($message)
- .hide();
- $('body')
- .append($indicator);
- };
-
- self.show = function(message, icon) {
- self._show(message, icon);
- const id = lodashUniqueId();
- self.active.push({
- id,
- message,
- icon,
- });
- return id;
- };
-
- self.hide = function(hides) {
- if (lodashIsString(hides)) {
- hides = [hides];
- }
- lodashEach(hides, (id) => {
- lodashRemove(self.active, {
- id,
- });
- });
- if (lodashIsEmpty(self.active)) {
- self._hide();
- } else {
- const def = lodashLast(self.active);
- self._show(def.message, def.icon);
- }
- };
-
- self.replace = function(hides, message, icon) {
- self.hide(hides);
- return self.show(message, icon);
- };
-
- self._show = function(message, icon) {
- if (!$indicator) {
- init();
- }
- if (icon) {
- $indicator.removeClass('message');
- $icon.attr('src', icon)
- .show();
- } else {
- $indicator.addClass('message');
- $icon.removeAttr('src')
- .hide();
- }
- $message.html(message);
- $indicator.show();
- };
-
- self._hide = function() {
- if ($indicator) {
- $indicator.hide();
- }
- };
-
- self.searching = function(hides) {
- if (hides) {
- self.hide(hides);
- }
- return self.show('Searching for Data', 'images/activity.gif');
- };
-
- self.loading = function(hides) {
- if (hides) {
- self.hide(hides);
- }
- return self.show('Loading', 'images/activity.gif');
- };
-
- self.noData = function(hides) {
- if (hides) {
- self.hide(hides);
- }
- // return self.show('No Data Available', 'images/red-x.svg');
- };
-
- self.delayed = function(promise, delay) {
- delay = delay || 1000;
- let id;
- const timeout = setTimeout(() => {
- id = self.loading();
- }, delay);
- promise.always(() => {
- clearTimeout(timeout);
- if (id) {
- self.hide(id);
- }
- });
- };
-
- return self;
-}());
diff --git a/web/js/ui/indicator.test.js b/web/js/ui/indicator.test.js
deleted file mode 100644
index 44f0e20c6..000000000
--- a/web/js/ui/indicator.test.js
+++ /dev/null
@@ -1,85 +0,0 @@
-import jQuery from 'jquery';
-import indicator from './indicator';
-
-const unmocked = {};
-
-beforeAll(() => {
- unmocked._show = indicator._show;
- unmocked._hide = indicator._hide;
- unmocked.hide = indicator.hide;
-});
-
-beforeEach(() => { indicator.active = []; });
-
-afterEach(() => {
- indicator._show = unmocked._show;
- indicator._hide = unmocked._hide;
- indicator.hide = unmocked.hide;
-});
-
-test('delayed indicator shown', (done) => {
- indicator._show = jest.fn();
- indicator.hide = jest.fn();
- const promise = jQuery.Deferred();
- indicator.delayed(promise, 10);
- setTimeout(() => {
- promise.resolve();
- expect(indicator._show).toBeCalled();
- expect(indicator.hide).toBeCalled();
- done();
- }, 50);
-});
-
-test('delayed indicator not shown', (done) => {
- indicator._show = jest.fn();
- indicator.hide = jest.fn();
- const promise = jQuery.Deferred();
- indicator.delayed(promise, 1000);
- setTimeout(() => {
- promise.resolve();
- expect(indicator._show).not.toBeCalled();
- expect(indicator.hide).not.toBeCalled();
- done();
- }, 50);
-});
-
-test('pop message', () => {
- indicator._show = jest.fn();
- indicator._hide = jest.fn();
-
- indicator.show('Bottom');
- const id = indicator.show('Top');
- indicator.hide(id);
-
- expect(indicator.active).toHaveLength(1);
- expect(indicator.active[0].message).toBe('Bottom');
-});
-
-test('remove bottom message', () => {
- indicator._show = jest.fn();
- indicator._hide = jest.fn();
-
- const id = indicator.show('Bottom');
- indicator.show('Top');
- indicator.hide(id);
-
- expect(indicator.active).toHaveLength(1);
- expect(indicator.active[0].message).toBe('Top');
-});
-
-test('hide group', () => {
- indicator._show = jest.fn();
- indicator._hide = jest.fn();
-
- const indicators = {
- two: null,
- three: null,
- };
- indicator.show('One');
- indicators.two = indicator.show('Two');
- indicators.three = indicator.show('Three');
- indicator.hide(indicators);
-
- expect(indicator.active).toHaveLength(1);
- expect(indicator.active[0].message).toBe('One');
-});
diff --git a/web/js/ui/ui.js b/web/js/ui/ui.js
deleted file mode 100644
index 03d092218..000000000
--- a/web/js/ui/ui.js
+++ /dev/null
@@ -1,113 +0,0 @@
-import 'jquery-ui-bundle/jquery-ui';
-import loadingIndicator from './indicator';
-
-export default (function(self) {
- // Export other ui methods
- self.indicator = loadingIndicator;
- /**
- * General error handler.
- *
- * Displays a dialog box with the error message. If an exception object
- * is passed in, its contents will be printed to the console.
- *
- * @method error
- * @static
- *
- * @param {Exception} cause The exception object that caused the error
- */
- self.error = function(...args) {
- console.error(args);
-
- self.notify(
- "<div class='error-header'>"
- + 'An unexpected error has occurred'
- + '</div>'
- + "<div class='error-body'>Please reload the page and try "
- + 'again. If you continue to have problems, contact us at '
- + "<a href='mailto:@MAIL@'>"
- + '@MAIL@</a>'
- + '</div>',
- 'Error',
- );
- };
-
- /**
- * Displays a message to the end user in a dialog box.
- *
- * @method notify
- * @static
- *
- * @param {string} message The message to display to the user.
- *
- * @param [title="Notice"] {string} Title for the dialog box.
- */
- self.notify = function(message, title, width, callback) {
- const $dialog = self.getDialog();
- title = title || 'Notice';
- width = width || 300;
- $dialog
- .html(message)
- .dialog({
- title,
- width,
- minHeight: 1,
- height: 'auto',
- show: {
- effect: 'fade',
- duration: 400,
- },
- hide: {
- effect: 'fade',
- duration: 200,
- },
- closeText: '',
- })
- .on('dialogclose', function() {
- $(this).off('dialogclose');
- if (callback) {
- callback();
- }
- });
- };
-
- const getComponent = function(marker) {
- const $element = $('<div></div>').addClass(marker);
- $('body').append($element);
- return $element;
- };
-
- const closeComponent = function(marker, fnClose) {
- const selector = `.${marker}`;
- const $element = $(selector);
- if ($element.length !== 0) {
- fnClose($element);
- }
- };
-
- const closeDialog = function($element) {
- if ($element.length !== 0) {
- if ($element.dialog) {
- $element.dialog('close');
- }
- $element.remove();
- }
- };
-
- const closeMenu = function($element) {
- if ($element.length !== 0) {
- $element.remove();
- }
- };
-
- self.close = function() {
- closeComponent('wv-dialog', closeDialog);
- closeComponent('wv-menu', closeMenu);
- };
-
- self.getDialog = function(marker) {
- self.close(marker);
- return getComponent(marker || 'wv-dialog', closeDialog);
- };
-
- return self;
-}({}));
diff --git a/web/js/util/browser.js b/web/js/util/browser.js
index b60f2f04e..04b2910de 100644
--- a/web/js/util/browser.js
+++ b/web/js/util/browser.js
@@ -92,10 +92,8 @@ export default (function() {
self.constrained = tests.constrained();
self.dimensions = self.tests.getWindowDimensions();
};
- $(window).on('resize', onResize);
- $(() => {
- onResize();
- });
+ window.addEventListener('resize', onResize);
+ onResize();
};
// The following functions should not be used directly. Use the values
@@ -225,7 +223,7 @@ export default (function() {
};
self.tests.getWindowDimensions = function() {
- return [$(window).width(), $(window).height()];
+ return [window.innerWidth, window.innerHeight];
};
self.tests.constrained = function() {
diff --git a/web/js/util/load.js b/web/js/util/load.js
index 77de76d06..b8bc9f947 100644
--- a/web/js/util/load.js
+++ b/web/js/util/load.js
@@ -1,45 +1,33 @@
import lodashSize from 'lodash/size';
-import wvui from '../ui/ui';
import brand from '../brand';
export default (function() {
const self = {};
const configPromises = {};
- let loading = 0;
- let indicatorTimeout = null;
- let indicatorId = null;
self.config = function(root, attr, url) {
- let promise = $.Deferred();
+ let promise = Promise;
+
// If a request is already outstanding, chain to that one
if (configPromises[url]) {
- configPromises[url].done(promise.resolve)
- .fail(promise.reject);
+ configPromises[url]
+ .then(promise.resolve)
+ .catch(promise.reject);
return promise;
}
+
if (root[attr] && lodashSize(root[attr]) > 0) {
promise.resolve(root[attr]);
} else {
- loading += 1;
- promise = $.getJSON(brand.url(url));
- if (loading === 1) {
- indicatorTimeout = setTimeout(() => {
- indicatorId = wvui.indicator.loading();
- }, 2000);
- }
- promise.done((result) => {
- root[attr] = result;
- })
- .always(() => {
+ promise = fetch(brand.url(url))
+ .then((response) => response.json())
+ .then((result) => {
+ root[attr] = result;
+ })
+ .finally(() => {
delete configPromises[url];
- loading -= 1;
- if (loading === 0) {
- clearTimeout(indicatorTimeout);
- indicatorTimeout = null;
- if (indicatorId) wvui.indicator.hide(indicatorId);
- }
})
- .fail(wvui.error);
+ .catch((err) => console.log(err));
configPromises[url] = promise;
}
diff --git a/web/js/util/util.js b/web/js/util/util.js
index a7593dfc3..d60219bef 100644
--- a/web/js/util/util.js
+++ b/web/js/util/util.js
@@ -2,9 +2,7 @@ import {
isObject as lodashIsObject,
each as lodashEach,
} from 'lodash';
-import Cache from 'cachai';
import moment from 'moment';
-import wvui from '../ui/ui';
import browser from './browser';
import events from './events';
import load from './load';
@@ -693,22 +691,6 @@ export default (function(self) {
return self.now();
};
- /**
- * General error handler.
- *
- * This function delegates to
- * {{#crossLink "wv.ui/error:method"}}wv.ui.error{{/crossLink}}.
- * For custom error handling, replace this function.
- *
- * @method error
- * @static
- * @param {string} message Message to display to the end user.
- * @param {Exception} cause The exception object that caused the error
- */
- self.error = function(message, cause) {
- wvui.error(message, cause);
- };
-
/**
* General warning handler.
*
@@ -755,64 +737,18 @@ export default (function(self) {
// eslint-disable-next-line no-restricted-properties
return Math.sqrt(Math.pow(r1 - r2, 2) + Math.pow(g1 - g2, 2) + Math.pow(b1 - b2, 2));
};
+
self.fetch = function(url, mimeType) {
- return new Promise((resolve, reject) => fetch(url)
- .then((response) => (mimeType === 'application/json'
- ? response.json()
- : response.text()))
- .then((data) => {
- resolve(data);
- })
- .catch((error) => {
- reject(error);
- }));
+ return new Promise(
+ (resolve, reject) => fetch(url)
+ .then((response) => (mimeType === 'application/json'
+ ? response.json()
+ : response.text()))
+ .then(resolve)
+ .catch(reject),
+ );
};
- /**
- * Submits an AJAX request or retreives the result from the cache.
- *
- * @class wv.util.ajaxCache
- * @constructor
- * @param {Number} [spec.size] maximum number of items to store in the
- * cache.
- * @param {Object} [spec.options] options to pass to jscache on setItem.
- *
- */
- self.ajaxCache = function(spec) {
- spec = spec || {};
- const size = spec.size || null;
- const options = spec.options || {};
- const cache = new Cache(size);
-
- return {
- /**
- * Submits an AJAX request using jQuery.ajax or retrieves the
- * results from cache.
- *
- * @method submit
- * @param {Object} parameters Parameters to pass to the jQuery.ajax
- * call.
- * @return {jQuery.Deferred} a deferred object that will resolve
- * when the query returns, or resolves immediately if the results
- * are cached.
- */
- submit(parameters) {
- const key = `url=${parameters.url}`;
- const results = cache.getItem(key);
-
- if (results) {
- return $.Deferred()
- .resolve(results)
- .promise();
- }
- const promise = $.ajax(parameters);
- promise.done((results) => {
- cache.setItem(key, results, options);
- });
- return promise;
- },
- };
- };
self.errorReport = function(errors) {
// eslint-disable-next-line no-unused-vars
let layersRemoved = 0;
@@ -824,9 +760,9 @@ export default (function(self) {
}
});
};
+
/**
- * Wraps a function in a try/catch block that invokes wv.util.error
- * if an exception is thrown.
+ * Wraps a function in a try/catch block that logs error if thrown
*
* @param {function} func the function to wrap
* @return the function wrapped in a try/catch block.
@@ -836,7 +772,7 @@ export default (function(self) {
try {
return func.apply(func, args);
} catch (error) {
- self.error(error);
+ console.error(error);
}
};
};
@@ -877,28 +813,6 @@ export default (function(self) {
});
};
- // FIXME: Should be replaced with $.when
- self.ajaxJoin = function(calls) {
- let completed = 0;
- const result = {};
- const deferred = $.Deferred();
-
- $.each(calls, (index, call) => {
- call.promise.done((data) => {
- result[call.item] = data;
- completed += 1;
- if (completed === calls.length) {
- deferred.resolve(result);
- }
- })
- .fail((jqXHR, textStatus, errorThrown) => {
- deferred.reject(jqXHR, textStatus, errorThrown);
- });
- });
-
- return deferred.promise();
- };
-
// Converts a string to a form that can be safely used as an identifier.
//
// Currently only converts '.' and ':' and ',' to __xx__ where xx is the hex
@@ -1128,5 +1042,27 @@ export default (function(self) {
return txt.value;
};
+ /**
+ * Load additional scripts sequentially
+ * @param {*} scripts
+ * @param {*} fn
+ */
+ self.loadScipts = (scripts = [], fn) => {
+ const head = document.head || document.getElementsByTagName('head')[0];
+ const loadFile = (index) => {
+ if (scripts.length > index) {
+ const fileref = document.createElement('script');
+ fileref.setAttribute('type', 'text/javascript');
+ fileref.setAttribute('src', scripts[index]);
+ head.appendChild(fileref);
+ // Load next script
+ fileref.onload = () => { loadFile(index + 1); };
+ } else if (fn) {
+ fn();
+ }
+ };
+ loadFile(0);
+ };
+
return self;
}({}));
diff --git a/webpack.config.js b/webpack.config.js
index 588181ce7..1384f9e92 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -156,13 +156,6 @@ module.exports = {
},
exclude: babelLoaderExcludes,
},
- {
- test: require.resolve('jquery'),
- loader: 'expose-loader',
- options: {
- exposes: ['$', 'jQuery'],
- },
- },
{
test: /\.(sa|sc|c)ss$/,
use: [