moksha/api/widgets/selectable/templates/selectable.mak | 2 moksha/public/javascript/moksha.js | 77 ++++++++++++++++- moksha/public/javascript/ui/moksha.ui.grid.js | 5 + 3 files changed, 81 insertions(+), 3 deletions(-)
New commits: commit 3a3b4d9e5303ffe79a985086d3583229f116bf48 Merge: 59e2b32... dffa550... Author: John (J5) Palmieri johnp@redhat.com Date: Wed Apr 29 16:43:30 2009 -0400
Merge branch 'master' of git+ssh://johnp@git.fedorahosted.org/git/moksha
commit 59e2b324205f67ec801b5d6d4f822b757d8cf28b Author: John (J5) Palmieri johnp@redhat.com Date: Wed Apr 29 16:42:45 2009 -0400
add url rewriting for all links with attribute moksha_url="dynamic|static"
diff --git a/moksha/api/widgets/selectable/templates/selectable.mak b/moksha/api/widgets/selectable/templates/selectable.mak index 0414525..10ecc2b 100644 --- a/moksha/api/widgets/selectable/templates/selectable.mak +++ b/moksha/api/widgets/selectable/templates/selectable.mak @@ -8,7 +8,7 @@ <ul> % for j, item in enumerate(c['items']): <li> - <a id="${content_id}_${i}_${j}" href="javascript:moksha.goto('${item['link']}')" >${item['label']}</a> + <a id="${content_id}_${i}_${j}" href="${item['link']}" moksha_url="dynamic">${item['label']}</a> % if 'data' in item: <script type="text/javascript"> <% diff --git a/moksha/public/javascript/moksha.js b/moksha/public/javascript/moksha.js index 62c404d..e1513fb 100644 --- a/moksha/public/javascript/moksha.js +++ b/moksha/public/javascript/moksha.js @@ -118,6 +118,50 @@ moksha = { },
/****************************************************************** + * Filter anchors in a fragment of HTML or jQuery DOM marked with + * a moksha_url attribute so that they have updated static links + * (e.g. run moksha.url on them) + * and dynamic moksha.goto links + * + * Dynamic links will eventually be able to load the correct tabs + * on click and static links are used when the user opens the link + * in another browser window. + * + * moksha_url="dynamic" - make both a dynamic and static link + * moksha_url="static" - only make a static link + ******************************************************************/ + update_marked_anchors: function(fragment) { + if (!fragment.jquery) + fragment = $(fragment); + + var $a_list = $('a[moksha_url]', fragment); + + var _goto = function(e) { + var href = $(this).data('dynamic_href.moksha'); + moksha.goto(href); + + return false; + } + + $.each($a_list, function(i, e) { + var $e = $(e) + var href = $e.attr('href'); + var moksha_url = $e.attr('moksha_url'); + + if (moksha_url.toLowerCase() == 'dynamic') { + $e.data('dynamic_href.moksha', href); + $e.unbind('click.moksha').bind('click.moksha', _goto); + } + + href = moksha.url(href); + e.href = href; + } + ); + + return fragment; + }, + + /****************************************************************** * Filter resources in a fragment of HTML or jQuery DOM * so that they aren't double loaded. Right now this is only * scripts but could be expanded to css and other loaded @@ -131,6 +175,7 @@ moksha = {
var $f = moksha.filter_scripts(fragment); $f = moksha.filter_links($f); + $f = moksha.update_marked_anchors($f); return $f; },
@@ -255,6 +300,33 @@ moksha = { },
prepend_base_url: function(base_url) { + // make sure we haven't already prepended the base url + // always remove leading slashes + var leading_slashes = /^/+/; + + var base_split = base_url.replace(leading_slashes, '').split('/'); + var dir_split = this.directory.replace(leading_slashes, '').split('/'); + + var should_exit = true; + for (i in base_split) { + + try { + var b = base_split[i]; + var d = dir_split[i]; + } catch (e) { + should_exit = false; + break; + } + + if (b != d) { + should_exit = false; + break; + } + } + + if (should_exit) + return; + this.directory = base_url + this.directory; this.directory = this._normalize_path(this.directory);
@@ -288,7 +360,8 @@ moksha = { }
var query = qlist.join('&') - url += '?'+ query; + if(query) + url += '?'+ query;
if (this.anchor) url += '#' + this.anchor; @@ -459,11 +532,11 @@ moksha = { params = {};
var purl = moksha.parseUri(url); - purl.update_query_string(params);
if (!purl.protocol) { var burl = moksha.get_base_url(); purl.prepend_base_url(burl); + purl.update_query_string(params);
moksha.csrf_rewrite_uri(purl); } diff --git a/moksha/public/javascript/ui/moksha.ui.grid.js b/moksha/public/javascript/ui/moksha.ui.grid.js index 1db6403..a51d9a5 100644 --- a/moksha/public/javascript/ui/moksha.ui.grid.js +++ b/moksha/public/javascript/ui/moksha.ui.grid.js @@ -70,6 +70,8 @@ return;
var $new_row = jQuery(o.row_template.apply(row_data)); + moksha.update_marked_anchors($new_row); + var $ph = self.$rowplaceholder; if (i == -1 || row_count == i) { var row_class = o.rowClass + '_' + row_count.toString(); @@ -308,6 +310,9 @@ if (rowtemplate.length) rowtemplate.after(self.$rowplaceholder);
+ var $a = jQuery('a[href]', rowtemplate); + $.each($a, function(i,e) { $(e).attr('moksha_url', 'dynamic') }); + // hack to get the full html of the template including the root tag // this also removes the template from the document var container_div = jQuery('<div />');
moksha-commits@lists.fedorahosted.org