Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Modularize utils

Jo Sprague9821196a0271
diff --git a/web/js/brand.js b/web/js/brand.js
new file mode 100644
index 000000000..a28a274a4
--- /dev/null
+++ b/web/js/brand.js
@@ -0,0 +1,2 @@
+/* This file is just a stub to test the browserify build task */
+export default function () {};
diff --git a/web/js/index.js b/web/js/index.js
index b5291dde1..4038d587e 100644
--- a/web/js/index.js
+++ b/web/js/index.js
@@ -1 +1,3 @@
export { default as stub } from './stub';
+export { default as polyfill } from './polyfill';
+export { default as util } from './util/util';
diff --git a/web/js/polyfill.js b/web/js/polyfill.js
new file mode 100644
index 000000000..44f3410dd
--- /dev/null
+++ b/web/js/polyfill.js
@@ -0,0 +1,220 @@
+// ===========================================================================
+// Polyfills and browser quirks - DEPRECATED
+// This file is full of lots of old hacks, that are kept around to avoid
+// breaking things, but they should be removed when possible.
+// Now that we're transpiling code, YOU SHOULD NOT ADD TO THIS FILE
+// ===========================================================================
+
+import $ from 'jquery';
+import { default as browser } from './util/browser.js';
+
+export default function () {
+ /*
+ * Date.toISOString
+ *
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
+ */
+ if (!Date.prototype.toISOString) {
+ (function () {
+ function pad (number) {
+ if (number < 10) {
+ return '0' + number;
+ }
+ return number;
+ }
+
+ Date.prototype.toISOString = function () {
+ return this.getUTCFullYear() +
+ '-' + pad(this.getUTCMonth() + 1) +
+ '-' + pad(this.getUTCDate()) +
+ 'T' + pad(this.getUTCHours()) +
+ ':' + pad(this.getUTCMinutes()) +
+ ':' + pad(this.getUTCSeconds()) +
+ '.' + (this.getUTCMilliseconds() / 1000)
+ .toFixed(3)
+ .slice(2, 5) +
+ 'Z';
+ };
+ }());
+ }
+
+ /*
+ * console
+ */
+ if (!window.console) {
+ (function () {
+ window.console = {
+ log: function () {},
+ warn: function () {},
+ info: function () {},
+ error: function () {}
+ };
+ })();
+ }
+
+ /*
+ * Get rid of address bar on iphone/ipod
+ */
+ (function () {
+ var execute = function () {
+ window.scrollTo(0, 0);
+ if (document.body) {
+ document.body.style.height = '100%';
+ if (!(/(iphone|ipod)/.test(navigator.userAgent.toLowerCase()))) {
+ if (document.body.parentNode) {
+ document.body.parentNode.style.height = '100%';
+ }
+ }
+ }
+ };
+ setTimeout(execute, 700);
+ setTimeout(execute, 1500);
+ })();
+
+ /*
+ * Hide the URL bar
+ */
+ (function () {
+ window.scrollTo(0, 0);
+ })();
+
+ /*
+ * setTimeout that properly sets this and allows arguments. The only case where
+ * this is helpful at the moment is IE9 -- only attempt to do this in that case
+ *
+ * https://developer.mozilla.org/en-US/docs/Web/API/Window.setTimeout
+ */
+ if (browser.ie && browser.version <= 9) {
+ (function () {
+ var __nativeST__ = window.setTimeout,
+ __nativeSI__ = window.setInterval;
+
+ window.setTimeout = function (vCallback, nDelay /*, argumentToPass1, argumentToPass2, etc. */) {
+ var oThis = this,
+ aArgs = Array.prototype.slice.call(arguments, 2);
+ return __nativeST__(vCallback instanceof Function ? function () {
+ vCallback.apply(oThis, aArgs);
+ } : vCallback, nDelay);
+ };
+
+ window.setInterval = function (vCallback, nDelay /*, argumentToPass1, argumentToPass2, etc. */) {
+ var oThis = this,
+ aArgs = Array.prototype.slice.call(arguments, 2);
+ return __nativeSI__(vCallback instanceof Function ? function () {
+ vCallback.apply(oThis, aArgs);
+ } : vCallback, nDelay);
+ };
+ })();
+ }
+
+ /*
+ * String.contains
+ *
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/contains
+ */
+ if (!('contains' in String.prototype)) {
+ (function () {
+ String.prototype.contains = function (str, startIndex) {
+ return String.prototype.indexOf.call(this, str,
+ startIndex) !== -1;
+ };
+ })();
+ }
+
+ /*
+ * String.startsWith
+ *
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
+ */
+ if (!String.prototype.startsWith) {
+ (function () {
+ Object.defineProperty(String.prototype, 'startsWith', {
+ enumerable: false,
+ configurable: false,
+ writable: false,
+ value: function (searchString, position) {
+ position = position || 0;
+ return this.indexOf(searchString, position) === position;
+ }
+ });
+ })();
+ }
+
+ /*
+ * String.endsWith
+ *
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
+ */
+ if (!String.prototype.endsWith) {
+ (function () {
+ Object.defineProperty(String.prototype, 'endsWith', {
+ enumerable: false,
+ configurable: false,
+ writable: false,
+ value: function (searchString, position) {
+ position = position || this.length;
+ position = position - searchString.length;
+ var lastIndex = this.lastIndexOf(searchString);
+ return lastIndex !== -1 && lastIndex === position;
+ }
+ });
+ })();
+ }
+
+ /*
+ * Mobile device quirks. This section is mostly overwriting things that jquery.mobile is adding
+ */
+ (function () {
+ if (navigator.userAgent.match(/Android/i) ||
+ navigator.userAgent.match(/webOS/i) ||
+ navigator.userAgent.match(/iPhone/i) ||
+ navigator.userAgent.match(/iPad/i) ||
+ navigator.userAgent.match(/iPod/i) ||
+ navigator.userAgent.match(/BlackBerry/i) ||
+ navigator.userAgent.match(/Windows Phone/i)
+ ) {
+ mobile = true;
+ if (!(window.orientation == 90 || window.orientation == -90)) {
+ portrait = true;
+ }
+ }
+
+ if (navigator.userAgent.indexOf('iPhone') != -1 || navigator.userAgent.indexOf('Android') != -1) {
+ // In Safari, the true version is after "Safari"
+ if (navigator.userAgent.indexOf('Safari') != -1) {
+ // Set a variable to use later
+ mobileSafari = true;
+ }
+ addEventListener('load', function () {
+ if (mobile) {
+ $('.layerPicker a[href=\'#DataDownload\']')
+ .hide();
+ }
+ setHeight();
+ window.scrollTo(0, 1);
+ $('#app, .ui-mobile, .ui-mobile .ui-page')
+ .css('min-height', 0);
+ }, false);
+ addEventListener('orientationchange', function () {
+ window.scrollTo(0, 1);
+ setHeight();
+ }, false);
+ }
+
+ // Set the div height
+ function setHeight ($body) {
+ if (navigator.userAgent.match(/(iPad|iPhone|iPod touch);.*CPU.*OS 6_\d/i)) {
+ var new_height = $(window)
+ .height();
+ // if mobileSafari 6 add +60px
+ new_height += 60;
+ $('#app')
+ .css('min-height', 0)
+ .css('height', new_height);
+ } else {
+ $('#app, .ui-mobile, .ui-mobile .ui-page')
+ .css('min-height', 0);
+ }
+ }
+ })();
+}
diff --git a/web/js/ui/ui.js b/web/js/ui/ui.js
new file mode 100644
index 000000000..a28a274a4
--- /dev/null
+++ b/web/js/ui/ui.js
@@ -0,0 +1,2 @@
+/* This file is just a stub to test the browserify build task */
+export default function () {};
diff --git a/web/js/util/browser.js b/web/js/util/browser.js
new file mode 100644
index 000000000..95654cbd9
--- /dev/null
+++ b/web/js/util/browser.js
@@ -0,0 +1,212 @@
+import $ from 'jquery';
+
+export default (function () {
+ var self = {};
+
+ /**
+ * True if Internet Explorer was detected in the user-agent string.
+ *
+ * @attribute ie
+ * @type Boolean
+ */
+ self.ie = false;
+
+ /**
+ * True if Safari was detected in the user-agent string.
+ *
+ * @attribute safari
+ * @type Boolean
+ */
+ self.safari = false;
+
+ self.firefox = false;
+
+ /**
+ * Major version number of the browser detected in the user-agent string.
+ * If the version is not important for Worldview at the moment, this
+ * value will be null.
+ *
+ * @attribute version
+ * @type Number
+ */
+ self.version = null;
+
+ /**
+ * True if the screen size is small enough (width less than 740px) to
+ * require special mobile device behavior.
+ *
+ * @attribute small
+ * @type Boolean
+ */
+ self.small = false;
+ self.constrained = false;
+
+ /**
+ * True if this browser properly supports cross-origin resource
+ * sharing.
+ *
+ * @attribute cors
+ * @type Boolean
+ */
+ self.cors = true;
+
+ /**
+ * True if this browser properly supports web workers.
+ *
+ * @attribute webWorkers
+ * @type Boolean
+ */
+ self.webWorkers = true;
+
+ /**
+ * True if local storage is available in the browser. This will return
+ * false if local storage is supported, but cannot be used because
+ * it is running in private mode.
+ *
+ * @attribute localStorage
+ * @type Boolean
+ */
+ self.localStorage = false;
+ self.history = true;
+ self.touchDevice = false;
+
+ self.mobileWidth = 740;
+ self.constrainedHeight = 320;
+
+ var init = function () {
+ var tests = self.tests;
+
+ if (tests.safari()) {
+ self.safari = true;
+ self.version = tests.safariVersion();
+ } else if (tests.ie()) {
+ self.ie = true;
+ self.version = tests.ieVersion();
+ } else if (tests.firefox()) {
+ self.firefox = true;
+ }
+
+ self.cors = tests.cors();
+ self.webWorkers = tests.webWorkers();
+ self.localStorage = tests.localStorage();
+ self.small = tests.small();
+ self.history = tests.history();
+ self.touchDevice = tests.touchDevice();
+
+ var onResize = function () {
+ self.small = tests.small();
+ self.constrained = tests.constrained();
+ };
+ $(window)
+ .on('resize', onResize);
+ $(function () {
+ onResize();
+ });
+ };
+
+ // The following functions should not be used directly. Use the values
+ // set in the init function. These functions are useful for testing.
+ self.tests = {};
+
+ self.tests.navigator = function () {
+ return navigator;
+ };
+
+ self.tests.window = function (property) {
+ // Some browsers throw an error when attempting to access restricted Window objects
+ try {
+ return window[property];
+ } catch (error) {
+ return false;
+ }
+ };
+
+ self.tests.safari = function () {
+ var navigator = self.tests.navigator();
+ if (/ Chrome\//.test(navigator.userAgent)) {
+ return false;
+ }
+ return (/ Safari\//)
+ .test(navigator.userAgent);
+ };
+
+ self.tests.safariVersion = function () {
+ var navigator = self.tests.navigator();
+ var version = navigator.userAgent.match(/ Version\/([^ ]+)/);
+ if (version) {
+ return parseInt(version[1].split('.')[0]);
+ }
+ };
+
+ self.tests.ie = function () {
+ var navigator = self.tests.navigator();
+ if (/MSIE /.test(navigator.userAgent)) {
+ return true;
+ }
+ // IE 11
+ return navigator.appName === 'Netscape' && /Trident/.test(navigator.userAgent);
+ };
+
+ self.tests.firefox = function () {
+ return navigator.userAgent.toLowerCase()
+ .indexOf('firefox') > -1;
+ };
+
+ self.tests.touchDevice = function () {
+ var el = document.createElement('div');
+ el.setAttribute('ontouchstart', 'return;');
+ return typeof el.ontouchstart === 'function';
+ };
+
+ self.tests.ieVersion = function () {
+ var navigator = self.tests.navigator();
+ var version = navigator.userAgent.match(/MSIE ([\d\.]+)/);
+ if (version) {
+ return parseInt(version[1].split('.')[0]);
+ }
+ };
+
+ self.tests.cors = function () {
+ if (self.tests.safari() && self.tests.safariVersion() <= 6) {
+ return false;
+ }
+ return !self.tests.ie();
+ };
+
+ self.tests.webWorkers = function () {
+ return self.tests.window('Worker');
+ };
+
+ self.tests.localStorage = function () {
+ if (!self.tests.window('localStorage')) {
+ return false;
+ }
+ try {
+ var uid = new Date();
+ var result;
+ localStorage.setItem(uid, uid);
+ result = localStorage.getItem(uid) == uid;
+ localStorage.removeItem(uid);
+ return result && true;
+ } catch (error) {
+ return false;
+ }
+ };
+
+ self.tests.small = function () {
+ return $(window)
+ .width() < self.mobileWidth;
+ };
+
+ self.tests.constrained = function () {
+ return $(window)
+ .height() < self.constrainedHeight;
+ };
+
+ self.tests.history = function () {
+ return window.history && window.history.replaceState;
+ };
+
+ init();
+ return self;
+})();
diff --git a/web/js/util/wv.util.events.js b/web/js/util/events.js
similarity index 82%
rename from web/js/util/wv.util.events.js
rename to web/js/util/events.js
index 3ea4fc0ba..becc3c65f 100644
--- a/web/js/util/wv.util.events.js
+++ b/web/js/util/events.js
@@ -1,7 +1,6 @@
-var wv = wv || {};
-wv.util = wv.util || {};
+import { each, pull } from 'lodash';
-wv.util.events = wv.util.events || function () {
+export default function () {
var self = {};
// Object of event types. Each event type is an array of listeners.
@@ -24,7 +23,7 @@ wv.util.events = wv.util.events || function () {
self.off = function (event, callback) {
var listeners = events[event];
if (listeners) {
- _.pull(listeners, callback);
+ pull(listeners, callback);
}
return self;
};
@@ -42,10 +41,10 @@ wv.util.events = wv.util.events || function () {
return;
}
var eventArguments = Array.prototype.slice.call(arguments, 1);
- _.each(events[event], function (listener) {
+ each(events[event], function (listener) {
listener.apply(self, eventArguments);
});
- _.each(allListeners, function (listener) {
+ each(allListeners, function (listener) {
listener.apply(self, eventArguments);
});
return self;
diff --git a/web/js/util/wv.util.load.js b/web/js/util/load.js
similarity index 70%
rename from web/js/util/wv.util.load.js
rename to web/js/util/load.js
index e78f9bdad..e5ba0b2f6 100644
--- a/web/js/util/wv.util.load.js
+++ b/web/js/util/load.js
@@ -1,7 +1,9 @@
-var wv = wv || {};
-wv.util = wv.util || {};
+import $ from 'jquery';
+import { size } from 'lodash';
+import { default as uiUtils } from '../ui/ui.js';
+import { default as brand } from '../brand.js';
-wv.util.load = wv.util.load || (function () {
+export default (function () {
var self = {};
var configPromises = {};
var loading = 0;
@@ -16,14 +18,14 @@ wv.util.load = wv.util.load || (function () {
.fail(promise.reject);
return promise;
}
- if (root[attr] && _.size(root[attr]) > 0) {
+ if (root[attr] && size(root[attr]) > 0) {
promise.resolve(root[attr]);
} else {
loading += 1;
- promise = $.getJSON(wv.brand.url(url));
+ promise = $.getJSON(brand.url(url));
if (loading === 1) {
indicatorTimeout = setTimeout(function () {
- indicatorId = wv.ui.indicator.loading();
+ indicatorId = uiUtils.indicator.loading();
}, 2000);
}
promise.done(function (result) {
@@ -35,10 +37,10 @@ wv.util.load = wv.util.load || (function () {
if (loading === 0) {
clearTimeout(indicatorTimeout);
indicatorTimeout = null;
- wv.ui.indicator.hide(indicatorId);
+ uiUtils.indicator.hide(indicatorId);
}
})
- .fail(wv.util.error);
+ .fail(uiUtils.error);
configPromises[url] = promise;
}
diff --git a/web/js/util/wv.util.js b/web/js/util/util.js
similarity index 96%
rename from web/js/util/wv.util.js
rename to web/js/util/util.js
index a9697162e..579bd6665 100644
--- a/web/js/util/wv.util.js
+++ b/web/js/util/util.js
@@ -1,16 +1,21 @@
-/**
- * @module wv.util
- */
-var wv = wv || {};
-
-/**
- * General utilities
- *
- * @class wv.util
- * @static
- */
-wv.util = (function (self) {
+/* global ntptEventTag */
+
+import $ from 'jquery';
+import { each, isNull } from 'lodash';
+import { default as uiUtils } from '../ui/ui.js';
+import { default as browser } from './browser.js';
+import { default as events } from './events.js';
+import { default as load } from './load.js';
+
+export default (function () {
+ var self = {};
var canvas = null;
+
+ // Export other util methods
+ self.browser = browser;
+ self.events = events;
+ self.load = load;
+
// Needed anymore?
self.LAYER_GROUPS = {
baselayers: {
@@ -104,9 +109,9 @@ wv.util = (function (self) {
self.toQueryString = function (kvps, exceptions) {
exceptions = exceptions || {};
var parts = [];
- _.each(kvps, function (value, key) {
+ each(kvps, function (value, key) {
var part = key + '=' + encodeURIComponent(value);
- _.each(exceptions, function (exception) {
+ each(exceptions, function (exception) {
var regexp = new RegExp(exception, 'ig');
var decoded = decodeURIComponent(exception);
part = part.replace(regexp, decoded);
@@ -446,7 +451,7 @@ wv.util = (function (self) {
day = daysInMonth;
}
var newDate = new Date(Date.UTC(year, month, day));
- newDate = new Date(wv.util.clamp(newDate, minDate, maxDate));
+ newDate = new Date(self.clamp(newDate, minDate, maxDate));
return newDate;
};
@@ -475,7 +480,7 @@ wv.util = (function (self) {
*/
self.fromCompactTimestamp = function (str) {
var v = str.match(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{3})/);
- if (_.isNull(v)) {
+ if (isNull(v)) {
throw new Error('Invalid timestamp:' + str);
}
return new Date(Date.UTC(
@@ -530,7 +535,7 @@ wv.util = (function (self) {
* @param {Exception} cause The exception object that caused the error
*/
self.error = function (message, cause) {
- wv.ui.error(message, cause);
+ uiUtils.error(message, cause);
};
/**
@@ -638,7 +643,7 @@ wv.util = (function (self) {
try {
return func.apply(func, arguments);
} catch (error) {
- wv.util.error(error);
+ self.error(error);
}
};
};
@@ -742,7 +747,7 @@ wv.util = (function (self) {
};
self.setCoordinateFormat = function (type) {
- if (!wv.util.browser.localStorage) return;
+ if (!browser.localStorage) return;
if (type !== 'latlon-dd' && type !== 'latlon-dms') {
throw new Error('Invalid coordinate format: ' + type);
}
@@ -750,7 +755,7 @@ wv.util = (function (self) {
};
self.getCoordinateFormat = function () {
- if (!wv.util.browser.localStorage) return 'latlon-dd';
+ if (!browser.localStorage) return 'latlon-dd';
return localStorage.getItem('coordinateFormat') || 'latlon-dd';
};
@@ -786,4 +791,4 @@ wv.util = (function (self) {
};
return self;
-})(wv.util || {});
+})();
diff --git a/web/js/util/wv.util.browser.js b/web/js/util/wv.util.browser.js
deleted file mode 100644
index 029a80382..000000000
--- a/web/js/util/wv.util.browser.js
+++ /dev/null
@@ -1,438 +0,0 @@
-/**
- * @module wv.util
- */
-var wv = wv || {};
-wv.util = wv.util || {};
-
-/**
- * Feature detection and user-agent sniffing for web browser.
- *
- * Including this script will also install polyfills and work around
- * browser quirks as needed.
- *
- * @class wv.util.browser
- * @static
- */
-wv.util.browser = wv.util.browser || (function () {
- var self = {};
-
- /**
- * True if Internet Explorer was detected in the user-agent string.
- *
- * @attribute ie
- * @type Boolean
- */
- self.ie = false;
-
- /**
- * True if Safari was detected in the user-agent string.
- *
- * @attribute safari
- * @type Boolean
- */
- self.safari = false;
-
- self.firefox = false;
-
- /**
- * Major version number of the browser detected in the user-agent string.
- * If the version is not important for Worldview at the moment, this
- * value will be null.
- *
- * @attribute version
- * @type Number
- */
- self.version = null;
-
- /**
- * True if the screen size is small enough (width less than 740px) to
- * require special mobile device behavior.
- *
- * @attribute small
- * @type Boolean
- */
- self.small = false;
- self.constrained = false;
-
- /**
- * True if this browser properly supports cross-origin resource
- * sharing.
- *
- * @attribute cors
- * @type Boolean
- */
- self.cors = true;
-
- /**
- * True if this browser properly supports web workers.
- *
- * @attribute webWorkers
- * @type Boolean
- */
- self.webWorkers = true;
-
- /**
- * True if local storage is available in the browser. This will return
- * false if local storage is supported, but cannot be used because
- * it is running in private mode.
- *
- * @attribute localStorage
- * @type Boolean
- */
- self.localStorage = false;
- self.history = true;
- self.touchDevice = false;
-
- self.mobileWidth = 740;
- self.constrainedHeight = 320;
-
- var init = function () {
- var tests = self.tests;
-
- if (tests.safari()) {
- self.safari = true;
- self.version = tests.safariVersion();
- } else if (tests.ie()) {
- self.ie = true;
- self.version = tests.ieVersion();
- } else if (tests.firefox()) {
- self.firefox = true;
- }
-
- self.cors = tests.cors();
- self.webWorkers = tests.webWorkers();
- self.localStorage = tests.localStorage();
- self.small = tests.small();
- self.history = tests.history();
- self.touchDevice = tests.touchDevice();
-
- var onResize = function () {
- self.small = tests.small();
- self.constrained = tests.constrained();
- };
- $(window)
- .on('resize', onResize);
- $(function () {
- onResize();
- });
- };
-
- // The following functions should not be used directly. Use the values
- // set in the init function. These functions are useful for testing.
- self.tests = {};
-
- self.tests.navigator = function () {
- return navigator;
- };
-
- self.tests.window = function (property) {
- // Some browsers throw an error when attempting to access restricted Window objects
- try {
- return window[property];
- } catch (error) {
- return false;
- }
- };
-
- self.tests.safari = function () {
- var navigator = self.tests.navigator();
- if (/ Chrome\//.test(navigator.userAgent)) {
- return false;
- }
- return (/ Safari\//)
- .test(navigator.userAgent);
- };
-
- self.tests.safariVersion = function () {
- var navigator = self.tests.navigator();
- var version = navigator.userAgent.match(/ Version\/([^ ]+)/);
- if (version) {
- return parseInt(version[1].split('.')[0]);
- }
- };
-
- self.tests.ie = function () {
- var navigator = self.tests.navigator();
- if (/MSIE /.test(navigator.userAgent)) {
- return true;
- }
- // IE 11
- return navigator.appName === 'Netscape' && /Trident/.test(navigator.userAgent);
- };
-
- self.tests.firefox = function () {
- return navigator.userAgent.toLowerCase()
- .indexOf('firefox') > -1;
- };
-
- self.tests.touchDevice = function () {
- var el = document.createElement('div');
- el.setAttribute('ontouchstart', 'return;');
- return typeof el.ontouchstart === 'function';
- };
-
- self.tests.ieVersion = function () {
- var navigator = self.tests.navigator();
- var version = navigator.userAgent.match(/MSIE ([\d\.]+)/);
- if (version) {
- return parseInt(version[1].split('.')[0]);
- }
- };
-
- self.tests.cors = function () {
- if (self.tests.safari() && self.tests.safariVersion() <= 6) {
- return false;
- }
- return !self.tests.ie();
- };
-
- self.tests.webWorkers = function () {
- return self.tests.window('Worker');
- };
-
- self.tests.localStorage = function () {
- if (!self.tests.window('localStorage')) {
- return false;
- }
- try {
- var uid = new Date();
- var result;
- localStorage.setItem(uid, uid);
- result = localStorage.getItem(uid) == uid;
- localStorage.removeItem(uid);
- return result && true;
- } catch (error) {
- return false;
- }
- };
-
- self.tests.small = function () {
- return $(window)
- .width() < self.mobileWidth;
- };
-
- self.tests.constrained = function () {
- return $(window)
- .height() < self.constrainedHeight;
- };
-
- self.tests.history = function () {
- return window.history && window.history.replaceState;
- };
-
- init();
- return self;
-})();
-
-// ===========================================================================
-// Polyfills and browser quirks
-// ===========================================================================
-
-/*
- * Date.toISOString
- *
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
- */
-if (!Date.prototype.toISOString) {
- (function () {
- function pad (number) {
- if (number < 10) {
- return '0' + number;
- }
- return number;
- }
-
- Date.prototype.toISOString = function () {
- return this.getUTCFullYear() +
- '-' + pad(this.getUTCMonth() + 1) +
- '-' + pad(this.getUTCDate()) +
- 'T' + pad(this.getUTCHours()) +
- ':' + pad(this.getUTCMinutes()) +
- ':' + pad(this.getUTCSeconds()) +
- '.' + (this.getUTCMilliseconds() / 1000)
- .toFixed(3)
- .slice(2, 5) +
- 'Z';
- };
- }());
-}
-
-/*
- * console
- */
-if (!window.console) {
- (function () {
- window.console = {
- log: function () {},
- warn: function () {},
- info: function () {},
- error: function () {}
- };
- })();
-}
-
-/*
- * Get rid of address bar on iphone/ipod
- */
-(function () {
- var execute = function () {
- window.scrollTo(0, 0);
- if (document.body) {
- document.body.style.height = '100%';
- if (!(/(iphone|ipod)/.test(navigator.userAgent.toLowerCase()))) {
- if (document.body.parentNode) {
- document.body.parentNode.style.height = '100%';
- }
- }
- }
- };
- setTimeout(execute, 700);
- setTimeout(execute, 1500);
-})();
-
-/*
- * Hide the URL bar
- */
-(function () {
- window.scrollTo(0, 0);
-})();
-
-/*
- * setTimeout that properly sets this and allows arguments. The only case where
- * this is helpful at the moment is IE9 -- only attempt to do this in that case
- *
- * https://developer.mozilla.org/en-US/docs/Web/API/Window.setTimeout
- */
-if (wv.util.browser.ie && wv.util.browser.version <= 9) {
- (function () {
- var __nativeST__ = window.setTimeout,
- __nativeSI__ = window.setInterval;
-
- window.setTimeout = function (vCallback, nDelay /*, argumentToPass1, argumentToPass2, etc. */) {
- var oThis = this,
- aArgs = Array.prototype.slice.call(arguments, 2);
- return __nativeST__(vCallback instanceof Function ? function () {
- vCallback.apply(oThis, aArgs);
- } : vCallback, nDelay);
- };
-
- window.setInterval = function (vCallback, nDelay /*, argumentToPass1, argumentToPass2, etc. */) {
- var oThis = this,
- aArgs = Array.prototype.slice.call(arguments, 2);
- return __nativeSI__(vCallback instanceof Function ? function () {
- vCallback.apply(oThis, aArgs);
- } : vCallback, nDelay);
- };
- })();
-}
-
-/*
- * String.contains
- *
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/contains
- */
-if (!('contains' in String.prototype)) {
- (function () {
- String.prototype.contains = function (str, startIndex) {
- return String.prototype.indexOf.call(this, str,
- startIndex) !== -1;
- };
- })();
-}
-
-/*
- * String.startsWith
- *
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
- */
-if (!String.prototype.startsWith) {
- (function () {
- Object.defineProperty(String.prototype, 'startsWith', {
- enumerable: false,
- configurable: false,
- writable: false,
- value: function (searchString, position) {
- position = position || 0;
- return this.indexOf(searchString, position) === position;
- }
- });
- })();
-}
-
-/*
- * String.endsWith
- *
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
- */
-if (!String.prototype.endsWith) {
- (function () {
- Object.defineProperty(String.prototype, 'endsWith', {
- enumerable: false,
- configurable: false,
- writable: false,
- value: function (searchString, position) {
- position = position || this.length;
- position = position - searchString.length;
- var lastIndex = this.lastIndexOf(searchString);
- return lastIndex !== -1 && lastIndex === position;
- }
- });
- })();
-}
-
-/*
- * Mobile device quirks. This section is mostly overwriting things that jquery.mobile is adding
- */
-(function () {
- if (navigator.userAgent.match(/Android/i) ||
- navigator.userAgent.match(/webOS/i) ||
- navigator.userAgent.match(/iPhone/i) ||
- navigator.userAgent.match(/iPad/i) ||
- navigator.userAgent.match(/iPod/i) ||
- navigator.userAgent.match(/BlackBerry/i) ||
- navigator.userAgent.match(/Windows Phone/i)
- ) {
- mobile = true;
- if (!(window.orientation == 90 || window.orientation == -90)) {
- portrait = true;
- }
- }
-
- if (navigator.userAgent.indexOf('iPhone') != -1 || navigator.userAgent.indexOf('Android') != -1) {
- // In Safari, the true version is after "Safari"
- if (navigator.userAgent.indexOf('Safari') != -1) {
- // Set a variable to use later
- mobileSafari = true;
- }
- addEventListener('load', function () {
- if (mobile) {
- $('.layerPicker a[href=\'#DataDownload\']')
- .hide();
- }
- setHeight();
- window.scrollTo(0, 1);
- $('#app, .ui-mobile, .ui-mobile .ui-page')
- .css('min-height', 0);
- }, false);
- addEventListener('orientationchange', function () {
- window.scrollTo(0, 1);
- setHeight();
- }, false);
- }
-
- // Set the div height
- function setHeight ($body) {
- if (navigator.userAgent.match(/(iPad|iPhone|iPod touch);.*CPU.*OS 6_\d/i)) {
- var new_height = $(window)
- .height();
- // if mobileSafari 6 add +60px
- new_height += 60;
- $('#app')
- .css('min-height', 0)
- .css('height', new_height);
- } else {
- $('#app, .ui-mobile, .ui-mobile .ui-page')
- .css('min-height', 0);
- }
- }
-})();
diff --git a/web/js/wv.main.js b/web/js/wv.main.js
index 51ecc6ef0..6a4fb01b7 100644
--- a/web/js/wv.main.js
+++ b/web/js/wv.main.js
@@ -75,6 +75,9 @@ import {debugConfig, debug} from './debug';
import Brand from './brand';
import Tour from './tour';
+import { default as polyfill } from './polyfill';
+polyfill(); // Polyfills some browser features
+
// Document ready function
window.onload = () => {
var errors = [];