{% load url from future %}
{% block aloha %}
 {% if perms.editor.edit_site %}
  <link href="{{ STATIC_URL }}editor/style.css" rel="stylesheet">
  <script type="text/javascript">
    Aloha = {}; Aloha.settings = {};
    Aloha.settings.baseUrl = '{{ STATIC_URL }}aloha/lib/';
    Aloha.settings.locale = 'fr';
    Aloha.settings.sidebar = {
      tabs: {
          attributes : [ 'attributepanel'],
          comments: [ 'comments' ]
      }
    }
    Aloha.settings.plugins = {
      format: {
                // all elements with no specific configuration get this configuration
      config: [  'b', 'i', 'p', 'sub', 'sup', 'del', 'title', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'pre', 'removeFormat' ],
              editables: {
                // no formatting allowed for title
                '#top-text': []
              },
              removeFormats: [ 'strong', 'em', 'b', 'i', 's', 'cite', 'q', 'code', 'abbr', 'del', 'sub', 'sup', 'span'],
              },
      list: {
              // all elements with no specific configuration get an UL, just for fun :)
      config: [ 'ul', 'ol' ],
              editables: {
                // Even if this is configured it is not set because OL and UL are not allowed in H1.
                '#top-text': []
              }
            },
      listenforcer: {
      editables: [ '.aloha-enforce-lists' ]
                    },
      abbr: {
              // all elements with no specific configuration get an UL, just for fun :)
      config: [ 'abbr' ],
              editables: {
                // Even if this is configured it is not set because OL and UL are not allowed in H1.
                '#top-text': []
              }
            },
      link: {
              // all elements with no specific configuration may insert links
      config: [ 'a' ],
              editables: {
                // No links in the title.
                '#top-text': []
              },
              // all links that match the targetregex will get set the target
              // e.g. ^(?!.*aloha-editor.com).* matches all href except aloha-editor.com
      targetregex: '^(?!.*aloha-editor.com).*',
                   // this target is set when either targetregex matches or not set
                   // e.g. _blank opens all links in new window
                   target: '_blank',
                   // the same for css class as for target
                   cssclassregex: '^(?!.*aloha-editor.com).*',
                   cssclass: 'aloha',
                   // use all resources of type website for autosuggest
                   objectTypeFilter: ['website'],
                   // handle change of href
                   onHrefChange: function ( obj, href, item ) {
                     var jQuery = Aloha.require( 'aloha/jquery' );
                     if ( item ) {
                       jQuery( obj ).attr( 'data-name', item.name );
                     } else {
                       jQuery( obj ).removeAttr( 'data-name' );
                     }
                   }
            },
      table: {
               // all elements with no specific configuration are not allowed to insert tables
      config: [ 'table' ],
              editables: {
                // Don't allow tables in top-text
                '#top-text': [ '' ]
              },
      summaryinsidebar: true,
                        // [{name:'green', text:'Green', tooltip:'Green is cool', iconClass:'GENTICS_table GENTICS_button_green', cssClass:'green'}]
                        tableConfig: [
                        { name: 'hor-minimalist-a' },
                        { name: 'box-table-a' },
                        { name: 'hor-zebra' },
                        ],
                        columnConfig: [
                        { name: 'table-style-bigbold',  iconClass: 'aloha-button-col-bigbold' },
                        { name: 'table-style-redwhite', iconClass: 'aloha-button-col-redwhite' }
              ],
                rowConfig: [
                { name: 'table-style-bigbold',  iconClass: 'aloha-button-row-bigbold' },
                { name: 'table-style-redwhite', iconClass: 'aloha-button-row-redwhite' }
              ]
             },
      image: {
      config:{
               'fixedAspectRatio' : false,
               'maxWidth'         : 600,
               'minWidth'         : 20,
               'maxHeight'        : 600,
               'minHeight'        : 20,
               'globalselector'   : '.global',
               'ui': {
                 'oneTab': true
               }
             },
             'fixedAspectRatio' : false,
             'maxWidth'         : 600,
             'minWidth'         : 20,
             'maxHeight'        : 600,
             'minHeight'        : 20,
             'globalselector'   : '.global',
             'ui': {
               'oneTab' : true,
               'align'  : false,
               'margin' : false
             }
             },
      cite: {
      referenceContainer: '#references'
            },
      formatlesspaste :{
      formatlessPasteOption : true,
                              strippedElements : [
                                "em",
                              "strong",
                              "small",
                              "s",
                              "cite",
                              "q",
                              "dfn",
                              "abbr",
                              "time",
                              "code",
                              "var",
                              "samp",
                              "kbd",
                              "sub",
                              "sup",
                              "i",
                              "b",
                              "u",
                              "mark",
                              "ruby",
                              "rt",
                              "rp",
                              "bdi",
                              "bdo",
                              "ins",
                              "del"]
                       }
              ,
                'numerated-headers': {
      numeratedactive: false
                }
      }
  </script>

  <script type="text/javascript" src="{{ STATIC_URL }}aloha/lib/aloha.js" data-aloha-plugins="common/format,
    common/table,
    common/highlighteditables,
    common/link,
    common/image,
    common/list,
    common/undo,
    common/paste,
    extra/attributes,
    extra/sourceview,
    common/characterpicker,
    common/commands,
    common/contenthandler,
    external/colorselector"></script>
  <script type="text/javascript">
    function editor_activate() {
          Aloha.jQuery('#editor-switch').html("Désactiver l'éditeur");
          Aloha.jQuery('.aloha-editable').aloha();
          Aloha.jQuery('.aloha-editable').css('display','inherit');
          Aloha.bind('aloha-editable-deactivated', function(event, myeditable){
            var $ = Aloha.jQuery;
            var container = $(myeditable.editable.obj[0]);
            var html = container.html();
            var name = container.data('name');
            var url = container.data('url');
            var data = {'name': name, 'content': html };
            if (url) {
                data['url'] = url;
            }
            $.ajax({
              type: 'PUT',
              url: '{% url "editor-handler" %}',
              data: JSON.stringify(data),
              mimeType: "application/j-son;charset=UTF-8",
            });
          });
    }
    Aloha.ready(function () {
        if ($.cookie('editor_activated') == '1') {
          editor_activate();
        }
    })
  </script>
  <link rel="stylesheet" href="{{ STATIC_URL }}aloha/css/aloha.css"/>
 {% endif %}
{% endblock %}
