eads@2: Drupal.behaviors.dndLibrary = function(context) { eads@2: var libraries = Drupal.settings.dndEnabledLibraries; eads@2: eads@2: // Loop over libraries keyed by the textarea they are associated with eads@2: for (var textarea_id in libraries) { eads@2: eads@2: var library = $('#' + textarea_id + '-dnd-library'); eads@2: eads@2: // Ajax pager: This seems like it is bad to be here eads@2: $('.pager a', library).click(function(e, data) { eads@2: $.getJSON(this.href, function(data) { eads@2: $('.library', library).html(''); eads@2: for (item in data.library) { eads@2: $('.library', library).append(data.library[item].library); eads@2: Drupal.settings.dndEditorRepresentations[item] = data.library[item].editor; eads@2: Drupal.behaviors.dndLibrary(context); // Durn event reattachment eads@2: } eads@2: }); eads@2: return false; eads@2: }); eads@2: eads@2: // Bind Drag and Drop plugin invocation to wywsiwygAttach event eads@2: $('#' + textarea_id).bind('wysiwygAttach', function(e, data) { eads@2: var settings = { eads@2: renderRepresentation: function(target, drop, representation_id) { eads@2: console.log(representation_id); eads@2: return Drupal.settings.dndEditorRepresentations[representation_id]; eads@2: } eads@2: } eads@2: settings = $.extend(settings, libraries[textarea_id]); eads@2: eads@2: // Get editor attachment function eads@2: var editor_fn = 'attach_' + data.editor; eads@2: if ($.isFunction(window.Drupal.behaviors.dndLibrary[editor_fn])) { eads@2: window.Drupal.behaviors.dndLibrary[editor_fn](data, settings); eads@2: } eads@2: }); eads@2: eads@2: // @TODO track and clear intervals to save memory at the cost of eads@2: // more processing? eads@2: $('#' + textarea_id).bind('wysiwygDetach', function(e, data) { eads@2: console.log('detach'); eads@2: }); eads@2: } eads@2: } eads@2: eads@2: Drupal.behaviors.dndLibrary.attach_tinymce = function(data, settings) { eads@2: var tiny = tinyMCE.getInstanceById(data.field); eads@2: $('#'+ data.field +'-wrapper iframe').load(function() { eads@2: settings = $.extend({ eads@2: targets: $('#'+ data.field +'-wrapper iframe'), eads@2: insertAfter: '

_

', eads@2: postprocessDrop: function() { eads@2: // Get our special span, select it, delete it, and hope the caret eads@2: // resets correctly. eads@2: tiny.selection.select(tiny.dom.get('__caret')); eads@2: tiny.execCommand('Delete', false, null); eads@2: tiny.dom.remove('__caret'); eads@2: } eads@2: }, settings); eads@2: eads@2: $(settings.drop_selector).dnd(settings); eads@2: }); eads@2: }