Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-599: Permalink code cleaned up

Mike McGann11a889d82c45
diff --git a/etc/ant/js.build.xml b/etc/ant/js.build.xml
index a055f3cae..844c5022b 100644
--- a/etc/ant/js.build.xml
+++ b/etc/ant/js.build.xml
@@ -2,7 +2,7 @@
<filelist id="js.files" dir="${build.web.dir}">
<file name="ext/preloadjs/preloadjs.min.js"/>
-
+
<file name="ext/jquery/jquery.js"/>
<file name="ext/jquery-ui/jquery-ui.min.js"/>
<file name="ext/jquery.mobile/jquery.mobile.js"/>
@@ -20,7 +20,7 @@
<file name="ext/mobiscroll/mobiscroll.android.js"/>
<file name="ext/mobiscroll/mobiscroll.android-ics.js"/>
<file name="ext/mobiscroll/mobiscroll.wp.js"/>
-
+
<file name="ext/yui/yahoo/yahoo.js"/>
<file name="ext/yui/event/event.js"/>
<file name="ext/yui/dom/dom.js"/>
@@ -36,7 +36,7 @@
<file name="ext/joyride/jquery.cookie.js"/>
<file name="ext/joyride/jquery.joyride.js"/>
<file name="ext/joyride/modernizr.mq.js"/>
-
+
<file name="ext/openlayers/OpenLayers.debug.js"/>
<file name="ext/jcrop/jcrop.js"/>
<file name="ext/jquery.dd/jquery.dd.js"/>
@@ -48,7 +48,7 @@
<file name="ext/proj4js/EPSG_3031.js"/>
<file name="ext/proj4js/EPSG_3413.js"/>
<file name="ext/proj4js/EPSG_3995.js"/>
-
+
<file name="js/Date.js"/>
<file name="js/Logging.js"/>
@@ -69,7 +69,7 @@
<file name="js/products.js"/>
<file name="js/sote.js"/>
<file name="js/events.js"/>
-
+
<file name="js/Worldview.js"/>
<file name="js/Worldview/About.js"/>
<file name="js/Worldview/Support.js"/>
@@ -81,12 +81,12 @@
<file name="js/Worldview/Indicator.js"/>
<file name="js/Worldview/AjaxCache.js"/>
<file name="js/Worldview/AjaxJoin.js"/>
-
+
<file name="js/Worldview/Palette.js"/>
<file name="js/Worldview/Palette/ColorBar.js"/>
<file name="js/Worldview/Palette/Palette.js"/>
<file name="js/Worldview/Palette/PaletteSelector.js"/>
-
+
<file name="js/Worldview/Map.js"/>
<file name="js/Worldview/Map/CanvasTile.js"/>
<file name="js/Worldview/Map/MapSet.js"/>
@@ -103,7 +103,7 @@
<file name="js/Worldview/DataDownload/ECHO/Geometry.js"/>
<file name="js/Worldview/DataDownload/ECHO/MockClient.js"/>
- <file name="js/Worldview/DataDownload/Handler.js"/>
+ <file name="js/Worldview/DataDownload/Handler.js"/>
<file name="js/Worldview/DataDownload/Handler/Base.js"/>
<file name="js/Worldview/DataDownload/Handler/MODISSwathMultiDay.js"/>
<file name="js/Worldview/DataDownload/Handler/AquaSwathMultiDay.js"/>
@@ -113,15 +113,15 @@
<file name="js/Worldview/DataDownload/Handler/MODISMix.js"/>
<file name="js/Worldview/DataDownload/Handler/List.js"/>
<file name="js/Worldview/DataDownload/Handler/CollectionList.js"/>
-
+
<file name="js/Worldview/DataDownload/Layers/Button.js"/>
<file name="js/Worldview/DataDownload/Layers/Grid.js"/>
<file name="js/Worldview/DataDownload/Layers/Hover.js"/>
<file name="js/Worldview/DataDownload/Layers/QueryMask.js"/>
<file name="js/Worldview/DataDownload/Layers/Selection.js"/>
<file name="js/Worldview/DataDownload/Layers/Swath.js"/>
-
- <file name="js/Worldview/DataDownload/Results/AntiMeridianMulti.js"/>
+
+ <file name="js/Worldview/DataDownload/Results/AntiMeridianMulti.js"/>
<file name="js/Worldview/DataDownload/Results/Chain.js"/>
<file name="js/Worldview/DataDownload/Results/CollectPreferred.js"/>
<file name="js/Worldview/DataDownload/Results/CollectVersions.js"/>
@@ -149,7 +149,7 @@
<file name="js/Worldview/DataDownload/SelectionListPanel.js"/>
<file name="js/Worldview/DataDownload/DownloadListPanel.js"/>
<file name="js/Worldview/DataDownload/WgetPage.js"/>
-
+
<file name="js/Worldview/Widget/Map.js"/>
<file name="js/Worldview/Widget/Palette.js"/>
<file name="js/Worldview/Widget/WorldviewMap.js"/>
@@ -157,9 +157,10 @@
<file name="js/Worldview/Widget/Opacity.js"/>
<file name="js/Worldview/Widget/CRS.js"/>
<file name="js/Worldview/Widget/DataDownload.js"/>
+ <file name="js/Worldview/Widget/Permalink.js"/>
<file name="js/tour.js"/>
<file name="js/main.js"/>
</filelist>
-
+
</project>
\ No newline at end of file
diff --git a/src/index.html b/src/index.html
index c8cbca13f..b98801649 100644
--- a/src/index.html
+++ b/src/index.html
@@ -223,6 +223,7 @@
<!-- 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/Worldview/Widget/Permalink.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/tour.js"></script>
@@ -237,7 +238,7 @@
<li class='toolbar-icon'><div id='info_drop'><div id='info' title='Information'><img src='images/information.png' /></div><div class='hidden'><a href="mailto:[email protected]?subject=Feedback for EOSDIS Worldview tool" target="_blank" title='Feedback'>Feedback</a><a href='javascript:Worldview.Tour.start(null, false, true);' title='Start Tour'>Start Tour</a><a href='javascript:Worldview.About.show();' title='About Worldview'>About</a></div></div></li>
<li class='toolbar-icon'><div id='camera'></div></li>
<li class='toolbar-icon'><div id="switch"></div></li>
- <li class='toolbar-icon'><a id='perma_link' class='toolbar-link' title='Permalink' href='javascript:Worldview.Permalink.show();'><img src='images/permalink.png' /></a></li>
+ <li class='toolbar-icon'><a id='perma_link' class='toolbar-link' title='Permalink' href='javascript:Worldview.Widget.Permalink.show();'><img src='images/permalink.png' /></a></li>
</ul>
</div>
diff --git a/src/js/Worldview/Permalink.js b/src/js/Worldview/Permalink.js
index a520b5e99..f6e8ae00f 100644
--- a/src/js/Worldview/Permalink.js
+++ b/src/js/Worldview/Permalink.js
@@ -1,10 +1,10 @@
/*
* NASA Worldview
- *
+ *
* This code was originally developed at NASA/Goddard Space Flight Center for
- * the Earth Science Data and Information System (ESDIS) project.
+ * the Earth Science Data and Information System (ESDIS) project.
*
- * Copyright (C) 2013 United States Government as represented by the
+ * Copyright (C) 2013 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
@@ -16,33 +16,41 @@
Worldview.namespace("Permalink");
$(function() {
-
+
// This namespace
var ns = Worldview.Permalink;
-
- var permOverlay = null;
-
+
+ var ALLOWED_PARAMETERS = {
+ map: true,
+ products: true,
+ time: true,
+ "switch": true,
+ palettes: true,
+ opacity: true,
+ dataDowload: true
+ };
+
/**
* Constant: ENCODING_EXCEPTIONS
- * Characters that should not be encoded with encodeURI component. An
+ * Characters that should not be encoded with encodeURI component. An
* array of objects where each object contains "match" which is the
- * regular expression to match after encoding, and "replace" which is the
+ * regular expression to match after encoding, and "replace" which is the
* string to replace the match after encoding.
*/
- ns.ENCODING_EXCEPTIONS = [
+ ns.ENCODING_EXCEPTIONS = [
{ match: new RegExp("%2C", "g"), replace: "," }
];
-
+
/**
* Function: fromObject
* Returns a query string using the properties and values of an object.
- *
+ *
* Parameters:
* values - The object to convert to a query string
- *
+ *
* Returns:
* The query string with special characters escaped.
- *
+ *
* Example:
* (begin code)
* > Worldview.Permalink.fromObject({
@@ -60,13 +68,13 @@ $(function() {
}
qs += encode(key) + "=" + encode(values[key]);
}
- return "?" + qs;
+ return "?" + qs;
};
-
+
/**
* Function: fromRegistry
* Returns a query string that is the concatenated value of all components.
- *
+ *
* Returns:
* The query string to use as a permalink with special characters escaped.
*/
@@ -80,108 +88,52 @@ $(function() {
var fields = comps[i].obj.getValue().split("=");
var key = fields[0];
var value = fields[1];
- parameters[key] = value;
+ if ( ALLOWED_PARAMETERS[key] ) {
+ parameters[key] = value;
+ }
}
}
- }
+ }
return ns.fromObject(parameters);
};
-
+
/**
* Function: decode
- * Converts all escaped characters in the query string to actual
+ * Converts all escaped characters in the query string to actual
* characters.
- *
+ *
* Parameters:
* queryString - The query string to decode
- *
+ *
* Returns:
* The query string with all escaped characters converted to the actual
* characters.
- *
+ *
* Example:
* (begin code)
* > Worldview.Permalink.decode("?foo=%20bar")
* "?foo= bar"
* (end code)
*/
- ns.decode = function(queryString) {
+ ns.decode = function(queryString) {
if ( queryString.length === 0 ) {
return "";
}
- // Remove the question mark from the query string if it exists,
+ // Remove the question mark from the query string if it exists,
// add it back later if needed
var questionMark = "";
if ( queryString.substring(0, 1) === "?" ) {
- queryString = queryString.substring(1);
- questionMark = "?";
+ queryString = queryString.substring(1);
+ questionMark = "?";
}
var parts = queryString.split("&");
var decoded = [];
- $.each(parts, function(index, part) {
+ $.each(parts, function(index, part) {
decoded.push(decodeURIComponent(part));
});
return questionMark + decoded.join("&");
};
-
- /**
- * Function: show
- * Display a dialog box to the user showing the current permalink.
- */
- ns.show = function() {
- if ( permOverlay === null ) {
- permOverlay = new YAHOO.widget.Panel("panel_perm", {
- width: "300px",
- zIndex: 1020,
- visible: false
- });
- var item = "<div id='permpanel' >" +
- "<!-- <h3>Permalink:</h3> -->"+
- "<span style='font-weight:400; font-size:12px; line-spacing:24px;'>Copy and paste the following link to share this view:</span>" +
- "<input type='text' value='' name='permalink_content' id='permalink_content' />" +
- "</div>";
- permOverlay.setHeader("Permalink");
- permOverlay.setBody(item);
- permOverlay.render(document.body);
- }
-
- var qs = ns.fromRegistry();
-
- // FIXME: Some components currently have values that are not supposed
- // to be in the query string or return undefined values. For now,
- // pick out the actual values that are really needed
- var map = Worldview.extractFromQuery("map", qs);
- var products = Worldview.extractFromQuery("products", qs);
- var time = Worldview.extractFromQuery("time", qs);
- var s = Worldview.extractFromQuery("switch", qs);
-
- var link = "?map="+map+"&products="+products+"&time="+time+"&switch="+s;
-
- var palettes = Worldview.extractFromQuery("palettes", qs);
- if ( palettes ) {
- link += "&palettes=" + palettes;
- }
- var opacity = Worldview.extractFromQuery("opacity", qs);
- if ( opacity ) {
- link += "&opacity=" + opacity;
- }
- var dataDownload = Worldview.extractFromQuery("dataDownload", qs);
- if ( dataDownload ) {
- link += "&dataDownload=" + dataDownload;
- }
- var url = window.location.href;
- var prefix = url.split("?")[0];
- prefix = (prefix !== null && prefix !== undefined) ? prefix: url;
-
- $('#permalink_content').val(prefix + link);
-
- permOverlay.show();
- permOverlay.center();
-
- document.getElementById('permalink_content').focus();
- document.getElementById('permalink_content').select();
- };
-
+
/*
* Encode the URI component but convert exceptions back to their original
* values.
@@ -189,9 +141,9 @@ $(function() {
var encode = function(value) {
var encoded = encodeURIComponent(value);
$.each(ns.ENCODING_EXCEPTIONS, function(index, exception) {
- encoded = encoded.replace(exception.match, exception.replace);
+ encoded = encoded.replace(exception.match, exception.replace);
});
return encoded;
};
-
+
});
diff --git a/src/js/Worldview/Widget/Permalink.js b/src/js/Worldview/Widget/Permalink.js
new file mode 100644
index 000000000..c0fb3cebd
--- /dev/null
+++ b/src/js/Worldview/Widget/Permalink.js
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+/**
+ * Namespace: Worldview.Permalink
+ * Handles permalinks
+ */
+Worldview.namespace("Widget");
+
+Worldview.Widget.Permalink = (function() {
+
+ var permOverlay = null;
+
+ var ns = {};
+
+ /**
+ * Function: show
+ * Display a dialog box to the user showing the current permalink.
+ */
+ ns.show = function() {
+ if ( permOverlay === null ) {
+ permOverlay = new YAHOO.widget.Panel("panel_perm", {
+ width: "300px",
+ zIndex: 1020,
+ visible: false
+ });
+ var item = "<div id='permpanel' >" +
+ "<!-- <h3>Permalink:</h3> -->"+
+ "<span style='font-weight:400; font-size:12px; line-spacing:24px;'>Copy and paste the following link to share this view:</span>" +
+ "<input type='text' value='' name='permalink_content' id='permalink_content' />" +
+ "</div>";
+ permOverlay.setHeader("Permalink");
+ permOverlay.setBody(item);
+ permOverlay.render(document.body);
+ }
+
+ var qs = Worldview.Permalink.fromRegistry();
+ var url = window.location.href;
+ var prefix = url.split("?")[0];
+ prefix = (prefix !== null && prefix !== undefined) ? prefix: url;
+
+ $('#permalink_content').val(prefix + qs);
+
+ permOverlay.show();
+ permOverlay.center();
+
+ document.getElementById('permalink_content').focus();
+ document.getElementById('permalink_content').select();
+ };
+
+ return ns;
+
+})();