Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Date sliders to wv.date.sliders.js

Mike McGann3cfa1889cbee
diff --git a/Gruntfile.js b/Gruntfile.js
index 040c6af23..fc69f741e 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -497,7 +497,7 @@ module.exports = function(grunt) {
]);
grunt.registerTask("doc", ["yuidoc"]);
- grunt.registerTask("lint", ["csslint", "jshint"]);
+ grunt.registerTask("lint", ["jshint"]);
grunt.registerTask("test", ["buster"]);
grunt.registerTask("rpm", ["build", "rpm_only"]);
grunt.registerTask("clean", "remove:build");
diff --git a/etc/config/config/defaults.json b/etc/config/config/defaults.json
index d042d1058..e250f508b 100644
--- a/etc/config/config/defaults.json
+++ b/etc/config/config/defaults.json
@@ -11,5 +11,5 @@
{"id": "antarctic_coastlines" }
]
},
- "archiveStartDate": "2013-05-08"
+ "archiveStartDate": "2012-05-08"
}
diff --git a/etc/deploy/wv.css.json b/etc/deploy/wv.css.json
index 4d9208d0f..f68a7bfc0 100644
--- a/etc/deploy/wv.css.json
+++ b/etc/deploy/wv.css.json
@@ -4,7 +4,7 @@
"src/css/palette.css",
"src/css/map.css",
"src/css/map-ol2.css",
- "src/css/dateSpan.css",
+ "src/css/wv.date.css",
"src/css/menuPicker.css",
"src/css/accordionPicker.css",
"src/css/bank.css",
diff --git a/etc/deploy/wv.js.json b/etc/deploy/wv.js.json
index 0b22e81bb..24edc2029 100644
--- a/etc/deploy/wv.js.json
+++ b/etc/deploy/wv.js.json
@@ -1,4 +1,6 @@
[
+ "src/js/util/wv.util.polyfill.js",
+
"src/js/Date.js",
"src/js/Logging.js",
@@ -105,7 +107,7 @@
"src/js/Worldview/Widget/LayerSideBar.js",
"src/js/Worldview/Widget/ActiveLayers.js",
"src/js/Worldview/Widget/AddLayers.js",
- "src/js/Worldview/Widget/DateSlider.js",
+ "src/js/date/wv.date.sliders.js",
"src/js/Worldview/Widget/DateWheels.js",
"src/js/Worldview/Widget/Map.js",
"src/js/Worldview/Widget/Palette.js",
diff --git a/package.json b/package.json
index e0ef76c04..ed1acd4a4 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "worldview-master",
- "version": "0.7.0",
+ "version": "0.6.3",
"release": "1",
"author": "Worldview Team <[email protected]>",
"description": "Browse full-resolution, near real-time satellite imagery",
diff --git a/src/css/dateSpan.css b/src/css/dateSpan.css
deleted file mode 100644
index 37043248e..000000000
--- a/src/css/dateSpan.css
+++ /dev/null
@@ -1,90 +0,0 @@
-#timeds, #timemds {position:relative;}
-#timemds {display:none;}
-
-div.dwv, div.dwl, div.dw-i { font-weight:700; }
-.dwbw {width: 40%;}
-.dwb-c {display:none;}
-
-.datespan ul, menu, dir{
- -webkit-margin-before: 0em;
- -webkit-margin-after: 0em;
- -webkit-margin-start: 0px;
- -webkit-margin-end: 0px;
- -webkit-padding-start: 0px;
-
-}
-.spanContainerLabel {width:25%; float:left; text-shadow:none; display:block; margin-top:20px; text-align:center; font-size:.1em; color:#fff;}
-.spanContainerLabelDate,.spanContainerLabelDay {display:block; font-size:.25em;}
-.spanContainerLabelDay{font-size:.16em;}
-.spanContainer { float:left; min-height:100%; width:100%;}
-div.datespan {width:auto; overflow:hidden; background:none;
-}
-.datespan div.olMap {width:11.78%; height:100px;
-float:left;
--moz-box-shadow: 0 0 5px 5px #111;
--webkit-box-shadow: 0 0 5px 5px #111;
-box-shadow: 0 0 5px 5px #111;
-/*border:#fff 1px solid;*/
-margin:20px 0 0 2.5% !important;
-position:relative; left:-1.25%;
-display:block;
-}
-a.ecbutton { display:block; width:24px; height:24px; float:left; position:relative; background: transparent; left:-28px; top:3px;}
-a.collapse {background-image: url("../images/collapseDown.png"); background-repeat:no-repeat;}
-a.expand {background-image: url("../images/expandUp.png"); background-repeat:no-repeat;}
-.dateSpanSlider {display:none !important;}
-
-input.ui-slider-input {width:0px; margin:0px;}
-
-div.slider {/*background: rgba(45,50,55,.75);*/ margin-bottom:0px; /*box-shadow: 0px 0px 4px 1px #bbb;*/
-
-background: -moz-linear-gradient(top, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0.7) 50%, rgba(0,0,0,0.8) 100%); /* FF3.6+ */
-background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0.6)), color-stop(50%,rgba(0,0,0,0.7)), color-stop(100%,rgba(0,0,0,0.8))); /* Chrome,Safari4+ */
-background: -webkit-linear-gradient(top, rgba(0,0,0,0.6) 0%,rgba(0,0,0,0.7) 50%,rgba(0,0,0,0.8) 100%); /* Chrome10+,Safari5.1+ */
-background: -o-linear-gradient(top, rgba(0,0,0,0.6) 0%,rgba(0,0,0,0.7) 50%,rgba(0,0,0,0.8) 100%); /* Opera 11.10+ */
-background: -ms-linear-gradient(top, rgba(0,0,0,0.6) 0%,rgba(0,0,0,0.7) 50%,rgba(0,0,0,0.8) 100%); /* IE10+ */
-background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%,rgba(0,0,0,0.7) 50%,rgba(0,0,0,0.8) 100%); /* W3C */
-
-
-height:23px;
-
-}
-:root ul.sliderLabel { filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#99000000', endColorstr='#cc000000',GradientType=0 ) \0/IE9; } /* IE9 */
-
-ul.sliderLabel {text-shadow: none; color:#fff; margin:-20px 0 0 0; background:none; overflow:hidden; }
-ul.sliderLabel li {float:left; background:none; margin:0px; text-align:center; overflow:hidden; font-weight: 700; font-size: 0.9em; padding: 0.1em 0;}
-div.sliderDivYear {clear:both;}
-div.sliderDivMonth {background: rgba(25,30,35,0.5);}
-div.sliderDivDay { }
-#timesliderLabelDay {margin:-24px 0 0;}
-.disabledItem {color:rgba(125,125,125,0.9) !important;}
-a.ui-slider-handle {position:relative; height:80%; top:-3%; background: rgba(31,143,237,.26); border: #1f8fed 2px solid; }
-div.ui-slider {border:none; background:rgba(0,0,0,0.05); /*<-----Fix for IE10*/ margin:0px; top:0px; height:23px;}
-
-/*.sliderDivDay a.ui-slider-handle {margin-left:-15px !important;}
-.sliderDivMonth a.ui-slider-handle {width:54px; margin-left:-30px !important;}
-.sliderDivYear a.ui-slider-handle {width:54px; margin-left:-30px !important;}*/
-
-.dateHolder,#linkmode {display:inline-block; float:left; width:6em; /*background: rgba(45,50,55,.75);*/ margin-bottom:10px; margin-top:3px;text-shadow:none; color:#fff; font-weight:bold; font-size:.9em; text-align:center; padding:0.3em 0px; padding-right:28px;
- border-radius: 0 5px 5px 0;
-
-background: -moz-linear-gradient(top, rgba(0,0,0,0.5) 0%, rgba(0,0,0,0.6) 50%, rgba(0,0,0,0.7) 100%); /* FF3.6+ */
-background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0.5)), color-stop(50%,rgba(0,0,0,0.6)), color-stop(100%,rgba(0,0,0,0.7))); /* Chrome,Safari4+ */
-background: -webkit-linear-gradient(top, rgba(0,0,0,0.5) 0%,rgba(0,0,0,0.6) 50%,rgba(0,0,0,0.7) 100%); /* Chrome10+,Safari5.1+ */
-background: -o-linear-gradient(top, rgba(0,0,0,0.5) 0%,rgba(0,0,0,0.6) 50%,rgba(0,0,0,0.7) 100%); /* Opera 11.10+ */
-background: -ms-linear-gradient(top, rgba(0,0,0,0.5) 0%,rgba(0,0,0,0.6) 50%,rgba(0,0,0,0.7) 100%); /* IE10+ */
-background: linear-gradient(to bottom, rgba(0,0,0,0.5) 0%,rgba(0,0,0,0.6) 50%,rgba(0,0,0,0.7) 100%); /* W3C */
-filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#80000000', endColorstr='#b3000000',GradientType=0 ); /* IE6-9 */
- /*-moz-box-shadow: 0 -1px 15px #fff;
- -webkit-box-shadow: 0 -1px 15px #fff;*/
- /*box-shadow: 0 0px 4px 1px #bbb;*/}
-
-#linkmode {border:none; text-shadow:none;}
-/*a.ui-slider-handle{height:130px; display:block; width:14%; background:rgba(228,108,10,.2); border:#E46C0A 2px solid; z-index:1004; position:relative; top:-142px; margin: 10px 0 0 -7% !important; padding: 5px 0 5px 0; }*/
-/*span.sliderText {font: 14px/14px "Gill Sans", sans-serif, serif; font-weight:500; color:#fff; text-shadow:none; z-index:1005;}*/
-a.ui-btn {margin:0;}
-a.ui-shadow {box-shadow:none;}
-a.ui-btn-up-c {box-shadow:none;}
-#mapdiv {margin:0; padding:0; left:0px;}
-
-.dateitem {cursor:pointer !important;}
diff --git a/src/css/wv.date.css b/src/css/wv.date.css
new file mode 100644
index 000000000..7ba535c71
--- /dev/null
+++ b/src/css/wv.date.css
@@ -0,0 +1,229 @@
+/*
+ * 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.
+ */
+
+#timeds, #timemds {
+ position: relative;
+}
+
+#timemds {
+ display: none;
+}
+
+.dwv, .dwl, .dw-i {
+ font-weight: 700;
+}
+
+.dwbw {
+ width: 40%;
+}
+
+.dwb-c {
+ display: none;
+}
+
+.datespan ul, menu, dir {
+ -webkit-margin-before: 0em;
+ -webkit-margin-after: 0em;
+ -webkit-margin-start: 0px;
+ -webkit-margin-end: 0px;
+ -webkit-padding-start: 0px;
+}
+
+.spanContainerLabel {
+ width: 25%;
+ float: left;
+ text-shadow: none;
+ display: block;
+ margin-top: 20px;
+ text-align: center;
+ font-size: .1em;
+ color: #fff;
+}
+
+.spanContainerLabelDate, .spanContainerLabelDay {
+ display: block;
+ font-size: .25em;
+}
+
+.spanContainerLabelDay {
+ font-size: .16em;
+}
+
+.spanContainer {
+ float: left;
+ min-height: 100%;
+ width: 100%;
+}
+
+div.datespan {
+ width: auto;
+ overflow: hidden;
+ background: none;
+}
+
+.datespan div.olMap {
+ width: 11.78%;
+ height: 100px;
+ float: left;
+ -moz-box-shadow: 0 0 5px 5px #111;
+ -webkit-box-shadow: 0 0 5px 5px #111;
+ box-shadow: 0 0 5px 5px #111;
+ margin: 20px 0 0 2.5% !important;
+ position: relative;
+ left: -1.25%;
+ display: block;
+}
+
+a.ecbutton {
+ display: block;
+ width: 24px;
+ height: 24px;
+ float: left;
+ position: relative;
+ background: transparent;
+ left: -28px;
+ top: 3px;
+}
+
+a.collapse {
+ background-image: url("../images/collapseDown.png");
+ background-repeat: no-repeat;
+}
+
+a.expand {
+ background-image: url("../images/expandUp.png");
+ background-repeat: no-repeat;
+}
+
+.dateSpanSlider {
+ display: none !important;
+}
+
+input.ui-slider-input {
+ width: 0px;
+ margin: 0px;
+}
+
+.slider {/*background: rgba(45,50,55,.75);*/
+ margin-bottom: 0px; /*box-shadow: 0px 0px 4px 1px #bbb;*/
+ background: -moz-linear-gradient(top, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0.7) 50%, rgba(0,0,0,0.8) 100%); /* FF3.6+ */
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0.6)), color-stop(50%,rgba(0,0,0,0.7)), color-stop(100%,rgba(0,0,0,0.8))); /* Chrome,Safari4+ */
+ background: -webkit-linear-gradient(top, rgba(0,0,0,0.6) 0%,rgba(0,0,0,0.7) 50%,rgba(0,0,0,0.8) 100%); /* Chrome10+,Safari5.1+ */
+ background: -o-linear-gradient(top, rgba(0,0,0,0.6) 0%,rgba(0,0,0,0.7) 50%,rgba(0,0,0,0.8) 100%); /* Opera 11.10+ */
+ background: -ms-linear-gradient(top, rgba(0,0,0,0.6) 0%,rgba(0,0,0,0.7) 50%,rgba(0,0,0,0.8) 100%); /* IE10+ */
+ background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%,rgba(0,0,0,0.7) 50%,rgba(0,0,0,0.8) 100%); /* W3C */
+ height: 23px;
+ cursor: pointer;
+}
+
+:root ul.sliderLabel {
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#99000000', endColorstr='#cc000000',GradientType=0 ) \0/IE9;
+}/* IE9 */
+
+ul.sliderLabel {
+ text-shadow: none;
+ color: #fff;
+ margin: -20px 0 0 0;
+ background: none;
+ overflow: hidden;
+}
+
+ul.sliderLabel li {
+ float: left;
+ background: none;
+ margin: 0px;
+ text-align: center;
+ overflow: hidden;
+ font-weight: 700;
+ font-size: 0.9em;
+ padding: 0.1em 0;
+}
+
+div.sliderDivYear {
+ clear: both;
+}
+
+div.sliderDivMonth {
+ background: rgba(25,30,35,0.5);
+}
+
+#timesliderLabelDay {
+ margin: -24px 0 0;
+}
+
+.disabledItem {
+ color: rgba(125,125,125,0.9) !important;
+}
+
+a.ui-slider-handle {
+ position: relative;
+ height: 80%;
+ top: -3%;
+ background: rgba(31,143,237,.26);
+ border: #1f8fed 2px solid;
+}
+
+div.ui-slider {
+ border: none;
+ background: rgba(0,0,0,0.05); /*<-----Fix for IE10*/
+ margin: 0px;
+ top: 0px;
+ height: 23px;
+}
+
+.dateHolder, #linkmode {
+ display: inline-block;
+ float: left;
+ width: 6em; /*background: rgba(45,50,55,.75);*/
+ margin-bottom: 10px;
+ margin-top: 3px;
+ text-shadow: none;
+ color: #fff;
+ font-weight: bold;
+ font-size: .9em;
+ text-align: center;
+ padding: 0.3em 0px;
+ padding-right: 28px;
+ border-radius: 0 5px 5px 0;
+ background: -moz-linear-gradient(top, rgba(0,0,0,0.5) 0%, rgba(0,0,0,0.6) 50%, rgba(0,0,0,0.7) 100%); /* FF3.6+ */
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0.5)), color-stop(50%,rgba(0,0,0,0.6)), color-stop(100%,rgba(0,0,0,0.7))); /* Chrome,Safari4+ */
+ background: -webkit-linear-gradient(top, rgba(0,0,0,0.5) 0%,rgba(0,0,0,0.6) 50%,rgba(0,0,0,0.7) 100%); /* Chrome10+,Safari5.1+ */
+ background: -o-linear-gradient(top, rgba(0,0,0,0.5) 0%,rgba(0,0,0,0.6) 50%,rgba(0,0,0,0.7) 100%); /* Opera 11.10+ */
+ background: -ms-linear-gradient(top, rgba(0,0,0,0.5) 0%,rgba(0,0,0,0.6) 50%,rgba(0,0,0,0.7) 100%); /* IE10+ */
+ background: linear-gradient(to bottom, rgba(0,0,0,0.5) 0%,rgba(0,0,0,0.6) 50%,rgba(0,0,0,0.7) 100%); /* W3C */
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#80000000', endColorstr='#b3000000',GradientType=0 ); /* IE6-9 */
+}
+
+#linkmode {
+ border: none;
+ text-shadow: none;
+}
+
+a.ui-btn {
+ margin: 0;
+}
+
+a.ui-shadow {
+ box-shadow: none;
+}
+
+a.ui-btn-up-c {
+ box-shadow: none;
+}
+
+#mapdiv {
+ margin: 0;
+ padding: 0;
+ left: 0;
+}
+
+
+
diff --git a/src/data/config.json b/src/data/config.json
index e231cdae3..20f2eec8c 100644
--- a/src/data/config.json
+++ b/src/data/config.json
@@ -345,7 +345,7 @@
}
},
"defaults": {
- "archiveStartDate": "2013-05-08",
+ "archiveStartDate": "2012-05-08",
"projection": "geographic",
"startingLayers": {
"baselayers": [
diff --git a/src/index.html b/src/index.html
index c2833ca61..157ee70bf 100644
--- a/src/index.html
+++ b/src/index.html
@@ -57,7 +57,7 @@
<!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/pages.css">
<!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/map.css">
<!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/map-ol2.css">
- <!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/dateSpan.css">
+ <!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/wv.date.css">
<!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/menuPicker.css">
<!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/accordionPicker.css">
<!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/bank.css">
@@ -113,6 +113,8 @@
<!-- 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>
@@ -215,7 +217,7 @@
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Widget/LayerSideBar.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Widget/ActiveLayers.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Widget/AddLayers.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Widget/DateSlider.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.sliders.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Widget/DateWheels.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>
diff --git a/src/js/Worldview/Legacy/date.js b/src/js/Worldview/Legacy/date.js
index 5d7c8d479..c94540992 100644
--- a/src/js/Worldview/Legacy/date.js
+++ b/src/js/Worldview/Legacy/date.js
@@ -26,7 +26,7 @@ Worldview.Legacy.Date = function(model) {
};
self.setValue = function(value) {
- model.set(self.id + "=" + model.selected.toISOString());
+ model.set(self.id + "=" + model.selected.toISOString().split("T")[0]);
};
self.getValue = function() {
@@ -40,6 +40,21 @@ Worldview.Legacy.Date = function(model) {
fire();
};
+ self.parse = function(queryString, object) {
+ var timeString = Worldview.extractFromQuery("time", queryString);
+ if ( !timeString ) {
+ object.time = Worldview.today();
+ } else {
+ try {
+ object.time = Date.parseISOString(timeString).clearUTCTime();
+ } catch ( error ) {
+ this.log.warn("Invalid time: " + timeString + ", reason: " +
+ error);
+ object.time = Worldview.today();
+ }
+ }
+ };
+
var fire = function() {
REGISTRY.fire(self);
};
diff --git a/src/js/Worldview/Widget/WorldviewMap.js b/src/js/Worldview/Widget/WorldviewMap.js
index 6c6c6423b..ef0b4d615 100644
--- a/src/js/Worldview/Widget/WorldviewMap.js
+++ b/src/js/Worldview/Widget/WorldviewMap.js
@@ -73,7 +73,7 @@ Worldview.Widget.WorldviewMap = function(containerId, config) {
if ( last.queryString === queryString ) {
return;
}
- log.debug("WorldviewMap: updateComponent", queryString);
+ //console.log("WorldviewMap: updateComponent", queryString);
var state = REGISTRY.getState();
diff --git a/src/js/date/wv.date.model.js b/src/js/date/wv.date.model.js
index 5d416e486..a6b9ac765 100644
--- a/src/js/date/wv.date.model.js
+++ b/src/js/date/wv.date.model.js
@@ -73,6 +73,7 @@ wv.date.model = wv.date.model || function(config) {
* @param {Date} date The day to display. If the day is before the
* archive start date, it is set to the archive start date. If the day
* is after UTC today, it is set to UTC today.
+ * @return {Boolean} true if the date was updated, otherwise false.
*/
self.select = function(date) {
if ( date < self.archiveStartDate ) {
@@ -81,10 +82,13 @@ wv.date.model = wv.date.model || function(config) {
date = wv.util.today();
}
+ var updated = false;
if ( !self.selected || date.getTime() !== self.selected.getTime() ) {
self.selected = date;
self.events.trigger("select", date);
+ updated = true;
}
+ return updated;
};
/**
@@ -94,7 +98,7 @@ wv.date.model = wv.date.model || function(config) {
* @return {String} current day in the form of ``time=YYYY-MM-DD``
*/
self.toPermalink = function() {
- return "time=" + self.selected.toISOString();
+ return "time=" + self.selected.toISOString().split("T")[0];
};
/**
@@ -111,8 +115,8 @@ wv.date.model = wv.date.model || function(config) {
var query = wv.util.fromQueryString(queryString);
if ( query.time ) {
try {
- var value = Date.parseDateUTC(query.time);
- self.set(value);
+ var value = wv.util.parseDateUTC(query.time);
+ self.select(value);
} catch ( error ) {
wv.util.warn("Invalid date: " + query.time + ": " + error);
}
diff --git a/src/js/date/wv.date.sliders.js b/src/js/date/wv.date.sliders.js
new file mode 100644
index 000000000..97836ea7a
--- /dev/null
+++ b/src/js/date/wv.date.sliders.js
@@ -0,0 +1,331 @@
+/*
+ * 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.date
+ */
+var wv = wv || {};
+wv.date = wv.date || {};
+
+/**
+ * Undocumented.
+ *
+ * @class wv.date.sliders
+ */
+wv.date.sliders = wv.date.sliders || function(models, config) {
+
+ var id = "timeds";
+ var selector = "#" + id;
+ var SLIDER_WIDTH = 1000;
+ var DAY_IN_MS = 24*60*60*1000;
+ var sliders = {};
+ var ranges = {};
+ var months = [31,28,31,30,31,30,31,31,30,31,30,31];
+ var sliderContent = [];
+ var $container;
+ var model = models.date;
+
+ var self = {};
+
+ self.startDate = new Date(Date.UTC(2012, 4, 8, 0, 0, 0));
+ self.endDate = wv.util.today();
+ self.isCollapsed = false;
+
+ var init = function() {
+ sliders["Year"] = [];
+ var currentYear = wv.util.now().getUTCFullYear();
+ sliders["Year"] = _.range(2000, currentYear + 1);
+ sliders["Month"] = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug',
+ 'Sep','Oct','Nov','Dec'];
+ sliders["Day"] = _.range(1, 31 + 1);
+
+ $container = $(selector);
+ render();
+
+ model.events.on("select", function(date) {
+ update();
+ });
+ $(window).on("resize", refreshSliders);
+ update();
+ };
+
+ var render = function() {
+ if ( wv.ui.mobile() ) {
+ $("#timeds").css("display","none");
+ }
+ $container.addClass("datespan");
+
+ var $dateHolder = $("<div></div>")
+ .attr("id", id + "dateHolder")
+ .addClass("dateHolder");
+ $container.append($dateHolder);
+
+ var $ecbutton = $("<a></a>")
+ .addClass("ecbutton")
+ .addClass("collapse")
+ .attr("id", id + "ecbutton");
+ $container.append($ecbutton);
+
+ createSlider("Year");
+ createSlider("Month");
+ createSlider("Day");
+
+ $(selector + "ecbutton").on("click", toggle);
+ };
+
+ var createSlider = function(type) {
+ var $slider = $("<div></div>")
+ .attr("id", id + "sliderDiv" + type)
+ .addClass("sliderDiv" + type)
+ .addClass("slider");
+
+ var $sliderInput = $("<input></input>")
+ .attr("type", "range")
+ .attr("name", "slider")
+ .attr("id", id + "slider" + type)
+ .addClass("dateSpanSlider")
+ .attr("value", SLIDER_WIDTH)
+ .attr("min", 0)
+ .attr("max", SLIDER_WIDTH)
+ .attr("step", 1);
+ $slider.append($sliderInput);
+ $container.append($slider);
+
+ var width = 0;
+ var wwidth = $(window).width() - 10;
+ var labels = sliders[type];
+
+ if ( labels != undefined ) {
+ width = 50/labels.length;
+ width = width.toFixed(1);
+ var pwidth = width/100;
+ var pwwidth = Math.floor(pwidth*wwidth);
+ var spacer = 50/labels.length;
+ spacer = spacer.toFixed(1);
+ var pspacer = spacer/100;
+ var pwspacer = Math.floor(wwidth*pspacer/2);
+ var finalwidth = (pwwidth+pwspacer+pwspacer);
+
+ var $label = $("<ul></ul>")
+ .addClass("sliderLabel")
+ .attr("id", id + "sliderLabel" + type);
+ for ( var i = 0; i < labels.length; ++i ) {
+ var $item = $("<li></li>")
+ .attr("id", id + type + "sliderItem" + i)
+ .html(labels[i])
+ .css("width", Math.floor(wwidth*pwidth) + "px")
+ .css("margin-left", Math.floor(wwidth*pspacer/2) + "px")
+ .css("margin-right", Math.floor(wwidth*pspacer/2) + "px");
+ $label.append($item);
+ }
+ $container.append($label);
+ }
+
+ var labelslength = labels.length;
+ $('#' + id + 'slider' + type)
+ .slider()
+ .bind("change", { type: type }, handleSlide);
+ var labelWidth = finalwidth * labels.length;
+ $('#' + id + 'slider' + type)
+ .siblings('.ui-slider')
+ .css('width', labelWidth + "px");
+ $('#' + id + 'slider' + type)
+ .siblings('.ui-slider')
+ .bind("vmouseup", { type:type }, snap);
+ if ( width != 0 ) {
+ var handleWidth = (width * 1.1).toFixed(1);
+ $('.sliderDiv'+type+' a.ui-slider-handle')
+ .css('width', handleWidth + "%");
+ }
+ };
+
+ var refreshSlider = function(type) {
+ var labels = sliders[type];
+ var wwidth = $(window).width() - 10;
+
+ if ( labels != undefined ) {
+ var width = 50/labels.length;
+ width = width.toFixed(1);
+ var pwidth = width/100;
+ var pwwidth = Math.floor(pwidth*wwidth);
+ var spacer = 50/labels.length;
+ spacer = spacer.toFixed(1);
+ var pspacer = spacer/100;
+ var pwspacer = Math.floor(wwidth*pspacer/2);
+ var finalwidth = (pwwidth+pwspacer+pwspacer);
+ $('#' + id + 'sliderLabel' + type)
+ .children()
+ .css('width', Math.floor(wwidth*pwidth) + "px");
+ $('#' + id + 'sliderLabel' + type)
+ .children()
+ .css('margin-left', Math.floor(wwidth*pspacer/2) + "px");
+ $('#' + id + 'sliderLabel' + type)
+ .children()
+ .css('margin-right', Math.floor(wwidth*pspacer/2) + "px");
+ var handleWidth = finalwidth*labels.length;
+ $('#' + id + 'slider' + type)
+ .siblings('.ui-slider')
+ .css('width', handleWidth + "px");
+ }
+ };
+
+ var handleSlide = function(e, ui) {
+ var value = e.target.value;
+ var type = e.data.type;
+ var oldDate = model.selected;
+ var newDate = new Date(oldDate.getTime());
+ var numitems = sliders[type].length;
+ var displacement = Math.floor(value*(numitems/SLIDER_WIDTH));
+
+ if ( sliders[type][displacement] && displacement >= ranges[type].min && displacement <= ranges[type].max ) {
+ if ( type === "Year" ) {
+ newDate.setUTCFullYear(sliders[type][displacement]);
+ }
+ else if ( type === "Month" ) {
+ if ( oldDate.getUTCDate() > months[displacement]) {
+ newDate.setUTCDate(months[displacement]);
+ }
+ newDate.setUTCMonth(displacement);
+ }
+ else if ( type === "Day" ) {
+ if ( sliders[type][displacement] <= months[oldDate.getUTCMonth()] ) {
+ newDate.setUTCDate(sliders[type][displacement]);
+ }
+ }
+ model.select(newDate);
+ } else {
+ update();
+ }
+ validate();
+
+ };
+
+ var toggle = function(e, ui) {
+ if ( self.isCollapsed ) {
+ $('.ecbutton').removeClass('expand').addClass('collapse');
+ $('.ecbutton').attr("title","Hide Date Slider");
+ $(".horizontalContainer").css("width","100%");
+ self.isCollapsed = false;
+ showSliders();
+ } else {
+ $('.ecbutton').removeClass('collapse').addClass('expand');
+ $('.ecbutton').attr("title","Show Date Slider");
+ $(".horizontalContainer").css("width","auto");
+ self.isCollapsed = true;
+ hideSliders();
+ }
+ };
+
+ var hideSliders = function() {
+ for ( var i in sliders ) {
+ $("#" + id + "sliderDiv" + i).css('display','none');
+ }
+ $('.sliderLabel').css("display","none");
+ };
+
+ var showSliders = function() {
+ for ( var i in sliders ) {
+ $("#" + id + "sliderDiv" + i).css('display','block');
+ }
+ $('.sliderLabel').css("display","block");
+ };
+
+ var update = function() {
+ validate();
+ var value = model.selected;
+ var values = {};
+ values["Year"] = sliders["Year"].indexOf(value.getUTCFullYear());
+ values["Month"] = value.getUTCMonth();
+ values["Day"] = sliders["Day"].indexOf(value.getUTCDate());
+
+ _.each(values, function(x, type) {
+ var numitems = sliders[type].length;
+ var displacement = values[type];
+ var width = SLIDER_WIDTH / numitems;
+ var move = displacement * width + (width / 4) - (width * .05);
+ move = move.toFixed(1);
+ $("#" + id + "slider" + type).val(move).slider("refresh");
+ });
+ setVisualDate();
+ };
+
+ var setVisualDate = function() {
+ var dateString = model.selected.toISOString().split("T")[0];
+ $('#' + id + 'dateHolder').html(dateString);
+ };
+
+ var refreshSliders = function() {
+ if ( wv.ui.mobile() ) {
+ $("#" + self.containerId).hide();
+ } else {
+ $("#" + self.containerId).show();
+ setTimeout(function() {
+ refreshSlider("Year");
+ refreshSlider("Month");
+ refreshSlider("Day");
+ },100);
+ }
+ };
+
+ var validate = function() {
+ var curr = new Date(model.selected.getTime());
+ var startYear = self.startDate.getUTCFullYear();
+ var startMonth = self.startDate.getUTCMonth();
+ var startDay = self.startDate.getUTCDate();
+ var endYear = self.endDate.getUTCFullYear();
+ var endMonth = self.endDate.getUTCMonth();
+ var endDay = self.endDate.getUTCDate();
+ for ( var type in sliders ) {
+ ranges[type] = { min: Number.MAX_VALUE, max: -Number.MAX_VALUE };
+ for ( var i = 0; i < sliders[type].length; ++i ) {
+ var descriptor = id + type + "sliderItem" + i;
+ if ( type === "Year" ) {
+ var year = sliders[type][i];
+ if ( year < startYear || year > endYear) {
+ $("#" + descriptor).addClass("disabledItem");
+ }
+ else {
+ ranges[type].min = Math.min(ranges[type].min, i);
+ ranges[type].max = Math.max(ranges[type].max, i);
+ $("#" + descriptor).removeClass("disabledItem");
+ }
+ }
+ if ( type === "Month"){
+ if ( (curr.getUTCFullYear() == startYear && i < startMonth) || (curr.getUTCFullYear() == endYear && i > endMonth) ) {
+ $("#" + descriptor).addClass("disabledItem");
+ }
+ else {
+ ranges[type].min = Math.min(ranges[type].min, i);
+ ranges[type].max = Math.max(ranges[type].max, i);
+ $("#" + descriptor).removeClass("disabledItem");
+ }
+ }
+ if ( type === "Day" ) {
+ if( (sliders[type][i] > months[curr.getUTCMonth()]) || (curr.getUTCFullYear() == startYear && curr.getUTCMonth() == startMonth && sliders[type][i] < startDay) || (curr.getUTCFullYear() == endYear && curr.getUTCMonth() == endMonth && sliders[type][i] > endDay) ){
+ $("#" + descriptor).addClass("disabledItem");
+ }
+ else {
+ ranges[type].min = Math.min(ranges[type].min, i);
+ ranges[type].max = Math.max(ranges[type].max, i);
+ $("#" + descriptor).removeClass("disabledItem");
+ }
+ }
+ }
+ }
+ };
+
+ var snap = function() {
+ update();
+ };
+
+ init();
+ return self;
+};
diff --git a/src/js/main.js b/src/js/main.js
index fba761c43..57917e2ff 100644
--- a/src/js/main.js
+++ b/src/js/main.js
@@ -139,7 +139,7 @@ $(function() {// Initialize "static" vars
});
var addLayers = Worldview.Widget.AddLayers(config, layersModel,
projectionModel);
- var dateSlider = new Worldview.Widget.DateSlider(models, config);
+ ui.dateSliders = wv.date.sliders(models, config);
var dateWheels = new Worldview.Widget.DateWheels(models, config);
var map = Worldview.Widget.WorldviewMap("map", config);
var rubberBand = new SOTE.widget.RubberBand("camera", {
diff --git a/src/js/ui/wv.ui.js b/src/js/ui/wv.ui.js
index f79fbcbac..839645706 100644
--- a/src/js/ui/wv.ui.js
+++ b/src/js/ui/wv.ui.js
@@ -22,6 +22,18 @@ 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.
*
diff --git a/src/js/util/wv.util.js b/src/js/util/wv.util.js
index 241a00413..6d8b22dfe 100644
--- a/src/js/util/wv.util.js
+++ b/src/js/util/wv.util.js
@@ -114,6 +114,18 @@ wv.util = (function(self) {
return d;
};
+ /**
+ * Converts a date into an ISO string with only the date portion.
+ *
+ * @method toISOStringDate
+ * @static
+ * @param date {Date} the date to convert
+ * @return {string} ISO string in the form of ``YYYY-MM-DD``.
+ */
+ self.toISOStringDate = function(date) {
+ return date.toISOString().split("T")[0];
+ };
+
/**
* Sets a date to UTC midnight.
*
@@ -153,7 +165,7 @@ wv.util = (function(self) {
* fields set to zero or an overriden value.
*/
self.today = function() {
- return self.clearTimeUTC(new Date());
+ return self.clearTimeUTC(self.now());
};
/**
diff --git a/src/js/util/wv.util.polyfill.js b/src/js/util/wv.util.polyfill.js
new file mode 100644
index 000000000..948cdf5bc
--- /dev/null
+++ b/src/js/util/wv.util.polyfill.js
@@ -0,0 +1,36 @@
+/*
+ * 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/date/wv.date.model-test.js b/test/date/wv.date.model-test.js
index e0e503e93..2d511b414 100644
--- a/test/date/wv.date.model-test.js
+++ b/test/date/wv.date.model-test.js
@@ -12,6 +12,7 @@
buster.testCase("wv.date.model", {
config: null,
+ now: null,
setUp: function() {
this.config = {
@@ -19,9 +20,9 @@ buster.testCase("wv.date.model", {
archiveStartDate: "2013-01-01"
}
};
- this.stub(wv.util, "today", function() {
- return new Date(2013, 0, 15, 0, 0, 0);
- });
+ var now = new Date(Date.UTC(2013, 0, 15));
+ this.now = now;
+ this.stub(wv.util, "now").returns(now);
},
"Initializes to today": function() {
@@ -50,13 +51,41 @@ buster.testCase("wv.date.model", {
},
"Select new date": function() {
- var d = new Date(2013, 0, 5, 0, 0, 0);
+ var d = new Date(Date.UTC(2013, 0, 5));
var listener = this.stub();
var date = wv.date.model(this.config);
date.events.on("select", listener);
date.select(d);
buster.assert.equals(date.selected, d);
buster.assert.calledWith(listener, d);
+ },
+
+ "To permalink": function() {
+ var d = new Date(Date.UTC(2013, 0, 5));
+ var date = wv.date.model(this.config);
+ date.select(d);
+ buster.assert.equals(date.toPermalink(), "time=2013-01-05");
+ },
+
+ "From valid permalink": function() {
+ var d = new Date(Date.UTC(2013, 0, 5));
+ var date = wv.date.model(this.config);
+ date.fromPermalink("time=2013-01-05");
+ buster.assert.equals(date.selected, d);
+ },
+
+ "Not selected when time is not in permalink": function() {
+ var date = wv.date.model(this.config);
+ date.fromPermalink("foo=2013-01-05");
+ buster.assert.equals(date.selected, this.now);
+ },
+
+ "Warning emitted when time is invalid": function() {
+ var date = wv.date.model(this.config);
+ this.stub(wv.util, "warn");
+ date.fromPermalink("time=X");
+ buster.assert.equals(date.selected, this.now);
+ buster.assert.calledOnce(wv.util.warn);
}
});
\ No newline at end of file
diff --git a/test/util/wv.util-test.js b/test/util/wv.util-test.js
index 2799ad0ad..c903a7beb 100644
--- a/test/util/wv.util-test.js
+++ b/test/util/wv.util-test.js
@@ -72,6 +72,11 @@ buster.testCase("wv.util", {
});
},
+ "toISOStringDate: Converts date": function() {
+ var d = new Date(Date.UTC(2013, 0, 15));
+ buster.assert.equals(wv.util.toISOStringDate(d), "2013-01-15");
+ },
+
"clearTimeUTC: Time set to UTC midnight": function() {
var d = new Date(2013, 02, 15, 12, 34, 56, 789);
wv.util.clearTimeUTC(d);