Mercurial > defr > drupal > scald > dnd
diff dnd.module @ 28:7d6bf2dca269
Completely broken library registration, fixed a typo.
author | David Eads <eads@chicagotech.org> |
---|---|
date | Tue, 17 Mar 2009 06:25:47 -0500 |
parents | 9a92410be362 |
children | 37ca57016cbe |
line wrap: on
line diff
--- a/dnd.module Fri Mar 13 19:34:05 2009 -0500 +++ b/dnd.module Tue Mar 17 06:25:47 2009 -0500 @@ -30,7 +30,7 @@ */ function dnd_theme() { return array( - 'dnd_library' => array('arguments' => array('element' => NULL, 'settings' => NULL), 'template' => 'dnd-library'), + 'dnd_library' => array('arguments' => array('library' => NULL, 'library_id' => NULL), 'template' => 'dnd-library'), ); } @@ -76,20 +76,6 @@ function dnd_process_textarea($element, $edit, $form_state, $form) { if ($element['#dnd-enabled']) { - // 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'); - $settings = array(); // We take a string or an object or an array @@ -104,63 +90,39 @@ } // Set some important defaults - $settings = array('library_id' => $element['#id'] . DND_ID_SUFFIX) + $settings; + if (function_exists($settings['callback']) && ($library = $settings['callback']($element))) { + $settings = array('library_id' => $element['#id'] . DND_ID_SUFFIX) + $settings; + unset($settings['callback']); - // Add enabled libraries to settings for tracking - drupal_add_js(array( - 'dndEnabledLibraries' => array($element['#id'] => $settings), - ), 'setting'); + // 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'); - $element['#suffix'] = theme('dnd_library', $element, $settings) . $element['#suffix']; + // 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'); + + $element['#suffix'] = theme('dnd_library', $library['library'], $settings['library_id']) . $element['#suffix']; + } + } return $element; } -/** - * Drag and drop library template preprocessor. - */ -function template_preprocess_dnd_library(&$variables) { - global $base_url; - list($element, $settings) = array($variables['element'], $variables['settings']); - - // Get library via a backdoor HTTP request. This is plenty fast for this - // application and keeps things nice and consistent. - if (!($url = parse_url($settings['url']))) { - return t('This library is not available'); - } - - // Handle both relative and absolute urls - if (!isset($url['scheme'])) { - $settings['url'] = $base_url .'/'. $settings['url']; - } - - $request = drupal_http_request($settings['url']); - - // We must remove some Drupal escaping - $json = json_decode(str_replace(array('\x3c', '\x3e', '\x26', "\'"), array("<", ">", "&", "'"), $request->data), TRUE); - - // Generate an array of editor representations to add - if (is_array($json['editor_representations'])) { - foreach ($json['editor_representations'] as $editor_id=>$editor_item) { - $editor_representations[$editor_id] = $editor_item; - } - } - - // Generate an array of library previews to add - if (is_array($json['library_previews'])) { - foreach ($json['library_previews'] as $preview_id=>$preview_item) { - $library_previews[$preview_id] = $preview_item; - } - } - - // Store editor representations in Drupal setting - drupal_add_js(array( - 'dndEditorRepresentations' => $editor_representations, - 'dndLibraryPreviews' => $library_previews, - ), 'setting'); - - $variables['library_id'] = $settings['library_id']; - $variables['header'] = $json['header']; - $variables['library'] = $json['library']; - $variables['footer'] = $json['footer']; -} +function template_preprocess_dnd_library($library) {}