eads@1
|
1 <?php |
eads@1
|
2 |
eads@2
|
3 // A suffix for auto generated IDs |
eads@2
|
4 define(DND_ID_SUFFIX, '-dnd-library'); |
eads@2
|
5 |
eads@1
|
6 /** |
eads@1
|
7 * Implementation of hook_menu(). |
eads@1
|
8 */ |
eads@1
|
9 function dnd_menu() { |
eads@1
|
10 $items = array(); |
eads@1
|
11 $items['admin/settings/dnd'] = array( |
eads@1
|
12 'title' => 'Drag and Drop Library', |
eads@1
|
13 'page callback' => 'dnd_admin', |
eads@1
|
14 'description' => 'Configure drag-and-drop enabled textareas.', |
eads@1
|
15 'access arguments' => array('administer dnd'), |
eads@1
|
16 'file' => 'dnd.admin.inc', |
eads@1
|
17 ); |
eads@1
|
18 return $items; |
eads@1
|
19 } |
eads@1
|
20 |
eads@1
|
21 /** |
eads@1
|
22 * Implementation of hook_perm(). |
eads@1
|
23 */ |
eads@1
|
24 function dnd_perm() { |
eads@1
|
25 return array('administer dnd'); |
eads@1
|
26 } |
eads@2
|
27 |
eads@2
|
28 /** |
eads@2
|
29 * Implementation of hook_theme(). |
eads@2
|
30 */ |
eads@2
|
31 function dnd_theme() { |
eads@2
|
32 return array( |
eads@28
|
33 'dnd_library' => array('arguments' => array('library' => NULL, 'library_id' => NULL), 'template' => 'dnd-library'), |
eads@2
|
34 ); |
eads@2
|
35 } |
eads@2
|
36 |
eads@2
|
37 |
eads@2
|
38 /** |
eads@2
|
39 * Implementation of hook_elements(). |
eads@2
|
40 * |
eads@2
|
41 * Overload textareas. |
eads@2
|
42 */ |
eads@2
|
43 function dnd_elements() { |
eads@2
|
44 $type = array(); |
eads@2
|
45 $type['textarea'] = array( |
eads@2
|
46 '#input' => TRUE, |
eads@2
|
47 '#cols' => 60, |
eads@2
|
48 '#rows' => 5, |
eads@2
|
49 '#resizable' => TRUE, |
eads@2
|
50 '#dnd-enabled' => FALSE, |
eads@2
|
51 '#dnd-settings' => NULL, |
eads@2
|
52 '#process' => array('form_expand_ahah', 'dnd_process_textarea'), |
eads@2
|
53 ); |
eads@2
|
54 return $type; |
eads@2
|
55 } |
eads@2
|
56 |
eads@2
|
57 /** |
eads@2
|
58 * Settings array: |
eads@21
|
59 * What should it take, if anything? Probably a source * maybe editor specific configuration shit? |
eads@2
|
60 * |
eads@2
|
61 * - source for library json/ajax shit |
eads@2
|
62 * - target selector |
eads@2
|
63 * - item selector |
eads@2
|
64 * |
eads@2
|
65 * perhaps like so: |
eads@2
|
66 * |
eads@2
|
67 * global => |
eads@2
|
68 * droppable targets |
eads@2
|
69 * library source for textarea |
eads@2
|
70 * |
eads@2
|
71 * tinymce/othereditor => |
eads@2
|
72 * target selector logic |
eads@2
|
73 * configuration options |
eads@2
|
74 * callback should be smart about attachment and detachment |
eads@2
|
75 */ |
eads@21
|
76 function dnd_process_textarea($element, $edit, $form_state, $form) { |
eads@2
|
77 if ($element['#dnd-enabled']) { |
eads@20
|
78 |
eads@2
|
79 $settings = array(); |
eads@2
|
80 |
eads@18
|
81 // We take a string or an object or an array |
eads@2
|
82 if (is_string($element['#dnd-settings'])) { |
eads@2
|
83 // @TODO load settings |
eads@2
|
84 } |
eads@2
|
85 else if (is_object($element['#dnd-settings'])) { |
eads@2
|
86 $settings = (array) $element['#dnd-settings']; |
eads@2
|
87 } |
eads@2
|
88 else if (is_array($element['#dnd-settings'])) { |
eads@2
|
89 $settings = $element['#dnd-settings']; |
eads@2
|
90 } |
eads@2
|
91 |
eads@30
|
92 $settings = array('library_id' => $element['#id'] . DND_ID_SUFFIX) + $settings; |
eads@2
|
93 |
eads@30
|
94 // BeautyTips |
eads@30
|
95 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/other_libs/excanvas_0002/excanvas-compressed.js'); |
eads@30
|
96 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/other_libs/jquery.hoverIntent.minified.js'); |
eads@30
|
97 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/jquery.bt.js'); |
eads@2
|
98 |
eads@30
|
99 // Dependencies |
eads@30
|
100 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.url.packed.js'); |
eads@30
|
101 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.fieldselection.js'); |
eads@30
|
102 drupal_add_js('misc/jquery.form.js'); |
eads@28
|
103 |
eads@30
|
104 // Drag and drop |
eads@30
|
105 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.draganddrop.js'); |
eads@30
|
106 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/dnd-library.js'); |
eads@28
|
107 |
eads@30
|
108 drupal_add_js(array( |
eads@30
|
109 'dndEnabledLibraries' => array($element['#id'] => $settings), |
eads@30
|
110 ), 'setting'); |
eads@28
|
111 |
eads@30
|
112 // Store editor representations in Drupal setting |
eads@30
|
113 drupal_add_js(array( |
eads@30
|
114 'dndEditorRepresentations' => $library['editor_representations'], |
eads@30
|
115 'dndLibraryPreviews' => $library['library_previews'], |
eads@30
|
116 ), 'setting'); |
eads@30
|
117 |
eads@30
|
118 // Note that we brute force the wrapper |
eads@30
|
119 $element['#suffix'] = '<div class="dnd-library-wrapper" id="'. $settings['library_id'] .'"></div>'. $element['#suffix']; |
eads@28
|
120 |
eads@2
|
121 } |
eads@2
|
122 return $element; |
eads@2
|
123 } |
eads@2
|
124 |
eads@28
|
125 function template_preprocess_dnd_library($library) {} |
eads@29
|
126 |
eads@29
|
127 /** |
eads@29
|
128 * Implementation of hook_wywiwyg_plugin(). |
eads@29
|
129 */ |
eads@30
|
130 function dnd_wysiwyg_plugin($editor, $version=0) { |
eads@30
|
131 $plugins = array(); |
eads@29
|
132 switch ($editor) { |
eads@29
|
133 case 'tinymce': |
eads@30
|
134 if ($version > 3) { |
eads@30
|
135 $plugins['atomic'] = array( |
eads@30
|
136 'type' => 'external', |
eads@30
|
137 'title' => t('Atomic selection plugin'), |
eads@30
|
138 '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.'), |
eads@30
|
139 'extensions' => array('atomic' => t('Atomic Selection')), |
eads@30
|
140 'path' => drupal_get_path('module', 'dnd') .'/js/tinymce/atomic/editor_plugin.js', |
eads@30
|
141 'url' => 'http://sourceforge.net/tracker/index.php?func=detail&aid=2519211&group_id=103281&atid=738747', |
eads@30
|
142 'load' => TRUE, |
eads@30
|
143 ); |
eads@30
|
144 $plugins['noneditable'] = array( |
eads@30
|
145 'path' => drupal_get_path('module', 'wysiwyg') .'/tinymce/jscripts/tiny_mce/plugins/noneditable/editor_plugin.js', |
eads@30
|
146 'extensions' => array('noneditable' => t('Noneditable')), |
eads@30
|
147 'load' => TRUE, |
eads@30
|
148 ); |
eads@30
|
149 } |
eads@29
|
150 break; |
eads@29
|
151 } |
eads@30
|
152 return $plugins; |
eads@29
|
153 } |