{# most, if not all javascripts should go here
   this template is included at the very bottow of the
   main template "base.html"
#}
<div id="no-javascript">
  <noscript class="noscript">
    {% trans app_name = settings.APP_SHORT_NAME %}Please note: {{ app_name }} requires javascript to work properly, please enable javascript in your browser, <a href="{{ noscript_url }}">here is how</a>{% endtrans %}
  </noscript>
  <script>
    //IE fix to hide the red margin
    var noscript = document.getElementsByTagName('noscript')[0];
    noscript.style.padding = '0px';
    noscript.style.backgroundColor = 'transparent';
  </script>
{% if settings.DEBUG %}
  {% include "meta/dev_grid.html" %}
{% endif %}
</div>
{# this section cannot be compressed because lots of data is runtime #}
<script>
  askbot['urls']['mark_read_message'] = '{{ url('read_message') }}';
  askbot['urls']['get_tags_by_wildcard'] = '{{ url('get_tags_by_wildcard') }}';
  askbot['urls']['get_tag_list'] = '{{ url('get_tag_list') }}';
  askbot['urls']['follow_user'] = '/followit/follow/user/{{ '{{' }}userId{{ '}}' }}/';
  askbot['urls']['unfollow_user'] = '/followit/unfollow/user/{{'{{'}}userId{{'}}'}}/';
  askbot['urls']['user_signin'] = '{{ settings.LOGIN_URL }}';
  askbot['urls']['getEditor'] = '{{ url('get_editor') }}';
  {% if settings.MULTILINGUAL %}
    askbot['urls']['translateUrl'] = '{{ url('translate_url') }}';
  {% endif %}
  askbot['urls']['apiGetQuestions'] = '{{ url('api_get_questions') }}';
  askbot['urls']['ask'] = '{{ url('ask') }}';
  askbot['urls']['questions'] = '{{ url('questions') }}';
  askbot['settings']['groupsEnabled'] = {{ settings.GROUPS_ENABLED|as_js_bool }};
  askbot['settings']['static_url'] = '{{ settings.STATIC_URL }}';
  askbot['settings']['minSearchWordLength'] = {{ min_search_word_length }};
  askbot['settings']['mathjaxEnabled'] = {{ settings.ENABLE_MATHJAX|as_js_bool }};
  askbot['settings']['markupCodeFriendly'] = {{ settings.MARKUP_CODE_FRIENDLY|as_js_bool }};
  askbot['settings']['videoEmbeddingEnabled'] = {{ settings.ENABLE_VIDEO_EMBEDDING|as_js_bool }};
  askbot['settings']['autoLinkEnabled'] = {{ settings.ENABLE_AUTO_LINKING|as_js_bool }};
  {% if settings.ENABLE_AUTO_LINKING %}
    askbot['settings']['autoLinkPatterns'] = {{ settings.AUTO_LINK_PATTERNS|tojson }};
    askbot['settings']['autoLinkUrls'] = {{ settings.AUTO_LINK_URLS|tojson }};
  {% endif %}
  askbot['settings']['sharingSuffixText'] = '{{ settings.SHARING_SUFFIX_TEXT|escape }}';
  askbot['settings']['errorPlacement'] = 'after-label';
  askbot['data']['maxCommentLength'] = {{ settings.MAX_COMMENT_LENGTH }};
  askbot['settings']['editorType'] = '{{ settings.EDITOR_TYPE }}';
  askbot['settings']['commentsEditorType'] = '{{ settings.COMMENTS_EDITOR_TYPE|escapejs }}';
  askbot['settings']['allowedHtmlElements'] = {{ ALLOWED_HTML_ELEMENTS|tojson }};
  askbot['messages']['askYourQuestion'] = '{{ settings.WORDS_ASK_YOUR_QUESTION|escapejs }}';
  askbot['messages']['acceptOwnAnswer'] = '{{ settings.WORDS_ACCEPT_OR_UNACCEPT_OWN_ANSWER|escapejs }}';
  askbot['messages']['followQuestions'] = '{{ settings.WORDS_FOLLOW_QUESTIONS|escapejs }}';
  {% if settings.ALLOWED_UPLOAD_FILE_TYPES %}
    askbot['settings']['allowedUploadFileTypes'] = [
      "{{ settings.ALLOWED_UPLOAD_FILE_TYPES|join('", "')|replace('.','') }}"
    ];
  {% else %}
    askbot['settings']['allowedUploadFileTypes'] = [];
  {% endif %}
  askbot['data']['haveFlashNotifications'] = {{ user_messages|as_js_bool }};
  askbot['data']['activeTab'] = '{{ active_tab }}';
  askbot['settings']['csrfCookieName'] = '{{ settings.CSRF_COOKIE_NAME }}';
  {% if search_state %}
    askbot['data']['searchUrl'] = '{{ search_state.query_string()|escapejs }}';
  {% else %}
    askbot['data']['searchUrl'] = '';
  {% endif %}
</script>
{# everything below until the custom js and google analytics is compressable #}
<form name="scroll-pos-form"><input id="scroll-mem" type="text" style="display: none;"/></form>
{% compress js %}
  <script src="{{ '/jslib/jquery-3.6.0.min.js'|media }}"></script>
  <script src="{{ '/jslib/jquery.modal.min.js'|media }}"></script>
  <script src="{{ '/jslib/timeago.js'|media }}"></script>
  <!-- History.js -->
  <script src="{{ '/jslib/jquery.history.js'|media }}"></script>
  <!-- Utils.js -->
  <script src="{{ '/js/utils.js'|media }}"></script>
  <script src="{{ '/js/scroll_memory.js'|media }}"></script>
  <script src="{{ '/js/utils/q_sutils.js'|media }}"></script>
  <script src="{{ '/js/utils/wrapped_element.js'|media }}"></script>
  <script src="{{ '/js/utils/wait_icon.js'|media }}"></script>
  <script src="{{ '/js/utils/paginator.js'|media }}"></script>
  <script src="{{ '/js/utils/limited_width_image.js'|media }}"></script>
  <script src="{{ '/js/utils/one_shot_form.js'|media }}"></script>
  <script src="{{ '/js/utils/link.js'|media }}"></script>
  <script src="{{ '/js/utils/widget.js'|media }}"></script>
  <script src="{{ '/js/utils/tipped_input.js'|media }}"></script>
  <script src="{{ '/js/utils/flash_alert.js'|media }}"></script>
  <script src="{{ '/js/utils/alert_box.js'|media }}"></script>
  <script src="{{ '/js/utils/simple_content.js'|media }}"></script>
  <script src="{{ '/js/utils/simple_control.js'|media }}"></script>
  <script src="{{ '/js/utils/post_expander.js'|media }}"></script>
  <script src="{{ '/js/utils/edit_link.js'|media }}"></script>
  <script src="{{ '/js/utils/comment_convert_link.js'|media }}"></script>
  <script src="{{ '/js/utils/delete_icon.js'|media }}"></script>
  <script src="{{ '/js/utils/modal_dialog.js'|media }}"></script>
  <script src="{{ '/js/utils/confirm_dialog.js'|media }}"></script>
  <script src="{{ '/js/utils/file_upload_dialog.js'|media }}"></script>
  <script src="{{ '/js/utils/video_modal.js'|media }}"></script>
  <script src="{{ '/js/utils/toggle.js'|media }}"></script>
  <script src="{{ '/js/utils/ajax_toggle.js'|media }}"></script>
  <script src="{{ '/js/utils/dropdown_menu.js'|media }}"></script>
  <script src="{{ '/js/utils/box_item_content.js'|media }}"></script>
  <script src="{{ '/js/utils/select_box_item.js'|media }}"></script>
  <script src="{{ '/js/utils/select_box.js'|media }}"></script>
  <script src="{{ '/js/utils/group_dropdown.js'|media }}"></script>
  <script src="{{ '/js/utils/tag.js'|media }}"></script>
  <script src="{{ '/js/utils/hover_card.js'|media }}"></script>
  <script src="{{ '/js/utils/perms_hover_card.js'|media }}"></script>
  <script src="{{ '/js/utils/show_perms_trigger.js'|media }}"></script>
  <script src="{{ '/js/utils/autocompleter.js'|media }}"></script>
  <script src="{{ '/js/utils/lang_nav.js'|media }}"></script>
  <script src="{{ '/jslib/se_hilite.js'|media }}"></script>
  <script src="{{ '/jslib/json.js'|media }}"></script>
  <script src="{{ '/jslib/jquery-fieldselection.js'|media }}"></script>
  {% if settings.USE_ASKBOT_LOGIN_SYSTEM and use_login_page == False %}
    <script src="{{ '/js/jquery-openid/jquery.authenticator.js'|media }}"></script>
  {% endif %}
  <!-- End Utils.js -->
  <script src="{{ '/js/searchbar/drop_menu.js'|media }}"></script>
  <script src="{{ '/js/searchbar/tag_warning_box.js'|media }}"></script>
  {% if settings.SEARCH_FRONTEND_SRC_URL %}
    <script src="{{settings.SEARCH_FRONTEND_SRC_URL}}"</script>
  {% else %}
    <script src="{{ '/js/searchbar/full_text_search.js'|media }}"></script>
  {% endif %}
  <script src="{{ '/js/searchbar/tag_search.js'|media }}"></script>
  <script src="{{ '/js/utils/ask_button.js'|media }}"></script>
{% endcompress %}
<script>
  /*<![CDATA[*/
  $(document).ready(function(){
    // focus input on the search bar endcomment
    var activeTab = askbot['data']['activeTab'];
    if (inArray(activeTab, ['users', 'questions', 'tags', 'badges'])) {
      var searchInput = $('.js-search-input');
    } else if (activeTab === 'ask') {
      var searchInput = $('#id_title');
    } else {
      var searchInput = undefined;
      animateHashes();
    }

    var wasScrolled = $('#scroll-mem').val();
    if (searchInput && !wasScrolled) {
      searchInput.focus();
      putCursorAtEnd(searchInput);
    }

    {% if not settings.SEARCH_FRONTEND_SRC_URL %}
      var haveFullTextSearchTab = inArray(activeTab, ['questions', 'badges', 'ask']);
      var haveUserProfilePage = $('body').hasClass('user-profile-page');
      if ((haveUserProfilePage || haveFullTextSearchTab) && searchInput && searchInput.length) {
        var search = new FullTextSearch();
        askbot['controllers'] = askbot['controllers'] || {};
        askbot['controllers']['fullTextSearch'] = search;
        search.setSearchUrl(askbot['data']['searchUrl']);
        if (activeTab === 'ask') {
          search.setAskButtonEnabled(false);
        }
        search.decorate(searchInput);
      }
    {% endif %}

    if (activeTab === 'tags') {
      var search = new TagSearch();
      search.decorate(searchInput);
    }

    if (askbot['data']['userIsAdminOrMod']) {
      $('body').addClass('admin');
    }
    if (askbot['settings']['groupsEnabled']) {
      askbot['urls']['add_group'] = "{{ url('add_group') }}";
      var group_dropdown = new GroupDropdown({{ group_list }});
      $('.groups-dropdown').append(group_dropdown.getElement());
    }
    var userRep = $('#userToolsNav .reputation');
    if (userRep.length) {
      var showPermsTrigger = new ShowPermsTrigger();
      showPermsTrigger.decorate(userRep);
    }
  });

  if (askbot['data']['haveFlashNotifications']) {
    $('#validate_email_alert').click(function(){notify.close(true)})
    notify.show();
  }

  var langNav = $('.lang-nav');
  if (langNav.length) {
    var nav = new LangNav();
    nav.decorate(langNav);
  }
  /*]]>*/
</script>
{% include "meta/custom_javascript.html" ignore missing %}
{# stuff below should not be compressed #}
{% if settings.ENABLE_MATHJAX %}
  {# we don't want to load mathjax just in case, only if it is really enabled #}
  <script src="{{settings.MATHJAX_BASE_URL}}/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
    if (typeof MathJax != 'undefined') {
      MathJax.Hub.Config({
        extensions: ["tex2jax.js"],
        jax: ["input/TeX","output/HTML-CSS"],
        tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}
      });
    } else {
      console.log('Could not load MathJax');
    }
  </script>
{% endif %}
{% if settings.USE_CUSTOM_JS %}
  <script src="{{ url('custom_js') }}?v={{ settings.MEDIA_RESOURCE_REVISION }}"></script>
{% endif %}
{% if settings.GOOGLE_ANALYTICS_KEY %}
<script>
  var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
  document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js'%3E%3C/script%3E"));
</script>
<script>
  try {
    var pageTracker = _gat._getTracker('{{ settings.GOOGLE_ANALYTICS_KEY }}');
    pageTracker._trackPageview();
  } catch(err) {}
</script>
{% endif %}
