diff options
Diffstat (limited to 'templates/content/js')
-rw-r--r-- | templates/content/js/com.cnprog.admin.js | 13 | ||||
-rw-r--r-- | templates/content/js/com.cnprog.i18n.js | 31 | ||||
-rw-r--r-- | templates/content/js/com.cnprog.post.js | 314 | ||||
-rw-r--r-- | templates/content/js/com.cnprog.utils.js | 7 | ||||
-rw-r--r-- | templates/content/js/jquery.form.js | 654 | ||||
-rw-r--r-- | templates/content/js/wmd/wmd.js | 2 |
6 files changed, 875 insertions, 146 deletions
diff --git a/templates/content/js/com.cnprog.admin.js b/templates/content/js/com.cnprog.admin.js new file mode 100644 index 00000000..73b5768f --- /dev/null +++ b/templates/content/js/com.cnprog.admin.js @@ -0,0 +1,13 @@ +$().ready( function(){ + var options = { + success: function(a,b){$('.admin #action_status').html($.i18n._('changes saved'));}, + dataType:'json', + timeout:5000, + url: $.i18n._('/') + $.i18n._('moderate-user/') + viewUserID + '/' + }; + var form = $('.admin #moderate_user_form').ajaxForm(options); + var box = $('.admin input#id_is_approved').click(function(){ + $('.admin #action_status').html($.i18n._('sending data...')); + form.ajaxSubmit(options); + }); +}); diff --git a/templates/content/js/com.cnprog.i18n.js b/templates/content/js/com.cnprog.i18n.js index 6ba8b59d..d2356abc 100644 --- a/templates/content/js/com.cnprog.i18n.js +++ b/templates/content/js/com.cnprog.i18n.js @@ -20,7 +20,7 @@ var i18nZh = { 'post recovered':"操作成功!该帖子已被恢复。", 'post deleted':"操作成功!该帖子已删除。", 'add comment':'添加评论', - 'community reputation points':'社区积分', + 'community karma points':'社区积分', 'to comment, need':'评论需要', 'delete this comment':'删除此评论', 'hide comments':"隐藏评论", @@ -53,27 +53,29 @@ var i18nZh = { 'redo':'重做', 'enter image url':'<b>输入图片地址</b></p><p>示例:<br />http://www.example.com/image.jpg \"我的截图\"', 'enter url':'<b>输入Web地址</b></p><p>示例:<br />http://www.cnprog.com/ \"我的网站\"</p>"', - 'upload image':'或者上传本地图片:', + 'upload image':'或者上传本地图片:' }; var i18nEn = { - '>15 points requried to upvote':'>15 points requried to upvote ', + '/':'/', + 'need >15 points to report spam':'need >15 points to report spam ', + '>15 points requried to upvote':'>15 points required to upvote ', 'tags cannot be empty':'please enter at least one tag', - 'anonymous users cannot vote':'anonymous users cannot vote ', - 'anonymous users cannot select favorite questions':'anonymous users cannot select favorite questions ', - 'to comment, need': 'to comment, need reputation ', + 'anonymous users cannot vote':'sorry, anonymous users cannot vote ', + 'anonymous users cannot select favorite questions':'sorry, anonymous users cannot select favorite questions ', + 'to comment, need': '(to comment other people\'s posts, karma ', 'please see':'please see ', - 'community reputation points':' ', + 'community karma points':' or more is necessary) - ', 'upload image':'Upload image:', 'enter image url':'enter URL of the image, e.g. http://www.example.com/image.jpg \"image title\"', 'enter url':'enter Web address, e.g. http://www.example.com \"page title\"', 'daily vote cap exhausted':'sorry, you\'ve used up todays vote cap', - 'cannot pick own answer as best':'cannot accept own answer', - 'cannot revoke old vote':'older votes cannot be revoked', + 'cannot pick own answer as best':'sorry, you cannot accept your own answer', + 'cannot revoke old vote':'sorry, older votes cannot be revoked', 'please confirm offensive':'are you sure this post is offensive, contains spam, advertising, malicious remarks, etc.?', - 'flag offensive cap exhausted':'sorry, you\'ve used up todays cap of flagging offensive messages', + 'flag offensive cap exhausted':'sorry, you\'ve used up todays cap of flagging offensive messages ', 'confirm delete':'are you sure you want to delete this?', - 'anonymous users cannot delete/undelete':'anonymous users cannot delete or undelete posts', + 'anonymous users cannot delete/undelete':'sorry, anonymous users cannot delete or undelete posts', 'post recovered':'your post is now restored!', 'post deleted':'your post has been deleted', 'confirm delete comment':'do you really want to delete this comment?', @@ -82,6 +84,9 @@ var i18nEn = { 'content minchars': 'please enter more than {0} characters', 'title minchars':"please enter at least {0} characters", 'characters':'characters left', + 'cannot vote for own posts':'sorry, you cannot vote for your own posts', + 'cannot flag message as offensive twice':'cannot flag message as offensive twice ', + '>100 points required to downvote':'>100 points required to downvote ' }; var i18nEs = { @@ -106,7 +111,7 @@ var i18nEs = { 'post recovered':"publicación recuperada", 'post deleted':"publicación borrada。", 'add comment':'agregar comentario', - 'community reputation points':'reputación comunitaria', + 'community karma points':'reputación comunitaria', 'to comment, need':'para comentar, necesita reputación', 'delete this comment':'borrar este comentario', 'hide comments':"ocultar comentarios", @@ -141,7 +146,7 @@ var i18nEs = { 'enter url':'introduzca direcciones web, ejemplo:<br />http://www.cnprog.com/ \"titulo del enlace\"</p>"', 'upload image':'cargar imagen:', 'questions/' : 'preguntas/', - 'vote/' : 'votar/', + 'vote/' : 'votar/' }; var i18n = { diff --git a/templates/content/js/com.cnprog.post.js b/templates/content/js/com.cnprog.post.js index aa6c51b6..58db9b33 100644 --- a/templates/content/js/com.cnprog.post.js +++ b/templates/content/js/com.cnprog.post.js @@ -52,31 +52,25 @@ var Vote = function(){ var acceptAnonymousMessage = $.i18n._('insufficient privilege'); var acceptOwnAnswerMessage = $.i18n._('cannot pick own answer as best'); - var favoriteAnonymousMessage = $.i18n._('anonymous users cannot select favorite questions') - + "<a href='/account/signin/?next=/questions/{{QuestionID}}'>" - + $.i18n._('please login') + "</a>"; - var voteAnonymousMessage = $.i18n._('anonymous users cannot vote') - + "<a href='/account/signin/?next=/questions/{{QuestionID}}'>" + + var pleaseLogin = "<a href='" + $.i18n._("/") + $.i18n._("account/") + $.i18n._("signin/") + + "?next=" + $.i18n._("/") + $.i18n._("questions/") + "{{QuestionID}}'>" + $.i18n._('please login') + "</a>"; - var upVoteRequiredScoreMessage = $.i18n._('>15 points requried to upvote') - + $.i18n._('please see') + "<a href='/faq'>faq</a>"; - var downVoteRequiredScoreMessage = $.i18n._('>100 points requried to downvote') - + $.i18n._('please see') + "<a href='/faq'>faq</a>"; + + var pleaseSeeFAQ = $.i18n._('please see') + "<a href='" + $.i18n._("/") + $.i18n._("faq/") + "'>faq</a>"; + + 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; var voteOwnDeniedMessage = $.i18n._('cannot vote for own posts'); - var voteRequiredMoreVotes = $.i18n._('daily vote cap exhausted') - + $.i18n._('please see') + "<a href='/faq'>faq</a>"; - var voteDenyCancelMessage = $.i18n._('cannot revoke old vote') - + $.i18n._('please see') + "<a href='/faq'>faq</a>"; + var voteRequiredMoreVotes = $.i18n._('daily vote cap exhausted') + pleaseSeeFAQ; + var voteDenyCancelMessage = $.i18n._('cannot revoke old vote') + pleaseSeeFAQ; var offensiveConfirmation = $.i18n._('please confirm offensive'); - var offensiveAnonymousMessage = $.i18n._('anonymous users cannot flag offensive posts') - + "<a href='/account/signin/?next=/questions/{{QuestionID}}'>" - + $.i18n._('please login') + "</a>"; - var offensiveTwiceMessage = $.i18n._('cannot flag message as offensive twice') - + $.i18n._('please see') + "<a href='/faq'>faq</a>"; - var offensiveNoFlagsLeftMessage = $.i18n._('flag offensive cap exhausted') - + $.i18n._('please see') + "<a href='/faq'>faq</a>"; - var offensiveNoPermissionMessage = $.i18n._('need >15 points to report spam') - + $.i18n._('please see') + "<a href='/faq'>faq</a>"; + var offensiveAnonymousMessage = $.i18n._('anonymous users cannot flag offensive posts') + pleaseLogin; + var offensiveTwiceMessage = $.i18n._('cannot flag message as offensive twice') + pleaseSeeFAQ; + var offensiveNoFlagsLeftMessage = $.i18n._('flag offensive cap exhausted') + pleaseSeeFAQ; + var offensiveNoPermissionMessage = $.i18n._('need >15 points to report spam') + pleaseSeeFAQ; var removeConfirmation = $.i18n._('confirm delete'); var removeAnonymousMessage = $.i18n._('anonymous users cannot delete/undelete'); var recoveredMessage = $.i18n._('post recovered'); @@ -94,7 +88,7 @@ var Vote = function(){ removeQuestion: 9, removeAnswer:10, questionSubscribeUpdates:11, - questionUnsubscribeUpdates:12, + questionUnsubscribeUpdates:12 }; var getFavoriteButton = function(){ @@ -131,7 +125,7 @@ var Vote = function(){ }; var getOffensiveQuestionFlag = function(){ - var offensiveQuestionFlag = 'table[id=question-table] span[class='+ offensiveClassFlag +']'; + var offensiveQuestionFlag = '#question-table span[class='+ offensiveClassFlag +']'; return $(offensiveQuestionFlag); }; @@ -157,17 +151,17 @@ var Vote = function(){ var setVoteImage = function(voteType, undo, object){ var flag = undo ? "" : "-on"; var arrow = (voteType == VoteType.questionUpVote || voteType == VoteType.answerUpVote) ? "up" : "down"; - object.attr("src", "/content/images/vote-arrow-"+ arrow + flag +".png"); + object.attr("src", $.i18n._("/") + "content/images/vote-arrow-"+ arrow + flag +".png"); // if undo voting, then undo the pair of arrows. if(undo){ if(voteType == VoteType.questionUpVote || voteType == VoteType.questionDownVote){ - $(getQuestionVoteUpButton()).attr("src", "/content/images/vote-arrow-up.png"); - $(getQuestionVoteDownButton()).attr("src", "/content/images/vote-arrow-down.png"); + $(getQuestionVoteUpButton()).attr("src", $.i18n._("/") + "content/images/vote-arrow-up.png"); + $(getQuestionVoteDownButton()).attr("src", $.i18n._("/") + "content/images/vote-arrow-down.png"); } else{ - $(getAnswerVoteUpButton(postId)).attr("src", "/content/images/vote-arrow-up.png"); - $(getAnswerVoteDownButton(postId)).attr("src", "/content/images/vote-arrow-down.png"); + $(getAnswerVoteUpButton(postId)).attr("src", $.i18n._("/") + "content/images/vote-arrow-up.png"); + $(getAnswerVoteDownButton(postId)).attr("src", $.i18n._("/") + "content/images/vote-arrow-down.png"); } } }; @@ -182,42 +176,42 @@ var Vote = function(){ if(questionAuthorId == currentUserId){ var acceptedButtons = 'div.'+ voteContainerId +' img[id^='+ imgIdPrefixAccept +']'; $(acceptedButtons).unbind('click').click(function(event){ - Vote.accept($(event.target)) + Vote.accept($(event.target)); }); } // set favorite question var favoriteButton = getFavoriteButton(); favoriteButton.unbind('click').click(function(event){ - Vote.favorite($(event.target)) + Vote.favorite($(event.target)); }); // question vote up var questionVoteUpButton = getQuestionVoteUpButton(); questionVoteUpButton.unbind('click').click(function(event){ - Vote.vote($(event.target), VoteType.questionUpVote) + Vote.vote($(event.target), VoteType.questionUpVote); }); var questionVoteDownButton = getQuestionVoteDownButton(); questionVoteDownButton.unbind('click').click(function(event){ - Vote.vote($(event.target), VoteType.questionDownVote) + Vote.vote($(event.target), VoteType.questionDownVote); }); var answerVoteUpButton = getAnswerVoteUpButtons(); answerVoteUpButton.unbind('click').click(function(event){ - Vote.vote($(event.target), VoteType.answerUpVote) + Vote.vote($(event.target), VoteType.answerUpVote); }); var answerVoteDownButton = getAnswerVoteDownButtons(); answerVoteDownButton.unbind('click').click(function(event){ - Vote.vote($(event.target), VoteType.answerDownVote) + Vote.vote($(event.target), VoteType.answerDownVote); }); getOffensiveQuestionFlag().unbind('click').click(function(event){ - Vote.offensive(this, VoteType.offensiveQuestion) + Vote.offensive(this, VoteType.offensiveQuestion); }); getOffensiveAnswerFlags().unbind('click').click(function(event){ - Vote.offensive(this, VoteType.offensiveAnswer) + Vote.offensive(this, VoteType.offensiveAnswer); }); getremoveQuestionLink().unbind('click').click(function(event){ @@ -234,7 +228,7 @@ var Vote = function(){ }); getremoveAnswersLinks().unbind('click').click(function(event){ - Vote.remove(this, VoteType.removeAnswer) + Vote.remove(this, VoteType.removeAnswer); }); }; @@ -243,14 +237,14 @@ var Vote = function(){ type: "POST", cache: false, dataType: "json", - url: "/" + $.i18n._("questions/") + questionId + "/" + $.i18n._("vote/"), + url: $.i18n._("/") + $.i18n._("questions/") + questionId + "/" + $.i18n._("vote/"), data: { "type": voteType, "postId": postId }, error: handleFail, success: function(data){callback(object, voteType, data)}}); }; var handleFail = function(xhr, msg){ - alert("Callback invoke error: " + msg) + alert("Callback invoke error: " + msg); }; // callback function for Accept Answer action @@ -262,19 +256,19 @@ var Vote = function(){ showMessage(object, acceptOwnAnswerMessage); } else if(data.status == "1"){ - object.attr("src", "/content/images/vote-accepted.png"); + object.attr("src", $.i18n._("/") + "content/images/vote-accepted.png"); $("#"+answerContainerIdPrefix+postId).removeClass("accepted-answer"); $("#"+commentLinkIdPrefix+postId).removeClass("comment-link-accepted"); } else if(data.success == "1"){ var acceptedButtons = 'div.'+ voteContainerId +' img[id^='+ imgIdPrefixAccept +']'; - $(acceptedButtons).attr("src", "/content/images/vote-accepted.png"); + $(acceptedButtons).attr("src", $.i18n._("/") + "content/images/vote-accepted.png"); var answers = ("div[id^="+answerContainerIdPrefix +"]"); $(answers).removeClass("accepted-answer"); var commentLinks = ("div[id^="+answerContainerIdPrefix +"] div[id^="+ commentLinkIdPrefix +"]"); $(commentLinks).removeClass("comment-link-accepted"); - object.attr("src", "/content/images/vote-accepted-on.png"); + object.attr("src", $.i18n._("/") + "content/images/vote-accepted-on.png"); $("#"+answerContainerIdPrefix+postId).addClass("accepted-answer"); $("#"+commentLinkIdPrefix+postId).addClass("comment-link-accepted"); } @@ -288,7 +282,7 @@ var Vote = function(){ showMessage(object, favoriteAnonymousMessage.replace("{{QuestionID}}", questionId)); } else if(data.status == "1"){ - object.attr("src", "/content/images/vote-favorite-off.png"); + object.attr("src", $.i18n._("/") + "content/images/vote-favorite-off.png"); var fav = getFavoriteNumber(); fav.removeClass("my-favorite-number"); if(data.count == 0) @@ -296,7 +290,7 @@ var Vote = function(){ fav.text(data.count); } else if(data.success == "1"){ - object.attr("src", "/content/images/vote-favorite-on.png"); + object.attr("src", $.i18n._("/") + "/content/images/vote-favorite-on.png"); var fav = getFavoriteNumber(); fav.text(data.count); fav.addClass("my-favorite-number"); @@ -310,69 +304,75 @@ var Vote = function(){ if(data.allowed == "0" && data.success == "0"){ showMessage(object, voteAnonymousMessage.replace("{{QuestionID}}", questionId)); } - else if(data.allowed == "-3"){ + else if (data.allowed == "-3"){ showMessage(object, voteRequiredMoreVotes); } - else if(data.allowed == "-2"){ - if(voteType == VoteType.questionUpVote || voteType == VoteType.answerUpVote){ + else if (data.allowed == "-2"){ + if (voteType == VoteType.questionUpVote || voteType == VoteType.answerUpVote){ showMessage(object, upVoteRequiredScoreMessage); } - else if(voteType == VoteType.questionDownVote || voteType == VoteType.answerDownVote){ + else if (voteType == VoteType.questionDownVote || voteType == VoteType.answerDownVote){ showMessage(object, downVoteRequiredScoreMessage); } } - else if(data.allowed == "-1"){ + else if (data.allowed == "-1"){ showMessage(object, voteOwnDeniedMessage); } - else if(data.status == "2"){ + else if (data.status == "2"){ showMessage(object, voteDenyCancelMessage); } - else if(data.status == "1"){ + else if (data.status == "1"){ setVoteImage(voteType, true, object); setVoteNumber(object, data.count); } - else if(data.success == "1"){ + else if (data.success == "1"){ setVoteImage(voteType, false, object); setVoteNumber(object, data.count); - if(data.message.length > 0) + if (data.message.length > 0){ showMessage(object, data.message); + } } }; var callback_offensive = function(object, voteType, data){ object = $(object); - if(data.allowed == "0" && data.success == "0"){ + if (data.allowed == "0" && data.success == "0"){ showMessage(object, offensiveAnonymousMessage.replace("{{QuestionID}}", questionId)); } - else if(data.allowed == "-3"){ + else if (data.allowed == "-3"){ showMessage(object, offensiveNoFlagsLeftMessage); } - else if(data.allowed == "-2"){ + else if (data.allowed == "-2"){ showMessage(object, offensiveNoPermissionMessage); } - else if(data.status == "1"){ + else if (data.status == "1"){ showMessage(object, offensiveTwiceMessage); } - else if(data.success == "1"){ + else if (data.success == "1"){ $(object).children('span[class=darkred]').text("("+ data.count +")"); } }; var callback_remove = function(object, voteType, data){ - if(data.allowed == "0" && data.success == "0"){ + if (data.allowed == "0" && data.success == "0"){ showMessage(object, removeAnonymousMessage.replace("{{QuestionID}}", questionId)); } else if (data.success == "1"){ - if (removeActionType == 'delete'){ - postNode.addClass('deleted'); - postRemoveLink.innerHTML = $.i18n._('undelete'); - showMessage(object, deletedMessage); - } - else if (removeActionType == 'undelete') { - postNode.removeClass('deleted'); - postRemoveLink.innerHTML = $.i18n._('delete'); - showMessage(object, recoveredMessage); - } + if (voteType == VoteType.removeQuestion){ + window.location.href = $.i18n._("/") + $.i18n._("questions/"); + } + else { + if (removeActionType == 'delete'){ + postNode.addClass('deleted'); + postRemoveLink.innerHTML = $.i18n._('undelete'); + showMessage(object, deletedMessage); + } + else if (removeActionType == 'undelete') { + postNode.removeClass('deleted'); + postRemoveLink.innerHTML = $.i18n._('delete'); + showMessage(object, recoveredMessage); + } + } } }; @@ -391,7 +391,7 @@ var Vote = function(){ }, favorite: function(object){ - if(!currentUserId || currentUserId.toUpperCase() == "NONE"){ + if (!currentUserId || currentUserId.toUpperCase() == "NONE"){ showMessage(object, favoriteAnonymousMessage.replace("{{QuestionID}}", questionId)); return false; } @@ -399,14 +399,14 @@ var Vote = function(){ }, vote: function(object, voteType){ - if(!currentUserId || currentUserId.toUpperCase() == "NONE"){ + if (!currentUserId || currentUserId.toUpperCase() == "NONE"){ showMessage(object, voteAnonymousMessage.replace("{{QuestionID}}", questionId)); return false; } - if(voteType == VoteType.answerUpVote){ + if (voteType == VoteType.answerUpVote){ postId = object.attr("id").substring(imgIdPrefixAnswerVoteup.length); } - else if(voteType == VoteType.answerDownVote){ + else if (voteType == VoteType.answerDownVote){ postId = object.attr("id").substring(imgIdPrefixAnswerVotedown.length); } @@ -414,39 +414,43 @@ var Vote = function(){ }, offensive: function(object, voteType){ - if(!currentUserId || currentUserId.toUpperCase() == "NONE"){ + if (!currentUserId || currentUserId.toUpperCase() == "NONE"){ showMessage($(object), offensiveAnonymousMessage.replace("{{QuestionID}}", questionId)); return false; } - if(confirm(offensiveConfirmation)){ + if (confirm(offensiveConfirmation)){ postId = object.id.substr(object.id.lastIndexOf('-') + 1); submit(object, voteType, callback_offensive); } }, remove: function(object, voteType){ - if(!currentUserId || currentUserId.toUpperCase() == "NONE"){ + if (!currentUserId || currentUserId.toUpperCase() == "NONE"){ showMessage($(object), removeAnonymousMessage.replace("{{QuestionID}}", questionId)); return false; } - if(confirm(removeConfirmation)){ - bits = object.id.split('-'); - postId = bits.pop();/* this seems to be used within submit! */ - postType = bits.shift(); - - if (postType == 'answer'){ - postNode = $('#answer-container-' + postId); - postRemoveLink = object; - if (postNode.hasClass('deleted')){ - removeActionType = 'undelete'; - } - else { - removeActionType = 'delete'; - } - } + bits = object.id.split('-'); + postId = bits.pop();/* this seems to be used within submit! */ + postType = bits.shift(); + + var do_proceed = false; + if (postType == 'answer'){ + postNode = $('#answer-container-' + postId); + postRemoveLink = object; + if (postNode.hasClass('deleted')){ + removeActionType = 'undelete'; + do_proceed = true; + } + else { + removeActionType = 'delete'; + do_proceed = confirm(removeConfirmation); + } + } + else { + do_proceed = confirm(removeConfirmation); + } + if (do_proceed) { submit($(object), voteType, callback_remove); - - } } } @@ -457,21 +461,24 @@ var Vote = function(){ function createComments(type) { var objectType = type; var jDivInit = function(id) { - return $("#comments-" + objectType + '-' + id); + return $("#comments-container-" + objectType + '-' + id); }; var appendLoaderImg = function(id) { - appendLoader("#comments-" + objectType + '-' + id + " div.comments"); + appendLoader("#comments-container-" + objectType + '-' + id); }; - var canPostComments = function(id, jDiv) { - var jHidden = jDiv.siblings("#can-post-comments-" + objectType + '-' + id); + var canPostComments = function(id) { + var jHidden = $("#can-post-comments-" + objectType + '-' + id); return jHidden.val().toLowerCase() == "true"; }; - var renderForm = function(id, jDiv) { + var renderForm = function(id) { var formId = "form-comments-" + objectType + "-" + id; - if (canPostComments(id, jDiv)) { + var jDiv = $('#comments-link-' + objectType + "-" + id).parent(); + $(jDiv).css('background','none'); + $(jDiv).css('padding-left',0); + if (canPostComments(id)) { 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)" '; @@ -490,64 +497,79 @@ function createComments(type) { else { var divId = "comments-rep-needed-" + objectType + '-' + id; if (jDiv.find("#" + divId).length == 0) { - jDiv.append('<div id="' + divId + '" style="color:red">' + jDiv.append('<p id="' + divId + '" class="comment">' + $.i18n._('to comment, need') + ' ' + - + repNeededForComments + ' ' + $.i18n._('community reputation points') - + '<a href="/faq" class="comment-user">' + $.i18n._('please see') + 'faq</a></span>'); + + repNeededForComments + ' ' + $.i18n._('community karma points') + + '<a href="' + $.i18n._('/') + $.i18n._('faq/') + '" class="comment-user">' + + $.i18n._('please see') + 'faq</a></span></p>'); } } }; var getComments = function(id, jDiv) { - appendLoaderImg(id); - $.getJSON("/" + objectType + "s/" + id + "/comments/", function(json) { showComments(id, json); }); + //appendLoaderImg(id); + $.getJSON($.i18n._("/") + objectType + "s/" + id + "/" + $.i18n._("comments/") + , function(json) { showComments(id, json); }); }; var showComments = function(id, json) { var jDiv = jDivInit(id); - jDiv = jDiv.find("div.comments"); // this div should contain any fetched comments.. - jDiv.find("div[id^='comment-" + objectType + "-'" + "]").remove(); // clean previous calls.. - + //jDiv = jDiv.find("div.comments"); // this div should contain any fetched comments.. + //jDiv.find("div[id^='comment-" + objectType + "-'" + "]").remove(); // clean previous calls.. + jDiv.children().remove(); removeLoader(); - if (json && json.length > 0) { for (var i = 0; i < json.length; i++) renderComment(jDiv, json[i]); - jDiv.children().show(); } }; + var renderDeleteCommentIcon = function(post_id, delete_url){ + if (canPostComments(post_id)){ + var html = ''; + var img = $.i18n._("/") + "content/images/close-small.png"; + var imgHover = $.i18n._("/") + "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 += '\')" 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) { - var html = '<div id="comment-' + objectType + "-" + json.id + '" style="display:none">' + json.text; - html += json.user_url ? ' – <a href="' + json.user_url + '"' : '<span'; + var html = '<p id="comment-' + json.id + '" class="comment" style="display:none">' + json.text; + html += json.user_url ? ' - <a href="' + json.user_url + '"' : '<span'; html += ' class="comment-user">' + json.user_display_name + (json.user_url ? '</a>' : '</span>'); - html += ' <span class="comment-date">(' + json.add_date + ')</span>'; + html += ' (' + json.comment_age + ')'; + + if (json.delete_url){ + html += renderDeleteCommentIcon(json.object_id, json.delete_url); + } if (json.delete_url) { - var img = "/content/images/close-small.png"; - var imgHover = "/content/images/close-small-hover.png"; - html += '<img onclick="' + objectType + 'Comments.deleteComment($(this), ' + json.object_id + ', \'' + json.delete_url + '\')" src="' + img; - html += '" onmouseover="$(this).attr(\'src\', \'' + imgHover + '\')" onmouseout="$(this).attr(\'src\', \'' + img - html += '\')" title="' + $.i18n._('delete this comment') + '" />'; } - html += '</div>'; + html += '</p>'; jDiv.append(html); }; var postComment = function(id, formId) { - appendLoaderImg(id); + //appendLoaderImg(id); var formSelector = "#" + formId; var textarea = $(formSelector + " textarea"); + //todo fix url translations!!! $.ajax({ type: "POST", - url: "/" + objectType + "s/" + id + "/comments/", + url: $.i18n._("/") + objectType + "s/" + id + "/" + $.i18n._("comments/"), dataType: "json", data: { comment: textarea.val() }, success: function(json) { @@ -569,18 +591,52 @@ function createComments(type) { init: function() { // Setup "show comments" clicks.. - $("a[id^='comments-link-" + objectType + "-" + "']").unbind("click").click(function() { commentsFactory[objectType].show($(this).attr("id").substr(("comments-link-" + objectType + "-").length)); }); + $("a[id^='comments-link-" + objectType + "-" + "']").unbind("click").click(function() { + commentsFactory[objectType].show($(this).attr("id").substr(("comments-link-" + objectType + "-").length)); + }); + + var cBox = $("[id^='comments-container-" + objectType + "']"); + cBox.each( function(i){ + var post_id = $(this).attr('id').replace('comments-container-' + objectType + '-', ''); + $(this).children().each( + function(i){ + var comment_id = $(this).attr('id').replace('comment-',''); + var delete_url = $.i18n._('/') + objectType + 's/' + post_id + '/' + + $.i18n._('comments/') + comment_id + '/' + $.i18n._('delete/'); + var html = $(this).html(); + var CommentsClass; + if (objectType == 'question'){ + CommentsClass = questionComments; + } + else if (objectType == 'answer') { + CommentsClass = answerComments; + } + var delete_icon = $(this).find('img.delete-icon'); + 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'); + } + ); + delete_icon.unbind('mouseout').bind('mouseout', + function(){ + $(this).attr('src',$.i18n._('/') + 'content/images/close-small.png'); + } + ); + } + ); + }); }, show: function(id) { var jDiv = jDivInit(id); getComments(id, jDiv); - renderForm(id, jDiv); + renderForm(id); jDiv.show(); - if (canPostComments(id, jDiv)) jDiv.find("textarea").get(0).focus(); - jDiv.siblings("a").unbind("click").click(function(){ - commentsFactory[objectType].hide(id); - }).text($.i18n._('hide comments')); + + var link = $('#comments-link-' + objectType + '-' + id); + if (canPostComments(id)) link.parent().find("textarea").get(0).focus(); + link.remove(); }, hide: function(id) { @@ -596,9 +652,9 @@ function createComments(type) { deleteComment: function(jImg, id, deleteUrl) { if (confirm($.i18n._('confirm delete comment'))) { jImg.hide(); - appendLoaderImg(id); $.post(deleteUrl, { dataNeeded: "forIIS7" }, function(json) { - showComments(id, json); + var par = jImg.parent(); + par.remove(); }, "json"); } }, diff --git a/templates/content/js/com.cnprog.utils.js b/templates/content/js/com.cnprog.utils.js index e271ed78..fff61759 100644 --- a/templates/content/js/com.cnprog.utils.js +++ b/templates/content/js/com.cnprog.utils.js @@ -23,7 +23,8 @@ var notify = function() { }, close: function(doPostback) { if (doPostback) { - $.post("/messages/markread/", { formdata: "required" }); + $.post($.i18n._("/") + $.i18n._("messages/") + + $.i18n._("markread/"), { formdata: "required" }); } $(".notify").fadeOut("fast"); $("body").css("margin-top", "0"); @@ -35,7 +36,7 @@ var notify = function() { function appendLoader(containerSelector) { $(containerSelector).append('<img class="ajax-loader" ' - +'src="/content/images/indicator.gif" title="' + +'src="' + $.i18n._('/') + 'content/images/indicator.gif" title="' +$.i18n._('loading...') +'" alt="' +$.i18n._('loading...') @@ -103,7 +104,7 @@ var CPValidator = function(){ return { tags: { required: " " + $.i18n._('tags cannot be empty'), - maxlength: " " + $.i18n._('tablimits info'), + maxlength: " " + $.i18n._('tablimits info') }, text: { required: " " + $.i18n._('content cannot be empty'), diff --git a/templates/content/js/jquery.form.js b/templates/content/js/jquery.form.js new file mode 100644 index 00000000..443114fd --- /dev/null +++ b/templates/content/js/jquery.form.js @@ -0,0 +1,654 @@ +/* + * jQuery Form Plugin + * version: 2.33 (22-SEP-2009) + * @requires jQuery v1.2.6 or later + * + * Examples and documentation at: http://malsup.com/jquery/form/ + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + */ +;(function($) { + +/* + Usage Note: + ----------- + Do not use both ajaxSubmit and ajaxForm on the same form. These + functions are intended to be exclusive. Use ajaxSubmit if you want + to bind your own submit handler to the form. For example, + + $(document).ready(function() { + $('#myForm').bind('submit', function() { + $(this).ajaxSubmit({ + target: '#output' + }); + return false; // <-- important! + }); + }); + + Use ajaxForm when you want the plugin to manage all the event binding + for you. For example, + + $(document).ready(function() { + $('#myForm').ajaxForm({ + target: '#output' + }); + }); + + When using ajaxForm, the ajaxSubmit function will be invoked for you + at the appropriate time. +*/ + +/** + * ajaxSubmit() provides a mechanism for immediately submitting + * an HTML form using AJAX. + */ +$.fn.ajaxSubmit = function(options) { + // fast fail if nothing selected (http://dev.jquery.com/ticket/2752) + if (!this.length) { + log('ajaxSubmit: skipping submit process - no element selected'); + return this; + } + + if (typeof options == 'function') + options = { success: options }; + + var url = $.trim(this.attr('action')); + if (url) { + // clean url (don't include hash vaue) + url = (url.match(/^([^#]+)/)||[])[1]; + } + url = url || window.location.href || ''; + + options = $.extend({ + url: url, + type: this.attr('method') || 'GET' + }, options || {}); + + // hook for manipulating the form data before it is extracted; + // convenient for use with rich editors like tinyMCE or FCKEditor + var veto = {}; + this.trigger('form-pre-serialize', [this, options, veto]); + if (veto.veto) { + log('ajaxSubmit: submit vetoed via form-pre-serialize trigger'); + return this; + } + + // provide opportunity to alter form data before it is serialized + if (options.beforeSerialize && options.beforeSerialize(this, options) === false) { + log('ajaxSubmit: submit aborted via beforeSerialize callback'); + return this; + } + + var a = this.formToArray(options.semantic); + if (options.data) { + options.extraData = options.data; + for (var n in options.data) { + if(options.data[n] instanceof Array) { + for (var k in options.data[n]) + a.push( { name: n, value: options.data[n][k] } ); + } + else + a.push( { name: n, value: options.data[n] } ); + } + } + + // give pre-submit callback an opportunity to abort the submit + if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) { + log('ajaxSubmit: submit aborted via beforeSubmit callback'); + return this; + } + + // fire vetoable 'validate' event + this.trigger('form-submit-validate', [a, this, options, veto]); + if (veto.veto) { + log('ajaxSubmit: submit vetoed via form-submit-validate trigger'); + return this; + } + + var q = $.param(a); + + if (options.type.toUpperCase() == 'GET') { + options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q; + options.data = null; // data is null for 'get' + } + else + options.data = q; // data is the query string for 'post' + + var $form = this, callbacks = []; + if (options.resetForm) callbacks.push(function() { $form.resetForm(); }); + if (options.clearForm) callbacks.push(function() { $form.clearForm(); }); + + // perform a load on the target only if dataType is not provided + if (!options.dataType && options.target) { + var oldSuccess = options.success || function(){}; + callbacks.push(function(data) { + $(options.target).html(data).each(oldSuccess, arguments); + }); + } + else if (options.success) + callbacks.push(options.success); + + options.success = function(data, status) { + for (var i=0, max=callbacks.length; i < max; i++) + callbacks[i].apply(options, [data, status, $form]); + }; + + // are there files to upload? + var files = $('input:file', this).fieldValue(); + var found = false; + for (var j=0; j < files.length; j++) + if (files[j]) + found = true; + + var multipart = false; +// var mp = 'multipart/form-data'; +// multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp); + + // options.iframe allows user to force iframe mode + if (options.iframe || found || multipart) { + // hack to fix Safari hang (thanks to Tim Molendijk for this) + // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d + if (options.closeKeepAlive) + $.get(options.closeKeepAlive, fileUpload); + else + fileUpload(); + } + else{ + $.ajax(options); + } + + // fire 'notify' event + this.trigger('form-submit-notify', [this, options]); + return this; + + + // private function for handling file uploads (hat tip to YAHOO!) + function fileUpload() { + var form = $form[0]; + + if ($(':input[name=submit]', form).length) { + alert('Error: Form elements must not be named "submit".'); + return; + } + + var opts = $.extend({}, $.ajaxSettings, options); + var s = $.extend(true, {}, $.extend(true, {}, $.ajaxSettings), opts); + + var id = 'jqFormIO' + (new Date().getTime()); + var $io = $('<iframe id="' + id + '" name="' + id + '" src="about:blank" />'); + var io = $io[0]; + + $io.css({ position: 'absolute', top: '-1000px', left: '-1000px' }); + + var xhr = { // mock object + aborted: 0, + responseText: null, + responseXML: null, + status: 0, + statusText: 'n/a', + getAllResponseHeaders: function() {}, + getResponseHeader: function() {}, + setRequestHeader: function() {}, + abort: function() { + this.aborted = 1; + $io.attr('src','about:blank'); // abort op in progress + } + }; + + var g = opts.global; + // trigger ajax global events so that activity/block indicators work like normal + if (g && ! $.active++) $.event.trigger("ajaxStart"); + if (g) $.event.trigger("ajaxSend", [xhr, opts]); + + if (s.beforeSend && s.beforeSend(xhr, s) === false) { + s.global && $.active--; + return; + } + if (xhr.aborted) + return; + + var cbInvoked = 0; + var timedOut = 0; + + // add submitting element to data if we know it + var sub = form.clk; + if (sub) { + var n = sub.name; + if (n && !sub.disabled) { + options.extraData = options.extraData || {}; + options.extraData[n] = sub.value; + if (sub.type == "image") { + options.extraData[name+'.x'] = form.clk_x; + options.extraData[name+'.y'] = form.clk_y; + } + } + } + + // take a breath so that pending repaints get some cpu time before the upload starts + setTimeout(function() { + // make sure form attrs are set + var t = $form.attr('target'), a = $form.attr('action'); + + // update form attrs in IE friendly way + form.setAttribute('target',id); + if (form.getAttribute('method') != 'POST') + form.setAttribute('method', 'POST'); + if (form.getAttribute('action') != opts.url) + form.setAttribute('action', opts.url); + + // ie borks in some cases when setting encoding + if (! options.skipEncodingOverride) { + $form.attr({ + encoding: 'multipart/form-data', + enctype: 'multipart/form-data' + }); + } + + // support timout + if (opts.timeout) + setTimeout(function() { timedOut = true; cb(); }, opts.timeout); + + // add "extra" data to form if provided in options + var extraInputs = []; + try { + if (options.extraData) + for (var n in options.extraData) + extraInputs.push( + $('<input type="hidden" name="'+n+'" value="'+options.extraData[n]+'" />') + .appendTo(form)[0]); + + // add iframe to doc and submit the form + $io.appendTo('body'); + io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false); + form.submit(); + } + finally { + // reset attrs and remove "extra" input elements + form.setAttribute('action',a); + t ? form.setAttribute('target', t) : $form.removeAttr('target'); + $(extraInputs).remove(); + } + }, 10); + + var domCheckCount = 50; + + function cb() { + if (cbInvoked++) return; + + io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false); + + var ok = true; + try { + if (timedOut) throw 'timeout'; + // extract the server response from the iframe + var data, doc; + + doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document; + + var isXml = opts.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc); + log('isXml='+isXml); + if (!isXml && (doc.body == null || doc.body.innerHTML == '')) { + if (--domCheckCount) { + // in some browsers (Opera) the iframe DOM is not always traversable when + // the onload callback fires, so we loop a bit to accommodate + cbInvoked = 0; + setTimeout(cb, 100); + return; + } + log('Could not access iframe DOM after 50 tries.'); + return; + } + + xhr.responseText = doc.body ? doc.body.innerHTML : null; + xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc; + xhr.getResponseHeader = function(header){ + var headers = {'content-type': opts.dataType}; + return headers[header]; + }; + + if (opts.dataType == 'json' || opts.dataType == 'script') { + // see if user embedded response in textarea + var ta = doc.getElementsByTagName('textarea')[0]; + if (ta) + xhr.responseText = ta.value; + else { + // account for browsers injecting pre around json response + var pre = doc.getElementsByTagName('pre')[0]; + if (pre) + xhr.responseText = pre.innerHTML; + } + } + else if (opts.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) { + xhr.responseXML = toXml(xhr.responseText); + } + data = $.httpData(xhr, opts.dataType); + } + catch(e){ + ok = false; + $.handleError(opts, xhr, 'error', e); + } + + // ordering of these callbacks/triggers is odd, but that's how $.ajax does it + if (ok) { + opts.success(data, 'success'); + if (g) $.event.trigger("ajaxSuccess", [xhr, opts]); + } + if (g) $.event.trigger("ajaxComplete", [xhr, opts]); + if (g && ! --$.active) $.event.trigger("ajaxStop"); + if (opts.complete) opts.complete(xhr, ok ? 'success' : 'error'); + + // clean up + setTimeout(function() { + $io.remove(); + xhr.responseXML = null; + }, 100); + }; + + function toXml(s, doc) { + if (window.ActiveXObject) { + doc = new ActiveXObject('Microsoft.XMLDOM'); + doc.async = 'false'; + doc.loadXML(s); + } + else + doc = (new DOMParser()).parseFromString(s, 'text/xml'); + return (doc && doc.documentElement && doc.documentElement.tagName != 'parsererror') ? doc : null; + }; + }; +}; + +/** + * ajaxForm() provides a mechanism for fully automating form submission. + * + * The advantages of using this method instead of ajaxSubmit() are: + * + * 1: This method will include coordinates for <input type="image" /> elements (if the element + * is used to submit the form). + * 2. This method will include the submit element's name/value data (for the element that was + * used to submit the form). + * 3. This method binds the submit() method to the form for you. + * + * The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely + * passes the options argument along after properly binding events for submit elements and + * the form itself. + */ +$.fn.ajaxForm = function(options) { + return this.ajaxFormUnbind().bind('submit.form-plugin', function() { + $(this).ajaxSubmit(options); + return false; + }).bind('click.form-plugin', function(e) { + var $el = $(e.target); + if (!($el.is(":submit,input:image"))) { + return; + } + var form = this; + form.clk = e.target; + if (e.target.type == 'image') { + if (e.offsetX != undefined) { + form.clk_x = e.offsetX; + form.clk_y = e.offsetY; + } else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin + var offset = $el.offset(); + form.clk_x = e.pageX - offset.left; + form.clk_y = e.pageY - offset.top; + } else { + form.clk_x = e.pageX - e.target.offsetLeft; + form.clk_y = e.pageY - e.target.offsetTop; + } + } + // clear form vars + setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 10); + }); +}; + +// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm +$.fn.ajaxFormUnbind = function() { + return this.unbind('submit.form-plugin click.form-plugin'); +}; + +/** + * formToArray() gathers form element data into an array of objects that can + * be passed to any of the following ajax functions: $.get, $.post, or load. + * Each object in the array has both a 'name' and 'value' property. An example of + * an array for a simple login form might be: + * + * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ] + * + * It is this array that is passed to pre-submit callback functions provided to the + * ajaxSubmit() and ajaxForm() methods. + */ +$.fn.formToArray = function(semantic) { + var a = []; + if (this.length == 0) return a; + + var form = this[0]; + var els = semantic ? form.getElementsByTagName('*') : form.elements; + if (!els) return a; + for(var i=0, max=els.length; i < max; i++) { + var el = els[i]; + var n = el.name; + if (!n) continue; + + if (semantic && form.clk && el.type == "image") { + // handle image inputs on the fly when semantic == true + if(!el.disabled && form.clk == el) { + a.push({name: n, value: $(el).val()}); + a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y}); + } + continue; + } + + var v = $.fieldValue(el, true); + if (v && v.constructor == Array) { + for(var j=0, jmax=v.length; j < jmax; j++) + a.push({name: n, value: v[j]}); + } + else if (v !== null && typeof v != 'undefined') + a.push({name: n, value: v}); + } + + if (!semantic && form.clk) { + // input type=='image' are not found in elements array! handle it here + var $input = $(form.clk), input = $input[0], n = input.name; + if (n && !input.disabled && input.type == 'image') { + a.push({name: n, value: $input.val()}); + a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y}); + } + } + return a; +}; + +/** + * Serializes form data into a 'submittable' string. This method will return a string + * in the format: name1=value1&name2=value2 + */ +$.fn.formSerialize = function(semantic) { + //hand off to jQuery.param for proper encoding + return $.param(this.formToArray(semantic)); +}; + +/** + * Serializes all field elements in the jQuery object into a query string. + * This method will return a string in the format: name1=value1&name2=value2 + */ +$.fn.fieldSerialize = function(successful) { + var a = []; + this.each(function() { + var n = this.name; + if (!n) return; + var v = $.fieldValue(this, successful); + if (v && v.constructor == Array) { + for (var i=0,max=v.length; i < max; i++) + a.push({name: n, value: v[i]}); + } + else if (v !== null && typeof v != 'undefined') + a.push({name: this.name, value: v}); + }); + //hand off to jQuery.param for proper encoding + return $.param(a); +}; + +/** + * Returns the value(s) of the element in the matched set. For example, consider the following form: + * + * <form><fieldset> + * <input name="A" type="text" /> + * <input name="A" type="text" /> + * <input name="B" type="checkbox" value="B1" /> + * <input name="B" type="checkbox" value="B2"/> + * <input name="C" type="radio" value="C1" /> + * <input name="C" type="radio" value="C2" /> + * </fieldset></form> + * + * var v = $(':text').fieldValue(); + * // if no values are entered into the text inputs + * v == ['',''] + * // if values entered into the text inputs are 'foo' and 'bar' + * v == ['foo','bar'] + * + * var v = $(':checkbox').fieldValue(); + * // if neither checkbox is checked + * v === undefined + * // if both checkboxes are checked + * v == ['B1', 'B2'] + * + * var v = $(':radio').fieldValue(); + * // if neither radio is checked + * v === undefined + * // if first radio is checked + * v == ['C1'] + * + * The successful argument controls whether or not the field element must be 'successful' + * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls). + * The default value of the successful argument is true. If this value is false the value(s) + * for each element is returned. + * + * Note: This method *always* returns an array. If no valid value can be determined the + * array will be empty, otherwise it will contain one or more values. + */ +$.fn.fieldValue = function(successful) { + for (var val=[], i=0, max=this.length; i < max; i++) { + var el = this[i]; + var v = $.fieldValue(el, successful); + if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) + continue; + v.constructor == Array ? $.merge(val, v) : val.push(v); + } + return val; +}; + +/** + * Returns the value of the field element. + */ +$.fieldValue = function(el, successful) { + var n = el.name, t = el.type, tag = el.tagName.toLowerCase(); + if (typeof successful == 'undefined') successful = true; + + if (successful && (!n || el.disabled || t == 'reset' || t == 'button' || + (t == 'checkbox' || t == 'radio') && !el.checked || + (t == 'submit' || t == 'image') && el.form && el.form.clk != el || + tag == 'select' && el.selectedIndex == -1)) + return null; + + if (tag == 'select') { + var index = el.selectedIndex; + if (index < 0) return null; + var a = [], ops = el.options; + var one = (t == 'select-one'); + var max = (one ? index+1 : ops.length); + for(var i=(one ? index : 0); i < max; i++) { + var op = ops[i]; + if (op.selected) { + var v = op.value; + if (!v) // extra pain for IE... + v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value; + if (one) return v; + a.push(v); + } + } + return a; + } + return el.value; +}; + +/** + * Clears the form data. Takes the following actions on the form's input fields: + * - input text fields will have their 'value' property set to the empty string + * - select elements will have their 'selectedIndex' property set to -1 + * - checkbox and radio inputs will have their 'checked' property set to false + * - inputs of type submit, button, reset, and hidden will *not* be effected + * - button elements will *not* be effected + */ +$.fn.clearForm = function() { + return this.each(function() { + $('input,select,textarea', this).clearFields(); + }); +}; + +/** + * Clears the selected form elements. + */ +$.fn.clearFields = $.fn.clearInputs = function() { + return this.each(function() { + var t = this.type, tag = this.tagName.toLowerCase(); + if (t == 'text' || t == 'password' || tag == 'textarea') + this.value = ''; + else if (t == 'checkbox' || t == 'radio') + this.checked = false; + else if (tag == 'select') + this.selectedIndex = -1; + }); +}; + +/** + * Resets the form data. Causes all form elements to be reset to their original value. + */ +$.fn.resetForm = function() { + return this.each(function() { + // guard against an input with the name of 'reset' + // note that IE reports the reset function as an 'object' + if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) + this.reset(); + }); +}; + +/** + * Enables or disables any matching elements. + */ +$.fn.enable = function(b) { + if (b == undefined) b = true; + return this.each(function() { + this.disabled = !b; + }); +}; + +/** + * Checks/unchecks any matching checkboxes or radio buttons and + * selects/deselects and matching option elements. + */ +$.fn.selected = function(select) { + if (select == undefined) select = true; + return this.each(function() { + var t = this.type; + if (t == 'checkbox' || t == 'radio') + this.checked = select; + else if (this.tagName.toLowerCase() == 'option') { + var $sel = $(this).parent('select'); + if (select && $sel[0] && $sel[0].type == 'select-one') { + // deselect all other options + $sel.find('option').selected(false); + } + this.selected = select; + } + }); +}; + +// helper fn for console logging +// set $.fn.ajaxSubmit.debug to true to enable debug logging +function log() { + if ($.fn.ajaxSubmit.debug && window.console && window.console.log) + window.console.log('[jquery.form] ' + Array.prototype.join.call(arguments,'')); +}; + +})(jQuery); diff --git a/templates/content/js/wmd/wmd.js b/templates/content/js/wmd/wmd.js index 7b611dba..0bdc55b6 100644 --- a/templates/content/js/wmd/wmd.js +++ b/templates/content/js/wmd/wmd.js @@ -54,7 +54,7 @@ Attacklab.wmdBase = function(){ var uploadImageHTML ="<div>" + $.i18n._('upload image') + "</div>" + "<input type=\"file\" name=\"file-upload\" id=\"file-upload\" size=\"26\" "+ "onchange=\"return ajaxFileUpload($('#image-url'));\"/><br>" + - "<img id=\"loading\" src=\"/content/images/indicator.gif\" style=\"display:none;\"/>"; + "<img id=\"loading\" src=\"" + $.i18n._("/") + "content/images/indicator.gif\" style=\"display:none;\"/>"; // The default text that appears in the dialog input box when entering // links. |