comparison js/dnd-library.js @ 25:e71df38143d1

Added element counting, but there is a bug in textarea click counting -- it only works properly once a count has already been started via another mechanism.
author David Eads <eads@chicagotech.org>
date Wed, 11 Mar 2009 14:07:50 -0500
parents 4f58fa0a9a6d
children 9a92410be362
comparison
equal deleted inserted replaced
24:4f58fa0a9a6d 25:e71df38143d1
151 151
152 // Basic textareas 152 // Basic textareas
153 Drupal.behaviors.dndLibrary.attach_none = function(data, settings) { 153 Drupal.behaviors.dndLibrary.attach_none = function(data, settings) {
154 settings = $.extend({ 154 settings = $.extend({
155 targets: $('#'+ data.field), 155 targets: $('#'+ data.field),
156 processTextAreaClick: function(target, clicked, representation_id, e, data) { 156 processTextAreaClick: function(clicked, representation_id, e, data) {
157 var target = this, $target = $(target);
158
159 // Update element count
160 Drupal.behaviors.dndLibrary.countElements.call(target, representation_id);
161
157 var snippet = '<p class="dnd-dropped-wrapper">' + Drupal.settings.dndEditorRepresentations[representation_id].body + '</p>'; 162 var snippet = '<p class="dnd-dropped-wrapper">' + Drupal.settings.dndEditorRepresentations[representation_id].body + '</p>';
158 $(target).replaceSelection(snippet, true); 163 $target.replaceSelection(snippet, true);
159 } 164 }
160 }, settings); 165 }, settings);
161 $(settings.drop_selector).dnd(settings); 166 $(settings.drop_selector).dnd(settings);
162 } 167 }
163 168
197 processIframeDrop: function(drop, id_selector) { 202 processIframeDrop: function(drop, id_selector) {
198 var representation_id = id_selector.call(this, drop); 203 var representation_id = id_selector.call(this, drop);
199 var representation = Drupal.settings.dndEditorRepresentations[representation_id].body; 204 var representation = Drupal.settings.dndEditorRepresentations[representation_id].body;
200 var target = this, $target = $(target), $drop = $(drop), block; 205 var target = this, $target = $(target), $drop = $(drop), block;
201 206
202 // Keep a counter 207 // Update element count
203 var counter = $target.data('representation_counter'); 208 Drupal.behaviors.dndLibrary.countElements.call(target, representation_id);
204 if (!counter) {
205 counter = {}
206 counter[representation_id] = 1;
207 } else if (counter && !counter[representation_id]) {
208 counter[representation_id] = 1;
209 } else {
210 counter[representation_id] = counter[representation_id] + 1;
211 }
212 $target.data('representation_counter', counter);
213 209
214 // Search through block level parents 210 // Search through block level parents
215 $drop.parents().each(function() { 211 $drop.parents().each(function() {
216 var $this = $(this); 212 var $this = $(this);
217 if ($this.css('display') == 'block') { 213 if ($this.css('display') == 'block') {
289 } 285 }
290 }, settings); 286 }, settings);
291 287
292 $(settings.drop_selector).dnd(settings); 288 $(settings.drop_selector).dnd(settings);
293 } 289 }
290
291
292 // Keep a counter of times a representation ID has been used
293 Drupal.behaviors.dndLibrary.countElements = function(representation_id) {
294 // We need to track element usage betwen all editors, so we look for the
295 // parent form item
296 $target = $(this).parents('.form-item');
297 var counter = $target.data('representation_counter');
298 if (!counter) {
299 counter = {}
300 counter[representation_id] = 1;
301 } else if (counter && !counter[representation_id]) {
302 counter[representation_id] = 1;
303 } else {
304 counter[representation_id] = counter[representation_id] + 1;
305 }
306 $target.data('representation_counter', counter);
307 }