Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Support to wv.util.browser

Mike McGann2570f23afe13
diff --git a/buster.js b/buster.js
index 89a634375..2a94042c8 100644
--- a/buster.js
+++ b/buster.js
@@ -20,7 +20,13 @@ config["wv"] = {
"src/ext/wv.main/jscache-gitba01cdc/cache.js",
],
src: [
- "src/js/**/wv.*.js"
+ "src/js/wv.*.js",
+ "src/js/util/wv.*.js",
+ "src/js/date/wv.*.js",
+ "src/js/layers/wv.*.js",
+ "src/js/link/wv.*.js",
+ "src/js/palette/wv.*.js",
+ "src/js/proj/wv.*.js",
],
tests: [
"test/**/*.js"
diff --git a/etc/deploy/wv.js.json b/etc/deploy/wv.js.json
index 2594e82d2..254dccfa6 100644
--- a/etc/deploy/wv.js.json
+++ b/etc/deploy/wv.js.json
@@ -1,6 +1,4 @@
[
- "src/js/util/wv.util.polyfill.js",
-
"src/js/Date.js",
"src/js/Logging.js",
@@ -11,24 +9,46 @@
"src/js/events.js",
"src/js/wv.brand.js",
+
"src/js/util/wv.util.js",
+ "src/js/util/wv.util.browser.js",
"src/js/util/wv.util.events.js",
+
"src/js/ui/wv.ui.js",
"src/js/ui/wv.ui.about.js",
+ "src/js/ui/wv.ui.indicator.js",
+
+ "src/js/proj/wv.proj.model.js",
+ "src/js/proj/wv.proj.ui.js",
+
+ "src/js/date/wv.date.model.js",
+ "src/js/date/wv.date.sliders.js",
+ "src/js/date/wv.date.label.js",
+ "src/js/date/wv.date.wheels.js",
+
+ "src/js/layers/wv.layers.model.js",
+ "src/js/layers/wv.layers.sidebar.js",
+ "src/js/layers/wv.layers.active.js",
+ "src/js/layers/wv.layers.add.js",
+
+ "src/js/palette/wv.palette.js",
+ "src/js/palette/wv.palette.model.js",
+
+ "src/js/link/wv.link.model.js",
+ "src/js/link/wv.link.ui.js",
+
+ "src/js/legacy/wv.legacy.switch_.js",
+ "src/js/legacy/wv.legacy.bank.js",
+ "src/js/legacy/wv.legacy.date.js",
+
"src/js/Worldview.js",
"src/js/Worldview/Support.js",
"src/js/Worldview/Support.js",
- "src/js/link/wv.link.model.js",
"src/js/Worldview/Scheduler.js",
"src/js/Worldview/Indicator.js",
"src/js/Worldview/AjaxCache.js",
"src/js/Worldview/AjaxJoin.js",
- "src/js/date/wv.date.model.js",
- "src/js/layers/wv.layers.model.js",
- "src/js/proj/wv.proj.model.js",
- "src/js/palette/wv.palette.model.js",
-
"src/js/Worldview/Palette.js",
"src/js/Worldview/Palette/ColorBar.js",
"src/js/Worldview/Palette/Palette.js",
@@ -97,13 +117,6 @@
"src/js/Worldview/DataDownload/DownloadListPanel.js",
"src/js/Worldview/DataDownload/BulkDownloadPage.js",
- "src/js/proj/wv.proj.ui.js",
- "src/js/layers/wv.layers.sidebar.js",
- "src/js/layers/wv.layers.active.js",
- "src/js/layers/wv.layers.add.js",
- "src/js/date/wv.date.sliders.js",
- "src/js/date/wv.date.label.js",
- "src/js/date/wv.date.wheels.js",
"src/js/Worldview/Widget/Map.js",
"src/js/Worldview/Widget/Palette.js",
"src/js/Worldview/Widget/WorldviewMap.js",
@@ -111,11 +124,6 @@
"src/js/Worldview/Widget/Opacity.js",
"src/js/Worldview/Widget/CRS.js",
"src/js/Worldview/Widget/DataDownload.js",
- "src/js/link/wv.link.ui.js",
-
- "src/js/legacy/wv.legacy.switch_.js",
- "src/js/legacy/wv.legacy.bank.js",
- "src/js/legacy/wv.legacy.date.js",
"src/js/tour.js",
"src/js/main.js"
diff --git a/src/index.html b/src/index.html
index 913c649cb..0c534a99f 100644
--- a/src/index.html
+++ b/src/index.html
@@ -113,8 +113,6 @@
<!-- link.prod --> <!-- <script type="text/javascript" src="js/wv.js?v=20131218215115174&mobile"></script> -->
- <!-- link.dev --> <script type="text/javascript" src="js/util/wv.util.polyfill.js"></script>
-
<!-- link.dev --> <script type="text/javascript" src="js/Logging.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Date.js"></script>
@@ -125,24 +123,43 @@
<!-- link.dev --> <script type="text/javascript" src="js/events.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/wv.brand.js"></script>
+
<!-- link.dev --> <script type="text/javascript" src="js/util/wv.util.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/util/wv.util.browser.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/util/wv.util.events.js"></script>
+
<!-- link.dev --> <script type="text/javascript" src="js/ui/wv.ui.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/ui/wv.ui.about.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/ui/wv.ui.indicator.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Support.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Scheduler.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/link/wv.link.model.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/AjaxCache.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/AjaxJoin.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/proj/wv.proj.model.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/proj/wv.proj.ui.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.model.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/proj/wv.proj.model.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.sliders.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.label.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.wheels.js"></script>
+
<!-- link.dev --> <script type="text/javascript" src="js/layers/wv.layers.model.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/layers/wv.layers.sidebar.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/layers/wv.layers.active.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/layers/wv.layers.add.js"></script>
+
+ <!-- link.dev --> <script type="text/javascript" src="js/palette/wv.palette.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/palette/wv.palette.model.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/link/wv.link.model.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/link/wv.link.ui.js"></script>
+
+ <!-- link.dev --> <script type="text/javascript" src="js/legacy/wv.legacy.switch_.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/legacy/wv.legacy.bank.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/legacy/wv.legacy.date.js"></script>
+
+ <!-- link.dev --> <script type="text/javascript" src="js/Worldview.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Scheduler.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/Worldview/AjaxCache.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/Worldview/AjaxJoin.js"></script>
+
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Palette.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Palette/ColorBar.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Palette/Palette.js"></script>
@@ -211,13 +228,6 @@
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/DownloadListPanel.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/BulkDownloadPage.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/proj/wv.proj.ui.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/layers/wv.layers.sidebar.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/layers/wv.layers.active.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/layers/wv.layers.add.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.sliders.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.label.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.wheels.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Widget/Map.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Widget/Palette.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Widget/WorldviewMap.js"></script>
@@ -225,11 +235,6 @@
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Widget/Opacity.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Widget/CRS.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Widget/DataDownload.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/link/wv.link.ui.js"></script>
-
- <!-- link.dev --> <script type="text/javascript" src="js/legacy/wv.legacy.switch_.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/legacy/wv.legacy.bank.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/legacy/wv.legacy.date.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/tour.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/main.js"></script>
diff --git a/src/js/Worldview/Support.js b/src/js/Worldview/Support.js
deleted file mode 100644
index 92da86c19..000000000
--- a/src/js/Worldview/Support.js
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * NASA Worldview
- *
- * This code was originally developed at NASA/Goddard Space Flight Center for
- * the Earth Science Data and Information System (ESDIS) project.
- *
- * Copyright (C) 2013 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-Worldview.namespace("Support");
-
-(function(ns) {
-
- var log = Logging.getLogger();
- var mobileSafari = false;
-
- ns.BROWSER = null;
- ns.VERSION = [];
-
- ns.allowCustomPalettes = function() {
- var result = true;
- var reason = "";
-
- if ( !window.Worker ) {
- result = false;
- reason = "No Web Workers";
- } else if ( ns.BROWSER === "Safari" && ns.VERSION[0]
- && ns.VERSION[0] < 6 ) {
- result = false;
- reason = "Safari version 6 required";
- } else if ( ns.BROWSER === "IE" ) {
- result = false;
- reason = "IE Unsupported";
- }
- if ( !result ) {
- log.warn("Custom palettes are not supported: " + reason);
- }
- return result;
- };
-
- ns.showUnsupportedMessage = function(featureName) {
- var prefix;
- if ( !featureName ) {
- prefix = "This feature";
- } else {
- prefix = "The " + featureName + " feature";
- }
- wv.ui.notify(prefix + " is not supported with your web " +
- "browser. Upgrade or try again in a different browser.");
- };
-
- ns.quirks = function() {
- jQueryLayerFix();
- shimConsole();
- checkMobile();
- fixSize();
- modernSetTimeout();
- polyfillStringContains();
- polyfillStringStartsWith();
- };
-
- var init = function() {
- if ( / Safari\//.test(navigator.userAgent) ) {
- ns.BROWSER = "Safari";
- var version = navigator.userAgent.match(/ Version\/([^ ]+)/);
- if ( version ) {
- ns.VERSION = version[1].split(".");
- }
- } else if ( navigator.appName == 'Microsoft Internet Explorer' ) {
- ns.BROWSER = "IE";
- }
- };
-
- /*
- * jQuery version 1.6 causes thousands of warnings to be emitted to the
- * console on WebKit based browsers with the following message:
- *
- * event.layerX and event.layerY are broken and deprecated in WebKit. They
- * will be removed from the engine in the near future.
- *
- * This has been fixed in jQuery 1.8 but Worldview currently doesn't
- * support that version. This fix copied from:
- *
- * http://stackoverflow.com/questions/7825448/webkit-issues-with-event-layerx-and-event-layery
- */
- var jQueryLayerFix = function() {
- // remove layerX and layerY
- var all = $.event.props,
- len = all.length,
- res = [];
- while (len--) {
- var el = all[len];
- if (el != 'layerX' && el != 'layerY') res.push(el);
- }
- $.event.props = res;
- };
-
- var shimConsole = function() {
- if ( !window.console ) {
- window.console = {
- log: function() {}
- };
- }
- };
-
- // Get rid of address bar on iphone/ipod
- var fixSize = function() {
- var execute = function() {
- window.scrollTo(0,0);
- 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);
- };
-
- var hideURLbar = function() {
- window.scrollTo(0, 0);
- };
-
- var checkMobile = function() {
- 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() {
- setTimeout(hideURLbar, 0);
- }, false);
- addEventListener("orientationchange", function() {
- setTimeout(hideURLbar, 0);
- }, false);
- }
-
- // Set the div height
- function setHeight($body) {
- if (navigator.userAgent.match(/(iPad|iPhone|iPod touch);.*CPU.*OS 7_\d/i)){
- $("div#app.ui-page.ui-body-c.ui-page-active").css("min-height", 0);
- }
- else {
- var new_height = $(window).height();
- // if mobileSafari add +60px
- new_height += 60;
- $body.css('min-height', 0 );
- $body.css('height', new_height );
- }
- }
- if (navigator.userAgent.match(/(iPad|iPhone|iPod touch);.*CPU.*OS 7_\d/i)){
- setHeight( $('#app') );
- $(window).resize(function() {
- setHeight($('#app'));
- });
- }
-
-
- };
-
- var modernSetTimeout = function() {
- // From https://developer.mozilla.org/en-US/docs/Web/API/Window.setTimeout
-
- // The only case where this is helpful at the moment is IE9 -- only
- // attempt to do this in that case
- if ( ns.BROWSER === "IE" && ns.VERSION <= 9 ) {
-
- 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);
- };
- }
- };
-
- var polyfillStringContains = function(){
- if ( ! ('contains' in String.prototype) ) {
- String.prototype.contains = function(str, startIndex) {
- return -1 !== String.prototype.indexOf.call(this, str,
- startIndex);
- };
- };
- };
-
- var polyfillStringStartsWith = function() {
- if (!String.prototype.startsWith) {
- Object.defineProperty(String.prototype, 'startsWith', {
- enumerable: false,
- configurable: false,
- writable: false,
- value: function (searchString, position) {
- position = position || 0;
- return this.indexOf(searchString, position) === position;
- }
- });
- }
- };
-
-
- init();
-
-})(Worldview.Support);
diff --git a/src/js/Worldview/Widget/Palette.js b/src/js/Worldview/Widget/Palette.js
index 62a9d4c8d..b34b4c0ea 100644
--- a/src/js/Worldview/Widget/Palette.js
+++ b/src/js/Worldview/Widget/Palette.js
@@ -133,8 +133,8 @@ Worldview.Widget.Palette = function(config, model, spec) {
self.loadFromQuery = function(queryString) {
var query = Worldview.queryStringToObject(queryString);
log.debug("Palette: loadFromQuery", query);
- if ( query.palettes && !Worldview.Support.allowCustomPalettes() ) {
- Worldview.Support.showUnsupportedMessage("custom palette");
+ if ( query.palettes && !wv.palette.supported ) {
+ wv.ui.unsupported("custom palette");
} else {
self.setValue(query.palettes);
}
diff --git a/src/js/date/wv.date.sliders.js b/src/js/date/wv.date.sliders.js
index d44080a7e..6666a3d7e 100644
--- a/src/js/date/wv.date.sliders.js
+++ b/src/js/date/wv.date.sliders.js
@@ -58,7 +58,7 @@ wv.date.sliders = wv.date.sliders || function(models, config) {
};
var render = function() {
- if ( wv.ui.mobile() ) {
+ if ( wv.util.browser.small ) {
$("#timeds").css("display","none");
}
$container.addClass("datespan");
@@ -248,7 +248,7 @@ wv.date.sliders = wv.date.sliders || function(models, config) {
};
var refreshSliders = function() {
- if ( wv.ui.mobile() ) {
+ if ( wv.util.browser.small ) {
$container.hide();
} else {
$container.show();
diff --git a/src/js/date/wv.date.wheels.js b/src/js/date/wv.date.wheels.js
index 3a0a9e4fb..f5498440b 100644
--- a/src/js/date/wv.date.wheels.js
+++ b/src/js/date/wv.date.wheels.js
@@ -71,7 +71,7 @@ wv.date.wheels = wv.date.wheels || function(models, config) {
};
var resize = function() {
- if ( wv.ui.mobile() ) {
+ if ( wv.util.browser.small ) {
$container.show();
} else {
$container.hide();
diff --git a/src/js/layers/wv.layers.active.js b/src/js/layers/wv.layers.active.js
index e0a111814..466847af1 100644
--- a/src/js/layers/wv.layers.active.js
+++ b/src/js/layers/wv.layers.active.js
@@ -351,8 +351,8 @@ wv.layers.active = wv.layers.active || function(models, config, spec) {
var openPaletteSelector = function(event) {
var $target = $(event.target);
- if ( !Worldview.Support.allowCustomPalettes() ) {
- Worldview.Support.showUnsupportedMessage();
+ if ( !wv.palette.supported ) {
+ wv.ui.unsupported();
} else {
paletteWidget.displaySelector($target.attr("data-layer"));
}
diff --git a/src/js/main.js b/src/js/main.js
index 65ae56af4..1857ffe3e 100644
--- a/src/js/main.js
+++ b/src/js/main.js
@@ -1,25 +1,8 @@
$(function() {// Initialize "static" vars
- var log = Logging.getLogger();
-
- // Place all logging needed on startup here. This should be emptied before
- // release
- var DEBUG_LOGGERS = [
- ];
-
- $.each(DEBUG_LOGGERS, function(index, name) {
- log.warn("Enabling logger:", name);
- Logging.debug(name);
- });
-
var loaded = false;
var entryPoint = function() {
-
- // Place any quirky browser related items in the function called
- // below.
- Worldview.Support.quirks();
-
// Place any resources that should be completely loaded before
// starting up the UI
var configURI = "data/config.json?v=" + wv.brand.BUILD_NONCE;
@@ -43,7 +26,7 @@ $(function() {// Initialize "static" vars
if ( config.parameters.loadDelay ) {
var delay = parseInt(config.parameters.loadDelay);
- log.warn("Delaying load for " + delay + " ms");
+ console.warn("Delaying load for " + delay + " ms");
setTimeout(function() {
init(config);
}, parseInt(config.parameters.loadDelay));
@@ -268,7 +251,7 @@ $(function() {// Initialize "static" vars
console.info(wv.brand.NAME + " - Version " + wv.brand.VERSION +
" - " + wv.brand.BUILD_TIMESTAMP);
} else {
- log.warn("Development version");
+ console.warn("Development version");
}
// Do not start the tour if coming in via permalink
@@ -287,9 +270,9 @@ $(function() {// Initialize "static" vars
try {
var now = Date.parseISOString(config.parameters.now);
Worldview.overrideNow(now);
- log.warn("Overriding now: " + now.toISOString());
+ console.warn("Overriding now: " + now.toISOString());
} catch ( error ) {
- log.error("Invalid now: " + query.now, error);
+ console.error("Invalid now: " + query.now, error);
}
}
diff --git a/src/js/palette/wv.palette.js b/src/js/palette/wv.palette.js
new file mode 100644
index 000000000..a953e3145
--- /dev/null
+++ b/src/js/palette/wv.palette.js
@@ -0,0 +1,31 @@
+/*
+ * NASA Worldview
+ *
+ * This code was originally developed at NASA/Goddard Space Flight Center for
+ * the Earth Science Data and Information System (ESDIS) project.
+ *
+ * Copyright (C) 2013 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+/**
+ * @module wv.palette
+ */
+var wv = wv || {};
+
+wv.palette = (function(self) {
+
+ self.supported = true;
+
+ var init = function() {
+ var browser = wv.util.browser;
+ if ( browser.ie || !browser.webWorkers || !browser.cors ) {
+ self.supported = false;
+ }
+ };
+
+ init();
+ return self;
+
+})(wv.palette || {});
diff --git a/src/js/tour.js b/src/js/tour.js
index 0e0a68a2d..cbab33259 100644
--- a/src/js/tour.js
+++ b/src/js/tour.js
@@ -14,14 +14,9 @@ Worldview.namespace("Tour");
* Create the splash screen and tour panels and control iteration over them.
*/
ns.start = function(storageEngine, hideSplash, noDisable) {
-
- var browser = Worldview.Support.BROWSER;
- var version = Worldview.Support.VERSION;
- if (browser === "IE" && version <= 9) {
+ if ( wv.util.browser.ie && wv.util.browser.version <= 9) {
if (noDisable) {
- wv.ui.notify("The Worldivew tour is not supported in " +
- "this browser version. Upgrade or try again in a " +
- "different browser.");
+ wv.ui.unsupported("tour");
}
return;
}
diff --git a/src/js/ui/wv.ui.about.js b/src/js/ui/wv.ui.about.js
index 489d1f9eb..6fc9c8dc5 100644
--- a/src/js/ui/wv.ui.about.js
+++ b/src/js/ui/wv.ui.about.js
@@ -35,7 +35,7 @@ wv.ui.about = wv.ui.about || (function() {
* @method show
*/
self.show = function() {
- if ( wv.ui.mobile() ) {
+ if ( wv.util.browser.small ) {
showMobile();
} else {
showDesktop();
diff --git a/src/js/ui/wv.ui.js b/src/js/ui/wv.ui.js
index dff915dd5..2ce4835be 100644
--- a/src/js/ui/wv.ui.js
+++ b/src/js/ui/wv.ui.js
@@ -22,18 +22,6 @@ var wv = wv || {};
*/
wv.ui = (function(self) {
- /**
- * Determines if the UI should use a compact mobile layout.
- *
- * @method mobile
- * @static
- * @return {Boolean} true if the window width is less than 720 pixels,
- * otherwise returns false.
- */
- self.mobile = function() {
- return $(window).width() < 720;
- };
-
/**
* General error handler.
*
@@ -107,6 +95,28 @@ wv.ui = (function(self) {
}
};
+ /**
+ * Displays a message to the end user that the feature is not supported
+ * in this web browser.
+ *
+ * @method unsupported
+ * @static
+ *
+ * @param {String} [featureName] If specified, the message will state
+ * "The <featureName> feature is not supported...". Otherwise it will
+ * state "This feature..."
+ */
+ self.unsupported = function(featureName) {
+ var prefix;
+ if ( !featureName ) {
+ prefix = "This feature";
+ } else {
+ prefix = "The " + featureName + " feature";
+ }
+ wv.ui.notify(prefix + " is not supported with your web " +
+ "browser. Upgrade or try again in a different browser.");
+ };
+
return self;
})(wv.ui || {});
\ No newline at end of file
diff --git a/src/js/util/wv.util.browser.js b/src/js/util/wv.util.browser.js
new file mode 100644
index 000000000..10ce43555
--- /dev/null
+++ b/src/js/util/wv.util.browser.js
@@ -0,0 +1,373 @@
+/*
+ * NASA Worldview
+ *
+ * This code was originally developed at NASA/Goddard Space Flight Center for
+ * the Earth Science Data and Information System (ESDIS) project.
+ *
+ * Copyright (C) 2013 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+/**
+ * @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;
+
+ /**
+ * 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 Integer
+ */
+ self.version = null;
+
+ /**
+ * True if the screen size is small enough (width less than 720px) to
+ * require special mobile device behavior.
+ *
+ * @attribute small
+ * @type Boolean
+ */
+ self.small = 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 = true;
+
+ 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();
+ }
+
+ self.cors = tests.cors();
+ self.webWorkers = tests.webWorkers();
+ self.localStorage = tests.localStorage();
+ self.small = tests.small();
+
+ $(window).resize(function() {
+ self.small = tests.small();
+ });
+ };
+
+ // 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) {
+ return window[property];
+
+ };
+
+ 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();
+ return /\(MSIE /.test(navigator.userAgent);
+ };
+
+ 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 true;
+ };
+
+ self.tests.webWorkers = function() {
+ if ( !self.tests.window("Worker") ) { return false; }
+ return true;
+ };
+
+ self.tests.localStorage = function() {
+ if ( !self.tests.window("localStorage") ) { return false; }
+ try { localStorage.getItem("item"); } catch ( error ) { return false; }
+ return true;
+ };
+
+ self.tests.small = function() {
+ return $(window).width() < 720;
+ };
+
+ 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() {}
+ };
+ })();
+}
+
+/*
+ * jQuery version 1.6 causes thousands of warnings to be emitted to the
+ * console on WebKit based browsers with the following message:
+ *
+ * event.layerX and event.layerY are broken and deprecated in WebKit. They
+ * will be removed from the engine in the near future.
+ *
+ * This has been fixed in jQuery 1.8 but Worldview currently doesn't
+ * support that version. This fix copied from:
+ *
+ * http://stackoverflow.com/questions/7825448/webkit-issues-with-event-layerx-and-event-layery
+ */
+(function() {
+ // remove layerX and layerY
+ var all = $.event.props,
+ len = all.length,
+ res = [];
+ while (len--) {
+ var el = all[len];
+ if (el != 'layerX' && el != 'layerY') res.push(el);
+ }
+ $.event.props = res;
+})();
+
+/*
+ * Get rid of address bar on iphone/ipod
+ */
+(function() {
+ var execute = function() {
+ window.scrollTo(0,0);
+ 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 -1 !== String.prototype.indexOf.call(this, str,
+ startIndex);
+ };
+ })();
+}
+
+/*
+ * 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;
+ }
+ });
+ })();
+}
+
+/*
+ * Mobile device quirks.
+ */
+(function() {
+ 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() {
+ setTimeout(hideURLbar, 0);
+ }, false);
+ addEventListener("orientationchange", function() {
+ setTimeout(hideURLbar, 0);
+ }, false);
+ }
+
+ // Set the div height
+ function setHeight($body) {
+ if (navigator.userAgent.match(/(iPad|iPhone|iPod touch);.*CPU.*OS 7_\d/i)){
+ $("div#app.ui-page.ui-body-c.ui-page-active").css("min-height", 0);
+ }
+ else {
+ var new_height = $(window).height();
+ // if mobileSafari add +60px
+ new_height += 60;
+ $body.css('min-height', 0 );
+ $body.css('height', new_height );
+ }
+ }
+ if (navigator.userAgent.match(/(iPad|iPhone|iPod touch);.*CPU.*OS 7_\d/i)){
+ setHeight( $('#app') );
+ $(window).resize(function() {
+ setHeight($('#app'));
+ });
+ }
+})();
diff --git a/src/js/util/wv.util.polyfill.js b/src/js/util/wv.util.polyfill.js
deleted file mode 100644
index a7efac033..000000000
--- a/src/js/util/wv.util.polyfill.js
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * NASA Worldview
- *
- * This code was originally developed at NASA/Goddard Space Flight Center for
- * the Earth Science Data and Information System (ESDIS) project.
- *
- * Copyright (C) 2013 - 2014 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-// 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';
- };
- }());
-}
-
diff --git a/test/util/wv.util.browser-test.js b/test/util/wv.util.browser-test.js
new file mode 100644
index 000000000..3327a858a
--- /dev/null
+++ b/test/util/wv.util.browser-test.js
@@ -0,0 +1,109 @@
+/*
+ * NASA Worldview
+ *
+ * This code was originally developed at NASA/Goddard Space Flight Center for
+ * the Earth Science Data and Information System (ESDIS) project.
+ *
+ * Copyright (C) 2013 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+buster.testCase("wv.util.browser", {
+
+ setUp: function() {
+ },
+
+ "Is Safari": function() {
+ this.stub(wv.util.browser.tests, "navigator").returns({
+ userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10"
+ });
+ buster.assert(wv.util.browser.tests.safari());
+ },
+
+ "Is not Safari": function() {
+ this.stub(wv.util.browser.tests, "navigator").returns({
+ userAgent: "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36"
+ });
+ buster.refute(wv.util.browser.tests.safari());
+ },
+
+ "Safari version": function() {
+ this.stub(wv.util.browser.tests, "navigator").returns({
+ userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10"
+ });
+ buster.assert.equals(wv.util.browser.tests.safariVersion(), 5);
+ },
+
+ "Is Internet Explorer": function() {
+ this.stub(wv.util.browser.tests, "navigator").returns({
+ userAgent: "Mozilla/5.0 (MSIE 9.0; Windows NT 6.1; Trident/5.0)"
+ });
+ buster.assert(wv.util.browser.tests.ie());
+ },
+
+ "Is not Internet Explorer": function() {
+ this.stub(wv.util.browser.tests, "navigator").returns({
+ userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:26.0) Gecko/20100101 Firefox/26.0"
+ });
+ buster.refute(wv.util.browser.tests.ie());
+ },
+
+ "Internet Explorer version": function() {
+ this.stub(wv.util.browser.tests, "navigator").returns({
+ userAgent: "Mozilla/5.0 (MSIE 9.0; Windows NT 6.1; Trident/5.0)"
+ });
+ buster.assert.equals(wv.util.browser.tests.ieVersion(), 9);
+ },
+
+ "CORS": function() {
+ this.stub(wv.util.browser.tests, "safari").returns(true);
+ this.stub(wv.util.browser.tests, "safariVersion").returns(7);
+ buster.assert(wv.util.browser.tests.cors());
+ },
+
+ "Non-working CORS on Safari version <= 6": function() {
+ this.stub(wv.util.browser.tests, "safari").returns(true);
+ this.stub(wv.util.browser.tests, "safariVersion").returns(6);
+ buster.refute(wv.util.browser.tests.cors());
+ },
+
+ "Web workers": function() {
+ this.stub(wv.util.browser.tests, "window").returns({});
+ buster.assert(wv.util.browser.tests.webWorkers());
+ },
+
+ "No web workers": function() {
+ this.stub(wv.util.browser.tests, "window").returns(undefined);
+ buster.refute(wv.util.browser.tests.webWorkers());
+ },
+
+ "Local storage": function() {
+ buster.assert(wv.util.browser.tests.localStorage);
+ },
+
+ "No local storage": function() {
+ this.stub(wv.util.browser.tests, "window").returns(undefined);
+ buster.refute(wv.util.browser.tests.localStorage());
+ },
+
+ "Disabled local storage": function() {
+ this.stub(localStorage, "getItem").throws();
+ buster.refute(wv.util.browser.tests.localStorage());
+ },
+
+ "Large device": function() {
+ this.stub(window, "$").returns({
+ width: this.stub().returns(1000)
+ });
+ buster.refute(wv.util.browser.tests.small());
+ },
+
+ "Small device": function() {
+ this.stub(window, "$").returns({
+ width: this.stub().returns(600)
+ });
+ buster.assert(wv.util.browser.tests.small());
+ },
+
+});