Mercurial > defr > drupal > scald > dnd
diff js/jquery.draganddrop.js @ 24:4f58fa0a9a6d
Cleaned up some library behavior, changed editor representation cache to track a title and a body for representations, to allow a little more dynamic composition.
author | David Eads <eads@chicagotech.org> |
---|---|
date | Wed, 11 Mar 2009 01:47:57 -0500 |
parents | 89fe0aca43d4 |
children | e71df38143d1 |
line wrap: on
line diff
--- a/js/jquery.draganddrop.js Tue Mar 10 13:55:27 2009 -0500 +++ b/js/jquery.draganddrop.js Wed Mar 11 01:47:57 2009 -0500 @@ -44,9 +44,14 @@ * textareaTargetClass: * A class to add to a draggable item if it can be dragged to a textarea. * - * processClass: + * processedClass: * A class to add to draggable items processed by DnD. * + * droppedClass: + * A class to add to images that are dropped (by default, this is used to + * ensure that a successful drop manifests the editor representation only + * once.) + * * interval: * How often to check the iframe for a drop, in milliseconds. * @@ -100,7 +105,7 @@ }, processIframeDrop: function(drop, id_selector) { var representation_id = opt.idSelector(drop); - $(drop).replaceWith(representation_id).wrap('<p class="dnd-dropped"></p>'); + $(drop).replaceWith(representation_id).wrap('<p class="'+ opt.droppedClass +'"></p>'); }, processTextAreaClick: function(target, clicked, representation_id) { var snippet = '<div><img src="'+ representation_id +'" /></div>'; @@ -111,7 +116,8 @@ iframeTargetClass: 'dnd-iframe-target', textareaTargetClass: 'dnd-textarea-target', - processedClass: 'dnd-processed' + processedClass: 'dnd-processed', + droppedClass: 'dnd-dropped' }, opt); @@ -122,8 +128,15 @@ $(targets).filter('iframe').each(function() { var target = this; var t = setInterval(function() { - $('img:not(.dnd-dropped)', $(target).contents()).each(function() { + $('img:not(.'+ opt.droppedClass +')', $(target).contents()).each(function() { opt.processIframeDrop.call(target, this, opt.idSelector); + var data = {'drop': this, 'representation_id': opt.idSelector(this)}; + + // Trigger event in container window + $(target).trigger('dnd_drop', data); + + // Trigger event in iframe + $(this).trigger('dnd_drop', data); }); }, opt.interval); @@ -140,7 +153,6 @@ return this.each(function() { if ($(this).is('img')) { var element = this, $element = $(element); - var representation_id = opt.idSelector(element); if (!representation_id) {