diff options
Diffstat (limited to 'askbot/skins/default/templates/question.html')
-rw-r--r-- | askbot/skins/default/templates/question.html | 143 |
1 files changed, 138 insertions, 5 deletions
diff --git a/askbot/skins/default/templates/question.html b/askbot/skins/default/templates/question.html index b2462faf..bc0dbdeb 100644 --- a/askbot/skins/default/templates/question.html +++ b/askbot/skins/default/templates/question.html @@ -9,15 +9,148 @@ <link rel="canonical" href="{{settings.APP_URL|strip_path}}{{question.get_absolute_url()}}" /> <link rel="stylesheet" type="text/css" href="{{'/js/wmd/wmd.css'|media}}" /> {% endblock %} +{% block forejs %} + <script type="text/javascript"> + //below is pure cross-browser javascript, no jQuery + (function(){ + var data = askbot['data']; + if (data['userIsAuthenticated']){ + var votes = {}; + {% for post_id in user_votes %} + votes['{{post_id}}'] = {{user_votes[post_id]}}; + {% endfor %} + data['user_votes'] = votes; + var posts = {}; + {% for post_id in user_post_id_list %} + posts['{{post_id}}'] = 1; + {% endfor %} + data['user_posts'] = posts; + } + + function render_vote_buttons(post_type, post_id){ + var upvote_btn = document.getElementById( + post_type + '-img-upvote-' + post_id + ); + var downvote_btn = document.getElementById( + post_type + '-img-downvote-' + post_id + ); + if (data['userIsAuthenticated']){ + if (post_id in data['user_votes']){ + var vote = data['user_votes'][post_id]; + if (vote == -1){ + var btn = downvote_btn; + } else if (vote == 1){ + var btn = upvote_btn; + } else { + return; + } + if (post_type == 'comment'){ + btn.className = btn.className + ' upvoted'; + } else { + btn.className = btn.className + ' on'; + } + } + } + } + function render_post_controls(post_id){ + if (data['userIsAdminOrMod']){ + return;//all functions on + } + var edit_btn = document.getElementById( + 'post-' + post_id + '-edit' + ) + if (post_id in data['user_posts']){ + //todo: remove edit button from older comments + return;//same here + } + if ( + data['userReputation'] < + {{settings.MIN_REP_TO_DELETE_OTHERS_COMMENTS}} + ) { + var delete_btn = document.getElementById( + 'post-' + post_id + '-delete' + ); + delete_btn.parentNode.removeChild(delete_btn); + } + edit_btn.parentNode.removeChild(edit_btn); + } + function render_add_comment_button(post_id, extra_comment_count){ + var can_add = false; + {% if user_can_post_comment %} + can_add = true; + {% else %} + if (post_id in data['user_posts']){ + can_add = true; + } + {% endif %} + var add_comment_btn = document.getElementById( + 'add-comment-to-post-' + post_id + ); + if (can_add === false){ + add_comment_btn.parentNode.removeChild(add_comment_btn); + return; + } + + var text = ''; + if (extra_comment_count > 0){ + if (can_add){ + text = + "{% trans %}post a comment / <strong>some</strong> more{% endtrans %}"; + } else { + text = + "{% trans %}see <strong>some</strong> more{% endtrans%}"; + } + } else { + if (can_add){ + text = "{% trans %}post a comment{% endtrans %}"; + } + } + add_comment_btn.innerHTML = text; + //add the count + for (node in add_comment_btn.childNodes){ + if (node.nodeName === 'strong'){ + node.innerHTML = extra_comment_count; + break; + } + } + } + askbot['functions'] = askbot['functions'] || {}; + askbot['functions']['renderPostVoteButtons'] = render_vote_buttons; + askbot['functions']['renderPostControls'] = render_post_controls; + askbot['functions']['renderAddCommentButton'] = render_add_comment_button; + })(); + </script> +{% endblock %} {% block content %} - {# ==== BEGIN: question/content.html ==== #} - {% include "question/content.html" %} - {# ==== END: question/content.html ==== #} + {% if is_cacheable %} + {% cache long_time "thread-content-html" thread.id %} + {% include "question/content.html" %} + {% endcache %} + {% else %} + {% include "question/content.html" %} + {% endif %} {% endblock %} {% block sidebar %} - {%include "question/sidebar.html" %} + {% include "question/sidebar.html" %} {% endblock %} {% block endjs %} - {%include "question/javascript.html" %} + {% include "question/javascript.html" %} + {# + <script type="text/javascript"> + var messages = askbot['messages']; + messages['upvote_question'] = gettext( + 'I like this question (click again to cancel)' + ); + messages['upvote_answer'] = gettext( + 'I like this answer (click again to cancel)' + ); + messages['downvote_question'] = gettext( + "I don't like this question (click again to cancel)" + ); + messages['downvote_answer'] = gettext( + "I don't like this answer (click again to cancel)" + ); + </script> + #} {% endblock %} |