summaryrefslogtreecommitdiffstats
path: root/askbot/templates/question.html
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-03-06 20:50:21 -0300
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-03-06 20:50:21 -0300
commitd13ee8aa889304ca95cbd8cc777ab5e957fbed54 (patch)
treeb2f484651b068e5df9c204fdff459633f7cd00e3 /askbot/templates/question.html
parentfb0df1a738d3a9dc01c5b54619f286148532c6ce (diff)
downloadaskbot-d13ee8aa889304ca95cbd8cc777ab5e957fbed54.tar.gz
askbot-d13ee8aa889304ca95cbd8cc777ab5e957fbed54.tar.bz2
askbot-d13ee8aa889304ca95cbd8cc777ab5e957fbed54.zip
added function to repost answer as comment under the latest previously posted answer
Diffstat (limited to 'askbot/templates/question.html')
-rw-r--r--askbot/templates/question.html92
1 files changed, 71 insertions, 21 deletions
diff --git a/askbot/templates/question.html b/askbot/templates/question.html
index e2e6f394..5fcea3a9 100644
--- a/askbot/templates/question.html
+++ b/askbot/templates/question.html
@@ -15,7 +15,43 @@
/*<![CDATA[*/
//below is pure cross-browser javascript, no jQuery
askbot['data']['userIsThreadModerator'] = {% if user_is_thread_moderator %}true{% else %}false{% endif %};
+ askbot['data']['oldestAnswerId'] = {% if oldest_answer_id %}{{ oldest_answer_id }}{% else %}-1{% endif %};
(function(){
+
+ var hasClass = function(node, selector) {
+ var classes = (" " + node.className + " ").split(' ');
+ for (var i = 0; i < classes.length; i++) {
+ if (classes[i] === selector) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ var findChildrenByClassName = function(node, className) {
+ var nodes = [];
+ var walk = function(node) {
+ if (hasClass(node, className)) {
+ nodes.push(node);
+ }
+ if (node.childNodes) {
+ for (var i=0; i < node.childNodes.length; i++) {
+ walk(node.childNodes[i]);
+ }
+ }
+ };
+ walk(node);
+ return nodes;
+ };
+
+ var removeNode = function(node) {
+ node.parentNode.removeChild(node);
+ };
+
+ var trim = function(text) {
+ return text.replace(/^\s+|\s+$/g, '');
+ };
+
var data = askbot['data'];
if (data['userIsAuthenticated']){
var votes = {};
@@ -57,20 +93,32 @@
}
function hide_convert_answer_links(post_id){
- var answer_convert_id = 'post-' + post_id + '-convert';
- var convert_answer = document.getElementById(answer_convert_id);
+ var id1 = 'post-' + post_id + '-convert';//for repost as Q comment
+ var repostAsQuestionComment = document.getElementById(id1);
+ var id2 = 'post-' + post_id + '-repost-as-comment-under-previous-answer';
+ var repostAsPrevAnsComment = document.getElementById(id2);
+ var extraOptsList = repostAsQuestionComment.parentNode;
+ var extraOpts = extraOptsList.parentNode;
if (data['userIsAdminOrMod']){
var answer_id = 'post-id-' + post_id;
var answer_container = document.getElementById(answer_id);
- var answer_element= answer_container.getElementsByClassName('answer-body')[0].children[1];
- if (
- answer_element.textContent.length >
- askbot['data']['maxCommentLength']
- ){
- convert_answer.parentNode.removeChild(convert_answer);
+ var answerBody = findChildrenByClassName(answer_container, 'answer-body')[0];
+ //todo: this is not reliable
+ var answerBodyNodes = answerBody.childNodes;
+ var answerElement = answerBodyNodes[answerBodyNodes.length - 1];
+ if (trim(answerElement.textContent).length > askbot['data']['maxCommentLength']) {
+ repostAsQuestionComment.parentNode.removeChild(repostAsQuestionComment);
+ repostAsPrevAnsComment.parentNode.removeChild(repostAsPrevAnsComment);
+ } else if (parseInt(post_id) === data['oldestAnswerId']) {
+ repostAsPrevAnsComment.parentNode.removeChild(repostAsPrevAnsComment);
}
} else{
- convert_answer.parentNode.removeChild(convert_answer);
+ repostAsQuestionComment.parentNode.removeChild(repostAsQuestionComment);
+ repostAsPrevAnsComment.parentNode.removeChild(repostAsPrevAnsComment);
+ }
+
+ if (extraOptsList.getElementsByTagName('li').length === 0) {
+ extraOpts.parentNode.removeChild(extraOpts);
}
}
@@ -87,21 +135,21 @@
if (data['userIsAdminOrMod']){
return;//all remaining functions stay on
}
- if (data['user_posts'] === undefined) {
- return;
- }
- if (post_id in data['user_posts']){
+ if (data['user_posts'] && post_id in data['user_posts']){
//todo: remove edit button from older comments
- return;//same here
+ return;
}
+ var deleteBtn = document.getElementById('post-' + post_id + '-delete');
+ var controls = deleteBtn.parentNode;
if (//maybe remove "delete" button
data['userReputation'] <
{{settings.MIN_REP_TO_DELETE_OTHERS_COMMENTS}}
) {
- var delete_btn = document.getElementById(
- 'post-' + post_id + '-delete'
- );
- delete_btn.parentNode.removeChild(delete_btn);
+ removeNode(deleteBtn);
+ }
+ var flags = findChildrenByClassName(controls, 'question-flag');
+ if (flags.length > 0) {
+ removeNode(flags[0]);
}
if (//maybe remove "edit" button
data['userReputation'] <
@@ -116,8 +164,10 @@
data['userReputation'] <
{{settings.MIN_REP_TO_RETAG_OTHERS_QUESTIONS}}
){
- var retag_btn = document.getElementById('retag');
- retag_btn.parentNode.removeChild(retag_btn);
+ var retagBtn = document.getElementById('retag');
+ if (retagBtn) {
+ retagBtn.parentNode.removeChild(retagBtn);
+ }
}
}
function render_add_comment_button(post_id, extra_comment_count){
@@ -188,7 +238,7 @@
function hide_convert_links(){
if (!askbot['data']['userIsAdminOrMod']){
- var links = document.getElementsByClassName('convert-comment');
+ var links = findChildrenByClassName(document, 'convert-comment');
for (i=0; i<links.length; i++){
links[i].setAttribute('style', 'display:none;');
}