summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--askbot/skins/default/media/js/live_search.js39
-rw-r--r--askbot/skins/default/media/js/post.js18
-rw-r--r--askbot/skins/default/media/js/tag_selector.js35
-rw-r--r--askbot/skins/default/media/js/utils.js110
4 files changed, 73 insertions, 129 deletions
diff --git a/askbot/skins/default/media/js/live_search.js b/askbot/skins/default/media/js/live_search.js
index 23f81acd..7d9ff020 100644
--- a/askbot/skins/default/media/js/live_search.js
+++ b/askbot/skins/default/media/js/live_search.js
@@ -184,33 +184,9 @@ $(document).ready(function(){
};
var render_tag = function(tag_name, linkable, deletable){
- var url = askbot['urls']['questions'] +
- '?tags=' + encodeURI(tag_name);
- var tag_title = $.i18n._(
- "see questions tagged '{tag}'"
- ).replace(
- '{tag}',
- tag_name
- );
- var tag_element = 'span';
- var tag_url = '';
- if (linkable){
- tag_element = 'a';
- tag_url = ' href="' + url + '" ';
- }
- html = '<' + tag_element +
- ' class="tag tag-right" ' +
- tag_url +
- ' title="' + tag_title + '" rel="tag"' +
- '>' + tag_name + '</' + tag_element + '>';
- if (deletable){
- html += '<span class="delete-icon"></span>';
- }
- var tag_class = 'tag-left';
- if (deletable){
- tag_class += ' deletable-tag';
- }
- return '<li class="' + tag_class + '">' + html + '</li>';
+ var tag = Tag(deletable);
+ tag.setLinkable(linkable);
+ return tag.getElement().outerHTML();
};
var render_tags = function(tags, linkable, deletable){
@@ -317,7 +293,13 @@ $(document).ready(function(){
search_tags.children().remove();
var tags_html = '';
$.each(tags, function(idx, tag){
- tags_html += render_tag(tag, false, true);
+ var tag = new Tag();
+ tag.setName(tag);
+ tag.setDeletable(true);
+ tag.setLinkable(false);
+ tag.setDeleteHandler(
+ );
+ tags_html += tag.getElement().outerHTML();
});
search_tags.html(tags_html);
};
@@ -411,7 +393,6 @@ $(document).ready(function(){
render_paginator(data['paginator']);
set_question_count(data['question_counter']);
render_search_tags(data['query_data']['tags']);
- activate_search_tag_deleters();
render_faces(data['faces']);
render_related_tags(data['related_tags']);
render_relevance_sort_tab();
diff --git a/askbot/skins/default/media/js/post.js b/askbot/skins/default/media/js/post.js
index b7cedb0e..17fdb0ee 100644
--- a/askbot/skins/default/media/js/post.js
+++ b/askbot/skins/default/media/js/post.js
@@ -626,21 +626,9 @@ var questionRetagger = function(){
var render_tag = function(tag_name){
//copy-paste from live search!!!
- var url = askbot['urls']['questions'] +
- '?tags=' + encodeURI(tag_name);
- var tag_title = $.i18n._(
- "see questions tagged '{tag}'"
- ).replace(
- '{tag}',
- tag_name
- );
- return '<li class="tag-left">' +
- '<a ' +
- 'class="tag tag-right" ' +
- 'href="' + url + '" ' +
- 'title="' + tag_title + '" rel="tag"' +
- '>' + tag_name + '</a>' +
- '</li>';
+ var tag = new Tag();
+ tag.setName(tag_name);
+ return tag.getElement().outerHTML();
};
var drawNewTags = function(new_tags){
diff --git a/askbot/skins/default/media/js/tag_selector.js b/askbot/skins/default/media/js/tag_selector.js
index 86bacc88..1b87d9b3 100644
--- a/askbot/skins/default/media/js/tag_selector.js
+++ b/askbot/skins/default/media/js/tag_selector.js
@@ -122,33 +122,24 @@ function pickedTags(){
to_tag_container
){
$.each(clean_tag_names, function(idx, tag_name){
- var new_tag = $('<li></li>');
- new_tag.addClass('deletable-tag');
- new_tag.addClass('tag-left');
- var tag_link = $('<a></a>');
- tag_link.addClass('tag-right');
- tag_link.addClass('tag')
- tag_link.attr('rel','tag');
- var tag_url = askbot['urls']['questions'] + '?tags=' + tag_name;
- tag_link.attr('href', tag_url);
- var del_link = $('<span></span>');
- del_link.addClass('delete-icon');
+ var tag = new Tag();
+ tag.setDeletable(true);
+ tag.setHandler
if (/\*$/.test(tag_name)){
- tag_html = tagname.replace(/\*$/,'&#10045;');
- tag_link.click(handleWildCardTagClick(tag_name, reason));
- } else {
- var tag_html = tagname;
+ tag.setLinkable(false);
+ tag.setHandler(function(){
+ handleWildcardClick(tag_name, reason);
+ });
}
tag_link.html(tag_html);
+ tag.setDeleteHandler(function(){
+ unpickTag(to_target, tag_name, reason, true);
+ });
- setupTagDeleteEvents(del_link, to_target, tag_name, reason, true);
-
- new_tag.append(tag_link);
- new_tag.append(del_link);
- to_tag_container.append(new_tag);
-
- to_target[tagname] = new_tag;
+ var tag_element = tag.getElement().outerHTML();
+ to_tag_container.append(tag_element);
+ to_target[tag_name] = tag_element;
});
};
diff --git a/askbot/skins/default/media/js/utils.js b/askbot/skins/default/media/js/utils.js
index 0e041040..9427bca5 100644
--- a/askbot/skins/default/media/js/utils.js
+++ b/askbot/skins/default/media/js/utils.js
@@ -31,6 +31,17 @@ var showMessage = function(element, msg, where) {
div.fadeIn("fast");
};
+//outer html hack - https://github.com/brandonaaron/jquery-outerhtml/
+(function($){
+ var div;
+ $.fn.outerHTML = function() {
+ var elem = this[0],
+ tmp;
+ return !elem ? null
+ : typeof ( tmp = elem.outerHTML ) === 'string' ? tmp
+ : ( div = div || $('<div/>') ).html( this.eq(0).clone() ).html();
+ };
+})(jQuery);
var makeKeyHandler = function(key, callback){
return function(e){
@@ -173,9 +184,9 @@ DeleteIcon.prototype.createDom = function(){
this.decorate($('<span />'));
};
-var Tag = function(deletable){
+var Tag = function(){
WrappedElement.call(this);
- this._deletable = deletable;
+ this._deletable = false;
this._delete_handler = null;
this._delete_icon_title = null;
this._tag_title = null;
@@ -193,8 +204,20 @@ Tag.prototype.setHtmlTag = function(html_tag){
this._html_tag = html_tag;
};
-Tag.prototype.disableLink = function(){
- this._inner_html_tag = 'span';
+Tag.prototype.setDeletable = function(is_deletable){
+ this._deletable = is_deletable;
+};
+
+Tag.prototype.setLinkable = function(yes_no){
+ if (yes_no === true){
+ this._inner_html_tag = 'a';
+ } else {
+ this._inner_html_tag = 'span';
+ }
+};
+
+Tag.prototype.isLinkable = function(){
+ return (this._inner_html_tag === 'a');
};
Tag.prototype.setUrlParams = function(url_params){
@@ -222,17 +245,22 @@ Tag.prototype.decorate = function(element){
this._delete_icon.setTitle(this._delete_icon_title);
}
this._delete_icon.setHandler(this.getDeleteHandler());
- DeleteIcon.decorate(this._element.find('delete-icon'));
+ DeleteIcon.decorate(this._element.find('.delete-icon'));
}
- var tag_element = this._element.find('.tag');
+ this._inner_element = this._element.find('.tag');
if (this._title !== null){
- tag_element.attr('title', this._title);
+ this._inner_element.attr('title', this._title);
}
if (this._handler !== null){
setupButtonEventHandlers(this._element.find('.tag'), this._handler);
}
};
+Tag.prototype.getDisplayTagName = function(){
+ //replaces the trailing * symbol with the unicode asterisk
+ return /\*$/.replace(this._name, '&#10045;');
+};
+
Tag.prototype.createDom = function(){
this._element = this.makeElement(this._html_tag);
//render the outer element
@@ -242,9 +270,8 @@ Tag.prototype.createDom = function(){
this._element.addClass('tag-left');
//render the inner element
- var in_tag = this._inner_html_tag;
this._inner_element = this.makeElement(this._inner_html_tag);
- if (in_tag === 'a'){
+ if (this.isLinkable()){
var url = askbot['urls']['questions'];
url += '?tag=' + escape(this._name);
if (this._url_params !== null){
@@ -254,10 +281,18 @@ Tag.prototype.createDom = function(){
}
this._inner_element.addClass('tag tag-right');
this._inner_element.attr('rel', 'tag');
- if (this._title !== null){
- this._inner_element.attr('title', this._title);
+ if (this._title === null){
+ this.setTitle(
+ $.i18n._(
+ "see questions tagged '{tag}'"
+ ).replace(
+ '{tag}',
+ tag_name
+ )
+ );
}
- this._inner_element.html(/\*$/.replace(this._name, '&#10045;'));
+ this._inner_element.attr('title', this._title);
+ this._inner_element.html(this.getDisplayTagName());
this._element.append(this._inner_element);
@@ -271,57 +306,6 @@ Tag.prototype.createDom = function(){
}
};
-from tag selector
- $.each(clean_tag_names, function(idx, tag_name){
- var new_tag = $('<li></li>');
- new_tag.addClass('deletable-tag');
- new_tag.addClass('tag-left');
- var tag_link = $('<a></a>');
- tag_link.addClass('tag-right');
- tag_link.addClass('tag')
- tag_link.attr('rel','tag');
- var tag_url = askbot['urls']['questions'] + '?tags=' + tag_name;
- tag_link.attr('href', tag_url);
- var del_link = $('<span></span>');
- del_link.addClass('delete-icon');
-
- if (/\*$/.test(tag_name)){
- tag_html = tagname.replace(/\*$/,'&#10045;');
- tag_link.click(handleWildCardTagClick(tag_name, reason));
- } else {
- var tag_html = tagname;
- }
- tag_link.html(tag_html);
-
- setupTagDeleteEvents(del_link, to_target, tag_name, reason, true);
-
- new_tag.append(tag_link);
- new_tag.append(del_link);
- to_tag_container.append(new_tag);
-
- to_target[tagname] = new_tag;
- });
-
-/* from poost.js */
- var render_tag = function(tag_name){
- //copy-paste from live search!!!
- var url = askbot['urls']['questions'] +
- '?tags=' + encodeURI(tag_name);
- var tag_title = $.i18n._(
- "see questions tagged '{tag}'"
- ).replace(
- '{tag}',
- tag_name
- );
- return '<li class="tag-left">' +
- '<a ' +
- 'class="tag tag-right" ' +
- 'href="' + url + '" ' +
- 'title="' + tag_title + '" rel="tag"' +
- '>' + tag_name + '</a>' +
- '</li>';
- };
-
/* from live search */
var render_tag = function(tag_name, linkable, deletable){
var url = askbot['urls']['questions'] +