# HG changeset patch # User David Eads # Date 1237343340 18000 # Node ID 2d49adbd8992dcb5cc0d96f77cec0702e3061d9d # Parent 37ca57016cbeb7441a8c84a68cd62d3295610a3c Start of applying a last layer of polish: starting the process of cleaning up the library code. diff -r 37ca57016cbe -r 2d49adbd8992 dnd.module --- a/dnd.module Tue Mar 17 10:59:50 2009 -0500 +++ b/dnd.module Tue Mar 17 21:29:00 2009 -0500 @@ -89,37 +89,34 @@ $settings = $element['#dnd-settings']; } - // Set some important defaults - if (function_exists($settings['callback']) && ($library = $settings['callback']($element))) { - $settings = array('library_id' => $element['#id'] . DND_ID_SUFFIX) + $settings; - unset($settings['callback']); + $settings = array('library_id' => $element['#id'] . DND_ID_SUFFIX) + $settings; - // BeautyTips - drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/other_libs/excanvas_0002/excanvas-compressed.js'); - drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/other_libs/jquery.hoverIntent.minified.js'); - drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/jquery.bt.js'); + // BeautyTips + drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/other_libs/excanvas_0002/excanvas-compressed.js'); + drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/other_libs/jquery.hoverIntent.minified.js'); + drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/jquery.bt.js'); - // Dependencies - drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.url.packed.js'); - drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.fieldselection.js'); - drupal_add_js('misc/jquery.form.js'); + // Dependencies + drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.url.packed.js'); + drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.fieldselection.js'); + drupal_add_js('misc/jquery.form.js'); - // Drag and drop - drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.draganddrop.js'); - drupal_add_js(drupal_get_path('module', 'dnd') .'/js/dnd-library.js'); + // Drag and drop + drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.draganddrop.js'); + drupal_add_js(drupal_get_path('module', 'dnd') .'/js/dnd-library.js'); - drupal_add_js(array( - 'dndEnabledLibraries' => array($element['#id'] => $settings), - ), 'setting'); + drupal_add_js(array( + 'dndEnabledLibraries' => array($element['#id'] => $settings), + ), 'setting'); - // Store editor representations in Drupal setting - drupal_add_js(array( - 'dndEditorRepresentations' => $library['editor_representations'], - 'dndLibraryPreviews' => $library['library_previews'], - ), 'setting'); - - $element['#suffix'] = theme('dnd_library', $library['library'], $settings['library_id']) . $element['#suffix']; - } + // Store editor representations in Drupal setting + drupal_add_js(array( + 'dndEditorRepresentations' => $library['editor_representations'], + 'dndLibraryPreviews' => $library['library_previews'], + ), 'setting'); + + // Note that we brute force the wrapper + $element['#suffix'] = '
'. $element['#suffix']; } return $element; @@ -130,10 +127,27 @@ /** * Implementation of hook_wywiwyg_plugin(). */ -function dnd_wysiwyg_plugin($editor) { +function dnd_wysiwyg_plugin($editor, $version=0) { + $plugins = array(); switch ($editor) { case 'tinymce': - dpm($editor); + if ($version > 3) { + $plugins['atomic'] = array( + 'type' => 'external', + 'title' => t('Atomic selection plugin'), + 'description' => t('This plugin forces a selection up to the outer container of a given element. It is available via the third party repository maintained by MoxieCode on SourceForge.'), + 'extensions' => array('atomic' => t('Atomic Selection')), + 'path' => drupal_get_path('module', 'dnd') .'/js/tinymce/atomic/editor_plugin.js', + 'url' => 'http://sourceforge.net/tracker/index.php?func=detail&aid=2519211&group_id=103281&atid=738747', + 'load' => TRUE, + ); + $plugins['noneditable'] = array( + 'path' => drupal_get_path('module', 'wysiwyg') .'/tinymce/jscripts/tiny_mce/plugins/noneditable/editor_plugin.js', + 'extensions' => array('noneditable' => t('Noneditable')), + 'load' => TRUE, + ); + } break; } + return $plugins; } diff -r 37ca57016cbe -r 2d49adbd8992 js/dnd-library.js --- a/js/dnd-library.js Tue Mar 17 10:59:50 2009 -0500 +++ b/js/dnd-library.js Tue Mar 17 21:29:00 2009 -0500 @@ -20,11 +20,15 @@ 'empty' : function(a, i, m) { return !$(a).filter(function(i) { return !$(this).is('br'); - }).length && !$.trim(a.textContent || a.innerText||$(a).text()||""); + }).length && !$.trim(a.textContent || a.innerText||$(a).text() || ""); } }); }) (jQuery); +/** + * Initialize and load drag and drop library and pass off rendering and + * behavior attachment. + */ Drupal.behaviors.dndLibrary = function(context) { $('.dnd-library-wrapper', context).each(function() { var $this = $(this); @@ -32,8 +36,8 @@ // 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)); - var settings = Drupal.settings.dndEnabledLibraries[$editor.get(0).id]; - var bt_settings = $.extend({ + // Set up some initial settings for BeautyTips + var settings = Drupal.settings.dndEnabledLibraries[$editor.get(0).id] = $.extend({ 'trigger': 'none', 'width': 375, 'spikeLength': 7, @@ -42,81 +46,32 @@ 'strokeWidth': 1, 'fill': '#ffd', 'strokeStyle': '#555' - }, settings.bt_settings); + }, Drupal.settings.dndEnabledLibraries[$editor.get(0).id]); // 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', $this).each(function () { - $(this).bt(Drupal.settings.dndLibraryPreviews[this.id], bt_settings); - var hover_opts = $.extend({ - '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(); } - }, settings.libraryHoverIntentOpts); - $(this).hoverIntent(hover_opts); + // Set up empty objects to keep track of things + Drupal.settings.dndEditorRepresentations = {}; + Drupal.settings.dndLibraryPreviews = {}; + + // Populate + $.getJSON(Drupal.settings.basePath + settings.url, function(data) { + Drupal.behaviors.dndLibrary.renderLibrary.call($this.get(0), data, $editor); }); - // Simple AJAX pager - $('.pager a', $this).click(function() { - $.getJSON(this.href, function(data) { - Drupal.behaviors.dndLibrary.refreshLibrary.call($this.get(0), data, $editor); - }); - Drupal.behaviors.dndLibrary(); - return false; - }); - - $('.view-filters input[type=submit]', $this).click(function() { - $(this).ajaxSubmit({ - 'url' : Drupal.settings.basePath + Drupal.settings.dndEnabledLibraries[$editor.get(0).id].url, - 'dataType': 'json', - 'success': function(responsetext, statustext) { - Drupal.behaviors.dndLibrary.refreshLibrary.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) { - if (!cached[editor_id]) { - $representation = $(Drupal.settings.dndEditorRepresentations[editor_id].body); - if ($representation.is('img') && $representation.get(0).src) { - $representation.attr('src', $representation.get(0).src); - } else { - $('img', $representation).each(function() { - this.attr('src', this.src); - }); - } - } - } - $.data($editor, 'dnd_preload', cached); }); } -Drupal.behaviors.dndLibrary.refreshLibrary = function(data, editor) { +Drupal.behaviors.dndLibrary.renderLibrary = function(data, editor) { $this = $(this); - $('.header', $this).html(data.header); - $('.library', $this).html(data.library); - $('.footer', $this).html(data.footer); + $this.html(data.library); + var settings = Drupal.settings.dndEnabledLibraries[editor.get(0).id]; var params = Drupal.wysiwyg.instances[editor.get(0).id]; + editor.trigger('wysiwygDetach', params); editor.trigger('wysiwygAttach', params); @@ -127,8 +82,44 @@ Drupal.settings.dndLibraryPreviews[preview_id] = data.library_previews[preview_id]; } - // Reattach behaviors - Drupal.behaviors.dndLibrary(); + // Add preview behavior to editor items (thanks, BeautyTips!) + $('.editor-item', $this).each(function () { + $(this).bt(Drupal.settings.dndLibraryPreviews[this.id], settings.bt_settings); + var hover_opts = $.extend({ + '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(); } + }, settings.libraryHoverIntentOpts); + $(this).hoverIntent(hover_opts); + }); + + // Preload images in editor representations + var cached = $.data($(editor), 'dnd_preload') || {}; + /*for (editor_id in Drupal.settings.dndEditorRepresentations) { + if (!cached[editor_id]) { + $representation = $(Drupal.settings.dndEditorRepresentations[editor_id].body); + if ($representation.is('img') && $representation.get(0).src) { + $representation.attr('src', $representation.get(0).src); + } else { + $('img', $representation).each(function() { + this.attr('src', this.src); + }); + } + } + } + $.data($(editor), 'dnd_preload', cached);*/ + } diff -r 37ca57016cbe -r 2d49adbd8992 modules/dnd_test/dnd-editor-item.tpl.php --- a/modules/dnd_test/dnd-editor-item.tpl.php Tue Mar 17 10:59:50 2009 -0500 +++ b/modules/dnd_test/dnd-editor-item.tpl.php Tue Mar 17 21:29:00 2009 -0500 @@ -1,1 +1,9 @@ - + + + + + + Lorem ipsum + + + diff -r 37ca57016cbe -r 2d49adbd8992 modules/dnd_test/dnd_test.module --- a/modules/dnd_test/dnd_test.module Tue Mar 17 10:59:50 2009 -0500 +++ b/modules/dnd_test/dnd_test.module Tue Mar 17 21:29:00 2009 -0500 @@ -30,7 +30,6 @@ $form['body_field']['body']['#dnd-enabled'] = TRUE; $form['body_field']['body']['#dnd-settings'] = array( 'drop_selector' => '#edit-body-dnd-library .drop', - 'callback' => 'dnd_test_dnd_library', 'url' => 'dnd-test/library/?json', ); $form['body_field']['body']['#rows'] = 28;