annotate js/dnd-library.js @ 11:99ba5941779c

JS Linted.
author David Eads <eads@chicagotech.org>
date Fri, 27 Feb 2009 00:49:22 -0600
parents c2eb995212bf
children 7a5f74482ee3
rev   line source
eads@2 1 Drupal.behaviors.dndLibrary = function(context) {
eads@4 2 $('.dnd-library-wrapper:not(.dnd-processed)', context).each(function() {
eads@4 3 var $this = $(this);
eads@2 4
eads@4 5 // This is a bad hack to lop off '-dnd-library' from the id to get the editor name
eads@4 6 var editor = this.id.slice(0, -12);
eads@2 7
eads@4 8 // Attempt to attach library
eads@4 9 //Drupal.behaviors.dndLibrary.attach_library(false, Drupal.wysiwyg.instances[editor]);
eads@2 10
eads@4 11 // Bind Drag and Drop plugin invocation to wywsiwygAttach event
eads@4 12 $('#' + editor).bind('wysiwygAttach', Drupal.behaviors.dndLibrary.attach_library);
eads@4 13
eads@4 14 // @TODO track and clear intervals to save memory at the cost of
eads@4 15 // more processing?
eads@4 16 $('#' + editor).bind('wysiwygDetach', Drupal.behaviors.dndLibrary.detach_library);
eads@4 17
eads@4 18 // Ajax pager
eads@4 19 $('.pager a', $this).click(function(e, data) {
eads@2 20 $.getJSON(this.href, function(data) {
eads@4 21 $('.header', $this).html(data.header);
eads@4 22 $('.library', $this).html(data.library);
eads@4 23 //$('.footer', $this).html(data.footer);
eads@4 24 for (editor_id in data.editor_representations) {
eads@4 25 Drupal.settings.dndEditorRepresentations[editor_id] = data.editor_representations[editor_id];
eads@2 26 }
eads@4 27 var params = Drupal.wysiwyg.instances[editor];
eads@4 28 $('#' + editor).trigger('wysiwygAttach', params);
eads@2 29 });
eads@2 30 return false;
eads@2 31 });
eads@2 32
eads@4 33 $this.addClass('dnd-processed');
eads@4 34 });
eads@4 35 }
eads@2 36
eads@4 37 Drupal.behaviors.dndLibrary.attach_library = function(e, data) {
eads@4 38 var settings = {
eads@4 39 renderRepresentation: function(target, drop, representation_id) {
eads@4 40 return Drupal.settings.dndEditorRepresentations[representation_id];
eads@4 41 }
eads@4 42 }
eads@4 43 settings = $.extend(settings, Drupal.settings.dndEnabledLibraries[data.field]);
eads@2 44
eads@4 45 var editor_fn = 'attach_' + data.editor;
eads@4 46 if ($.isFunction(window.Drupal.behaviors.dndLibrary[editor_fn])) {
eads@4 47 window.Drupal.behaviors.dndLibrary[editor_fn](data, settings);
eads@2 48 }
eads@2 49 }
eads@2 50
eads@4 51 Drupal.behaviors.dndLibrary.detach_library = function(e, data) {
eads@11 52 //console.log('detach');
eads@4 53 }
eads@4 54
eads@4 55
eads@2 56 Drupal.behaviors.dndLibrary.attach_tinymce = function(data, settings) {
eads@4 57
eads@4 58 var tiny_instance = tinyMCE.getInstanceById(data.field);
eads@4 59
eads@4 60 // If the Tiny instance exists, attach directly, otherwise wait until Tiny
eads@4 61 // has registered a new instance.
eads@4 62 if (tiny_instance) {
eads@4 63 Drupal.behaviors.dndLibrary._attach_tinymce(data, settings, tiny_instance);
eads@4 64 } else {
eads@4 65 var t = setInterval(function() {
eads@4 66 var tiny_instance = tinyMCE.getInstanceById(data.field);
eads@4 67 if (tiny_instance) {
eads@4 68 Drupal.behaviors.dndLibrary._attach_tinymce(data, settings, tiny_instance);
eads@4 69 clearInterval(t);
eads@2 70 }
eads@4 71 }, 100);
eads@4 72 }
eads@4 73 }
eads@2 74
eads@4 75 Drupal.behaviors.dndLibrary._attach_tinymce = function(data, settings, tiny_instance) {
eads@4 76 settings = $.extend({
eads@4 77 targets: $('#'+ data.field +'-wrapper iframe'),
eads@4 78 insertAfter: '<p><span id="__caret">_</span></p>',
eads@4 79 postprocessDrop: function(target, drop, element) {
eads@4 80 // Get our special span, select it, delete it, and hope the caret
eads@4 81 // resets correctly.
eads@4 82 tiny_instance.selection.select(tiny_instance.dom.get('__caret'));
eads@4 83 tiny_instance.execCommand('Delete', false, null);
eads@4 84 tiny_instance.dom.remove('__caret');
eads@4 85
eads@4 86 // Add some classes to the library items
eads@4 87 $(element).addClass('dnd-inserted');
eads@4 88 $(element).parents('.editor-item').addClass('dnd-child-inserted');
eads@4 89 }
eads@4 90 }, settings);
eads@4 91
eads@4 92 $(settings.drop_selector).dnd(settings);
eads@2 93 }