summaryrefslogtreecommitdiffstats
path: root/templates/content/js
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2009-12-08 22:50:45 -0500
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2009-12-08 22:50:45 -0500
commit9655bd421022dd6488b21184cc9fd0242c6b345e (patch)
tree8d9e58419b50630adc537ac92907d04946edc925 /templates/content/js
parent932b13188b08871e4f541f46c1dbb4eca693adfa (diff)
downloadaskbot-9655bd421022dd6488b21184cc9fd0242c6b345e.tar.gz
askbot-9655bd421022dd6488b21184cc9fd0242c6b345e.tar.bz2
askbot-9655bd421022dd6488b21184cc9fd0242c6b345e.zip
added interesting and ignored tag selectors (works) and per-tag subscription (not tested yet)
Diffstat (limited to 'templates/content/js')
-rw-r--r--templates/content/js/com.cnprog.admin.js2
-rw-r--r--templates/content/js/com.cnprog.post.js174
-rw-r--r--templates/content/js/com.cnprog.utils.js2
-rw-r--r--templates/content/js/compress.bat3
-rw-r--r--templates/content/js/flot-build.bat2
5 files changed, 174 insertions, 9 deletions
diff --git a/templates/content/js/com.cnprog.admin.js b/templates/content/js/com.cnprog.admin.js
index 73b5768f..cb1c1b15 100644
--- a/templates/content/js/com.cnprog.admin.js
+++ b/templates/content/js/com.cnprog.admin.js
@@ -3,7 +3,7 @@ $().ready( function(){
success: function(a,b){$('.admin #action_status').html($.i18n._('changes saved'));},
dataType:'json',
timeout:5000,
- url: $.i18n._('/') + $.i18n._('moderate-user/') + viewUserID + '/'
+ url: scriptUrl + $.i18n._('moderate-user/') + viewUserID + '/'
};
var form = $('.admin #moderate_user_form').ajaxForm(options);
var box = $('.admin input#id_is_approved').click(function(){
diff --git a/templates/content/js/com.cnprog.post.js b/templates/content/js/com.cnprog.post.js
index 5d58ff21..0d4c52d3 100644
--- a/templates/content/js/com.cnprog.post.js
+++ b/templates/content/js/com.cnprog.post.js
@@ -500,7 +500,7 @@ function createComments(type) {
jDiv.append('<p id="' + divId + '" class="comment">'
+ $.i18n._('to comment, need') + ' ' +
+ repNeededForComments + ' ' + $.i18n._('community karma points')
- + '<a href="' + $.i18n._('/') + $.i18n._('faq/') + '" class="comment-user">'
+ + '<a href="' + scriptUrl + $.i18n._('faq/') + '" class="comment-user">'
+ $.i18n._('please see') + 'faq</a></span></p>');
}
}
@@ -601,7 +601,7 @@ function createComments(type) {
$(this).children().each(
function(i){
var comment_id = $(this).attr('id').replace('comment-','');
- var delete_url = $.i18n._('/') + objectType + 's/' + post_id + '/'
+ var delete_url = scriptUrl + objectType + 's/' + post_id + '/'
+ $.i18n._('comments/') + comment_id + '/' + $.i18n._('delete/');
var html = $(this).html();
var CommentsClass;
@@ -615,12 +615,12 @@ function createComments(type) {
delete_icon.click(function(){CommentsClass.deleteComment($(this),comment_id,delete_url);});
delete_icon.unbind('mouseover').bind('mouseover',
function(){
- $(this).attr('src',$.i18n._('/') + 'content/images/close-small-hover.png');
+ $(this).attr('src',scriptUrl + 'content/images/close-small-hover.png');
}
);
delete_icon.unbind('mouseout').bind('mouseout',
function(){
- $(this).attr('src',$.i18n._('/') + 'content/images/close-small.png');
+ $(this).attr('src',scriptUrl + 'content/images/close-small.png');
}
);
}
@@ -670,12 +670,178 @@ function createComments(type) {
};
}
+function pickedTags(){
+
+ var sendAjax = function(tagname, reason, action, callback){
+ url = scriptUrl;
+ if (action == 'add'){
+ url += $.i18n._('mark-tag/');
+ if (reason == 'good'){
+ url += $.i18n._('interesting/');
+ }
+ else {
+ url += $.i18n._('ignored/');
+ }
+ }
+ else {
+ url += $.i18n._('unmark-tag/');
+ }
+ url = url + tagname + '/';
+
+ call_settings = {
+ type:'POST',
+ url:url
+ }
+ if (callback != false){
+ call_settings['success'] = callback;
+ }
+ $.ajax(call_settings);
+ }
+
+
+ var unpickTag = function(from_target ,tagname, reason, send_ajax){
+ //send ajax request to delete tag
+ var deleteTagLocally = function(){
+ from_target[tagname].remove();
+ delete from_target[tagname];
+ }
+ if (send_ajax){
+ sendAjax(tagname,reason,'remove',deleteTagLocally);
+ }
+ else {
+ deleteTagLocally();
+ }
+
+ }
+
+ var setupTagDeleteEvents = function(obj,tag_store,tagname,reason,send_ajax){
+ obj.unbind('mouseover').bind('mouseover', function(){
+ $(this).attr('src', scriptUrl + 'content/images/close-small-hover.png');
+ });
+ obj.unbind('mouseout').bind('mouseout', function(){
+ $(this).attr('src', scriptUrl + 'content/images/close-small-dark.png');
+ });
+ obj.click( function(){
+ unpickTag(tag_store,tagname,reason,send_ajax);
+ });
+ }
+
+ var handlePickedTag = function(obj,reason){
+ var tagname = $.trim($(obj).prev().attr('value'));
+ to_target = interestingTags;
+ from_target = ignoredTags;
+ if (reason == 'bad'){
+ to_target = ignoredTags;
+ from_target = interestingTags;
+ to_tag_container = $('div .tags.ignored');
+ }
+ else if (reason != 'good'){
+ return;
+ }
+ else {
+ to_tag_container = $('div .tags.interesting');
+ }
+
+ if (tagname in from_target){
+ unpickTag(from_target,tagname,reason,false);
+ }
+
+ if (!(tagname in to_target)){
+ //send ajax request to pick this tag
+
+ sendAjax(tagname,reason,'add',function(){
+ new_tag = $('<span></span>');
+ new_tag.addClass('deletable-tag');
+ tag_link = $('<a></a>');
+ tag_link.attr('rel','tag');
+ tag_link.attr('href', scriptUrl + $.i18n._('tags/') + tagname);
+ tag_link.html(tagname);
+ del_link = $('<img></img>');
+ del_link.addClass('delete-icon');
+ del_link.attr('src', scriptUrl + 'content/images/close-small-dark.png');
+
+ setupTagDeleteEvents(del_link, to_target, tagname, reason, true);
+
+ new_tag.append(tag_link);
+ new_tag.append(del_link);
+ to_tag_container.append(new_tag);
+
+ to_target[tagname] = new_tag;
+ });
+ }
+ }
+
+ var collectPickedTags = function(){
+ var good_prefix = 'interesting-tag-';
+ var bad_prefix = 'ignored-tag-';
+ var good_re = RegExp('^' + good_prefix);
+ var bad_re = RegExp('^' + bad_prefix);
+ interestingTags = {};
+ ignoredTags = {};
+ $('.deletable-tag').each(
+ function(i,item){
+ item_id = $(item).attr('id')
+ if (good_re.test(item_id)){
+ tag_name = item_id.replace(good_prefix,'');
+ tag_store = interestingTags;
+ reason = 'good';
+ }
+ else if (bad_re.test(item_id)){
+ tag_name = item_id.replace(bad_prefix,'');
+ tag_store = ignoredTags;
+ reason = 'bad';
+ }
+ else {
+ return;
+ }
+ tag_store[tag_name] = $(item);
+ setupTagDeleteEvents($(item).find('img'),tag_store,tag_name,reason,true)
+ }
+ );
+ }
+
+ var setupHideIgnoredQuestionsControl = function(){
+ $('#hideIgnoredTagsCb').unbind('click').click(function(){
+ $.ajax({
+ type: 'POST',
+ dataType: 'json',
+ cache: false,
+ url: scriptUrl + $.i18n._('command/'),
+ data: {command:'toggle-ignored-questions'}
+ });
+ });
+ }
+ return {
+ init: function(){
+ collectPickedTags();
+ setupHideIgnoredQuestionsControl();
+ $("#interestingTagInput, #ignoredTagInput").autocomplete(tags, {
+ minChars: 1,
+ matchContains: true,
+ max: 20,
+ multiple: true,
+ multipleSeparator: " ",
+ formatItem: function(row, i, max) {
+ return row.n + " ("+ row.c +")";
+ },
+ formatResult: function(row, i, max){
+ return row.n;
+ }
+
+ });
+ $("#interestingTagAdd").click(function(){handlePickedTag(this,'good')});
+ $("#ignoredTagAdd").click(function(){handlePickedTag(this,'bad')});
+ }
+ };
+}
+
var questionComments = createComments('question');
var answerComments = createComments('answer');
$().ready(function() {
questionComments.init();
answerComments.init();
+ pickedTags().init();
});
var commentsFactory = {'question' : questionComments, 'answer' : answerComments};
diff --git a/templates/content/js/com.cnprog.utils.js b/templates/content/js/com.cnprog.utils.js
index cf27c8a1..b19b6773 100644
--- a/templates/content/js/com.cnprog.utils.js
+++ b/templates/content/js/com.cnprog.utils.js
@@ -36,7 +36,7 @@ var notify = function() {
function appendLoader(containerSelector) {
$(containerSelector).append('<img class="ajax-loader" '
- +'src="' + $.i18n._('/') + 'content/images/indicator.gif" title="'
+ +'src="' + scriptUrl + 'content/images/indicator.gif" title="'
+$.i18n._('loading...')
+'" alt="'
+$.i18n._('loading...')
diff --git a/templates/content/js/compress.bat b/templates/content/js/compress.bat
index 41e1882a..5b2673cf 100644
--- a/templates/content/js/compress.bat
+++ b/templates/content/js/compress.bat
@@ -2,5 +2,4 @@
#java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 wmd\showdown.js -o wmd\showdown-min.js
#java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 com.cnprog.post.js -o com.cnprog.post.pack.js
java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 se_hilite_src.js -o se_hilite.js
-
-pause \ No newline at end of file
+pause
diff --git a/templates/content/js/flot-build.bat b/templates/content/js/flot-build.bat
index fc715e3a..f9f32cb7 100644
--- a/templates/content/js/flot-build.bat
+++ b/templates/content/js/flot-build.bat
@@ -1,3 +1,3 @@
java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 jquery.flot.js -o jquery.flot.pack.js
-pause \ No newline at end of file
+pause