Mercurial > defr > drupal > scald > dnd
view dnd.module @ 30:2d49adbd8992
Start of applying a last layer of polish: starting the process of cleaning up the library code.
author | David Eads <eads@chicagotech.org> |
---|---|
date | Tue, 17 Mar 2009 21:29:00 -0500 |
parents | 37ca57016cbe |
children | 767ebf925654 |
line wrap: on
line source
<?php // A suffix for auto generated IDs define(DND_ID_SUFFIX, '-dnd-library'); /** * Implementation of hook_menu(). */ function dnd_menu() { $items = array(); $items['admin/settings/dnd'] = array( 'title' => 'Drag and Drop Library', 'page callback' => 'dnd_admin', 'description' => 'Configure drag-and-drop enabled textareas.', 'access arguments' => array('administer dnd'), 'file' => 'dnd.admin.inc', ); return $items; } /** * Implementation of hook_perm(). */ function dnd_perm() { return array('administer dnd'); } /** * Implementation of hook_theme(). */ function dnd_theme() { return array( 'dnd_library' => array('arguments' => array('library' => NULL, 'library_id' => NULL), 'template' => 'dnd-library'), ); } /** * Implementation of hook_elements(). * * Overload textareas. */ function dnd_elements() { $type = array(); $type['textarea'] = array( '#input' => TRUE, '#cols' => 60, '#rows' => 5, '#resizable' => TRUE, '#dnd-enabled' => FALSE, '#dnd-settings' => NULL, '#process' => array('form_expand_ahah', 'dnd_process_textarea'), ); return $type; } /** * Settings array: * What should it take, if anything? Probably a source * maybe editor specific configuration shit? * * - source for library json/ajax shit * - target selector * - item selector * * perhaps like so: * * global => * droppable targets * library source for textarea * * tinymce/othereditor => * target selector logic * configuration options * callback should be smart about attachment and detachment */ function dnd_process_textarea($element, $edit, $form_state, $form) { if ($element['#dnd-enabled']) { $settings = array(); // We take a string or an object or an array if (is_string($element['#dnd-settings'])) { // @TODO load settings } else if (is_object($element['#dnd-settings'])) { $settings = (array) $element['#dnd-settings']; } else if (is_array($element['#dnd-settings'])) { $settings = $element['#dnd-settings']; } $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'); // 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'); 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'); // Note that we brute force the wrapper $element['#suffix'] = '<div class="dnd-library-wrapper" id="'. $settings['library_id'] .'"></div>'. $element['#suffix']; } return $element; } function template_preprocess_dnd_library($library) {} /** * Implementation of hook_wywiwyg_plugin(). */ function dnd_wysiwyg_plugin($editor, $version=0) { $plugins = array(); switch ($editor) { case 'tinymce': 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; }