/* Instantiate the {{ widget_name }} class. */
/* The IDs given should match those used in the template above. */
var widget_ids = new Array({{ Nwidget }});

{% for dim in dimensions %}
widget_ids[{{ loop.index0 }}] = "_anim_widget{{ id }}_{{ dim }}";
{% endfor %}

function create_widget() {
  var frame_data = {{ frames | safe }};
  var dim_vals = {{ init_dim_vals }};
  var keyMap = {{ key_data }};
  var notFound = "{{ notFound }}";

  var anim = new HoloViews.{{ widget_name }}(frame_data, "{{ id }}", widget_ids,
  keyMap, dim_vals, notFound, {{ load_json }}, "{{ mode }}",
  {{ cached }}, "{{ json_path}}", {{ dynamic }}, "{{ plot_id }}");

  HoloViews.index['{{ plot_id }}'] = anim;
}

{% for widget_data in widgets %}

{% if widget_data['type'] == 'slider' %}
HoloViews.init_slider('{{ id }}', '{{ plot_id }}', '{{ widget_data['dim'] }}', {{ widget_data['vals'] }}, {{ widget_data['next_vals'] }}, {{ widget_data['labels'] }}, {{ dynamic }}, {{ widget_data['step'] }}, {{ widget_data['default'] }}, '{{ widget_data['next_dim'] }}', {{ widget_data['dim_idx'] }}, {{ delay }}, '{{ CDN['jQueryUI'] }}', '{{ CDN['underscore'] }}')
{% elif widget_data['type']=='dropdown' %}
HoloViews.init_dropdown('{{ id }}', '{{ plot_id }}', '{{ widget_data['dim'] }}', {{ widget_data['vals'] }}, {{ widget_data['default'] }}, {{ widget_data['next_vals'] }}, {{ widget_data['labels'] }}, '{{ widget_data['next_dim'] }}', {{ widget_data['dim_idx'] }}, {{ dynamic }})
{% endif %}

{% endfor %}

create_widget();
{{ init_js }}
