annotate 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
rev   line source
eads@2 1 Drupal.behaviors.dndLibrary = function(context) {
eads@2 2 var libraries = Drupal.settings.dndEnabledLibraries;
eads@2 3
eads@2 4 // Loop over libraries keyed by the textarea they are associated with
eads@2 5 for (var textarea_id in libraries) {
eads@2 6
eads@2 7 var library = $('#' + textarea_id + '-dnd-library');
eads@2 8
eads@2 9 // Ajax pager: This seems like it is bad to be here
eads@2 10 $('.pager a', library).click(function(e, data) {
eads@2 11 $.getJSON(this.href, function(data) {
eads@2 12 $('.library', library).html('');
eads@2 13 for (item in data.library) {
eads@2 14 $('.library', library).append(data.library[item].library);
eads@2 15 Drupal.settings.dndEditorRepresentations[item] = data.library[item].editor;
eads@2 16 Drupal.behaviors.dndLibrary(context); // Durn event reattachment
eads@2 17 }
eads@2 18 });
eads@2 19 return false;
eads@2 20 });
eads@2 21
eads@2 22 // Bind Drag and Drop plugin invocation to wywsiwygAttach event
eads@2 23 $('#' + textarea_id).bind('wysiwygAttach', function(e, data) {
eads@2 24 var settings = {
eads@2 25 renderRepresentation: function(target, drop, representation_id) {
eads@2 26 console.log(representation_id);
eads@2 27 return Drupal.settings.dndEditorRepresentations[representation_id];
eads@2 28 }
eads@2 29 }
eads@2 30 settings = $.extend(settings, libraries[textarea_id]);
eads@2 31
eads@2 32 // Get editor attachment function
eads@2 33 var editor_fn = 'attach_' + data.editor;
eads@2 34 if ($.isFunction(window.Drupal.behaviors.dndLibrary[editor_fn])) {
eads@2 35 window.Drupal.behaviors.dndLibrary[editor_fn](data, settings);
eads@2 36 }
eads@2 37 });
eads@2 38
eads@2 39 // @TODO track and clear intervals to save memory at the cost of
eads@2 40 // more processing?
eads@2 41 $('#' + textarea_id).bind('wysiwygDetach', function(e, data) {
eads@2 42 console.log('detach');
eads@2 43 });
eads@2 44 }
eads@2 45 }
eads@2 46
eads@2 47 Drupal.behaviors.dndLibrary.attach_tinymce = function(data, settings) {
eads@2 48 var tiny = tinyMCE.getInstanceById(data.field);
eads@2 49 $('#'+ data.field +'-wrapper iframe').load(function() {
eads@2 50 settings = $.extend({
eads@2 51 targets: $('#'+ data.field +'-wrapper iframe'),
eads@2 52 insertAfter: '<p><span id="__caret">_</span></p>',
eads@2 53 postprocessDrop: function() {
eads@2 54 // Get our special span, select it, delete it, and hope the caret
eads@2 55 // resets correctly.
eads@2 56 tiny.selection.select(tiny.dom.get('__caret'));
eads@2 57 tiny.execCommand('Delete', false, null);
eads@2 58 tiny.dom.remove('__caret');
eads@2 59 }
eads@2 60 }, settings);
eads@2 61
eads@2 62 $(settings.drop_selector).dnd(settings);
eads@2 63 });
eads@2 64 }