Mercurial > defr > drupal > scald > dnd
changeset 14:ef7ad7b5baa4
Slightly changed matching mechanism to handle Firefox's crazy desire to make dropped src attributes relative.
author | David Eads <eads@chicagotech.org> |
---|---|
date | Fri, 27 Feb 2009 12:30:42 -0600 |
parents | d0e7287c7a55 |
children | 7a5f74482ee3 |
files | dnd_test/dnd_test.module js/dnd.js |
diffstat | 2 files changed, 20 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/dnd_test/dnd_test.module Fri Feb 27 11:51:28 2009 -0600 +++ b/dnd_test/dnd_test.module Fri Feb 27 12:30:42 2009 -0600 @@ -26,10 +26,6 @@ * This demonstrates how to attach Drag and Drop to a given textarea. */ function dnd_test_form_alter(&$form, &$form_state) { - - //global $_SERVER; - //dpm($_SERVER); - if ($form['#id'] == 'node-form' && $form['type']['#value'] == 'page') { drupal_add_css(drupal_get_path('module', 'dnd_test') .'/dnd_test.css'); $form['body_field']['body']['#dnd-enabled'] = TRUE; @@ -92,7 +88,7 @@ /** * Theme wrapper that spins out multiple library representations for a given - ;[''''* editor representation. This is because we want to demonstrate how to allow + * editor representation. This is because we want to demonstrate how to allow * for multiple versions (i.e. different sizes) of a single item */ function dnd_editor_items($i) { @@ -122,12 +118,12 @@ } //$variables['image'] = theme('image', drupal_get_path('module', 'dnd_test') .'/img/item-'. $img .'-thumb.jpg'); - $variables['image'] = '<img src="http://'. $_SERVER['SERVER_ADDR'] . base_path() . drupal_get_path('module', 'dnd_test') .'/img/item-'. $img .'-thumb.jpg?dnd_id='. $i .'-M" class="drop" />'; + $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'; $variables['author'] = 'David Eads'; foreach(array(t('S'), t('M'), t('L')) as $size) { - $sizes[] = '<img src="http://'. $_SERVER['SERVER_ADDR'] . base_path() . drupal_get_path('module', 'dnd_test') .'/img/icon/'. $size .'.png?dnd_id='. $i .'-'. $size .'" class="drop" />'; + $sizes[] = '<img src="http://'. $_SERVER['HTTP_HOST'] . base_path() . drupal_get_path('module', 'dnd_test') .'/img/icon/'. $size .'.png?dnd_id='. $i .'-'. $size .'" class="drop" />'; } $variables['sizes'] = '<ul><li>'. implode('</li><li>', $sizes) .'</li></ul>'; }
--- a/js/dnd.js Fri Feb 27 11:51:28 2009 -0600 +++ b/js/dnd.js Fri Feb 27 12:30:42 2009 -0600 @@ -169,25 +169,25 @@ // Watch the iframe for changes var t = setInterval(function() { - var match = $(selector, $(target).contents()); - if (match.length > 0) { - var drop = opt.preprocessDrop(target, match); // Must return a jquery object - var representation = opt.renderRepresentation(target, drop, representation_id); - - if (representation) { - if (opt.dropWrapper) { - drop.wrap(opt.dropWrapper); + $('img', $(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) { + drop.wrap(opt.dropWrapper); + } + if (opt.insertBefore) { + drop.before(opt.insertBefore); + } + if (opt.insertAfter) { + drop.after(opt.insertAfter); + } + drop.replaceWith(representation); + opt.postprocessDrop(target, drop, element); } - if (opt.insertBefore) { - drop.before(opt.insertBefore); - } - if (opt.insertAfter) { - drop.after(opt.insertAfter); - } - drop.replaceWith(representation); - opt.postprocessDrop(target, drop, element); } - } + }); }, opt.interval); // @TODO track the timer with $.data() so we can clear it? } else if ($(this).is('textarea')) {