Mercurial > defr > drupal > scald > dnd
comparison js/dnd-library.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 | 69db20fdbac2 |
children | e71df38143d1 |
comparison
equal
deleted
inserted
replaced
23:a72403cfa9a8 | 24:4f58fa0a9a6d |
---|---|
30 var $this = $(this); | 30 var $this = $(this); |
31 | 31 |
32 // This is a bad hack to lop off '-dnd-library' from the id to get the editor name | 32 // This is a bad hack to lop off '-dnd-library' from the id to get the editor name |
33 var $editor = $('#' + this.id.slice(0, -12)); | 33 var $editor = $('#' + this.id.slice(0, -12)); |
34 | 34 |
35 // Bind Drag and Drop plugin invocation to events emanating from Wysiwyg | 35 var settings = Drupal.settings.dndEnabledLibraries[$editor.get(0).id]; |
36 $editor.bind('wysiwygAttach', Drupal.behaviors.dndLibrary.attach_library); | 36 var bt_settings = $.extend({ |
37 $editor.bind('wysiwygDetach', Drupal.behaviors.dndLibrary.detach_library); | |
38 | |
39 // Add preview behavior to editor items (thanks, BeautyTips!) | |
40 $('.editor-item', context).each(function () { | |
41 $(this).bt(Drupal.settings.dndLibraryPreviews[this.id], { | |
42 'trigger': 'none', | 37 'trigger': 'none', |
43 'width': 375, | 38 'width': 375, |
44 'spikeLength': 7, | 39 'spikeLength': 7, |
45 'spikeGirth': 9, | 40 'spikeGirth': 9, |
46 'corner-radius' : 3, | 41 'corner-radius' : 3, |
47 'strokeWidth': 1, | 42 'strokeWidth': 1, |
48 'fill': '#ffd', | 43 'fill': '#ffd', |
49 'strokeStyle': '#555' | 44 'strokeStyle': '#555' |
50 }); | 45 }, settings.bt_settings); |
51 $(this).hoverIntent({ | 46 |
47 // Bind Drag and Drop plugin invocation to events emanating from Wysiwyg | |
48 $editor.bind('wysiwygAttach', Drupal.behaviors.dndLibrary.attach_library); | |
49 $editor.bind('wysiwygDetach', Drupal.behaviors.dndLibrary.detach_library); | |
50 | |
51 // Add preview behavior to editor items (thanks, BeautyTips!) | |
52 $('.editor-item', context).each(function () { | |
53 $(this).bt(Drupal.settings.dndLibraryPreviews[this.id], bt_settings); | |
54 var hover_opts = $.extend({ | |
52 'interval': 500, | 55 'interval': 500, |
53 'timeout' : 0, | 56 'timeout' : 0, |
54 'over': function() { | 57 'over': function() { |
55 var $this = $(this); | 58 var $this = $(this); |
56 this.btOn(); | 59 this.btOn(); |
61 $('img', $this).bind('click', function(e) { | 64 $('img', $this).bind('click', function(e) { |
62 $this.btOff(); | 65 $this.btOff(); |
63 }); | 66 }); |
64 }, | 67 }, |
65 'out': function() { this.btOff(); } | 68 'out': function() { this.btOff(); } |
66 }); | 69 }, settings.libraryHoverIntentOpts); |
70 $(this).hoverIntent(hover_opts); | |
67 }); | 71 }); |
68 | 72 |
69 // Simple AJAX pager | 73 // Simple AJAX pager |
70 $('.pager a', $this).click(function() { | 74 $('.pager a', $this).click(function() { |
71 $.getJSON(this.href, function(data) { | 75 $.getJSON(this.href, function(data) { |
89 | 93 |
90 // Preload images in editor representations | 94 // Preload images in editor representations |
91 var cached = $.data($editor, 'dnd_preload') || {}; | 95 var cached = $.data($editor, 'dnd_preload') || {}; |
92 for (editor_id in Drupal.settings.dndEditorRepresentations) { | 96 for (editor_id in Drupal.settings.dndEditorRepresentations) { |
93 if (!cached[editor_id]) { | 97 if (!cached[editor_id]) { |
94 $representation = $(Drupal.settings.dndEditorRepresentations[editor_id]); | 98 $representation = $(Drupal.settings.dndEditorRepresentations[editor_id].body); |
95 if ($representation.is('img') && $representation.get(0).src) { | 99 if ($representation.is('img') && $representation.get(0).src) { |
96 $representation.attr('src', $representation.get(0).src); | 100 $representation.attr('src', $representation.get(0).src); |
97 } else { | 101 } else { |
98 $('img', $representation).each(function() { | 102 $('img', $representation).each(function() { |
99 this.attr('src', this.src); | 103 this.attr('src', this.src); |
148 // Basic textareas | 152 // Basic textareas |
149 Drupal.behaviors.dndLibrary.attach_none = function(data, settings) { | 153 Drupal.behaviors.dndLibrary.attach_none = function(data, settings) { |
150 settings = $.extend({ | 154 settings = $.extend({ |
151 targets: $('#'+ data.field), | 155 targets: $('#'+ data.field), |
152 processTextAreaClick: function(target, clicked, representation_id, e, data) { | 156 processTextAreaClick: function(target, clicked, representation_id, e, data) { |
153 var snippet = '<p class="dnd-dropped-wrapper">' + Drupal.settings.dndEditorRepresentations[representation_id] + '</p>'; | 157 var snippet = '<p class="dnd-dropped-wrapper">' + Drupal.settings.dndEditorRepresentations[representation_id].body + '</p>'; |
154 $(target).replaceSelection(snippet, true); | 158 $(target).replaceSelection(snippet, true); |
155 } | 159 } |
156 }, settings); | 160 }, settings); |
157 $(settings.drop_selector).dnd(settings); | 161 $(settings.drop_selector).dnd(settings); |
158 } | 162 } |
168 } else { | 172 } else { |
169 var t = setInterval(function() { | 173 var t = setInterval(function() { |
170 var tiny_instance = tinyMCE.getInstanceById(data.field); | 174 var tiny_instance = tinyMCE.getInstanceById(data.field); |
171 if (tiny_instance) { | 175 if (tiny_instance) { |
172 Drupal.behaviors.dndLibrary._attach_tinymce(data, settings, tiny_instance); | 176 Drupal.behaviors.dndLibrary._attach_tinymce(data, settings, tiny_instance); |
177 $('#'+ data.field +'-wrapper').trigger('dnd_attach_library'); | |
173 clearInterval(t); | 178 clearInterval(t); |
174 } | 179 } |
175 }, 100); | 180 }, 100); |
176 } | 181 } |
177 } | 182 } |
189 | 194 |
190 settings = $.extend({ | 195 settings = $.extend({ |
191 targets: $('#'+ data.field +'-wrapper iframe'), | 196 targets: $('#'+ data.field +'-wrapper iframe'), |
192 processIframeDrop: function(drop, id_selector) { | 197 processIframeDrop: function(drop, id_selector) { |
193 var representation_id = id_selector.call(this, drop); | 198 var representation_id = id_selector.call(this, drop); |
194 var representation = Drupal.settings.dndEditorRepresentations[representation_id]; | 199 var representation = Drupal.settings.dndEditorRepresentations[representation_id].body; |
195 var target = this, $target = $(target), $drop = $(drop), block; | 200 var target = this, $target = $(target), $drop = $(drop), block; |
201 | |
202 // Keep a counter | |
203 var counter = $target.data('representation_counter'); | |
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); | |
196 | 213 |
197 // Search through block level parents | 214 // Search through block level parents |
198 $drop.parents().each(function() { | 215 $drop.parents().each(function() { |
199 var $this = $(this); | 216 var $this = $(this); |
200 if ($this.css('display') == 'block') { | 217 if ($this.css('display') == 'block') { |