Mercurial > defr > drupal > scald > dnd
diff 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 |
line wrap: on
line diff
--- a/js/dnd-library.js Fri Mar 06 14:26:06 2009 -0600 +++ b/js/dnd-library.js Sun Mar 08 20:29:57 2009 -0500 @@ -32,36 +32,41 @@ // This is a bad hack to lop off '-dnd-library' from the id to get the editor name var $editor = $('#' + this.id.slice(0, -12)); - // Bind Drag and Drop plugin invocation to events emanating from Wysiwyg $editor.bind('wysiwygAttach', Drupal.behaviors.dndLibrary.attach_library); $editor.bind('wysiwygDetach', Drupal.behaviors.dndLibrary.detach_library); + // Add preview behavior to editor items (thanks, BeautyTips!) $('.editor-item', context).each(function () { $(this).bt(Drupal.settings.dndLibraryPreviews[this.id], { - 'trigger' : 'none', - 'width' : 300, - 'spikeLength' : 7, - 'spikeGirth' : 9, + 'trigger': 'none', + 'width': 300, + 'spikeLength': 7, + 'spikeGirth': 9, 'corner-radius' : 3, - 'strokeWidth' : 1, - 'fill' : '#eee', + 'strokeWidth': 1, + 'fill': '#ffd', 'strokeStyle': '#555' }); - $(this).hover(function() { - var $this = $(this); - this.btOn(); - // Remove the preview once dragging of any image has commenced - $('img', $this).bind('drag', function(e) { - $this.btOff(); - }); - }, function() { - this.btOff(); + $(this).hoverIntent({ + 'interval': 500, + 'timeout' : 0, + 'over': function() { + var $this = $(this); + this.btOn(); + // Remove the preview once dragging of any image has commenced + $('img', $this).bind('drag', function(e) { + $this.btOff(); + }); + $('img', $this).bind('click', function(e) { + $this.btOff(); + }); + }, + 'out': function() { this.btOff(); } }); }); - - // Ajax pager + // Simple AJAX pager $('.pager a', $this).click(function() { $.getJSON(this.href, function(data) { Drupal.behaviors.dndLibrary.refreshLibrary.call($this.get(0), data, $editor); @@ -70,6 +75,18 @@ return false; }); + $('.view-filters form', $this).submit(function() { + $(this).ajaxSubmit({ + // @TODO add URL from settings and target more specifically... + 'dataType': 'json', + 'success': function(responsetext, statustext) { + drupal.behaviors.dndlibrary.responsetext.call($this.get(0), responsetext, $editor); + drupal.behaviors.dndlibrary(); + } + }); + return false; + }); + // Preload images in editor representations var cached = $.data($editor, 'dnd_preload') || {}; for (editor_id in Drupal.settings.dndEditorRepresentations) { @@ -132,7 +149,7 @@ Drupal.behaviors.dndLibrary.attach_none = function(data, settings) { settings = $.extend({ targets: $('#'+ data.field), - processTextAreaDrop: function(target, clicked, representation_id, e, data) { + processTextAreaClick: function(target, clicked, representation_id, e, data) { var snippet = '<p class="dnd-dropped-wrapper">' + Drupal.settings.dndEditorRepresentations[representation_id] + '</p>'; $(target).replaceSelection(snippet, true); } @@ -172,13 +189,13 @@ settings = $.extend({ targets: $('#'+ data.field +'-wrapper iframe'), - interval: 100, - processIframeDrop: function(target, dragged, dropped, representation_id) { + processIframeDrop: function(drop, id_selector) { + var representation_id = id_selector.call(this, drop); var representation = Drupal.settings.dndEditorRepresentations[representation_id]; - var $target = $(target), $dropped = $(dropped), $dragged = $(dragged), block; + var target = this, $target = $(target), $drop = $(drop), block; // Search through block level parents - $dropped.parents().each(function() { + $drop.parents().each(function() { var $this = $(this); if ($this.css('display') == 'block') { block = this; @@ -187,7 +204,7 @@ }); // Remove dropped item - $dropped.remove(); + $drop.remove(); // Create an element to insert var insert = dom.create('p', {'class' : 'dnd-dropped-wrapper', 'id' : 'dnd-inserted'}, representation); @@ -236,7 +253,7 @@ // If the next item exists and isn't an editor representation, drop the // caret at the beginning of the element, otherwise make a new paragraph // to advance the caret to. - if (next && !$(next).hasClass('dnd-dropped-wrapper')) { + if (next && !$(next).hasClass('dnd-droped-wrapper')) { $(next).prepend('<span id="__caret">_</span>'); } else { @@ -252,11 +269,6 @@ s.select(c); ed.execCommand('Delete', false, null); dom.remove(c); - - // Add some classes to the library items - $(dragged).addClass('dnd-inserted'); - drag_parents = $(dragged).parents('.editor-item'); - drag_parents.addClass('dnd-child-inserted'); } }, settings);