eads@1
|
1 <?php |
eads@1
|
2 |
eads@2
|
3 // A suffix for auto generated IDs |
franck@54
|
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@31
|
33 'dnd_library_wrapper' => array('arguments' => array('settings' => NULL, 'element' => NULL)), |
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 '#dnd-enabled' => FALSE, |
eads@2
|
47 '#dnd-settings' => NULL, |
eads@2
|
48 '#process' => array('form_expand_ahah', 'dnd_process_textarea'), |
eads@2
|
49 ); |
eads@2
|
50 return $type; |
eads@2
|
51 } |
eads@2
|
52 |
eads@2
|
53 /** |
eads@2
|
54 * Settings array: |
eads@21
|
55 * What should it take, if anything? Probably a source * maybe editor specific configuration shit? |
eads@2
|
56 * |
eads@2
|
57 * - source for library json/ajax shit |
eads@2
|
58 * - target selector |
eads@2
|
59 * - item selector |
eads@2
|
60 * |
eads@2
|
61 * perhaps like so: |
eads@2
|
62 * |
eads@2
|
63 * global => |
eads@2
|
64 * droppable targets |
eads@2
|
65 * library source for textarea |
eads@2
|
66 * |
eads@2
|
67 * tinymce/othereditor => |
eads@2
|
68 * target selector logic |
eads@2
|
69 * configuration options |
eads@2
|
70 * callback should be smart about attachment and detachment |
eads@2
|
71 */ |
eads@21
|
72 function dnd_process_textarea($element, $edit, $form_state, $form) { |
eads@2
|
73 if ($element['#dnd-enabled']) { |
eads@2
|
74 |
eads@2
|
75 $settings = array(); |
eads@2
|
76 |
eads@18
|
77 // We take a string or an object or an array |
eads@2
|
78 if (is_string($element['#dnd-settings'])) { |
eads@2
|
79 // @TODO load settings |
eads@2
|
80 } |
eads@2
|
81 else if (is_object($element['#dnd-settings'])) { |
eads@2
|
82 $settings = (array) $element['#dnd-settings']; |
eads@2
|
83 } |
eads@2
|
84 else if (is_array($element['#dnd-settings'])) { |
eads@2
|
85 $settings = $element['#dnd-settings']; |
eads@2
|
86 } |
eads@2
|
87 |
eads@2
|
88 $settings = array('library_id' => $element['#id'] . DND_ID_SUFFIX) + $settings; |
eads@2
|
89 |
eads@30
|
90 // BeautyTips |
eads@30
|
91 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/other_libs/excanvas_0002/excanvas-compressed.js'); |
eads@30
|
92 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/other_libs/jquery.hoverIntent.minified.js'); |
eads@30
|
93 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/bt/jquery.bt.js'); |
eads@7
|
94 |
eads@30
|
95 // Dependencies |
eads@30
|
96 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.url.packed.js'); |
eads@30
|
97 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.fieldselection.js'); |
eads@30
|
98 drupal_add_js('misc/jquery.form.js'); |
eads@28
|
99 |
eads@30
|
100 // Drag and drop |
eads@30
|
101 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/jquery.draganddrop.js'); |
eads@30
|
102 drupal_add_js(drupal_get_path('module', 'dnd') .'/js/dnd-library.js'); |
eads@28
|
103 |
eads@2
|
104 drupal_add_js(array( |
eads@2
|
105 'dndEnabledLibraries' => array($element['#id'] => $settings), |
eads@2
|
106 ), 'setting'); |
eads@2
|
107 |
eads@31
|
108 // Generate |
franck@34
|
109 $element['#prefix'] .= '<div class="dnd-library-wrapper" id="'. $settings['library_id'] .'"></div><div class="dnd-fields-wrapper">'; |
franck@34
|
110 $element['#suffix'] = '</div>'; |
franck@34
|
111 if (module_exists('mee')) { |
franck@34
|
112 drupal_add_css(drupal_get_path('module', 'mee') .'/css/mee.css'); |
franck@34
|
113 } |
eads@28
|
114 |
eads@2
|
115 } |
eads@2
|
116 return $element; |
eads@2
|
117 } |
eads@2
|
118 |
eads@29
|
119 /** |
eads@29
|
120 * Implementation of hook_wywiwyg_plugin(). |
eads@29
|
121 */ |
eads@30
|
122 function dnd_wysiwyg_plugin($editor, $version=0) { |
eads@30
|
123 $plugins = array(); |
eads@29
|
124 switch ($editor) { |
eads@29
|
125 case 'tinymce': |
eads@30
|
126 if ($version > 3) { |
eads@31
|
127 $plugins['forcecontainer'] = array( |
eads@31
|
128 'title' => t('Force Container Plugin'), |
eads@31
|
129 'description' => t('A custom plugin to forces a selection up to the outer container of a given element.'), |
eads@31
|
130 'extensions' => array('forcecontainer' => t('Force Container')), |
eads@31
|
131 'path' => drupal_get_path('module', 'dnd') .'/js/tinymce/forcecontainer/editor_plugin_src.js', |
eads@30
|
132 'load' => TRUE, |
eads@31
|
133 'options' => array( |
eads@31
|
134 'forcecontainer_class' => 'dnd-drop-wrapper', |
eads@31
|
135 'forcecontainer_trigger_dnd' => TRUE, |
eads@31
|
136 ), |
eads@30
|
137 ); |
eads@30
|
138 } |
eads@29
|
139 break; |
eads@29
|
140 } |
eads@30
|
141 return $plugins; |
eads@29
|
142 } |
eads@2
|
143 |
eads@2
|
144 |
eads@31
|
145 /** |
eads@31
|
146 * Theme the markup that will surround a library loaded via JSON. |
eads@31
|
147 */ |
eads@31
|
148 function theme_dnd_library_wrapper($settings, $element = NULL) { |
eads@31
|
149 return '<div id="'. $settings['library_id'] .'" class="dnd-library-wrapper"></div>'; |
eads@31
|
150 } |
eads@2
|
151 |