Move URL-parsing utility functions out of the team.
authorMike Taylor <mike@indexdata.com>
Wed, 5 Mar 2014 09:45:03 +0000 (09:45 +0000)
committerMike Taylor <mike@indexdata.com>
Wed, 5 Mar 2014 09:45:03 +0000 (09:45 +0000)
tools/htdocs/mkws.js

index 78f1e46..1a4f528 100644 (file)
@@ -847,7 +847,7 @@ function team($, teamName) {
 
 
     function mkwsSetLang()  {
-       var lang = parseQuerystring().lang || mkws_config.lang;
+       var lang = mkws.parseQuerystring().lang || mkws_config.lang;
        if (!lang || !mkws.locale_lang[lang]) {
            mkws_config.lang = ""
        } else {
@@ -969,7 +969,7 @@ function team($, teamName) {
 
        if (query.match(/^!param!/)) {
            var param = query.replace(/^!param!/, '');
-           query = getParameterByName(param);
+           query = mkws.getParameterByName(param);
            debug("obtained query '" + query + "' from param '" + param + "'");
            if (!query) {
                alert("This page has a MasterKey widget that needs a query specified by the '" + param + "' parameter");
@@ -997,30 +997,6 @@ function team($, teamName) {
     }
 
 
-    // implement $.parseQuerystring() for parsing URL parameters
-    function parseQuerystring() {
-       var nvpair = {};
-       var qs = window.location.search.replace('?', '');
-       var pairs = qs.split('&');
-       $.each(pairs, function(i, v){
-           var pair = v.split('=');
-           nvpair[pair[0]] = pair[1];
-       });
-       return nvpair;
-    }
-
-
-    // This function is taken from a StackOverflow answer
-    // http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/901144#901144
-    // ### should we unify this and parseQuerystring()?
-    function getParameterByName(name) {
-       name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
-       var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
-           results = regex.exec(location.search);
-       return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
-    }
-
-
     /* locale */
     function M(word) {
        var lang = mkws_config.lang;
@@ -1247,6 +1223,30 @@ function team($, teamName) {
     }
 
 
+    // implement $.parseQuerystring() for parsing URL parameters
+    mkws.parseQuerystring = function() {
+       var nvpair = {};
+       var qs = window.location.search.replace('?', '');
+       var pairs = qs.split('&');
+       $.each(pairs, function(i, v){
+           var pair = v.split('=');
+           nvpair[pair[0]] = pair[1];
+       });
+       return nvpair;
+    }
+
+
+    // This function is taken from a StackOverflow answer
+    // http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/901144#901144
+    // ### should we unify this and parseQuerystring()?
+    mkws.getParameterByName = function(name) {
+       name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
+       var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
+           results = regex.exec(location.search);
+       return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
+    }
+
+
     mkws.defaultTemplate = function(name)
     {
        if (name === 'Record') {