moksha/public/javascript/moksha.js | 64 ++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 22 deletions(-)
New commits: commit 8c04c39ad539e0c3ac408cd5b1f6c9079cb25572 Author: John (J5) Palmieri johnp@redhat.com Date: Wed Mar 25 17:35:39 2009 -0400
make uri parsing and updating more generic
* we can now pass a params dict and have the uri parsing object translate that into a query string instead of the csrf code doing it for just the csrf token
diff --git a/moksha/public/javascript/moksha.js b/moksha/public/javascript/moksha.js index 327f506..bde0601 100644 --- a/moksha/public/javascript/moksha.js +++ b/moksha/public/javascript/moksha.js @@ -94,29 +94,15 @@ moksha = { /******************************************************************** * Take a url and attach the csrf hash if available ********************************************************************/ - csrf_rewrite_url: function(url) { - if (typeof(moksha_csrf_token) === 'undefined' || !moksha_csrf_token) - return url; - + csrf_rewrite_url: function(url, params) { var ourl = moksha.parseUri(url);
- var proto = ourl.protocol; - if (proto) - proto += '://'; - var newurl = proto + ourl.authority + ourl.path; - var qlist = [] - ourl.queryKey['_csrf_token'] = moksha_csrf_token; - for (q in ourl.queryKey) { - qlist.push(q + '=' + ourl.queryKey[q]); - } + if (typeof(moksha_csrf_token) != 'undefined' && moksha_csrf_token) + params['_csrf_token'] = moksha_csrf_token;
- var query = qlist.join('&') - newurl += '?'+ query; + ourl.update_query_string(params);
- if (ourl.anchor) - newurl += '#' + ourl.anchor; - - return newurl; + return ourl.toString();
},
@@ -153,8 +139,11 @@ moksha = { * * TODO: Fast loading where we just switch tabs ********************************************************************/ - goto: function(url, target) { - window.location.href = moksha.csrf_rewrite_url(url); + goto: function(url, params, target) { + if (typeof(params) != 'object') + params = {} + + window.location.href = moksha.csrf_rewrite_url(url, params); },
/* @@ -174,9 +163,38 @@ moksha = { } };
+ var uriClass = function(){}; + uriClass.prototype = { + update_query_string :function(params) { + for (p in params) + this.queryKey[p] = params[p]; + }, + + toString: function() { + var proto = this.protocol; + if (proto) + proto += '://'; + + var url = proto + this.authority + this.path; + var qlist = [] + + for (q in this.queryKey) { + qlist.push(q + '=' + this.queryKey[q]); + } + + var query = qlist.join('&') + url += '?'+ query; + + if (this.anchor) + url += '#' + this.anchor; + + return url; + } + }; + var o = options, m = o.parser[o.strictMode ? "strict" : "loose"].exec(str), - uri = {}, + uri = new uriClass, i = 14;
while (i--) uri[o.key[i]] = m[i] || ""; @@ -189,6 +207,8 @@ moksha = { return uri; },
+ + }
})();
moksha-commits@lists.fedorahosted.org