diff options
Diffstat (limited to 'templates/content/js')
-rw-r--r-- | templates/content/js/com.cnprog.admin.js | 2 | ||||
-rw-r--r-- | templates/content/js/com.cnprog.editor.js | 2 | ||||
-rw-r--r-- | templates/content/js/com.cnprog.i18n.js | 2 | ||||
-rw-r--r-- | templates/content/js/com.cnprog.post.js | 63 | ||||
-rw-r--r-- | templates/content/js/com.cnprog.tag_selector.js | 45 | ||||
-rw-r--r-- | templates/content/js/com.cnprog.utils.js | 51 | ||||
-rw-r--r-- | templates/content/js/mediawiki-login.js | 29 |
7 files changed, 117 insertions, 77 deletions
diff --git a/templates/content/js/com.cnprog.admin.js b/templates/content/js/com.cnprog.admin.js index cb1c1b15..39dff48c 100644 --- a/templates/content/js/com.cnprog.admin.js +++ b/templates/content/js/com.cnprog.admin.js @@ -1,4 +1,4 @@ -$().ready( function(){ +$(document).ready( function(){ var options = { success: function(a,b){$('.admin #action_status').html($.i18n._('changes saved'));}, dataType:'json', diff --git a/templates/content/js/com.cnprog.editor.js b/templates/content/js/com.cnprog.editor.js index 6cfa2c74..18cc5166 100644 --- a/templates/content/js/com.cnprog.editor.js +++ b/templates/content/js/com.cnprog.editor.js @@ -65,4 +65,4 @@ function ajaxFileUpload(imageUrl) ) return false; -}
\ No newline at end of file +} diff --git a/templates/content/js/com.cnprog.i18n.js b/templates/content/js/com.cnprog.i18n.js index 7562628b..da9bf396 100644 --- a/templates/content/js/com.cnprog.i18n.js +++ b/templates/content/js/com.cnprog.i18n.js @@ -1,3 +1,5 @@ + +//var i18nLang; var i18nZh = { 'insufficient privilege':'用户权限不在操作范围', 'cannot pick own answer as best':'不能设置自己的回答为最佳答案', diff --git a/templates/content/js/com.cnprog.post.js b/templates/content/js/com.cnprog.post.js index a073d20f..668c80fe 100644 --- a/templates/content/js/com.cnprog.post.js +++ b/templates/content/js/com.cnprog.post.js @@ -61,7 +61,7 @@ var Vote = function(){ var pleaseSeeFAQ = $.i18n._('please see') + "<a href='" + scriptUrl + $.i18n._("faq/") + "'>faq</a>"; - var favoriteAnonymousMessage = $.i18n._('anonymous users cannot select favorite questions') + var favoriteAnonymousMessage = $.i18n._('anonymous users cannot select favorite questions'); var voteAnonymousMessage = $.i18n._('anonymous users cannot vote') + pleaseLogin; var upVoteRequiredScoreMessage = $.i18n._('>15 points requried to upvote') + pleaseSeeFAQ; var downVoteRequiredScoreMessage = $.i18n._('>100 points required to downvote') + pleaseSeeFAQ; @@ -242,7 +242,8 @@ var Vote = function(){ url: scriptUrl + $.i18n._("questions/") + questionId + "/" + $.i18n._("vote/"), data: { "type": voteType, "postId": postId }, error: handleFail, - success: function(data){callback(object, voteType, data)}}); + success: function(data){callback(object, voteType, data);} + }); }; var handleFail = function(xhr, msg){ @@ -287,8 +288,9 @@ var Vote = function(){ object.attr("src", scriptUrl + "content/images/vote-favorite-off.png"); var fav = getFavoriteNumber(); fav.removeClass("my-favorite-number"); - if(data.count == 0) + if(data.count === 0){ data.count = ''; + } fav.text(data.count); } else if(data.success == "1"){ @@ -456,9 +458,12 @@ var Vote = function(){ submit($(object), voteType, callback_remove); } } - } + }; } (); +var questionComments = createComments('question'); +var answerComments = createComments('answer'); +var commentsFactory = {'question' : questionComments, 'answer' : answerComments}; // site comments function createComments(type) { @@ -482,12 +487,12 @@ function createComments(type) { $(jDiv).css('background','none'); $(jDiv).css('padding-left',0); if (canPostComments(id)) { - if (jDiv.find("#" + formId).length == 0) { + if (jDiv.find("#" + formId).length === 0) { var form = '<form id="' + formId + '" class="post-comments"><div>'; form += '<textarea name="comment" cols="60" rows="5" maxlength="300" onblur="'+ objectType +'Comments.updateTextCounter(this)" '; form += 'onfocus="' + objectType + 'Comments.updateTextCounter(this)" onkeyup="'+ objectType +'Comments.updateTextCounter(this)"></textarea>'; - form += '<input type="submit" value="' - + $.i18n._('add comment') + '" /><br><span class="text-counter"></span>'; + form += '<input type="submit" value="' + + $.i18n._('add comment') + '" /><br><span class="text-counter"></span>'; form += '<span class="form-error"></span></div></form>'; jDiv.append(form); @@ -499,20 +504,20 @@ function createComments(type) { } else { var divId = "comments-rep-needed-" + objectType + '-' + id; - if (jDiv.find("#" + divId).length == 0) { - jDiv.append('<p id="' + divId + '" class="comment">' - + $.i18n._('to comment, need') + ' ' + - + repNeededForComments + ' ' + $.i18n._('community karma points') - + '<a href="' + scriptUrl + $.i18n._('faq/') + '" class="comment-user">' - + $.i18n._('please see') + 'faq</a></span></p>'); + if (jDiv.find("#" + divId).length === 0) { + jDiv.append('<p id="' + divId + '" class="comment">' + + $.i18n._('to comment, need') + ' ' + + repNeededForComments + ' ' + $.i18n._('community karma points') + + '<a href="' + scriptUrl + $.i18n._('faq/') + '" class="comment-user">' + + $.i18n._('please see') + 'faq</a></span></p>'); } } }; var getComments = function(id, jDiv) { //appendLoaderImg(id); - $.getJSON(scriptUrl + objectType + "s/" + id + "/" + $.i18n._("comments/") - , function(json) { showComments(id, json); }); + $.getJSON(scriptUrl + objectType + "s/" + id + "/" + $.i18n._("comments/"), + function(json) { showComments(id, json); }); }; var showComments = function(id, json) { @@ -523,8 +528,9 @@ function createComments(type) { jDiv.children().remove(); removeLoader(); if (json && json.length > 0) { - for (var i = 0; i < json.length; i++) + for (var i = 0; i < json.length; i++){ renderComment(jDiv, json[i]); + } jDiv.children().show(); } }; @@ -535,14 +541,14 @@ function createComments(type) { var img = scriptUrl + "content/images/close-small.png"; var imgHover = scriptUrl + "content/images/close-small-hover.png"; html += '<img class="delete-icon" onclick="' + objectType + 'Comments.deleteComment($(this), ' + post_id + ', \'' + delete_url + '\')" src="' + img; - html += '" onmouseover="$(this).attr(\'src\', \'' + imgHover + '\')" onmouseout="$(this).attr(\'src\', \'' + img + html += '" onmouseover="$(this).attr(\'src\', \'' + imgHover + '\')" onmouseout="$(this).attr(\'src\', \'' + img; html += '\')" title="' + $.i18n._('delete this comment') + '" />'; return html; } else{ return ''; } - } + }; // {"Id":6,"PostId":38589,"CreationDate":"an hour ago","Text":"hello there!","UserDisplayName":"Jarrod Dixon","UserUrl":"/users/3/jarrod-dixon","DeleteUrl":null} var renderComment = function(jDiv, json) { @@ -604,8 +610,8 @@ function createComments(type) { $(this).children().each( function(i){ var comment_id = $(this).attr('id').replace('comment-',''); - var delete_url = scriptUrl + objectType + 's/' + post_id + '/' - + $.i18n._('comments/') + comment_id + '/' + $.i18n._('delete/'); + var delete_url = scriptUrl + objectType + 's/' + post_id + '/' + + $.i18n._('comments/') + comment_id + '/' + $.i18n._('delete/'); var html = $(this).html(); var CommentsClass; if (objectType == 'question'){ @@ -638,14 +644,14 @@ function createComments(type) { jDiv.show(); var link = $('#comments-link-' + objectType + '-' + id); - if (canPostComments(id)) link.parent().find("textarea").get(0).focus(); + if (canPostComments(id)) { link.parent().find("textarea").get(0).focus(); } link.remove(); }, hide: function(id) { var jDiv = jDivInit(id); var len = jDiv.children("div.comments").children().length; - var anchorText = len == 0 ? $.i18n._('add a comment') : $.i18n._('comments') + ' (<b>' + len + "</b>)"; + var anchorText = len === 0 ? $.i18n._('add a comment') : $.i18n._('comments') + ' (<b>' + len + "</b>)"; jDiv.hide(); jDiv.siblings("a").unbind("click").click(function() { commentsFactory[objectType].show(id); }).html(anchorText); @@ -666,23 +672,18 @@ function createComments(type) { var length = textarea.value ? textarea.value.length : 0; var color = length > 270 ? "#f00" : length > 200 ? "#f60" : "#999"; var jSpan = $(textarea).siblings("span.text-counter"); - jSpan.html($.i18n._('can write') - + (300 - length) + ' ' - + $.i18n._('characters')).css("color", color); + jSpan.html($.i18n._('can write') + + (300 - length) + ' ' + + $.i18n._('characters')).css("color", color); } }; } -var questionComments = createComments('question'); -var answerComments = createComments('answer'); - -$().ready(function() { +$(document).ready(function() { questionComments.init(); answerComments.init(); }); -var commentsFactory = {'question' : questionComments, 'answer' : answerComments}; - /* Prettify http://www.apache.org/licenses/LICENSE-2.0 diff --git a/templates/content/js/com.cnprog.tag_selector.js b/templates/content/js/com.cnprog.tag_selector.js index f6c16c9c..06aefcfc 100644 --- a/templates/content/js/com.cnprog.tag_selector.js +++ b/templates/content/js/com.cnprog.tag_selector.js @@ -1,7 +1,8 @@ +//var scriptUrl, interestingTags, ignoredTags, tags, $; function pickedTags(){ var sendAjax = function(tagname, reason, action, callback){ - url = scriptUrl; + var url = scriptUrl; if (action == 'add'){ url += $.i18n._('mark-tag/'); if (reason == 'good'){ @@ -16,15 +17,15 @@ function pickedTags(){ } url = url + tagname + '/'; - call_settings = { + var call_settings = { type:'POST', url:url - } - if (callback != false){ - call_settings['success'] = callback; + }; + if (callback !== false){ + call_settings.success = callback; } $.ajax(call_settings); - } + }; var unpickTag = function(from_target ,tagname, reason, send_ajax){ @@ -32,7 +33,7 @@ function pickedTags(){ var deleteTagLocally = function(){ from_target[tagname].remove(); delete from_target[tagname]; - } + }; if (send_ajax){ sendAjax(tagname,reason,'remove',deleteTagLocally); } @@ -40,7 +41,7 @@ function pickedTags(){ deleteTagLocally(); } - } + }; var setupTagDeleteEvents = function(obj,tag_store,tagname,reason,send_ajax){ obj.unbind('mouseover').bind('mouseover', function(){ @@ -52,12 +53,13 @@ function pickedTags(){ 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; + var to_target = interestingTags; + var from_target = ignoredTags; + var to_tag_container; if (reason == 'bad'){ to_target = ignoredTags; from_target = interestingTags; @@ -78,13 +80,13 @@ function pickedTags(){ //send ajax request to pick this tag sendAjax(tagname,reason,'add',function(){ - new_tag = $('<span></span>'); + var new_tag = $('<span></span>'); new_tag.addClass('deletable-tag'); - tag_link = $('<a></a>'); + var 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>'); + var del_link = $('<img></img>'); del_link.addClass('delete-icon'); del_link.attr('src', scriptUrl + 'content/images/close-small-dark.png'); @@ -97,7 +99,7 @@ function pickedTags(){ to_target[tagname] = new_tag; }); } - } + }; var collectPickedTags = function(){ var good_prefix = 'interesting-tag-'; @@ -108,7 +110,8 @@ function pickedTags(){ ignoredTags = {}; $('.deletable-tag').each( function(i,item){ - item_id = $(item).attr('id') + var item_id = $(item).attr('id'); + var tag_name, tag_store; if (good_re.test(item_id)){ tag_name = item_id.replace(good_prefix,''); tag_store = interestingTags; @@ -123,10 +126,10 @@ function pickedTags(){ return; } tag_store[tag_name] = $(item); - setupTagDeleteEvents($(item).find('img'),tag_store,tag_name,reason,true) + setupTagDeleteEvents($(item).find('img'),tag_store,tag_name,reason,true); } ); - } + }; var setupHideIgnoredQuestionsControl = function(){ $('#hideIgnoredTagsCb').unbind('click').click(function(){ @@ -138,7 +141,7 @@ function pickedTags(){ data: {command:'toggle-ignored-questions'} }); }); - } + }; return { init: function(){ collectPickedTags(); @@ -157,8 +160,8 @@ function pickedTags(){ } }); - $("#interestingTagAdd").click(function(){handlePickedTag(this,'good')}); - $("#ignoredTagAdd").click(function(){handlePickedTag(this,'bad')}); + $("#interestingTagAdd").click(function(){handlePickedTag(this,'good');}); + $("#ignoredTagAdd").click(function(){handlePickedTag(this,'bad');}); } }; } diff --git a/templates/content/js/com.cnprog.utils.js b/templates/content/js/com.cnprog.utils.js index b19b6773..4c3aafba 100644 --- a/templates/content/js/com.cnprog.utils.js +++ b/templates/content/js/com.cnprog.utils.js @@ -1,6 +1,7 @@ +//var $, scriptUrl; var showMessage = function(object, msg) { - var div = $('<div class="vote-notification"><h3>' + msg + '</h3>(' - + $.i18n._('click to close') + ')</div>'); + var div = $('<div class="vote-notification"><h3>' + msg + '</h3>(' + + $.i18n._('click to close') + ')</div>'); div.click(function(event) { $(".vote-notification").fadeOut("fast", function() { $(this).remove(); }); @@ -35,18 +36,30 @@ var notify = function() { } (); function appendLoader(containerSelector) { - $(containerSelector).append('<img class="ajax-loader" ' - +'src="' + scriptUrl + 'content/images/indicator.gif" title="' - +$.i18n._('loading...') - +'" alt="' - +$.i18n._('loading...') - +'" />'); + $(containerSelector).append('<img class="ajax-loader" ' + + 'src="' + scriptUrl + 'content/images/indicator.gif" title="' + + $.i18n._('loading...') + + '" alt="' + + $.i18n._('loading...') + + '" />'); } function removeLoader() { $("img.ajax-loader").remove(); } +function setSubmitButtonDisabled(formSelector, isDisabled) { + $(formSelector).find("input[type='submit']").attr("disabled", isDisabled ? "true" : ""); +} + +function enableSubmitButton(formSelector) { + setSubmitButtonDisabled(formSelector, false); +} + +function disableSubmitButton(formSelector) { + setSubmitButtonDisabled(formSelector, true); +} + function setupFormValidation(formSelector, validationRules, validationMessages, onSubmitCallback) { enableSubmitButton(formSelector); $(formSelector).validate({ @@ -56,7 +69,7 @@ function setupFormValidation(formSelector, validationRules, validationMessages, errorClass: "form-error", errorPlacement: function(error, element) { var span = element.next().find("span.form-error"); - if (span.length == 0) { + if (span.length === 0) { span = element.parent().find("span.form-error"); } span.replaceWith(error); @@ -64,24 +77,16 @@ function setupFormValidation(formSelector, validationRules, validationMessages, submitHandler: function(form) { disableSubmitButton(formSelector); - if (onSubmitCallback) + if (onSubmitCallback){ onSubmitCallback(); - else + } + else{ form.submit(); + } } }); } -function enableSubmitButton(formSelector) { - setSubmitButtonDisabled(formSelector, false); -} -function disableSubmitButton(formSelector) { - setSubmitButtonDisabled(formSelector, true); -} -function setSubmitButtonDisabled(formSelector, isDisabled) { - $(formSelector).find("input[type='submit']").attr("disabled", isDisabled ? "true" : ""); -} - var CPValidator = function(){ return { getQuestionFormRules : function(){ @@ -108,11 +113,11 @@ var CPValidator = function(){ }, text: { required: " " + $.i18n._('content cannot be empty'), - minlength: jQuery.format(' ' + $.i18n._('content minchars')) + minlength: $.format(' ' + $.i18n._('content minchars')) }, title: { required: " " + $.i18n._('please enter title'), - minlength: jQuery.format(' ' + $.i18n._('title minchars')) + minlength: $.format(' ' + $.i18n._('title minchars')) } }; } diff --git a/templates/content/js/mediawiki-login.js b/templates/content/js/mediawiki-login.js new file mode 100644 index 00000000..f1805f88 --- /dev/null +++ b/templates/content/js/mediawiki-login.js @@ -0,0 +1,29 @@ +function toggleScreenNameInput(par1,par2){ + if ($(this).is(':checked')){ + $('.optional-screen-name').show(); + } + else { + $('#id_screen_name').val(''); + $('.optional-screen-name').hide(); + } +} + +function toggleScreenNameErrorMessage(e){ + var screen_name = $('#id_screen_name').val(); + if (screen_name != ''){ + $('.screen-name-error').hide(); + } + else{ + $('.screen-name-error').show(); + } +} + +$(document).ready( function(){ + var screen_name = $('#id_screen_name').val(); + var use_screen_name = $('#id_use_separate_screen_name').is(':checked'); + if (screen_name == '' && !use_screen_name){ + $('.optional-screen-name').hide(); + } + $('#id_use_separate_screen_name').unbind('click').click(toggleScreenNameInput); + $('#id_screen_name').unbind('keyup').keyup(toggleScreenNameErrorMessage); +}); |