{% load i18n %}
{% comment %}
    This is hosted using the Yahoo CDN. You can override this if you prefer to host locally.

    To include other parts of YUI, visit the configurator here:

    http://developer.yahoo.com/yui/articles/hosting/?editor&MIN
{% endcomment %}


{% comment %}
    TODO: YUI values should be superseded by DJANGO_WYSWYG_MEDIA_URL - should we just hardcode the name combo.js / combo.css or do something more configurable?
{% endcomment %}

<!-- Combo-handled YUI CSS files: -->
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?2.8.2r1/build/assets/skins/sam/skin.css">
<!-- Combo-handled YUI JS files: -->
<script type="text/javascript" src="http://yui.yahooapis.com/combo?2.8.2r1/build/yahoo-dom-event/yahoo-dom-event.js&2.8.2r1/build/container/container_core-min.js&2.8.2r1/build/menu/menu-min.js&2.8.2r1/build/element/element-min.js&2.8.2r1/build/button/button-min.js&2.8.2r1/build/editor/editor-min.js"></script>

<script type="text/javascript" charset="utf-8">
    "use strict";

    // This is required for Yahoo's skins:
    if( window.YAHOO ) {
        YAHOO.util.Event.onDOMReady(function() { YAHOO.util.Dom.addClass(document.body, 'yui-skin-sam'); });
    }


    /*
        This config is used for our standard rich editor on the site and in the
        Django admin area if you've modified the change_form.html to enable
        rich editing.

        See Yahoo's documentation for customization options:

        http://developer.yahoo.com/yui/editor/
    */

    var django_wysiwyg_editor_configs = [];   // allow custom settings per editor ID{% block django_wysiwyg_editor_config %}
    var django_wysiwyg_editor_config = {
        height: "400px",
        width: "624px",
        animate: true,
        autoHeight: true,
        // BUG: handleSubmit breaks contrib.admin's save-and-continue-editing feature - we can avoid by listening for blur events
        // This will cause the rich editor to update the original textarea's value when the containing form submit event fires
        handleSubmit: true,
        focusAtStart: false,
        toolbar: {
            //collapse: true,
            //titlebar: 'Body',
            draggable: false,
            buttons: [
            {
                group: 'fontstyle',
                label: '{% trans "Font Name and Size" %}',
                buttons: [
                    { type: 'select', label: 'Arial', value: 'fontname', disabled: true,
                      menu: [
                        { text: 'Arial', checked: true },
                        { text: 'Arial Black' },
                        { text: 'Comic Sans MS' },
                        { text: 'Courier New' },
                        { text: 'Georgia' },
                        { text: 'Impact' },
                        { text: 'Lucida Console' },
                        { text: 'Tahoma' },
                        { text: 'Times New Roman' },
                        { text: 'Trebuchet MS' },
                        { text: 'Verdana' }
                      ]
                    },
                    { type: 'spin', label: '13', value: 'fontsize', range: [9, 75], disabled: true }
                ]
            },
            {
                type: 'separator'
            },
            {
                group: 'textstyle',
                label: '{% trans "Font Style" %}',
                buttons: [
                    { type: 'push', label: '{% trans "Bold CTRL + SHIFT + B" %}', value: 'bold' },
                    { type: 'push', label: '{% trans "Italic CTRL + SHIFT + I" %}', value: 'italic' },
                    { type: 'push', label: '{% trans "Underline CTRL + SHIFT + U" %}', value: 'underline' },
                    { type: 'separator' },
                    { type: 'color', label: '{% trans "Font Color" %}', value: 'forecolor', disabled: true },
                    { type: 'color', label: '{% trans "Background Color" %}', value: 'backcolor', disabled: true }
                ]
            },
            {
                type: 'separator'
            },
            {
                group: 'indentlist',
                label: '{% trans "Lists" %}',
                buttons: [
                    { type: 'push', label: '{% trans "Create an Unordered List" %}', value: 'insertunorderedlist' },
                    { type: 'push', label: '{% trans "Create an Ordered List" %}', value: 'insertorderedlist' }
                ]
            },
            {
                type: 'separator'
            },
            {
                group: 'insertitem',
                label: '{% trans "Insert Item" %}',
                buttons: [
                    { type: 'push', label: '{% trans "HTML Link CTRL + SHIFT + L" %}', value: 'createlink', disabled: true },
                    { type: 'push', label: '{% trans "Insert Image" %}', value: 'insertimage' }
                ]
            }
            ]
        }
    };
{% endblock %}
    function django_wysiwyg_enable(editor_name, field_id, config)
    {
        if(!config) {
            config = django_wysiwyg_editor_configs[field_id] || django_wysiwyg_editor_config;
        }
        window[editor_name] = new YAHOO.widget.Editor(field_id, config);
        window[editor_name].render();
    }

    function django_wysiwyg_disable(editor_name)
    {
        var editor = window[editor_name];
        if(editor)
        {
            editor.saveHTML();
            editor.destroy();
            window[editor_name] = null;
        }
    }

    function django_wysiwyg_is_loaded()
    {
      return window.YAHOO != null
          && window.YAHOO.widget != null
          && window.YAHOO.widget.Editor != null;
    }
</script>
