Mercurial > defr > drupal > scald > dnd
comparison js/dnd-library.js @ 38:9e27e0aca323
Allow the library to specify a possible legend for the element.
This legend will be placed *outside* the atom representation, which means that
it's freely editable in the rich text and won't be taken over by Scald.
author | Franck Deroche <franck@defr.org> |
---|---|
date | Fri, 18 Sep 2009 15:17:05 +0200 |
parents | bb510db429c9 |
children | 3a8422ac941c |
comparison
equal
deleted
inserted
replaced
37:bb510db429c9 | 38:9e27e0aca323 |
---|---|
168 var target = this, $target = $(target); | 168 var target = this, $target = $(target); |
169 | 169 |
170 // Update element count | 170 // Update element count |
171 Drupal.behaviors.dndLibrary.countElements.call(target, representation_id); | 171 Drupal.behaviors.dndLibrary.countElements.call(target, representation_id); |
172 | 172 |
173 var snippet = '<p class="dnd-drop-wrapper">' + Drupal.settings.dndEditorRepresentations[representation_id].body + '</p>'; | 173 var rep = Drupal.settings.dndEditorRepresentations[representation_id]; |
174 var snippet = '<div class="dnd-drop-wrapper">' + rep.body + '</div>'; | |
175 if (rep.meta.legend) { | |
176 snippet += rep.meta.legend; | |
177 } | |
174 $target.replaceSelection(snippet, true); | 178 $target.replaceSelection(snippet, true); |
175 } | 179 } |
176 }, settings); | 180 }, settings); |
177 $(settings.drop_selector).dnd(settings); | 181 $(settings.drop_selector).dnd(settings); |
178 } | 182 } |
222 }); | 226 }); |
223 }, | 227 }, |
224 processIframeDrop: function(drop, id_selector) { | 228 processIframeDrop: function(drop, id_selector) { |
225 var representation_id = id_selector.call(this, drop); | 229 var representation_id = id_selector.call(this, drop); |
226 var representation = Drupal.settings.dndEditorRepresentations[representation_id].body; | 230 var representation = Drupal.settings.dndEditorRepresentations[representation_id].body; |
231 var legend = Drupal.settings.dndEditorRepresentations[representation_id].meta.legend; | |
227 var target = this, $target = $(target), $drop = $(drop), block; | 232 var target = this, $target = $(target), $drop = $(drop), block; |
228 | 233 |
229 // Update element count | 234 // Update element count |
230 Drupal.behaviors.dndLibrary.countElements(target, representation_id); | 235 Drupal.behaviors.dndLibrary.countElements(target, representation_id); |
231 | 236 |
240 | 245 |
241 // Remove dropped item | 246 // Remove dropped item |
242 $drop.remove(); | 247 $drop.remove(); |
243 | 248 |
244 // Create an element to insert | 249 // Create an element to insert |
245 var insert = dom.create('p', {'class' : 'dnd-drop-wrapper', 'id' : 'dnd-inserted'}, representation); | 250 var insert = dom.create('div', {'class' : 'dnd-drop-wrapper', 'id' : 'dnd-inserted'}, representation); |
246 | 251 |
247 // The no-parent case | 252 // The no-parent case |
248 if ($(block).is('body')) { | 253 if ($(block).is('body')) { |
249 s.setNode(insert); | 254 s.setNode(insert); |
250 } | 255 } |
252 var old_id = block.id; | 257 var old_id = block.id; |
253 block.id = 'target-block'; | 258 block.id = 'target-block'; |
254 $block = $('#target-block', $target.contents()); | 259 $block = $('#target-block', $target.contents()); |
255 | 260 |
256 // @TODO is finding the parent broken in safari?? | 261 // @TODO is finding the parent broken in safari?? |
257 $block.after('<p class="dnd-drop-wrapper" id="dnd-inserted">' + representation + '</p>'); | 262 var snip = '<div class="dnd-drop-wrapper" id="dnd-inserted">' + representation + '</div>'; |
263 if (legend) { | |
264 snip += legend; | |
265 } | |
266 $block.after(snip); | |
258 | 267 |
259 // The active target block should be empty | 268 // The active target block should be empty |
260 if ($('#target-block:dnd_empty', $target.contents()).length > 0) { | 269 if ($('#target-block:dnd_empty', $target.contents()).length > 0) { |
261 $('#target-block', $target.contents()).remove(); | 270 $('#target-block', $target.contents()).remove(); |
262 } else if (old_id) { | 271 } else if (old_id) { |