eads@2: Drupal.behaviors.dndLibrary = function(context) { eads@4: $('.dnd-library-wrapper:not(.dnd-processed)', context).each(function() { eads@4: var $this = $(this); eads@2: eads@4: // This is a bad hack to lop off '-dnd-library' from the id to get the editor name eads@4: var editor = this.id.slice(0, -12); eads@2: eads@4: // Attempt to attach library eads@4: //Drupal.behaviors.dndLibrary.attach_library(false, Drupal.wysiwyg.instances[editor]); eads@2: eads@4: // Bind Drag and Drop plugin invocation to wywsiwygAttach event eads@4: $('#' + editor).bind('wysiwygAttach', Drupal.behaviors.dndLibrary.attach_library); eads@4: eads@4: // @TODO track and clear intervals to save memory at the cost of eads@4: // more processing? eads@4: $('#' + editor).bind('wysiwygDetach', Drupal.behaviors.dndLibrary.detach_library); eads@4: eads@4: // Ajax pager eads@4: $('.pager a', $this).click(function(e, data) { eads@2: $.getJSON(this.href, function(data) { eads@4: $('.header', $this).html(data.header); eads@4: $('.library', $this).html(data.library); eads@4: //$('.footer', $this).html(data.footer); eads@4: for (editor_id in data.editor_representations) { eads@4: Drupal.settings.dndEditorRepresentations[editor_id] = data.editor_representations[editor_id]; eads@2: } eads@4: var params = Drupal.wysiwyg.instances[editor]; eads@4: $('#' + editor).trigger('wysiwygAttach', params); eads@2: }); eads@2: return false; eads@2: }); eads@2: eads@4: $this.addClass('dnd-processed'); eads@4: }); eads@4: } eads@2: eads@4: Drupal.behaviors.dndLibrary.attach_library = function(e, data) { eads@4: var settings = { eads@4: renderRepresentation: function(target, drop, representation_id) { eads@4: return Drupal.settings.dndEditorRepresentations[representation_id]; eads@4: } eads@4: } eads@4: settings = $.extend(settings, Drupal.settings.dndEnabledLibraries[data.field]); eads@2: eads@4: var editor_fn = 'attach_' + data.editor; eads@4: if ($.isFunction(window.Drupal.behaviors.dndLibrary[editor_fn])) { eads@4: window.Drupal.behaviors.dndLibrary[editor_fn](data, settings); eads@2: } eads@2: } eads@2: eads@4: Drupal.behaviors.dndLibrary.detach_library = function(e, data) { eads@11: //console.log('detach'); eads@4: } eads@4: eads@4: eads@2: Drupal.behaviors.dndLibrary.attach_tinymce = function(data, settings) { eads@4: eads@4: var tiny_instance = tinyMCE.getInstanceById(data.field); eads@4: eads@4: // If the Tiny instance exists, attach directly, otherwise wait until Tiny eads@4: // has registered a new instance. eads@4: if (tiny_instance) { eads@4: Drupal.behaviors.dndLibrary._attach_tinymce(data, settings, tiny_instance); eads@4: } else { eads@4: var t = setInterval(function() { eads@4: var tiny_instance = tinyMCE.getInstanceById(data.field); eads@4: if (tiny_instance) { eads@4: Drupal.behaviors.dndLibrary._attach_tinymce(data, settings, tiny_instance); eads@4: clearInterval(t); eads@2: } eads@4: }, 100); eads@4: } eads@4: } eads@2: eads@4: Drupal.behaviors.dndLibrary._attach_tinymce = function(data, settings, tiny_instance) { eads@4: settings = $.extend({ eads@4: targets: $('#'+ data.field +'-wrapper iframe'), eads@4: insertAfter: '

_

', eads@4: postprocessDrop: function(target, drop, element) { eads@4: // Get our special span, select it, delete it, and hope the caret eads@4: // resets correctly. eads@4: tiny_instance.selection.select(tiny_instance.dom.get('__caret')); eads@4: tiny_instance.execCommand('Delete', false, null); eads@4: tiny_instance.dom.remove('__caret'); eads@4: eads@4: // Add some classes to the library items eads@4: $(element).addClass('dnd-inserted'); eads@4: $(element).parents('.editor-item').addClass('dnd-child-inserted'); eads@4: } eads@4: }, settings); eads@4: eads@4: $(settings.drop_selector).dnd(settings); eads@2: }