]> git.openstreetmap.org Git - osqa.git/blob - forum/skins/default/media/js/osqa.main.js
6264fb42ee6e4a4aca8b63de7bd2a0fa3056ea54
[osqa.git] / forum / skins / default / media / js / osqa.main.js
1 var response_commands = {\r
2     update_post_score: function(id, inc) {\r
3         var $score_board = $('#post-' + id + '-score');\r
4         var current = parseInt($score_board.html())\r
5         if (isNaN(current)){\r
6             current = 0;\r
7         }\r
8         $score_board.html(current + inc)\r
9     },\r
10 \r
11     update_user_post_vote: function(id, vote_type) {\r
12         var $upvote_button = $('#post-' + id + '-upvote');\r
13         var $downvote_button = $('#post-' + id + '-downvote');\r
14 \r
15         $upvote_button.removeClass('on');\r
16         $downvote_button.removeClass('on');\r
17 \r
18         if (vote_type == 'up') {\r
19             $upvote_button.addClass('on');\r
20         } else if (vote_type == 'down') {\r
21             $downvote_button.addClass('on');\r
22         }\r
23     },\r
24 \r
25     update_favorite_count: function(inc) {\r
26         var $favorite_count = $('#favorite-count');\r
27         var count = parseInt($favorite_count.html());\r
28 \r
29         if (isNaN(count))\r
30             count = 0;\r
31 \r
32         count += inc;\r
33 \r
34         if (count == 0)\r
35             count = '';\r
36 \r
37         $favorite_count.html(count);\r
38     },\r
39 \r
40     update_favorite_mark: function(type) {\r
41         if (type == 'on') {\r
42             $('#favorite-mark').addClass('on');\r
43         } else {\r
44             $('#favorite-mark').removeClass('on');\r
45         }\r
46     },\r
47 \r
48     mark_accepted: function(id) {\r
49         $('.accepted-answer').removeClass('accepted-answer');\r
50         $('.accept-answer.on').removeClass('on');\r
51         \r
52         var $answer = $('#answer-container-' + id);\r
53         $answer.addClass('accepted-answer');\r
54         $answer.find('.accept-answer').addClass('on');\r
55     },\r
56 \r
57     unmark_accepted: function(id) {\r
58         var $answer = $('#answer-container-' + id);\r
59         $answer.removeClass('accepted-answer');\r
60         $answer.find('.accept-answer').removeClass('on');\r
61     },\r
62 \r
63     remove_comment: function(id) {\r
64         var $comment = $('#comment-' + id);\r
65         $comment.css('background', 'red')\r
66         $comment.fadeOut('slow', function() {\r
67             $comment.remove();    \r
68         });\r
69     },\r
70 \r
71     insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url) {\r
72         var $container = $('#comments-container-' + post_id);\r
73         var skeleton = $('#new-comment-skeleton-' + post_id).html().toString();\r
74 \r
75         skeleton = skeleton.replace(new RegExp('%ID%', 'g'), comment_id)\r
76                 .replace(new RegExp('%COMMENT%', 'g'), comment)\r
77                 .replace(new RegExp('%USERNAME%', 'g'), username)\r
78                 .replace(new RegExp('%PROFILE_URL%', 'g'), profile_url)\r
79                 .replace(new RegExp('%DELETE_URL%', 'g'), delete_url);\r
80 \r
81         $container.append(skeleton);\r
82 \r
83         $('#comment-' + comment_id).slideDown('slow');\r
84     },\r
85 \r
86     update_comment: function(comment_id, comment_text) {\r
87         var $comment = $('#comment-' + comment_id);\r
88         $comment.find('.comment-text').html(comment_text);\r
89 \r
90         $comment.slideDown('slow');\r
91     },\r
92 \r
93     mark_deleted: function(post_type, post_id) {\r
94         if (post_type == 'answer') {\r
95             var $answer = $('#answer-container-' + post_id);\r
96             $answer.addClass('deleted');\r
97         } else {\r
98             var $container = $('#question-table');\r
99             $container.addClass('deleted');\r
100         }\r
101     },\r
102 \r
103     set_subscription_button: function(text) {\r
104         $('.subscription_switch').html(text);\r
105     },\r
106 \r
107     set_subscription_status: function(text) {\r
108         $('.subscription-status').html(text);\r
109     }\r
110 }\r
111 \r
112 function show_message(object, msg) {\r
113     var div = $('<div class="vote-notification"><h3>' + msg + '</h3>(' +\r
114     'click to close' + ')</div>');\r
115 \r
116     div.click(function(event) {\r
117         $(".vote-notification").fadeOut("fast", function() { $(this).remove(); });\r
118     });\r
119 \r
120     object.parent().append(div);\r
121     div.fadeIn("fast");\r
122 }\r
123 \r
124 function process_ajax_response(data, el) {\r
125     if (!data.success && data['error_message'] != undefined) {\r
126         show_message(el, data.error_message)\r
127     } else if (typeof data['commands'] != undefined){\r
128         for (var command in data.commands) {\r
129             response_commands[command].apply(null, data.commands[command])\r
130         }\r
131 \r
132         if (data['message'] != undefined) {\r
133             show_message(el, data.message)\r
134         }\r
135     }\r
136 }\r
137 \r
138 $(function() {\r
139     $('a.ajax-command').live('click', function() {\r
140         var el = $(this);\r
141         $.getJSON(el.attr('href'), function(data) {\r
142             process_ajax_response(data, el);\r
143         });\r
144 \r
145         return false\r
146     });\r
147 \r
148     $('div.comment-form-container').each(function() {\r
149         var $container = $(this);\r
150         var $form = $container.find('form');\r
151         var $textarea = $container.find('textarea');\r
152         var $button = $container.find('input[type="submit"]');\r
153         var $chars_left_message = $('.comment-chars-left');\r
154         var $chars_counter = $container.find('.comments-char-left-count');\r
155 \r
156         var $comment_tools = $container.parent().find('.comment-tools');\r
157         var $add_comment_link = $comment_tools.find('.add-comment-link');\r
158         var $comments_container = $container.parent().find('.comments-container');\r
159 \r
160         var max_length = parseInt($chars_counter.html());\r
161         var comment_in_form = false;\r
162 \r
163         function cleanup_form() {\r
164             $textarea.val('');\r
165             $chars_counter.html(max_length);\r
166             $chars_left_message.removeClass('warn');\r
167             comment_in_form = false;\r
168         }\r
169 \r
170         cleanup_form();\r
171 \r
172         function calculate_chars_left() {\r
173             var length = $textarea.val().length;\r
174             var allow = true;\r
175 \r
176             if (length < max_length) {\r
177                 if (length < max_length * 0.75) {\r
178                     $chars_left_message.removeClass('warn');\r
179                 } else {\r
180                     $chars_left_message.addClass('warn');\r
181                 }\r
182             } else {\r
183                 allow = false;\r
184             }\r
185 \r
186             $chars_counter.html(max_length - length);\r
187             return allow;\r
188         }\r
189 \r
190         function show_comment_form() {\r
191             $container.slideDown('slow');\r
192             $add_comment_link.fadeOut('slow');\r
193         }\r
194 \r
195         function hide_comment_form() {\r
196             $container.slideUp('slow');\r
197             $add_comment_link.fadeIn('slow');\r
198         }\r
199 \r
200         $add_comment_link.click(function(){\r
201             cleanup_form();\r
202             show_comment_form();\r
203             return false;\r
204         });\r
205 \r
206         $comment_tools.find('.show-all-comments-link').click(function() {\r
207             $comments_container.find('.not_top_scorer').slideDown('slow');\r
208             $(this).fadeOut('slow');\r
209             $comment_tools.find('.comments-showing').fadeOut('slow');\r
210             return false;\r
211         });\r
212 \r
213         $('#' + $comments_container.attr('id') + ' .comment-edit').live('click', function() {\r
214             var $link = $(this);\r
215             var comment_id = /comment-(\d+)-edit/.exec($link.attr('id'))[1];\r
216             var $comment = $link.parents('.comment');\r
217             var comment_text = $comment.find('.comment-text').text().trim();\r
218 \r
219             comment_in_form = comment_id;\r
220             $textarea.val(comment_text);\r
221             calculate_chars_left();\r
222             $comment.slideUp('slow');\r
223             show_comment_form();\r
224             return false;\r
225         });\r
226 \r
227         $textarea.keyup(calculate_chars_left);\r
228 \r
229         $button.click(function() {\r
230             if ($textarea.val().length > max_length) {\r
231                 show_message($button, "Your comment exceeds the max number of characters allowed.");\r
232             } else {\r
233                 var post_data = {\r
234                     comment: $textarea.val()\r
235                 }\r
236 \r
237                 if (comment_in_form) {\r
238                     post_data['id'] = comment_in_form;\r
239                 }\r
240 \r
241                 $.post($form.attr('action'), post_data, function(data) {\r
242                     process_ajax_response(data, $button);\r
243                     cleanup_form();\r
244                 }, "json")\r
245             }\r
246 \r
247             hide_comment_form();\r
248             return false;\r
249         });\r
250     });\r
251 \r
252             \r
253 });\r
254 \r
255 //var scriptUrl, interestingTags, ignoredTags, tags, $;\r
256 function pickedTags(){\r
257 \r
258     var sendAjax = function(tagname, reason, action, callback){\r
259         var url = scriptUrl;\r
260         if (action == 'add'){\r
261             url += $.i18n._('mark-tag/');\r
262             if (reason == 'good'){\r
263                 url += $.i18n._('interesting/');\r
264             }\r
265             else {\r
266                 url += $.i18n._('ignored/');\r
267             }\r
268         }\r
269         else {\r
270             url += $.i18n._('unmark-tag/');\r
271         }\r
272         url = url + tagname + '/';\r
273 \r
274         var call_settings = {\r
275             type:'POST',\r
276             url:url\r
277         };\r
278         if (callback !== false){\r
279             call_settings.success = callback;\r
280         }\r
281         $.ajax(call_settings);\r
282     };\r
283 \r
284 \r
285     var unpickTag = function(from_target ,tagname, reason, send_ajax){\r
286         //send ajax request to delete tag\r
287         var deleteTagLocally = function(){\r
288             from_target[tagname].remove();\r
289             delete from_target[tagname];\r
290         };\r
291         if (send_ajax){\r
292             sendAjax(tagname,reason,'remove',deleteTagLocally);\r
293         }\r
294         else {\r
295             deleteTagLocally();\r
296         }\r
297 \r
298     };\r
299 \r
300     var setupTagDeleteEvents = function(obj,tag_store,tagname,reason,send_ajax){\r
301         obj.unbind('mouseover').bind('mouseover', function(){\r
302             $(this).attr('src', mediaUrl('media/images/close-small-hover.png'));\r
303         });\r
304         obj.unbind('mouseout').bind('mouseout', function(){\r
305             $(this).attr('src', mediaUrl('media/images/close-small-dark.png'));\r
306         });\r
307         obj.click( function(){\r
308             unpickTag(tag_store,tagname,reason,send_ajax);\r
309         });\r
310     };\r
311 \r
312     var handlePickedTag = function(obj,reason){\r
313         var tagname = $.trim($(obj).prev().attr('value'));\r
314         var to_target = interestingTags;\r
315         var from_target = ignoredTags;\r
316         var to_tag_container;\r
317         if (reason == 'bad'){\r
318             to_target = ignoredTags;\r
319             from_target = interestingTags;\r
320             to_tag_container = $('div .tags.ignored');\r
321         }\r
322         else if (reason != 'good'){\r
323             return;\r
324         }\r
325         else {\r
326             to_tag_container = $('div .tags.interesting');\r
327         }\r
328 \r
329         if (tagname in from_target){\r
330             unpickTag(from_target,tagname,reason,false);\r
331         }\r
332 \r
333         if (!(tagname in to_target)){\r
334             //send ajax request to pick this tag\r
335 \r
336             sendAjax(tagname,reason,'add',function(){\r
337                 var new_tag = $('<span></span>');\r
338                 new_tag.addClass('deletable-tag');\r
339                 var tag_link = $('<a></a>');\r
340                 tag_link.attr('rel','tag');\r
341                 tag_link.attr('href', scriptUrl + $.i18n._('tags/') + tagname);\r
342                 tag_link.html(tagname);\r
343                 var del_link = $('<img></img>');\r
344                 del_link.addClass('delete-icon');\r
345                 del_link.attr('src', mediaUrl('/media/images/close-small-dark.png'));\r
346 \r
347                 setupTagDeleteEvents(del_link, to_target, tagname, reason, true);\r
348 \r
349                 new_tag.append(tag_link);\r
350                 new_tag.append(del_link);\r
351                 to_tag_container.append(new_tag);\r
352 \r
353                 to_target[tagname] = new_tag;\r
354             });\r
355         }\r
356     };\r
357 \r
358     var collectPickedTags = function(){\r
359         var good_prefix = 'interesting-tag-';\r
360         var bad_prefix = 'ignored-tag-';\r
361         var good_re = RegExp('^' + good_prefix);\r
362         var bad_re = RegExp('^' + bad_prefix);\r
363         interestingTags = {};\r
364         ignoredTags = {};\r
365         $('.deletable-tag').each(\r
366             function(i,item){\r
367                 var item_id = $(item).attr('id');\r
368                 var tag_name, tag_store;\r
369                 if (good_re.test(item_id)){\r
370                     tag_name = item_id.replace(good_prefix,'');\r
371                     tag_store = interestingTags;\r
372                     reason = 'good';\r
373                 }\r
374                 else if (bad_re.test(item_id)){\r
375                     tag_name = item_id.replace(bad_prefix,'');\r
376                     tag_store = ignoredTags;\r
377                     reason = 'bad';\r
378                 }\r
379                 else {\r
380                     return;\r
381                 }\r
382                 tag_store[tag_name] = $(item);\r
383                 setupTagDeleteEvents($(item).find('img'),tag_store,tag_name,reason,true);\r
384             }\r
385         );\r
386     };\r
387 \r
388     var setupHideIgnoredQuestionsControl = function(){\r
389         $('#hideIgnoredTagsCb').unbind('click').click(function(){\r
390             $.ajax({\r
391                         type: 'POST',\r
392                         dataType: 'json',\r
393                         cache: false,\r
394                         url: scriptUrl + $.i18n._('command/'),\r
395                         data: {command:'toggle-ignored-questions'}\r
396                     });\r
397         });\r
398     };\r
399     return {\r
400         init: function(){\r
401             collectPickedTags();\r
402             setupHideIgnoredQuestionsControl();\r
403             $("#interestingTagInput, #ignoredTagInput").autocomplete("/matching_tags", {\r
404                 minChars: 1,\r
405                 matchContains: true,\r
406                 max: 20,\r
407                 /*multiple: false, - the favorite tags and ignore tags don't let you do multiple tags\r
408                 multipleSeparator: " "*/\r
409 \r
410                 formatItem: function(row, i, max, value) {\r
411                     return row[1].split(".")[0] + " (" + row[1].split(".")[1] + ")";\r
412                 },\r
413 \r
414                 formatResult: function(row, i, max, value){\r
415                     return row[0];\r
416                 }\r
417 \r
418             });\r
419             $("#interestingTagAdd").click(function(){handlePickedTag(this,'good');});\r
420             $("#ignoredTagAdd").click(function(){handlePickedTag(this,'bad');});\r
421         }\r
422     };\r
423 }\r
424 \r
425 $(document).ready( function(){\r
426     //if (window.tags != undefined)\r
427         pickedTags().init();\r
428 });\r
429 \r
430 Hilite={elementid:"content",exact:true,max_nodes:1000,onload:true,style_name:"hilite",style_name_suffix:true,debug_referrer:""};Hilite.search_engines=[["local","q"],["cnprog\\.","q"],["google\\.","q"],["search\\.yahoo\\.","p"],["search\\.msn\\.","q"],["search\\.live\\.","query"],["search\\.aol\\.","userQuery"],["ask\\.com","q"],["altavista\\.","q"],["feedster\\.","q"],["search\\.lycos\\.","q"],["alltheweb\\.","q"],["technorati\\.com/search/([^\\?/]+)",1],["dogpile\\.com/info\\.dogpl/search/web/([^\\?/]+)",1,true]];Hilite.decodeReferrer=function(d){var g=null;var e=new RegExp("");for(var c=0;c<Hilite.search_engines.length;c++){var f=Hilite.search_engines[c];e.compile("^http://(www\\.)?"+f[0],"i");var b=d.match(e);if(b){var a;if(isNaN(f[1])){a=Hilite.decodeReferrerQS(d,f[1])}else{a=b[f[1]+1]}if(a){a=decodeURIComponent(a);if(f.length>2&&f[2]){a=decodeURIComponent(a)}a=a.replace(/\'|"/g,"");a=a.split(/[\s,\+\.]+/);return a}break}}return null};Hilite.decodeReferrerQS=function(f,d){var b=f.indexOf("?");var c;if(b>=0){var a=new String(f.substring(b+1));b=0;c=0;while((b>=0)&&((c=a.indexOf("=",b))>=0)){var e,g;e=a.substring(b,c);b=a.indexOf("&",c)+1;if(e==d){if(b<=0){return a.substring(c+1)}else{return a.substring(c+1,b-1)}}else{if(b<=0){return null}}}}return null};Hilite.hiliteElement=function(f,e){if(!e||f.childNodes.length==0){return}var c=new Array();for(var b=0;b<e.length;b++){e[b]=e[b].toLowerCase();if(Hilite.exact){c.push("\\b"+e[b]+"\\b")}else{c.push(e[b])}}c=new RegExp(c.join("|"),"i");var a={};for(var b=0;b<e.length;b++){if(Hilite.style_name_suffix){a[e[b]]=Hilite.style_name+(b+1)}else{a[e[b]]=Hilite.style_name}}var d=function(m){var j=c.exec(m.data);if(j){var n=j[0];var i="";var h=m.splitText(j.index);var g=h.splitText(n.length);var l=m.ownerDocument.createElement("SPAN");m.parentNode.replaceChild(l,h);l.className=a[n.toLowerCase()];l.appendChild(h);return l}else{return m}};Hilite.walkElements(f.childNodes[0],1,d)};Hilite.hilite=function(){var a=Hilite.debug_referrer?Hilite.debug_referrer:document.referrer;var b=null;a=Hilite.decodeReferrer(a);if(a&&((Hilite.elementid&&(b=document.getElementById(Hilite.elementid)))||(b=document.body))){Hilite.hiliteElement(b,a)}};Hilite.walkElements=function(d,f,e){var a=/^(script|style|textarea)/i;var c=0;while(d&&f>0){c++;if(c>=Hilite.max_nodes){var b=function(){Hilite.walkElements(d,f,e)};setTimeout(b,50);return}if(d.nodeType==1){if(!a.test(d.tagName)&&d.childNodes.length>0){d=d.childNodes[0];f++;continue}}else{if(d.nodeType==3){d=e(d)}}if(d.nextSibling){d=d.nextSibling}else{while(f>0){d=d.parentNode;f--;if(d.nextSibling){d=d.nextSibling;break}}}}};if(Hilite.onload){if(window.attachEvent){window.attachEvent("onload",Hilite.hilite)}else{if(window.addEventListener){window.addEventListener("load",Hilite.hilite,false)}else{var __onload=window.onload;window.onload=function(){Hilite.hilite();__onload()}}}};\r
431 \r
432 var mediaUrl = function(resource){\r
433     return scriptUrl + 'm/' + osqaSkin + '/' + resource;\r
434 };\r
435 \r
436 /*\r
437  * jQuery i18n plugin\r
438  * @requires jQuery v1.1 or later\r
439  *\r
440  * Examples at: http://recurser.com/articles/2008/02/21/jquery-i18n-translation-plugin/\r
441  * Dual licensed under the MIT and GPL licenses:\r
442  *   http://www.opensource.org/licenses/mit-license.php\r
443  *   http://www.gnu.org/licenses/gpl.html\r
444  *\r
445  * Based on 'javascript i18n that almost doesn't suck' by markos\r
446  * http://markos.gaivo.net/blog/?p=100\r
447  *\r
448  * Revision: $Id$\r
449  * Version: 1.0.0  Feb-10-2008\r
450  */\r
451  (function($) {\r
452 /**\r
453  * i18n provides a mechanism for translating strings using a jscript dictionary.\r
454  *\r
455  */\r
456 \r
457 \r
458 /*\r
459  * i18n property list\r
460  */\r
461 $.i18n = {\r
462 \r
463 /**\r
464  * setDictionary()\r
465  * Initialise the dictionary and translate nodes\r
466  *\r
467  * @param property_list i18n_dict : The dictionary to use for translation\r
468  */\r
469         setDictionary: function(i18n_dict) {\r
470                 i18n_dict = i18n_dict;\r
471         },\r
472 \r
473 /**\r
474  * _()\r
475  * The actual translation function. Looks the given string up in the\r
476  * dictionary and returns the translation if one exists. If a translation\r
477  * is not found, returns the original word\r
478  *\r
479  * @param string str : The string to translate\r
480  * @param property_list params : params for using printf() on the string\r
481  * @return string : Translated word\r
482  *\r
483  */\r
484         _: function (str, params) {\r
485                 var transl = str;\r
486                 if (i18n_dict&& i18n_dict[str]) {\r
487                         transl = i18n_dict[str];\r
488                 }\r
489                 return this.printf(transl, params);\r
490         },\r
491 \r
492 /**\r
493  * toEntity()\r
494  * Change non-ASCII characters to entity representation\r
495  *\r
496  * @param string str : The string to transform\r
497  * @return string result : Original string with non-ASCII content converted to entities\r
498  *\r
499  */\r
500         toEntity: function (str) {\r
501                 var result = '';\r
502                 for (var i=0;i<str.length; i++) {\r
503                         if (str.charCodeAt(i) > 128)\r
504                                 result += "&#"+str.charCodeAt(i)+";";\r
505                         else\r
506                                 result += str.charAt(i);\r
507                 }\r
508                 return result;\r
509         },\r
510 \r
511 /**\r
512  * stripStr()\r
513  *\r
514  * @param string str : The string to strip\r
515  * @return string result : Stripped string\r
516  *\r
517  */\r
518         stripStr: function(str) {\r
519                 return str.replace(/^\s*/, "").replace(/\s*$/, "");\r
520         },\r
521 \r
522 /**\r
523  * stripStrML()\r
524  *\r
525  * @param string str : The multi-line string to strip\r
526  * @return string result : Stripped string\r
527  *\r
528  */\r
529         stripStrML: function(str) {\r
530                 // Split because m flag doesn't exist before JS1.5 and we need to\r
531                 // strip newlines anyway\r
532                 var parts = str.split('\n');\r
533                 for (var i=0; i<parts.length; i++)\r
534                         parts[i] = stripStr(parts[i]);\r
535 \r
536                 // Don't join with empty strings, because it "concats" words\r
537                 // And strip again\r
538                 return stripStr(parts.join(" "));\r
539         },\r
540 \r
541 /*\r
542  * printf()\r
543  * C-printf like function, which substitutes %s with parameters\r
544  * given in list. %%s is used to escape %s.\r
545  *\r
546  * Doesn't work in IE5.0 (splice)\r
547  *\r
548  * @param string S : string to perform printf on.\r
549  * @param string L : Array of arguments for printf()\r
550  */\r
551         printf: function(S, L) {\r
552                 if (!L) return S;\r
553 \r
554                 var nS = "";\r
555                 var tS = S.split("%s");\r
556 \r
557                 for(var i=0; i<L.length; i++) {\r
558                         if (tS[i].lastIndexOf('%') == tS[i].length-1 && i != L.length-1)\r
559                                 tS[i] += "s"+tS.splice(i+1,1)[0];\r
560                         nS += tS[i] + L[i];\r
561                 }\r
562                 return nS + tS[tS.length-1];\r
563         }\r
564 \r
565 };\r
566 \r
567 \r
568 })(jQuery);\r
569 \r
570 \r
571 //var i18nLang;\r
572 var i18nZh = {\r
573         'insufficient privilege':'??????????',\r
574         'cannot pick own answer as best':'??????????????',\r
575         'anonymous users cannot select favorite questions':'?????????????',\r
576         'please login':'??????',\r
577         'anonymous users cannot vote':'????????',\r
578         '>15 points requried to upvote':'??+15?????????',\r
579         '>100 points required to downvote':'??+100?????????',\r
580         'please see': '??',\r
581         'cannot vote for own posts':'??????????',\r
582         'daily vote cap exhausted':'????????????????',\r
583         'cannot revoke old vote':'??????????????',\r
584         'please confirm offensive':"??????????????????????",\r
585         'anonymous users cannot flag offensive posts':'???????????',\r
586         'cannot flag message as offensive twice':'???????',\r
587         'flag offensive cap exhausted':'?????????????5?\91??\92???',\r
588         'need >15 points to report spam':"??+15??????\91???\92?",\r
589         'confirm delete':"?????/????????",\r
590         'anonymous users cannot delete/undelete':"???????????????",\r
591         'post recovered':"?????????????",\r
592         'post deleted':"????????????",\r
593         'add comment':'????',\r
594         'community karma points':'????',\r
595         'to comment, need':'????',\r
596         'delete this comment':'?????',\r
597         'hide comments':"????",\r
598         'add a comment':"????",\r
599         'comments':"??",\r
600         'confirm delete comment':"?????????",\r
601         'characters':'??',\r
602         'can write':'???',\r
603         'click to close':'???????',\r
604         'loading...':'???...',\r
605         'tags cannot be empty':'???????',\r
606         'tablimits info':"??5????????????20????",\r
607         'content cannot be empty':'???????',\r
608         'content minchars': '????? {0} ???',\r
609         'please enter title':'??????',\r
610         'title minchars':"????? {0} ???",\r
611         'delete':'??',\r
612         'undelete':     '??',\r
613         'bold':'??',\r
614         'italic':'??',\r
615         'link':'???',\r
616         'quote':'??',\r
617         'preformatted text':'??',\r
618         'image':'??',\r
619         'numbered list':'??????',\r
620         'bulleted list':'??????',\r
621         'heading':'??',\r
622         'horizontal bar':'???',\r
623         'undo':'??',\r
624         'redo':'??',\r
625         'enter image url':'<b>??????</b></p><p>???<br />http://www.example.com/image.jpg   \"????\"',\r
626         'enter url':'<b>??Web??</b></p><p>???<br />http://www.cnprog.com/   \"????\"</p>"',\r
627         'upload image':'?????????'\r
628 };\r
629 \r
630 var i18nEn = {\r
631         'need >15 points to report spam':'need >15 points to report spam ',\r
632     '>15 points requried to upvote':'>15 points required to upvote ',\r
633         'tags cannot be empty':'please enter at least one tag',\r
634         'anonymous users cannot vote':'sorry, anonymous users cannot vote ',\r
635         'anonymous users cannot select favorite questions':'sorry, anonymous users cannot select favorite questions ',\r
636         'to comment, need': '(to comment other people\'s posts, karma ',\r
637         'please see':'please see ',\r
638         'community karma points':' or more is necessary) - ',\r
639         'upload image':'Upload image:',\r
640         'enter image url':'enter URL of the image, e.g. http://www.example.com/image.jpg \"image title\"',\r
641         'enter url':'enter Web address, e.g. http://www.example.com \"page title\"',\r
642         'daily vote cap exhausted':'sorry, you\'ve used up todays vote cap',\r
643         'cannot pick own answer as best':'sorry, you cannot accept your own answer',\r
644         'cannot revoke old vote':'sorry, older votes cannot be revoked',\r
645         'please confirm offensive':'are you sure this post is offensive, contains spam, advertising, malicious remarks, etc.?',\r
646         'flag offensive cap exhausted':'sorry, you\'ve used up todays cap of flagging offensive messages ',\r
647         'confirm delete':'are you sure you want to delete this?',\r
648         'anonymous users cannot delete/undelete':'sorry, anonymous users cannot delete or undelete posts',\r
649         'post recovered':'your post is now restored!',\r
650         'post deleted':'your post has been deleted',\r
651         'confirm delete comment':'do you really want to delete this comment?',\r
652         'can write':'have ',\r
653         'tablimits info':'up to 5 tags, no more than 20 characters each',\r
654         'content minchars': 'please enter more than {0} characters',\r
655         'title minchars':"please enter at least {0} characters",\r
656         'characters':'characters left',\r
657     'cannot vote for own posts':'sorry, you cannot vote for your own posts',\r
658     'cannot flag message as offensive twice':'cannot flag message as offensive twice ',\r
659         '>100 points required to downvote':'>100 points required to downvote '\r
660 };\r
661 \r
662 var i18nEs = {\r
663         'insufficient privilege':'privilegio insuficiente',\r
664         'cannot pick own answer as best':'no puede escoger su propia respuesta como la mejor',\r
665         'anonymous users cannot select favorite questions':'usuarios anonimos no pueden seleccionar',\r
666         'please login':'por favor inicie sesión',\r
667         'anonymous users cannot vote':'usuarios anónimos no pueden votar',\r
668         '>15 points requried to upvote': '>15 puntos requeridos para votar positivamente',\r
669         '>100 points required to downvote':'>100 puntos requeridos para votar negativamente',\r
670         'please see': 'por favor vea',\r
671         'cannot vote for own posts':'no se puede votar por sus propias publicaciones',\r
672         'daily vote cap exhausted':'cuota de votos diarios excedida',\r
673         'cannot revoke old vote':'no puede revocar un voto viejo',\r
674         'please confirm offensive':"por favor confirme ofensiva",\r
675         'anonymous users cannot flag offensive posts':'usuarios anónimos no pueden marcar publicaciones como ofensivas',\r
676         'cannot flag message as offensive twice':'no puede marcar mensaje como ofensivo dos veces',\r
677         'flag offensive cap exhausted':'cuota para marcar ofensivas ha sido excedida',\r
678         'need >15 points to report spam':"necesita >15 puntos para reportar spam",\r
679         'confirm delete':"¿Está seguro que desea borrar esto?",\r
680         'anonymous users cannot delete/undelete':"usuarios anónimos no pueden borrar o recuperar publicaciones",\r
681         'post recovered':"publicación recuperada",\r
682         'post deleted':"publicación borrada?",\r
683         'add comment':'agregar comentario',\r
684         'community karma points':'reputación comunitaria',\r
685         'to comment, need':'para comentar, necesita reputación',\r
686         'delete this comment':'borrar este comentario',\r
687         'hide comments':"ocultar comentarios",\r
688         'add a comment':"agregar comentarios",\r
689         'comments':"comentarios",\r
690         'confirm delete comment':"¿Realmente desea borrar este comentario?",\r
691         'characters':'caracteres faltantes',\r
692         'can write':'tiene ',\r
693         'click to close':'haga click para cerrar',\r
694         'loading...':'cargando...',\r
695         'tags cannot be empty':'las etiquetas no pueden estar vacías',\r
696         'tablimits info':"hasta 5 etiquetas de no mas de 20 caracteres cada una",\r
697         'content cannot be empty':'el contenido no puede estar vacío',\r
698         'content minchars': 'por favor introduzca mas de {0} caracteres',\r
699         'please enter title':'por favor ingrese un título',\r
700         'title minchars':"por favor introduzca al menos {0} caracteres",\r
701         'delete':'borrar',\r
702         'undelete':     'recuperar',\r
703         'bold': 'negrita',\r
704         'italic':'cursiva',\r
705         'link':'enlace',\r
706         'quote':'citar',\r
707         'preformatted text':'texto preformateado',\r
708         'image':'imagen',\r
709         'numbered list':'lista numerada',\r
710         'bulleted list':'lista no numerada',\r
711         'heading':'??',\r
712         'horizontal bar':'barra horizontal',\r
713         'undo':'deshacer',\r
714         'redo':'rehacer',\r
715         'enter image url':'introduzca la URL de la imagen, por ejemplo?<br />http://www.example.com/image.jpg   \"titulo de imagen\"',\r
716         'enter url':'introduzca direcciones web, ejemplo?<br />http://www.cnprog.com/   \"titulo del enlace\"</p>"',\r
717         'upload image':'cargar imagen?',\r
718         'questions/' : 'preguntas/',\r
719         'vote/' : 'votar/'\r
720 };\r
721 \r
722 var i18n = {\r
723         'en':i18nEn,\r
724         'zh_CN':i18nZh,\r
725         'es':i18nEs\r
726 };\r
727 \r
728 var i18n_dict = i18n[i18nLang];\r
729 \r
730 /*\r
731         jQuery TextAreaResizer plugin\r
732         Created on 17th January 2008 by Ryan O'Dell\r
733         Version 1.0.4\r
734 */(function($){var textarea,staticOffset;var iLastMousePos=0;var iMin=32;var grip;$.fn.TextAreaResizer=function(){return this.each(function(){textarea=$(this).addClass('processed'),staticOffset=null;$(this).wrap('<div class="resizable-textarea"><span></span></div>').parent().append($('<div class="grippie"></div>').bind("mousedown",{el:this},startDrag));var grippie=$('div.grippie',$(this).parent())[0];grippie.style.marginRight=(grippie.offsetWidth-$(this)[0].offsetWidth)+'px'})};function startDrag(e){textarea=$(e.data.el);textarea.blur();iLastMousePos=mousePosition(e).y;staticOffset=textarea.height()-iLastMousePos;textarea.css('opacity',0.25);$(document).mousemove(performDrag).mouseup(endDrag);return false}function performDrag(e){var iThisMousePos=mousePosition(e).y;var iMousePos=staticOffset+iThisMousePos;if(iLastMousePos>=(iThisMousePos)){iMousePos-=5}iLastMousePos=iThisMousePos;iMousePos=Math.max(iMin,iMousePos);textarea.height(iMousePos+'px');if(iMousePos<iMin){endDrag(e)}return false}function endDrag(e){$(document).unbind('mousemove',performDrag).unbind('mouseup',endDrag);textarea.css('opacity',1);textarea.focus();textarea=null;staticOffset=null;iLastMousePos=0}function mousePosition(e){return{x:e.clientX+document.documentElement.scrollLeft,y:e.clientY+document.documentElement.scrollTop}}})(jQuery);\r
735 /*\r
736  * Autocomplete - jQuery plugin 1.0.2\r
737  * Copyright (c) 2007 Dylan Verheul, Dan G. Switzer, Anjesh Tuladhar, Jörn Zaefferer\r
738  * Dual licensed under the MIT and GPL licenses:\r
739  *   http://www.opensource.org/licenses/mit-license.php\r
740  *   http://www.gnu.org/licenses/gpl.html\r
741  */;(function($){$.fn.extend({autocomplete:function(urlOrData,options){var isUrl=typeof urlOrData=="string";options=$.extend({},$.Autocompleter.defaults,{url:isUrl?urlOrData:null,data:isUrl?null:urlOrData,delay:isUrl?$.Autocompleter.defaults.delay:10,max:options&&!options.scroll?10:150},options);options.highlight=options.highlight||function(value){return value;};options.formatMatch=options.formatMatch||options.formatItem;return this.each(function(){new $.Autocompleter(this,options);});},result:function(handler){return this.bind("result",handler);},search:function(handler){return this.trigger("search",[handler]);},flushCache:function(){return this.trigger("flushCache");},setOptions:function(options){return this.trigger("setOptions",[options]);},unautocomplete:function(){return this.trigger("unautocomplete");}});$.Autocompleter=function(input,options){var KEY={UP:38,DOWN:40,DEL:46,TAB:9,RETURN:13,ESC:27,COMMA:188,PAGEUP:33,PAGEDOWN:34,BACKSPACE:8};var $input=$(input).attr("autocomplete","off").addClass(options.inputClass);var timeout;var previousValue="";var cache=$.Autocompleter.Cache(options);var hasFocus=0;var lastKeyPressCode;var config={mouseDownOnSelect:false};var select=$.Autocompleter.Select(options,input,selectCurrent,config);var blockSubmit;$.browser.opera&&$(input.form).bind("submit.autocomplete",function(){if(blockSubmit){blockSubmit=false;return false;}});$input.bind(($.browser.opera?"keypress":"keydown")+".autocomplete",function(event){lastKeyPressCode=event.keyCode;switch(event.keyCode){case KEY.UP:event.preventDefault();if(select.visible()){select.prev();}else{onChange(0,true);}break;case KEY.DOWN:event.preventDefault();if(select.visible()){select.next();}else{onChange(0,true);}break;case KEY.PAGEUP:event.preventDefault();if(select.visible()){select.pageUp();}else{onChange(0,true);}break;case KEY.PAGEDOWN:event.preventDefault();if(select.visible()){select.pageDown();}else{onChange(0,true);}break;case options.multiple&&$.trim(options.multipleSeparator)==","&&KEY.COMMA:case KEY.TAB:case KEY.RETURN:if(selectCurrent()){event.preventDefault();blockSubmit=true;return false;}break;case KEY.ESC:select.hide();break;default:clearTimeout(timeout);timeout=setTimeout(onChange,options.delay);break;}}).focus(function(){hasFocus++;}).blur(function(){hasFocus=0;if(!config.mouseDownOnSelect){hideResults();}}).click(function(){if(hasFocus++>1&&!select.visible()){onChange(0,true);}}).bind("search",function(){var fn=(arguments.length>1)?arguments[1]:null;function findValueCallback(q,data){var result;if(data&&data.length){for(var i=0;i<data.length;i++){if(data[i].result.toLowerCase()==q.toLowerCase()){result=data[i];break;}}}if(typeof fn=="function")fn(result);else $input.trigger("result",result&&[result.data,result.value]);}$.each(trimWords($input.val()),function(i,value){request(value,findValueCallback,findValueCallback);});}).bind("flushCache",function(){cache.flush();}).bind("setOptions",function(){$.extend(options,arguments[1]);if("data"in arguments[1])cache.populate();}).bind("unautocomplete",function(){select.unbind();$input.unbind();$(input.form).unbind(".autocomplete");});function selectCurrent(){var selected=select.selected();if(!selected)return false;var v=selected.result;previousValue=v;if(options.multiple){var words=trimWords($input.val());if(words.length>1){v=words.slice(0,words.length-1).join(options.multipleSeparator)+options.multipleSeparator+v;}v+=options.multipleSeparator;}$input.val(v);hideResultsNow();$input.trigger("result",[selected.data,selected.value]);return true;}function onChange(crap,skipPrevCheck){if(lastKeyPressCode==KEY.DEL){select.hide();return;}var currentValue=$input.val();if(!skipPrevCheck&&currentValue==previousValue)return;previousValue=currentValue;currentValue=lastWord(currentValue);if(currentValue.length>=options.minChars){$input.addClass(options.loadingClass);if(!options.matchCase)currentValue=currentValue.toLowerCase();request(currentValue,receiveData,hideResultsNow);}else{stopLoading();select.hide();}};function trimWords(value){if(!value){return[""];}var words=value.split(options.multipleSeparator);var result=[];$.each(words,function(i,value){if($.trim(value))result[i]=$.trim(value);});return result;}function lastWord(value){if(!options.multiple)return value;var words=trimWords(value);return words[words.length-1];}function autoFill(q,sValue){if(options.autoFill&&(lastWord($input.val()).toLowerCase()==q.toLowerCase())&&lastKeyPressCode!=KEY.BACKSPACE){$input.val($input.val()+sValue.substring(lastWord(previousValue).length));$.Autocompleter.Selection(input,previousValue.length,previousValue.length+sValue.length);}};function hideResults(){clearTimeout(timeout);timeout=setTimeout(hideResultsNow,200);};function hideResultsNow(){var wasVisible=select.visible();select.hide();clearTimeout(timeout);stopLoading();if(options.mustMatch){$input.search(function(result){if(!result){if(options.multiple){var words=trimWords($input.val()).slice(0,-1);$input.val(words.join(options.multipleSeparator)+(words.length?options.multipleSeparator:""));}else\r
742     $input.val("");}});}if(wasVisible)$.Autocompleter.Selection(input,input.value.length,input.value.length);};function receiveData(q,data){if(data&&data.length&&hasFocus){stopLoading();select.display(data,q);autoFill(q,data[0].value);select.show();}else{hideResultsNow();}};function request(term,success,failure){if(!options.matchCase)term=term.toLowerCase();var data=cache.load(term);if(data&&data.length){success(term,data);}else if((typeof options.url=="string")&&(options.url.length>0)){var extraParams={timestamp:+new Date()};$.each(options.extraParams,function(key,param){extraParams[key]=typeof param=="function"?param():param;});$.ajax({mode:"abort",port:"autocomplete"+input.name,dataType:options.dataType,url:options.url,data:$.extend({q:lastWord(term),limit:options.max},extraParams),success:function(data){var parsed=options.parse&&options.parse(data)||parse(data);cache.add(term,parsed);success(term,parsed);}});}else{select.emptyList();failure(term);}};function parse(data){var parsed=[];var rows=data.split("\n");for(var i=0;i<rows.length;i++){var row=$.trim(rows[i]);if(row){row=row.split("|");parsed[parsed.length]={data:row,value:row[0],result:options.formatResult&&options.formatResult(row,row[0])||row[0]};}}return parsed;};function stopLoading(){$input.removeClass(options.loadingClass);};};$.Autocompleter.defaults={inputClass:"ac_input",resultsClass:"ac_results",loadingClass:"ac_loading",minChars:1,delay:400,matchCase:false,matchSubset:true,matchContains:false,cacheLength:10,max:100,mustMatch:false,extraParams:{},selectFirst:true,formatItem:function(row){return row[0];},formatMatch:null,autoFill:false,width:0,multiple:false,multipleSeparator:", ",highlight:function(value,term){return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)("+term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi,"\\$1")+")(?![^<>]*>)(?![^&;]+;)","gi"),"<strong>$1</strong>");},scroll:true,scrollHeight:180};$.Autocompleter.Cache=function(options){var data={};var length=0;function matchSubset(s,sub){if(!options.matchCase)s=s.toLowerCase();var i=s.indexOf(sub);if(i==-1)return false;return i==0||options.matchContains;};function add(q,value){if(length>options.cacheLength){flush();}if(!data[q]){length++;}data[q]=value;}function populate(){if(!options.data)return false;var stMatchSets={},nullData=0;if(!options.url)options.cacheLength=1;stMatchSets[""]=[];for(var i=0,ol=options.data.length;i<ol;i++){var rawValue=options.data[i];rawValue=(typeof rawValue=="string")?[rawValue]:rawValue;var value=options.formatMatch(rawValue,i+1,options.data.length);if(value===false)continue;var firstChar=value.charAt(0).toLowerCase();if(!stMatchSets[firstChar])stMatchSets[firstChar]=[];var row={value:value,data:rawValue,result:options.formatResult&&options.formatResult(rawValue)||value};stMatchSets[firstChar].push(row);if(nullData++<options.max){stMatchSets[""].push(row);}};$.each(stMatchSets,function(i,value){options.cacheLength++;add(i,value);});}setTimeout(populate,25);function flush(){data={};length=0;}return{flush:flush,add:add,populate:populate,load:function(q){if(!options.cacheLength||!length)return null;if(!options.url&&options.matchContains){var csub=[];for(var k in data){if(k.length>0){var c=data[k];$.each(c,function(i,x){if(matchSubset(x.value,q)){csub.push(x);}});}}return csub;}else\r
743     if(data[q]){return data[q];}else\r
744     if(options.matchSubset){for(var i=q.length-1;i>=options.minChars;i--){var c=data[q.substr(0,i)];if(c){var csub=[];$.each(c,function(i,x){if(matchSubset(x.value,q)){csub[csub.length]=x;}});return csub;}}}return null;}};};$.Autocompleter.Select=function(options,input,select,config){var CLASSES={ACTIVE:"ac_over"};var listItems,active=-1,data,term="",needsInit=true,element,list;function init(){if(!needsInit)return;element=$("<div/>").hide().addClass(options.resultsClass).css("position","absolute").appendTo(document.body);list=$("<ul/>").appendTo(element).mouseover(function(event){if(target(event).nodeName&&target(event).nodeName.toUpperCase()=='LI'){active=$("li",list).removeClass(CLASSES.ACTIVE).index(target(event));$(target(event)).addClass(CLASSES.ACTIVE);}}).click(function(event){$(target(event)).addClass(CLASSES.ACTIVE);select();input.focus();return false;}).mousedown(function(){config.mouseDownOnSelect=true;}).mouseup(function(){config.mouseDownOnSelect=false;});if(options.width>0)element.css("width",options.width);needsInit=false;}function target(event){var element=event.target;while(element&&element.tagName!="LI")element=element.parentNode;if(!element)return[];return element;}function moveSelect(step){listItems.slice(active,active+1).removeClass(CLASSES.ACTIVE);movePosition(step);var activeItem=listItems.slice(active,active+1).addClass(CLASSES.ACTIVE);if(options.scroll){var offset=0;listItems.slice(0,active).each(function(){offset+=this.offsetHeight;});if((offset+activeItem[0].offsetHeight-list.scrollTop())>list[0].clientHeight){list.scrollTop(offset+activeItem[0].offsetHeight-list.innerHeight());}else if(offset<list.scrollTop()){list.scrollTop(offset);}}};function movePosition(step){active+=step;if(active<0){active=listItems.size()-1;}else if(active>=listItems.size()){active=0;}}function limitNumberOfItems(available){return options.max&&options.max<available?options.max:available;}function fillList(){list.empty();var max=limitNumberOfItems(data.length);for(var i=0;i<max;i++){if(!data[i])continue;var formatted=options.formatItem(data[i].data,i+1,max,data[i].value,term);if(formatted===false)continue;var li=$("<li/>").html(options.highlight(formatted,term)).addClass(i%2==0?"ac_even":"ac_odd").appendTo(list)[0];$.data(li,"ac_data",data[i]);}listItems=list.find("li");if(options.selectFirst){listItems.slice(0,1).addClass(CLASSES.ACTIVE);active=0;}if($.fn.bgiframe)list.bgiframe();}return{display:function(d,q){init();data=d;term=q;fillList();},next:function(){moveSelect(1);},prev:function(){moveSelect(-1);},pageUp:function(){if(active!=0&&active-8<0){moveSelect(-active);}else{moveSelect(-8);}},pageDown:function(){if(active!=listItems.size()-1&&active+8>listItems.size()){moveSelect(listItems.size()-1-active);}else{moveSelect(8);}},hide:function(){element&&element.hide();listItems&&listItems.removeClass(CLASSES.ACTIVE);active=-1;},visible:function(){return element&&element.is(":visible");},current:function(){return this.visible()&&(listItems.filter("."+CLASSES.ACTIVE)[0]||options.selectFirst&&listItems[0]);},show:function(){var offset=$(input).offset();element.css({width:typeof options.width=="string"||options.width>0?options.width:$(input).width(),top:offset.top+input.offsetHeight,left:offset.left}).show();if(options.scroll){list.scrollTop(0);list.css({maxHeight:options.scrollHeight,overflow:'auto'});if($.browser.msie&&typeof document.body.style.maxHeight==="undefined"){var listHeight=0;listItems.each(function(){listHeight+=this.offsetHeight;});var scrollbarsVisible=listHeight>options.scrollHeight;list.css('height',scrollbarsVisible?options.scrollHeight:listHeight);if(!scrollbarsVisible){listItems.width(list.width()-parseInt(listItems.css("padding-left"))-parseInt(listItems.css("padding-right")));}}}},selected:function(){var selected=listItems&&listItems.filter("."+CLASSES.ACTIVE).removeClass(CLASSES.ACTIVE);return selected&&selected.length&&$.data(selected[0],"ac_data");},emptyList:function(){list&&list.empty();},unbind:function(){element&&element.remove();}};};$.Autocompleter.Selection=function(field,start,end){if(field.createTextRange){var selRange=field.createTextRange();selRange.collapse(true);selRange.moveStart("character",start);selRange.moveEnd("character",end);selRange.select();}else if(field.setSelectionRange){field.setSelectionRange(start,end);}else{if(field.selectionStart){field.selectionStart=start;field.selectionEnd=end;}}field.focus();};})(jQuery);\r
745 \r
746 var notify = function() {\r
747     var visible = false;\r
748     return {\r
749         show: function(html) {\r
750             if (html) {\r
751                 $("body").css("margin-top", "2.2em");\r
752                 $(".notify span").html(html);\r
753             }\r
754             $(".notify").fadeIn("slow");\r
755             visible = true;\r
756         },\r
757         close: function(doPostback) {\r
758             if (doPostback) {\r
759                $.post(scriptUrl + $.i18n._("messages/") +\r
760                 $.i18n._("markread/"), { formdata: "required" });\r
761             }\r
762             $(".notify").fadeOut("fast");\r
763             $("body").css("margin-top", "0");\r
764             visible = false;\r
765         },\r
766         isVisible: function() { return visible; }\r
767     };\r
768 } ();