# HG changeset patch # User David Eads # Date 1236057757 21600 # Node ID 7a5f74482ee3a70e6453abc092e692604a87a817 # Parent ef7ad7b5baa41a7df508700c9badfd520727b3c2 More cross browser work, garbage collection for timers, etc. diff -r ef7ad7b5baa4 -r 7a5f74482ee3 dnd_test/dnd-editor-item.tpl.php --- a/dnd_test/dnd-editor-item.tpl.php Fri Feb 27 12:30:42 2009 -0600 +++ b/dnd_test/dnd-editor-item.tpl.php Mon Mar 02 23:22:37 2009 -0600 @@ -1,3 +1,1 @@ - - - + diff -r ef7ad7b5baa4 -r 7a5f74482ee3 dnd_test/dnd_test.module --- a/dnd_test/dnd_test.module Fri Feb 27 12:30:42 2009 -0600 +++ b/dnd_test/dnd_test.module Mon Mar 02 23:22:37 2009 -0600 @@ -117,7 +117,6 @@ $img = 1; } - //$variables['image'] = theme('image', drupal_get_path('module', 'dnd_test') .'/img/item-'. $img .'-thumb.jpg'); $variables['image'] = ''; $variables['title'] = t('Lorem Ipsum @count', array('@count' => $i)); $variables['date'] = 'Feb 18 2009'; @@ -141,5 +140,5 @@ else { $img = 1; } - $variables['image'] = theme('image', drupal_get_path('module', 'dnd_test') .'/img/item-'. $img .'-'. $size .'.jpg'); + $variables['image'] = theme('image', drupal_get_path('module', 'dnd_test') .'/img/item-'. $img .'-'. $size .'.jpg', 'foo', 'foo', array('class' => 'dnd-dropped')); } diff -r ef7ad7b5baa4 -r 7a5f74482ee3 js/dnd-library.js --- a/js/dnd-library.js Fri Feb 27 12:30:42 2009 -0600 +++ b/js/dnd-library.js Mon Mar 02 23:22:37 2009 -0600 @@ -25,6 +25,7 @@ Drupal.settings.dndEditorRepresentations[editor_id] = data.editor_representations[editor_id]; } var params = Drupal.wysiwyg.instances[editor]; + $('#' + editor).trigger('wysiwygDetach', params); $('#' + editor).trigger('wysiwygAttach', params); }); return false; @@ -49,7 +50,10 @@ } Drupal.behaviors.dndLibrary.detach_library = function(e, data) { - //console.log('detach'); + for (t in $(document).data('dnd_timers')) { + clearInterval(t); + } + $(document).removeData('dnd_timers'); } @@ -76,6 +80,13 @@ settings = $.extend({ targets: $('#'+ data.field +'-wrapper iframe'), insertAfter: '

_

', + + // Back out markup to render in place after parent container + preprocessDrop: function(target, drop) { + drop.id = 'DND-TMP-' + $.data(drop); + // Do some native tiny manipulations + return drop; + }, postprocessDrop: function(target, drop, element) { // Get our special span, select it, delete it, and hope the caret // resets correctly. diff -r ef7ad7b5baa4 -r 7a5f74482ee3 js/dnd.js --- a/js/dnd.js Fri Feb 27 12:30:42 2009 -0600 +++ b/js/dnd.js Mon Mar 02 23:22:37 2009 -0600 @@ -31,7 +31,7 @@ * the best experience. * * idSelector: - * A callback that parses a unique id out of a droppable element. B y default + * A callback that parses a unique id out of a droppable element. By default * this uses the id of the element, but one could parse out an ID based on * any part of the URL, interior markup, etc. * @@ -79,16 +79,15 @@ (function($) { $.fn.dnd = function(opt) { opt = $.extend({}, { - dropWrapper: '

', + interval: 250, + dropWrapper: '

', insertBefore: false, insertAfter: false, processedClass: 'dnd-processed', - interval: 100, - + ignoreClass: 'dnd-dropped', processTargets: function(targets) { return targets.each(function() { - //$('head', $(this).contents()).append(''); - //@TODO use jQuery.rules() + $('head', $(this).contents()).append(''); return this; }); }, @@ -117,24 +116,7 @@ return '' + representation_id + ''; }, - // Back out markup to render in place after parent container - preprocessDrop: function(target, drop) { - return drop; - var old_parent = false; - var element_id = ''; - - var parents = drop.parents(); - for (var i=0; i < parents.length; i++) { - if ($(parents[i]).is('body')) { - element_id = $(drop).get(0).id; - $(old_parent).after(drop.clone()); - drop.remove(); - } - old_parent = parents[i]; - } - return $('#'+ element_id, $(target).contents()); - }, - + preprocessDrop: function(target, drop) { return drop; }, postprocessDrop: function(target, drop, element) { $(element).addClass('dnd-inserted'); } @@ -165,18 +147,20 @@ targets.each(function() { if ($(this).is('iframe')) { var target = this; - var selector = 'img[src='+ element.src +']'; + + var selector = 'img:not(.' + opt.ignoreClass + ')'; // Watch the iframe for changes var t = setInterval(function() { - $('img', $(target).contents()).each(function() { + $(selector, $(target).contents()).each(function() { if (opt.idSelector(this) == representation_id) { var drop = opt.preprocessDrop(target, $(this)); // Must return a jquery object var representation = opt.renderRepresentation(target, drop, representation_id); if (representation) { - if (opt.dropWrapper) { + // Breaks IE 7! + /*if (opt.dropWrapper) { drop.wrap(opt.dropWrapper); - } + }*/ if (opt.insertBefore) { drop.before(opt.insertBefore); } @@ -186,10 +170,22 @@ drop.replaceWith(representation); opt.postprocessDrop(target, drop, element); } - } + } }); }, opt.interval); - // @TODO track the timer with $.data() so we can clear it? + + // Track current active timers -- this means you can implement + // your own garbage collection for specific interactions, such + // as paging. + var data = $(document).data('dnd_timers'); + if (data) { + data[data.length] = t; + } else { + data = new Array(); + data[0] = t; + } + $(document).data('dnd_timers', data); + } else if ($(this).is('textarea')) { //console.log('@TODO handle textareas via.... regexp?'); }