Mv team-local getParameterByName function to mkws.getParameterByName
authorMike Taylor <mike@indexdata.com>
Tue, 1 Apr 2014 12:20:13 +0000 (13:20 +0100)
committerMike Taylor <mike@indexdata.com>
Tue, 1 Apr 2014 12:20:13 +0000 (13:20 +0100)
So it can be accessed from both the team and individual widgets.

src/mkws-core.js

index e63d32e..de050e0 100644 (file)
@@ -106,6 +106,16 @@ mkws.objectWithParent = function(parent) {
 };
 
 
+// This function is taken from a StackOverflow answer
+// http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/901144#901144
+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.registerWidgetType = function(name, fn) {
     mkws.widgetType2function[name] = fn;
     mkws.log("registered widget-type '" + name + "'");