Mercurial > defr > drupal > scald > dnd
comparison js/dnd-library.js @ 20:89fe0aca43d4
Refactored the entire interval system, and started on form behavior.
| author | David Eads <eads@chicagotech.org> |
|---|---|
| date | Sun, 08 Mar 2009 20:29:57 -0500 |
| parents | d83073a08b25 |
| children | 69db20fdbac2 |
comparison
equal
deleted
inserted
replaced
| 19:d83073a08b25 | 20:89fe0aca43d4 |
|---|---|
| 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 | |
| 36 // Bind Drag and Drop plugin invocation to events emanating from Wysiwyg | 35 // Bind Drag and Drop plugin invocation to events emanating from Wysiwyg |
| 37 $editor.bind('wysiwygAttach', Drupal.behaviors.dndLibrary.attach_library); | 36 $editor.bind('wysiwygAttach', Drupal.behaviors.dndLibrary.attach_library); |
| 38 $editor.bind('wysiwygDetach', Drupal.behaviors.dndLibrary.detach_library); | 37 $editor.bind('wysiwygDetach', Drupal.behaviors.dndLibrary.detach_library); |
| 39 | 38 |
| 39 // Add preview behavior to editor items (thanks, BeautyTips!) | |
| 40 $('.editor-item', context).each(function () { | 40 $('.editor-item', context).each(function () { |
| 41 $(this).bt(Drupal.settings.dndLibraryPreviews[this.id], { | 41 $(this).bt(Drupal.settings.dndLibraryPreviews[this.id], { |
| 42 'trigger' : 'none', | 42 'trigger': 'none', |
| 43 'width' : 300, | 43 'width': 300, |
| 44 'spikeLength' : 7, | 44 'spikeLength': 7, |
| 45 'spikeGirth' : 9, | 45 'spikeGirth': 9, |
| 46 'corner-radius' : 3, | 46 'corner-radius' : 3, |
| 47 'strokeWidth' : 1, | 47 'strokeWidth': 1, |
| 48 'fill' : '#eee', | 48 'fill': '#ffd', |
| 49 'strokeStyle': '#555' | 49 'strokeStyle': '#555' |
| 50 }); | 50 }); |
| 51 $(this).hover(function() { | 51 $(this).hoverIntent({ |
| 52 var $this = $(this); | 52 'interval': 500, |
| 53 this.btOn(); | 53 'timeout' : 0, |
| 54 // Remove the preview once dragging of any image has commenced | 54 'over': function() { |
| 55 $('img', $this).bind('drag', function(e) { | 55 var $this = $(this); |
| 56 $this.btOff(); | 56 this.btOn(); |
| 57 }); | 57 // Remove the preview once dragging of any image has commenced |
| 58 }, function() { | 58 $('img', $this).bind('drag', function(e) { |
| 59 this.btOff(); | 59 $this.btOff(); |
| 60 }); | |
| 61 $('img', $this).bind('click', function(e) { | |
| 62 $this.btOff(); | |
| 63 }); | |
| 64 }, | |
| 65 'out': function() { this.btOff(); } | |
| 60 }); | 66 }); |
| 61 }); | 67 }); |
| 62 | 68 |
| 63 | 69 // Simple AJAX pager |
| 64 // Ajax pager | |
| 65 $('.pager a', $this).click(function() { | 70 $('.pager a', $this).click(function() { |
| 66 $.getJSON(this.href, function(data) { | 71 $.getJSON(this.href, function(data) { |
| 67 Drupal.behaviors.dndLibrary.refreshLibrary.call($this.get(0), data, $editor); | 72 Drupal.behaviors.dndLibrary.refreshLibrary.call($this.get(0), data, $editor); |
| 68 }); | 73 }); |
| 69 Drupal.behaviors.dndLibrary(); | 74 Drupal.behaviors.dndLibrary(); |
| 75 return false; | |
| 76 }); | |
| 77 | |
| 78 $('.view-filters form', $this).submit(function() { | |
| 79 $(this).ajaxSubmit({ | |
| 80 // @TODO add URL from settings and target more specifically... | |
| 81 'dataType': 'json', | |
| 82 'success': function(responsetext, statustext) { | |
| 83 drupal.behaviors.dndlibrary.responsetext.call($this.get(0), responsetext, $editor); | |
| 84 drupal.behaviors.dndlibrary(); | |
| 85 } | |
| 86 }); | |
| 70 return false; | 87 return false; |
| 71 }); | 88 }); |
| 72 | 89 |
| 73 // Preload images in editor representations | 90 // Preload images in editor representations |
| 74 var cached = $.data($editor, 'dnd_preload') || {}; | 91 var cached = $.data($editor, 'dnd_preload') || {}; |
| 130 | 147 |
| 131 // Basic textareas | 148 // Basic textareas |
| 132 Drupal.behaviors.dndLibrary.attach_none = function(data, settings) { | 149 Drupal.behaviors.dndLibrary.attach_none = function(data, settings) { |
| 133 settings = $.extend({ | 150 settings = $.extend({ |
| 134 targets: $('#'+ data.field), | 151 targets: $('#'+ data.field), |
| 135 processTextAreaDrop: function(target, clicked, representation_id, e, data) { | 152 processTextAreaClick: function(target, clicked, representation_id, e, data) { |
| 136 var snippet = '<p class="dnd-dropped-wrapper">' + Drupal.settings.dndEditorRepresentations[representation_id] + '</p>'; | 153 var snippet = '<p class="dnd-dropped-wrapper">' + Drupal.settings.dndEditorRepresentations[representation_id] + '</p>'; |
| 137 $(target).replaceSelection(snippet, true); | 154 $(target).replaceSelection(snippet, true); |
| 138 } | 155 } |
| 139 }, settings); | 156 }, settings); |
| 140 $(settings.drop_selector).dnd(settings); | 157 $(settings.drop_selector).dnd(settings); |
| 170 Drupal.behaviors.dndLibrary._attach_tinymce = function(data, settings, tiny_instance) { | 187 Drupal.behaviors.dndLibrary._attach_tinymce = function(data, settings, tiny_instance) { |
| 171 var ed = tiny_instance, dom = ed.dom, s = ed.selection; | 188 var ed = tiny_instance, dom = ed.dom, s = ed.selection; |
| 172 | 189 |
| 173 settings = $.extend({ | 190 settings = $.extend({ |
| 174 targets: $('#'+ data.field +'-wrapper iframe'), | 191 targets: $('#'+ data.field +'-wrapper iframe'), |
| 175 interval: 100, | 192 processIframeDrop: function(drop, id_selector) { |
| 176 processIframeDrop: function(target, dragged, dropped, representation_id) { | 193 var representation_id = id_selector.call(this, drop); |
| 177 var representation = Drupal.settings.dndEditorRepresentations[representation_id]; | 194 var representation = Drupal.settings.dndEditorRepresentations[representation_id]; |
| 178 var $target = $(target), $dropped = $(dropped), $dragged = $(dragged), block; | 195 var target = this, $target = $(target), $drop = $(drop), block; |
| 179 | 196 |
| 180 // Search through block level parents | 197 // Search through block level parents |
| 181 $dropped.parents().each(function() { | 198 $drop.parents().each(function() { |
| 182 var $this = $(this); | 199 var $this = $(this); |
| 183 if ($this.css('display') == 'block') { | 200 if ($this.css('display') == 'block') { |
| 184 block = this; | 201 block = this; |
| 185 return false; | 202 return false; |
| 186 } | 203 } |
| 187 }); | 204 }); |
| 188 | 205 |
| 189 // Remove dropped item | 206 // Remove dropped item |
| 190 $dropped.remove(); | 207 $drop.remove(); |
| 191 | 208 |
| 192 // Create an element to insert | 209 // Create an element to insert |
| 193 var insert = dom.create('p', {'class' : 'dnd-dropped-wrapper', 'id' : 'dnd-inserted'}, representation); | 210 var insert = dom.create('p', {'class' : 'dnd-dropped-wrapper', 'id' : 'dnd-inserted'}, representation); |
| 194 | 211 |
| 195 // The no-parent case | 212 // The no-parent case |
| 234 var next = $inserted.next().get(0); | 251 var next = $inserted.next().get(0); |
| 235 | 252 |
| 236 // If the next item exists and isn't an editor representation, drop the | 253 // If the next item exists and isn't an editor representation, drop the |
| 237 // caret at the beginning of the element, otherwise make a new paragraph | 254 // caret at the beginning of the element, otherwise make a new paragraph |
| 238 // to advance the caret to. | 255 // to advance the caret to. |
| 239 if (next && !$(next).hasClass('dnd-dropped-wrapper')) { | 256 if (next && !$(next).hasClass('dnd-droped-wrapper')) { |
| 240 $(next).prepend('<span id="__caret">_</span>'); | 257 $(next).prepend('<span id="__caret">_</span>'); |
| 241 } | 258 } |
| 242 else { | 259 else { |
| 243 var after = dom.create('p', {}, '<span id="__caret">_</span>'); | 260 var after = dom.create('p', {}, '<span id="__caret">_</span>'); |
| 244 dom.insertAfter(after, 'dnd-inserted'); | 261 dom.insertAfter(after, 'dnd-inserted'); |
| 250 // Force selection to reset the caret | 267 // Force selection to reset the caret |
| 251 var c = dom.get('__caret'); | 268 var c = dom.get('__caret'); |
| 252 s.select(c); | 269 s.select(c); |
| 253 ed.execCommand('Delete', false, null); | 270 ed.execCommand('Delete', false, null); |
| 254 dom.remove(c); | 271 dom.remove(c); |
| 255 | |
| 256 // Add some classes to the library items | |
| 257 $(dragged).addClass('dnd-inserted'); | |
| 258 drag_parents = $(dragged).parents('.editor-item'); | |
| 259 drag_parents.addClass('dnd-child-inserted'); | |
| 260 } | 272 } |
| 261 }, settings); | 273 }, settings); |
| 262 | 274 |
| 263 $(settings.drop_selector).dnd(settings); | 275 $(settings.drop_selector).dnd(settings); |
| 264 } | 276 } |
