diff js/dnd-library.js @ 24:4f58fa0a9a6d

Cleaned up some library behavior, changed editor representation cache to track a title and a body for representations, to allow a little more dynamic composition.
author David Eads <eads@chicagotech.org>
date Wed, 11 Mar 2009 01:47:57 -0500
parents 69db20fdbac2
children e71df38143d1
line wrap: on
line diff
--- a/js/dnd-library.js	Tue Mar 10 13:55:27 2009 -0500
+++ b/js/dnd-library.js	Wed Mar 11 01:47:57 2009 -0500
@@ -32,13 +32,8 @@
     // This is a bad hack to lop off '-dnd-library' from the id to get the editor name
     var $editor = $('#' + this.id.slice(0, -12)); 
 
-    // Bind Drag and Drop plugin invocation to events emanating from Wysiwyg
-    $editor.bind('wysiwygAttach', Drupal.behaviors.dndLibrary.attach_library);
-    $editor.bind('wysiwygDetach', Drupal.behaviors.dndLibrary.detach_library);
-
-    // Add preview behavior to editor items (thanks, BeautyTips!)
-    $('.editor-item', context).each(function () {
-      $(this).bt(Drupal.settings.dndLibraryPreviews[this.id], {
+    var settings = Drupal.settings.dndEnabledLibraries[$editor.get(0).id];
+    var bt_settings = $.extend({
         'trigger': 'none',
         'width': 375,
         'spikeLength': 7,
@@ -47,8 +42,16 @@
         'strokeWidth': 1,
         'fill': '#ffd',
         'strokeStyle': '#555'
-      });
-      $(this).hoverIntent({
+    }, settings.bt_settings); 
+
+    // Bind Drag and Drop plugin invocation to events emanating from Wysiwyg
+    $editor.bind('wysiwygAttach', Drupal.behaviors.dndLibrary.attach_library);
+    $editor.bind('wysiwygDetach', Drupal.behaviors.dndLibrary.detach_library);
+
+    // Add preview behavior to editor items (thanks, BeautyTips!)
+    $('.editor-item', context).each(function () {
+      $(this).bt(Drupal.settings.dndLibraryPreviews[this.id], bt_settings);
+      var hover_opts = $.extend({
         'interval': 500,
         'timeout' : 0,
         'over': function() {
@@ -63,7 +66,8 @@
           });
         }, 
         'out': function() { this.btOff(); }
-      });
+      }, settings.libraryHoverIntentOpts);
+      $(this).hoverIntent(hover_opts);
     });
 
     // Simple AJAX pager
@@ -91,7 +95,7 @@
     var cached = $.data($editor, 'dnd_preload') || {};
     for (editor_id in Drupal.settings.dndEditorRepresentations) {
       if (!cached[editor_id]) {
-        $representation = $(Drupal.settings.dndEditorRepresentations[editor_id]);
+        $representation = $(Drupal.settings.dndEditorRepresentations[editor_id].body);
         if ($representation.is('img') && $representation.get(0).src) { 
           $representation.attr('src', $representation.get(0).src);
         } else {
@@ -150,7 +154,7 @@
   settings = $.extend({
     targets: $('#'+ data.field),
     processTextAreaClick: function(target, clicked, representation_id, e, data) {
-      var snippet = '<p class="dnd-dropped-wrapper">' + Drupal.settings.dndEditorRepresentations[representation_id] + '</p>';
+      var snippet = '<p class="dnd-dropped-wrapper">' + Drupal.settings.dndEditorRepresentations[representation_id].body + '</p>';
       $(target).replaceSelection(snippet, true);
     }
   }, settings);
@@ -170,6 +174,7 @@
       var tiny_instance = tinyMCE.getInstanceById(data.field);
       if (tiny_instance) {
         Drupal.behaviors.dndLibrary._attach_tinymce(data, settings, tiny_instance);
+        $('#'+ data.field +'-wrapper').trigger('dnd_attach_library');
         clearInterval(t);
       }
     }, 100);
@@ -191,9 +196,21 @@
     targets: $('#'+ data.field +'-wrapper iframe'),
     processIframeDrop: function(drop, id_selector) {
       var representation_id = id_selector.call(this, drop);
-      var representation = Drupal.settings.dndEditorRepresentations[representation_id];
+      var representation = Drupal.settings.dndEditorRepresentations[representation_id].body;
       var target = this, $target = $(target), $drop = $(drop), block;
 
+      // Keep a counter
+      var counter = $target.data('representation_counter');      
+      if (!counter) {
+        counter = {}
+        counter[representation_id] = 1;
+      } else if (counter && !counter[representation_id]) {
+        counter[representation_id] = 1;
+      } else {
+        counter[representation_id] = counter[representation_id] + 1;
+      }
+      $target.data('representation_counter', counter);
+
       // Search through block level parents
       $drop.parents().each(function() {
         var $this = $(this);