{% extends "two_column_body.html" %}
{% import "macros.html" as macros %}
<!-- template ask.html -->
{% block title %}{% filter trim %}{% trans %}Ask Your Question{% endtrans %}{% endfilter %}{% endblock %}
{% block layout_class %}{{ super() }} ask-page{% endblock %}
{# main contents of ask form is in the template input_bar #}
{% block sidebar %}
  {% if settings.EDITOR_TYPE == 'markdown' %}
    <div class="sidebar-box">
      {% include "/components/markdown_help.html" %}
    </div>
  {% endif %}
{% endblock %}
{% block content %}
  <div class="info-box">
    {% include "ask/question_edit_tips.html" %}
  </div>
  {% include "ask/ask_form.html" %}
{% endblock %}
{% block endjs %}
  {% compress js %}
  <script src="{{ '/jslib/editor.js'|media }}"></script>
  <script src="{{ '/jslib/jquery.validate.js'|media }}"></script>
  <script src="{{ '/jslib/highlight.min.js'|media }}"></script>
  <script src="{{ '/js/editors/simple_editor.js'|media }}"></script>
  <script src="{{ '/js/utils/toggle.js'|media }}"></script>
  <script src="{{ '/js/utils/expander_toggle.js'|media }}"></script>
  <script src="{{ '/js/utils/draft_post.js'|media }}"></script>
  <script src="{{ '/js/pages/ask/draft_question.js'|media }}"></script>
  <script src="{{ '/js/editors/wmd_expander_toggle.js'|media }}"></script>
  <script src="{{ '/js/editors/wmd.js'|media }}"></script>
  <script src="{{ '/js/editors/folded_editor.js'|media }}"></script>
  <script src="{{ '/js/validators/question_validators.js'|media }}"></script>
  <script src="{{ '/js/forms/form.js'|media }}"></script>
  <script src="{{ '/js/forms/ask_form.js'|media }}"></script>
  <script src="{{ '/js/utils/proxy_author_inputs.js'|media }}"></script>
  {% endcompress %}
  {% if settings.EDITOR_TYPE == 'markdown' %}
    {% compress js %}
      {% include "meta/markdown_javascript.html" %}
    {% endcompress %}
  {% 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'] = '{{ gettext('User name:')|escapejs }}';
    (function() {
      var form = $('.js-ask-form');
      if (form.length == 1) {
        var askForm = new AskForm();
        askForm.decorate(form);
      }
    })();
    $(document).ready(function(){
      //set current module button style
      $('#editor').TextAreaResizer();
      //highlight code synctax when editor has new text

      //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') }}

      $("#editor").typeWatch({
        highlight: false,
        wait: 3000,
        captureLength: 5,
        callback: function() { hljs.highlightAll(); }
      });
      hljs.highlightAll();

      if (askbot['data']['userIsAuthenticated']) {
        var draftHandler = new DraftQuestion();
        draftHandler.decorate($('body'));
        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 %}
{% block js_templates %}
  {{ macros.tag_widget('none', deletable=True) }}
{% endblock %}
<!-- end template ask.html -->
