comparison js/dnd.js @ 4:c2eb995212bf

TONS of fixes in this commit.
author David Eads <eads@chicagotech.org>
date Thu, 19 Feb 2009 12:33:19 -0600
parents 5df0783706f7
children 99ba5941779c
comparison
equal deleted inserted replaced
3:5df0783706f7 4:c2eb995212bf
83 */ 83 */
84 84
85 (function($) { 85 (function($) {
86 $.fn.dnd = function(opt) { 86 $.fn.dnd = function(opt) {
87 opt = $.extend({}, { 87 opt = $.extend({}, {
88 dropWrapper: '<p class="dnd-inserted"></p>', 88 dropWrapper: '<p class="dnd-dropped"></p>',
89 insertBefore: '', 89 insertBefore: '',
90 insertAfter: '', 90 insertAfter: '',
91 processedClass: 'dnd-processed', 91 processedClass: 'dnd-processed',
92 disableClick: true,
92 93
93 processTargets: function(targets) { 94 processTargets: function(targets) {
94 return targets.each(function() { 95 return targets.each(function() {
95 $('head', $(this).contents()).append('<style type="text/css">.dnd-processed { display: none; }</style>'); 96 $('head', $(this).contents()).append('<style type="text/css">.dnd-processed { display: none; }</style>');
96 return this; 97 return this;
143 old_parent = parents[i]; 144 old_parent = parents[i];
144 } 145 }
145 return $('#'+ element_id, $(target).contents()); 146 return $('#'+ element_id, $(target).contents());
146 }, 147 },
147 148
148 postprocessDrop: function(target, drop) { return; } 149 postprocessDrop: function(target, drop, element) {
150 $(element).addClass('dnd-inserted');
151 }
149 152
150 }, opt); 153 }, opt);
151 154
152 // Initialize plugin 155 // Initialize plugin
153 var targets = opt.processTargets(opt.targets); 156 var targets = opt.processTargets(opt.targets);
157 if (opt.disableClick) { this.click(function() { return false; }) }
154 158
155 // Process! 159 // Process!
156 return this.each(function() { 160 return this.each(function() {
157 161
158 var element = this; 162 var element = this;
180 drop 184 drop
181 .before(opt.insertBefore) 185 .before(opt.insertBefore)
182 .after(opt.insertAfter) 186 .after(opt.insertAfter)
183 .wrap(opt.dropWrapper) 187 .wrap(opt.dropWrapper)
184 .replaceWith(opt.renderRepresentation(target, drop, representation_id)); 188 .replaceWith(opt.renderRepresentation(target, drop, representation_id));
185 opt.postprocessDrop(target, drop); 189 opt.postprocessDrop(target, drop, element);
186 } 190 }
187 }, 100); 191 }, 100);
188 // @TODO track the timer with $.data() so we can clear it? 192 // @TODO track the timer with $.data() so we can clear it?
189 } else if ($(this).is('textarea')) { 193 } else if ($(this).is('textarea')) {
190 console.log('@TODO handle textareas via.... regexp?'); 194 console.log('@TODO handle textareas via.... regexp?');