diff js/dnd-library.js @ 2:5a44c430b7ac

Added dnd_test module, tons and tons of fixes and changes.
author David Eads <eads@chicagotech.org>
date Tue, 17 Feb 2009 15:34:56 -0600
parents cee053085755
children c2eb995212bf
line wrap: on
line diff
--- a/js/dnd-library.js	Mon Feb 16 01:39:54 2009 -0600
+++ b/js/dnd-library.js	Tue Feb 17 15:34:56 2009 -0600
@@ -0,0 +1,64 @@
+Drupal.behaviors.dndLibrary = function(context) {
+  var libraries = Drupal.settings.dndEnabledLibraries;
+
+  // Loop over libraries keyed by the textarea they are associated with
+  for (var textarea_id in libraries) {
+
+    var library = $('#' + textarea_id + '-dnd-library');
+
+    // Ajax pager:  This seems like it is bad to be here
+    $('.pager a', library).click(function(e, data) {
+      $.getJSON(this.href, function(data) {
+        $('.library', library).html('');
+        for (item in data.library) {
+          $('.library', library).append(data.library[item].library);
+          Drupal.settings.dndEditorRepresentations[item] = data.library[item].editor;
+          Drupal.behaviors.dndLibrary(context);  // Durn event reattachment
+        }
+      });
+      return false;
+    });
+
+    // Bind Drag and Drop plugin invocation to wywsiwygAttach event
+    $('#' + textarea_id).bind('wysiwygAttach', function(e, data) {
+      var settings = {
+        renderRepresentation: function(target, drop, representation_id) {
+          console.log(representation_id);
+          return Drupal.settings.dndEditorRepresentations[representation_id];
+        }
+      }
+      settings = $.extend(settings, libraries[textarea_id]);
+
+      // Get editor attachment function
+      var editor_fn = 'attach_' + data.editor;
+      if ($.isFunction(window.Drupal.behaviors.dndLibrary[editor_fn])) {
+        window.Drupal.behaviors.dndLibrary[editor_fn](data, settings); 
+      }
+    });
+
+    // @TODO track and clear intervals to save memory at the cost of 
+    // more processing?
+    $('#' + textarea_id).bind('wysiwygDetach', function(e, data) {
+      console.log('detach');
+    });
+  }
+}
+
+Drupal.behaviors.dndLibrary.attach_tinymce = function(data, settings) {
+  var tiny = tinyMCE.getInstanceById(data.field);
+  $('#'+ data.field +'-wrapper iframe').load(function() {
+    settings = $.extend({
+      targets: $('#'+ data.field +'-wrapper iframe'),
+      insertAfter: '<p><span id="__caret">_</span></p>',
+      postprocessDrop: function() {
+        // Get our special span, select it, delete it, and hope the caret
+        // resets correctly.
+        tiny.selection.select(tiny.dom.get('__caret'));
+        tiny.execCommand('Delete', false, null);
+				tiny.dom.remove('__caret');
+      }
+    }, settings);
+
+    $(settings.drop_selector).dnd(settings);
+  });
+}