{% load compress %}{% load argonauts %}{% load staticfiles %}{% load widgy_tags %}
{% comment %}
Hitting return in a form clicks its first button. Without this dummy
button, the first button in the form would be a widget's delete button.
So instead of submitting the form as expected, <RET> would delete a
widget! The button can't be `display: none` because then it won't be
used.

name=_continue makes 'Save and continue editing' the default behavior in
the admin center.
{% endcomment %}
<input type="submit" name="_continue" style="position: absolute; left: -10000px;">

{% compress css %}
<link type="text/css" rel="stylesheet" href="{% static 'widgy/css/font-awesome.css' %}">
<link type="text/x-scss" rel="stylesheet" href="{% static 'widgy/css/widgy.scss' %}">
<link rel="stylesheet" href="{% static 'widgy/fancybox/jquery.fancybox-1.3.4.css' %}">
{% for scss_file in site.admin_scss_files %}
<link type="text/x-scss" href="{% static scss_file %}" rel="stylesheet">
{% endfor %}
{% endcompress %}
{% if html_name %}
<input type="hidden" name="{{ html_name }}" value="{{ value }}">
{% endif %}
{% block widgy_container %}
<ul class="widgy-tools">
  {% block widgy_tools %}
  {% get_action_links owner node as links %}
  {% for link in links %}
    <li><a class="{{ link.type }}" target="_blank" href="{{ link.url }}">{{ link.text }}</a></li>
  {% endfor %}
  {% endblock %}
</ul>
<div id="{{ html_id }}" class="widgy"></div>
{% endblock %}

<script>
  {# outside of compress js because it changes every request #}
  var require = {
    paths: {
      'jquery': './lib/jquery',
      'underscore': './lib/underscore',
      'backbone': './lib/backbone',
      'text': 'require/text'
    },
    config: {
      text: {
        useXhr: function (url, protocol, hostname, port) {
          // force XHR for all domains, requires CORS for cross-domain
          // https://github.com/requirejs/text#xhr-restrictions
          return true;
        }
      }
    },
    map: {
      // http://requirejs.org/docs/jquery.html#noconflictmap
      '*': { 'jquery': 'jquery-private' },
      'jquery-private': { 'jquery': 'jquery' }
    },
    {% comment %}
    This looks like it might not work on paths with quotes in them, but
    the output of staticfiles.static [static.static DOES NOT, fyi] does
    get escaped. It still doesn't work because you're not supposed to
    use entities inside of raw text elements, but short of our own tag
    just for this purpose there's nothing we can do about it.
    {% endcomment %}
    baseUrl: "{% static 'widgy/js' %}",
    urlArgs: {{ cachebust|json }}
  };
</script>
{% compress js %}
<script src="{% static 'widgy/js/require/require.js' %}"></script>
<script src="{% static 'widgy/js/widgy-main.js' %}"></script>
<script src="{% static 'widgy/fancybox/jquery.fancybox-1.3.4.js' %}"></script>
<script src="{% static 'widgy/js/widgy.admin.js' %}"></script>
{% endcompress %}

<script>
  require([ 'widgy' ], function(Widgy) {
    window.widgy = new Widgy('#' + {{ html_id|json }}, {{ node_dict|json }}, {{ api_url|json }});
  });
</script>
