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