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@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 '#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@31
|
112 // Generate |
franck@34
|
113 $element['#prefix'] .= '<div class="dnd-library-wrapper" id="'. $settings['library_id'] .'"></div><div class="dnd-fields-wrapper">'; |
franck@34
|
114 $element['#suffix'] = '</div>'; |
franck@34
|
115 if (module_exists('mee')) { |
franck@34
|
116 drupal_add_css(drupal_get_path('module', 'mee') .'/css/mee.css'); |
franck@34
|
117 } |
eads@28
|
118 |
eads@2
|
119 } |
eads@2
|
120 return $element; |
eads@2
|
121 } |
eads@2
|
122 |
eads@29
|
123 /** |
eads@29
|
124 * Implementation of hook_wywiwyg_plugin(). |
eads@29
|
125 */ |
eads@30
|
126 function dnd_wysiwyg_plugin($editor, $version=0) { |
eads@30
|
127 $plugins = array(); |
eads@29
|
128 switch ($editor) { |
eads@29
|
129 case 'tinymce': |
eads@30
|
130 if ($version > 3) { |
eads@31
|
131 $plugins['forcecontainer'] = array( |
eads@31
|
132 'title' => t('Force Container Plugin'), |
eads@31
|
133 'description' => t('A custom plugin to forces a selection up to the outer container of a given element.'), |
eads@31
|
134 'extensions' => array('forcecontainer' => t('Force Container')), |
eads@31
|
135 'path' => drupal_get_path('module', 'dnd') .'/js/tinymce/forcecontainer/editor_plugin_src.js', |
eads@30
|
136 'load' => TRUE, |
eads@31
|
137 'options' => array( |
eads@31
|
138 'forcecontainer_class' => 'dnd-drop-wrapper', |
eads@31
|
139 'forcecontainer_trigger_dnd' => TRUE, |
eads@31
|
140 ), |
eads@30
|
141 ); |
eads@30
|
142 } |
eads@29
|
143 break; |
eads@29
|
144 } |
eads@30
|
145 return $plugins; |
eads@29
|
146 } |
eads@31
|
147 |
eads@31
|
148 |
eads@31
|
149 /** |
eads@31
|
150 * Theme the markup that will surround a library loaded via JSON. |
eads@31
|
151 */ |
eads@31
|
152 function theme_dnd_library_wrapper($settings, $element = NULL) { |
eads@31
|
153 return '<div id="'. $settings['library_id'] .'" class="dnd-library-wrapper"></div>'; |
eads@31
|
154 } |
eads@31
|
155 |