Permalink
Browse files

More Javascript cleanup.

  • Loading branch information...
1 parent f24d2a6 commit 0fd63c26f59c2be71b79f0edd2defa973eaec219 @joto joto committed Jan 23, 2012
Showing with 40 additions and 44 deletions.
  1. +37 −41 web/public/js/taginfo.js
  2. +1 −1 web/views/key.erb
  3. +2 −2 web/viewsjs/search.js.erb
View
@@ -54,7 +54,7 @@ function resize_home() {
var tags = tagcloud_data();
var cloud = '';
for (var i=0; i < tags.length; i++) {
- cloud += '<a href="/keys/' + tags[i][0] + '" style="font-size: ' + tags[i][1] + 'px;">' + tags[i][0] + '</a> ';
+ cloud += '<a href="' + url_for_key(tags[i][0]) + '" style="font-size: ' + tags[i][1] + 'px;">' + tags[i][0] + '</a> ';
}
tagcloud.append(cloud);
@@ -149,18 +149,38 @@ function print_prevalent_value_list(key, list) {
}).join(' &bull; ');
}
-function link_to_value_with_title(key, value, extra) {
- var k = encodeURIComponent(key),
- v = encodeURIComponent(value),
- title = html_escape(value) + ' ' + extra;
+function html_escape(text) {
+ return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
+}
+
+function url_for_key(key) {
+ var k = encodeURIComponent(key);
+ if (key.match(/[=\/]/)) {
+ return '/keys/?key=' + k;
+ } else {
+ return '/keys/' + k;
+ }
+}
+function url_for_tag(key, value) {
+ var k = encodeURIComponent(key),
+ v = encodeURIComponent(value);
if (key.match(/[=\/]/) || value.match(/[=\/]/)) {
- return '<a href="/tags/?key=' + k + '&value=' + v + '" title="' + title + '" tipsy="e">' + pp_value(value) + '</a>';
+ return '/tags/?key=' + k + '&value=' + v;
} else {
- return '<a href="/tags/' + k + '=' + v + '" title="' + title + '" tipsy="e">' + pp_value(value) + '</a>';
+ return '/tags/' + k + '=' + v;
}
}
+function link_to_value_with_title(key, value, extra) {
+ var k = encodeURIComponent(key),
+ v = encodeURIComponent(value),
+ title = html_escape(value) + ' ' + extra,
+ url = url_for_tag(key, value);
+
+ return '<a href="' + url + '" title="' + title + '" tipsy="e">' + pp_value(value) + '</a>';
+}
+
function print_value_with_percent(value, fraction) {
var v1 = print_with_ts(value),
v2 = fraction.print_as_percent();
@@ -215,54 +235,30 @@ function pp_value_with_highlight(value, highlight) {
}
function link_to_value_with_highlight(key, value, highlight) {
- return '<a href="' + url_to_value(key, value) + '">' + pp_value_with_highlight(value, highlight) + '</a>';
-}
-
-function html_escape(text) {
- return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
+ return '<a href="' + url_for_tag(key, value) + '">' + pp_value_with_highlight(value, highlight) + '</a>';
}
-function link_to_key(key) {
- var k = encodeURIComponent(key);
+function link_to_key(key, highlight) {
+ var hk, k = encodeURIComponent(key);
- if (key.match(/[=\/]/)) {
- return '<a href="/keys/?key=' + k + '">' + pp_key(key) + '</a>';
+ if (highlight === undefined) {
+ hk = pp_key(key);
} else {
- return '<a href="/keys/' + k + '">' + pp_key(key) + '</a>';
+ var re = new RegExp('(' + highlight + ')', 'gi');
+ hk = key.replace(re, "<b>$1</b>");
}
-}
-function link_to_key_with_highlight(key, highlight) {
- var k = encodeURIComponent(key);
-
- var re = new RegExp('(' + highlight + ')', 'gi');
- var hk = key.replace(re, "<b>$1</b>");
-
- if (key.match(/[=\/]/)) {
- return '<a href="/keys/?key=' + k + '">' + hk + '</a>';
- } else {
- return '<a href="/keys/' + k + '">' + hk + '</a>';
- }
+ return '<a href="' + url_for_key(key) + '">' + hk + '</a>';
}
-function url_to_value(key, value) {
- var k = encodeURIComponent(key),
- v = encodeURIComponent(value);
- if (key.match(/[=\/]/) || value.match(/[=\/]/)) {
- return '/tags/?key=' + k + '&value=' + v;
- } else {
- return '/tags/' + k + '=' + v;
- }
+function link_to_value(key, value) {
+ return '<a href="' + url_for_tag(key, value) + '">' + pp_value(value) + '</a>';
}
function link_to_tag(key, value) {
return link_to_key(key) + '=' + link_to_value(key, value);
}
-function link_to_value(key, value) {
- return '<a href="' + url_to_value(key, value) + '">' + pp_value(value) + '</a>';
-}
-
function link_to_key_or_tag(key, value) {
var link = link_to_key(key);
if (value && value != '') {
View
@@ -138,7 +138,7 @@ function page_init2() {
})
.event('click', function() {
if (this.data().value != '(other)') {
- window.location = url_to_value(#{ @key_json }, this.data().value);
+ window.location = url_for_tag(#{ @key_json }, this.data().value);
}
})
.anchor('left')
@@ -13,7 +13,7 @@ var create_flexigrid_for = {
data.rows = jQuery.map(data.data, function(row, i) {
return { 'cell': [
print_with_ts(row.count_all),
- link_to_key_with_highlight(row.key, query)
+ link_to_key(row.key, query)
] };
});
return data;
@@ -59,7 +59,7 @@ var create_flexigrid_for = {
data.rows = jQuery.map(data.data, function(row, i) {
return { 'cell': [
print_with_ts(row.count_all),
- link_to_key_with_highlight(row.key, q[0]),
+ link_to_key(row.key, q[0]),
link_to_value_with_highlight(row.key, row.value, q[1])
] };
});

0 comments on commit 0fd63c2

Please sign in to comment.