{% extends "wiki/base.html" %}
{% load wiki_tags i18n sekizai_tags %}

{% block pagetitle %}{% trans "Add new article" %}{% endblock %}

{% block wiki_contents %}

  {% addtoblock "js" %}
  <script type="text/javascript" src="{{ STATIC_URL }}admin/js/urlify.js "></script>
  <script type="text/javascript">
  // Replacement of django's URLify that doesn't remove any words.
  function URLify(s, num_chars) {
      s = downcode(s);
      removelist = [];
      r = new RegExp('\\b(' + removelist.join('|') + ')\\b', 'gi');
      s = s.replace(r, '');
      // if downcode doesn't hit, the char will be stripped here
      s = s.replace(/[^-\w\s]/g, '');  // remove unneeded chars
      s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces
      s = s.replace(/[-\s]+/g, '-');   // convert spaces to hyphens
      s = s.toLowerCase();             // convert to lowercase
      return s.substring(0, num_chars);// trim to first num_chars chars
  }
  //<![CDATA[	
  (function($) {
	  $(document).ready(function (){
		  $("#id_title").keyup(function () {
			  var e = $("#id_slug")[0];
			  if(!e._changed) {
			    slug = URLify(this.value, 64);
			    wikislug = slug.replace(/\-/g, " ");
			    wikislug = wikislug.replace(/\w\S*/gi, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1);});
          wikislug = wikislug.replace(/\s*/g, "");
				  e.value = wikislug;
			  }
	      });
	  });
  })(jQuery);
  //]]>
  </script>
  {% endaddtoblock %}

  {% include "wiki/includes/editormedia.html" %}
  <h1 class="page-header">{% trans "Add new article" %}</h1>
  
  <form method="POST" class="form-horizontal">
    {% wiki_form create_form %}
    <div class="form-actions">
        <a href="{% url 'wiki:get' path=parent_urlpath.path %}" class="btn btn-large">
          <span class="icon-circle-arrow-left"></span>
          {% trans "Go back" %}
        </a>
        <button type="submit" name="save_changes" class="btn btn-primary btn-large">
          <span class="icon-plus"></span>
          {% trans "Create article" %}
        </button>
    </div>  
  </form>

{% endblock %}

