moksha/public/javascript/moksha.js | 44 +++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-)
New commits: commit bee9bbe934b9d3a064f6cba7ca3064b7473162fb Merge: f9b1a2b bd3068c Author: Luke Macken lmacken@redhat.com Date: Tue Nov 1 17:16:01 2011 -0400
Merge branch 'master' into dev
commit bd3068cee52c8683c2e510205321a5dfa9d9fb7e Author: John (J5) Palmieri johnp@redhat.com Date: Fri Oct 28 15:08:16 2011 -0400
add url_mask method to allow dynamic_goto to correctly rewrite url
diff --git a/moksha/public/javascript/moksha.js b/moksha/public/javascript/moksha.js index 4f811b8..fda03ec 100644 --- a/moksha/public/javascript/moksha.js +++ b/moksha/public/javascript/moksha.js @@ -414,16 +414,52 @@ moksha = { window.location.href = moksha.url(url, params); },
+ + // Applys a mask in the form of '/*/path' where the wild card inserts the + // element from the source_url. + // + // example: + // source_url = '/foo/bar/baz'; + // mask = '/alpha/*/beta'; + // url_mask(source_url, mask); + // > '/alpha/bar/beta' + url_mask: function (source_url, mask) { + var result = ''; + var split_mask = mask.split('/'); + var split_source = source_url.split('/'); + for (var i=0; i < split_mask.length; i++) { + if (i >= split_source.length) + return result; + + if (split_mask[i] == '*') + result += split_source[i]; + else + result += split_mask[i]; + result += '/' + } + return result; + }, + /******************************************************************** - * Take a url and target, attach the csrf hash if available and load + * Dynamically load a portion of the page ********************************************************************/ - dynamic_goto: function(url, params) { + dynamic_goto: function(url, params, target, display_path) { if (typeof(params) != 'object') params = {}
- var new_path = moksha.url(url, params); var current_path = location.pathname; - window.history.pushState({}, "", moksha.url(url, params)); + display_path = moksha.url(display_path); + + var masked_url = moksha.url_mask(current_path, display_path); + + window.history.pushState({}, "", masked_url); + function load_finish(html) { + $(target).html(html); + } + moksha.html_load(url, params, load_finish); + + // prevent link from reloading entire page if attached to onClick handler + return false; },
/*
moksha-commits@lists.fedorahosted.org