{% extends "two_column_body.html" %}
{% import "macros.html" as macros %}
<!-- template ask.html -->
{% block title %}{% spaceless %}{% trans %}Ask Your Question{% endtrans %}{% endspaceless %}{% endblock %}
{% block forestyle %}
    <link rel="stylesheet" type="text/css" href="{{"/js/wmd/wmd.css"|media}}" />
{% endblock %}
{# main contents of ask form is in the template input_bar #}
{% block sidebar %}
    {% if settings.EDITOR_TYPE == 'markdown' %}
        {% include "/widgets/markdown_help.html" %}
    {% endif %}
{% endblock %}
{% block content %}
    <div class="question-instructions">
        {% include "widgets/question_edit_tips.html" %}
    </div>
    {% include "widgets/ask_form.html" %}
{% endblock %}
{% block endjs %}
    <script type='text/javascript' src='{{"/js/editor.js"|media}}'></script>
    <script type='text/javascript' src='{{"/js/jquery.validate.js"|media}}'></script>
    <script type='text/javascript' src='{{"/js/post.js"|media}}'></script>
    {% if settings.EDITOR_TYPE == 'markdown' %}
        {% include "meta/markdown_javascript.html" %}
    {% endif %}
    {% include "meta/editor_data.html" %}
    {% if mandatory_tags %}
        {% include "meta/mandatory_tags_js.html" %}
    {% endif %}
    {% if settings.TAG_SOURCE == 'category-tree' %}
        {% include "meta/category_tree_js.html" %}
    {% endif %}
    <script type='text/javascript'>
        askbot['urls']['saveDraftQuestion'] = '{% url save_draft_question %}';
        askbot['messages']['userNamePrompt'] = '{% trans %}User name:{% endtrans %}';
        {% if settings.ENABLE_MATHJAX or settings.MARKUP_CODE_FRIENDLY %}
            var codeFriendlyMarkdown = true;
        {% else %}
            var codeFriendlyMarkdown = false;
        {% endif %}
        (function() {
            var bodyTriggerLink = $('.question-body-trigger');
            if (bodyTriggerLink.length === 1) {
                var foldedEditor = new FoldedEditor();
                foldedEditor.setExternalTrigger(bodyTriggerLink);
                foldedEditor.decorate($('.folded-editor'));
            }
        })();
        $().ready(function(){
            //set current module button style
            $('#editor').TextAreaResizer();
            //highlight code synctax when editor has new text
            $("#editor").typeWatch({highlight: false, wait: 3000,
                             captureLength: 5, callback: lanai.highlightSyntax});

            //toggle preview of editor
            //todo remove copy-paste
            var display = true;
            var txt = "[{% trans %}hide preview{% endtrans %}]";
            $('#pre-collapse').text(txt);
            $('#pre-collapse').bind('click', function(){
                txt = display ? "[{% trans %}show preview{% endtrans %}]" : "[{% trans %}hide preview{% endtrans %}]";
                display = !display;
                $('#previewer').toggle();
                $('#pre-collapse').text(txt);
            });
            //Tags autocomplete

            {{ macros.tag_autocomplete_js(id = '#id_tags') }}

            setupFormValidation($("#fmask"), CPValidator.getQuestionFormRules(), CPValidator.getQuestionFormMessages());
            lanai.highlightSyntax();

            if (askbot['data']['userIsAuthenticated']) {
                var draftHandler = new DraftQuestion();
                draftHandler.decorate($(document));
                window.onbeforeunload = function() {
                    var saveHandler = draftHandler.getSaveHandler();
                    saveHandler(true);
                    //var msg = gettext("%s, we've saved your draft, but...");
                    //return interpolate(msg, [askbot['data']['userName']]);
                };
            }
        });
    </script>
{% endblock %}

<!-- end template ask.html -->
