Mercurial > defr > drupal > scald > dnd
changeset 15:7a5f74482ee3
More cross browser work, garbage collection for timers, etc.
author | David Eads <eads@chicagotech.org> |
---|---|
date | Mon, 02 Mar 2009 23:22:37 -0600 |
parents | ef7ad7b5baa4 |
children | bb68dc3ad56f |
files | dnd_test/dnd-editor-item.tpl.php dnd_test/dnd_test.module js/dnd-library.js js/dnd.js |
diffstat | 4 files changed, 40 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ -<span class="mceNonEditable"> - <?php print $image; ?> -</span> +<?php print $image; ?>
--- 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'] = '<img src="http://'. $_SERVER['HTTP_HOST'] . base_path() . drupal_get_path('module', 'dnd_test') .'/img/item-'. $img .'-thumb.jpg?dnd_id='. $i .'-M" class="drop" />'; $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')); }
--- 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: '<p><span id="__caret">_</span></p>', + + // 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.
--- 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: '<p class="dnd-dropped"></p>', + interval: 250, + dropWrapper: '<p class="dnd-dropped-wrapper"></p>', insertBefore: false, insertAfter: false, processedClass: 'dnd-processed', - interval: 100, - + ignoreClass: 'dnd-dropped', processTargets: function(targets) { return targets.each(function() { - //$('head', $(this).contents()).append('<style type="text/css">.dnd-processed { display: none; }</style>'); - //@TODO use jQuery.rules() + $('head', $(this).contents()).append('<style type="text/css">img { display: none; } img.dnd-dropped {display: block; }</style>'); return this; }); }, @@ -117,24 +116,7 @@ return '<span id="dnd-' + representation_id +'-'+ count +'">' + representation_id + '</span>'; }, - // 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?'); }