view mee.js @ 12:da5d54d099b1

Fix the drag'n'drop, add a caption to the ressource manager. tableDrag makeDraggable method expect a standard DOM object, not the jQuery wrapper.
author Franck Deroche <franck@defr.org>
date Fri, 05 Jun 2009 09:56:08 +0200
parents 272628486e75
children 50a57b1517cb
line wrap: on
line source
Drupal.behaviors.mee = function(context) {
  $("div.mee-wrap-editor-library:not(.mee-processed)")
    .addClass('mee-processed')
    .find('> div.dnd-library-wrapper')
    .each(function() {
      var $editor = $('#' + this.id.slice(0, -12)); 
      $editor.bind('wysiwygAttach', Drupal.mee.attach);
      $editor.bind('wysiwygDetach', Drupal.mee.detach);
    })
    .end()
}

Drupal.mee = {
  attach: function(e, data) {
    var t = setInterval(function() {
      var tiny_instance = tinyMCE.getInstanceById(data.field);
      if (tiny_instance) {
        clearInterval(t);
        $(tiny_instance.editor_id)
          .find('iframe')
          .unbind('dnd_drop')
          .bind('dnd_drop', function(e, data) {
            var rep = Drupal.settings.dndEditorRepresentations[data.representation_id];
            $(this)
              .parents('div.mee-wrap-editor-library.mee-processed')
              .find('table.mee-ressource-manager')
              .each(function(i) {
                $(this).append(Drupal.mee.generate(
                  rep.title,
                  Drupal.tableDrag[this.id]
                ));
              });
          });
      }
    }, 100);
  },
  detach: function(e, data) {

  },
  generate: function(title, tableDrag) {
    var $select = $("<select />"), $tr = $('<tr />'), $td = $("<td />"), parity;
    $tr
      .addClass('draggable')
      .append($('<td></td>'))
      .append($('<td></td>').append(title));
    for (var i = -10; i <= 10; i++) {
      $select.append("<option>"+ i +"</option>");
    }
    $select.val(0).addClass('mee-rm-weight');
    $td.append($select);
    $tr.append($td);
    parity = $(tableDrag.table).find('tr').size() % 2 ? 'odd' : 'even';
    $tr.addClass(parity);
    tableDrag.makeDraggable($tr.get(0));
    return $tr;
  }
}