{% compress js %}
  <script src="{{ '/js/category_tree/tag_editor.js'|media }}"></script>
  <script src="{{ '/js/category_tree/category.js'|media }}"></script>
  <script src="{{ '/js/category_tree/category_adder.js'|media }}"></script>
  <script src="{{ '/js/category_tree/category_select_box.js'|media }}"></script>
  <script src="{{ '/js/category_tree/category_editor_toggle.js'|media }}"></script>
  <script src="{{ '/js/category_tree/category_selector.js'|media }}"></script>
  <script src="{{ '/js/category_tree/category_selector_loader.js'|media }}"></script>
{% endcompress %}
<script>
  var catSelectorLoader = new CategorySelectorLoader();
  catSelectorLoader.decorate($('.js-retag-btn'));
  askbot['functions'] = askbot['functions'] || {};
  askbot['functions']['initCategoryTree'] = function(){
    var sel_elems = $('.js-category-selector');
    if (sel_elems.length > 0) {
      var selector = new CategorySelector();
      selector.setData(JSON.parse('{{ category_tree_data|escapejs }}'));
      selector.decorate(sel_elems);
      selector.setState('select');

      var tag_editor = new TagEditor();
      tag_editor.decorate($('.tag-editor'));
      {% if question_detail_page == True %}
        {% for tag_name in question.get_tag_names() %}
          tag_editor.addTag('{{ tag_name }}');
        {% endfor %}
      {% endif %}
      selector.setSelectHandler(tag_editor.getAddTagHandler());
      return selector;
    }
  };
  askbot['functions']['initCategoryTree']();
  askbot['urls']['add_tag_category'] = '{{ url('add_tag_category') }}';
  askbot['urls']['rename_tag'] = '{{ url('rename_tag') }}';
  askbot['urls']['delete_tag'] = '{{ url('delete_tag') }}';
  askbot['urls']['cleanTagName'] = '{{ url('clean_tag_name') }}';
</script>
