Mercurial > defr > drupal > scald > dnd
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 27:9a92410be362 | 28:7d6bf2dca269 |
|---|---|
| 28 /** | 28 /** |
| 29 * Implementation of hook_theme(). | 29 * Implementation of hook_theme(). |
| 30 */ | 30 */ |
| 31 function dnd_theme() { | 31 function dnd_theme() { |
| 32 return array( | 32 return array( |
| 33 'dnd_library' => array('arguments' => array('element' => NULL, 'settings' => NULL), 'template' => 'dnd-library'), | 33 'dnd_library' => array('arguments' => array('library' => NULL, 'library_id' => NULL), 'template' => 'dnd-library'), |
| 34 ); | 34 ); |
| 35 } | 35 } |
| 36 | 36 |
| 37 | 37 |
| 38 /** | 38 /** |
| 74 * callback should be smart about attachment and detachment | 74 * callback should be smart about attachment and detachment |
| 75 */ | 75 */ |
| 76 function dnd_process_textarea($element, $edit, $form_state, $form) { | 76 function dnd_process_textarea($element, $edit, $form_state, $form) { |
| 77 if ($element['#dnd-enabled']) { | 77 if ($element['#dnd-enabled']) { |
| 78 | 78 |
| 79 // BeautyTips | |
| 80 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/other_libs/excanvas_0002/excanvas-compressed.js'); | |
| 81 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/other_libs/jquery.hoverIntent.minified.js'); | |
| 82 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/jquery.bt.js'); | |
| 83 | |
| 84 // Dependencies | |
| 85 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.url.packed.js'); | |
| 86 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.fieldselection.js'); | |
| 87 drupal_add_js('misc/jquery.form.js'); | |
| 88 | |
| 89 // Drag and drop | |
| 90 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.draganddrop.js'); | |
| 91 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/dnd-library.js'); | |
| 92 | |
| 93 $settings = array(); | 79 $settings = array(); |
| 94 | 80 |
| 95 // We take a string or an object or an array | 81 // We take a string or an object or an array |
| 96 if (is_string($element['#dnd-settings'])) { | 82 if (is_string($element['#dnd-settings'])) { |
| 97 // @TODO load settings | 83 // @TODO load settings |
| 102 else if (is_array($element['#dnd-settings'])) { | 88 else if (is_array($element['#dnd-settings'])) { |
| 103 $settings = $element['#dnd-settings']; | 89 $settings = $element['#dnd-settings']; |
| 104 } | 90 } |
| 105 | 91 |
| 106 // Set some important defaults | 92 // Set some important defaults |
| 107 $settings = array('library_id' => $element['#id'] . DND_ID_SUFFIX) + $settings; | 93 if (function_exists($settings['callback']) && ($library = $settings['callback']($element))) { |
| 94 $settings = array('library_id' => $element['#id'] . DND_ID_SUFFIX) + $settings; | |
| 95 unset($settings['callback']); | |
| 108 | 96 |
| 109 // Add enabled libraries to settings for tracking | 97 // BeautyTips |
| 110 drupal_add_js(array( | 98 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/other_libs/excanvas_0002/excanvas-compressed.js'); |
| 111 'dndEnabledLibraries' => array($element['#id'] => $settings), | 99 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/other_libs/jquery.hoverIntent.minified.js'); |
| 112 ), 'setting'); | 100 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/jquery.bt.js'); |
| 113 | 101 |
| 114 $element['#suffix'] = theme('dnd_library', $element, $settings) . $element['#suffix']; | 102 // Dependencies |
| 103 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.url.packed.js'); | |
| 104 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.fieldselection.js'); | |
| 105 drupal_add_js('misc/jquery.form.js'); | |
| 106 | |
| 107 // Drag and drop | |
| 108 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.draganddrop.js'); | |
| 109 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/dnd-library.js'); | |
| 110 | |
| 111 drupal_add_js(array( | |
| 112 'dndEnabledLibraries' => array($element['#id'] => $settings), | |
| 113 ), 'setting'); | |
| 114 | |
| 115 // Store editor representations in Drupal setting | |
| 116 drupal_add_js(array( | |
| 117 'dndEditorRepresentations' => $library['editor_representations'], | |
| 118 'dndLibraryPreviews' => $library['library_previews'], | |
| 119 ), 'setting'); | |
| 120 | |
| 121 $element['#suffix'] = theme('dnd_library', $library['library'], $settings['library_id']) . $element['#suffix']; | |
| 122 } | |
| 123 | |
| 115 } | 124 } |
| 116 return $element; | 125 return $element; |
| 117 } | 126 } |
| 118 | 127 |
| 119 /** | 128 function template_preprocess_dnd_library($library) {} |
| 120 * Drag and drop library template preprocessor. | |
| 121 */ | |
| 122 function template_preprocess_dnd_library(&$variables) { | |
| 123 global $base_url; | |
| 124 list($element, $settings) = array($variables['element'], $variables['settings']); | |
| 125 | |
| 126 // Get library via a backdoor HTTP request. This is plenty fast for this | |
| 127 // application and keeps things nice and consistent. | |
| 128 if (!($url = parse_url($settings['url']))) { | |
| 129 return t('This library is not available'); | |
| 130 } | |
| 131 | |
| 132 // Handle both relative and absolute urls | |
| 133 if (!isset($url['scheme'])) { | |
| 134 $settings['url'] = $base_url .'/'. $settings['url']; | |
| 135 } | |
| 136 | |
| 137 $request = drupal_http_request($settings['url']); | |
| 138 | |
| 139 // We must remove some Drupal escaping | |
| 140 $json = json_decode(str_replace(array('\x3c', '\x3e', '\x26', "\'"), array("<", ">", "&", "'"), $request->data), TRUE); | |
| 141 | |
| 142 // Generate an array of editor representations to add | |
| 143 if (is_array($json['editor_representations'])) { | |
| 144 foreach ($json['editor_representations'] as $editor_id=>$editor_item) { | |
| 145 $editor_representations[$editor_id] = $editor_item; | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 // Generate an array of library previews to add | |
| 150 if (is_array($json['library_previews'])) { | |
| 151 foreach ($json['library_previews'] as $preview_id=>$preview_item) { | |
| 152 $library_previews[$preview_id] = $preview_item; | |
| 153 } | |
| 154 } | |
| 155 | |
| 156 // Store editor representations in Drupal setting | |
| 157 drupal_add_js(array( | |
| 158 'dndEditorRepresentations' => $editor_representations, | |
| 159 'dndLibraryPreviews' => $library_previews, | |
| 160 ), 'setting'); | |
| 161 | |
| 162 $variables['library_id'] = $settings['library_id']; | |
| 163 $variables['header'] = $json['header']; | |
| 164 $variables['library'] = $json['library']; | |
| 165 $variables['footer'] = $json['footer']; | |
| 166 } |
