/[drupal]/contributions/sandbox/thox/ajax/ajax.module
ViewVC logotype

Contents of /contributions/sandbox/thox/ajax/ajax.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download) (as text)
Mon Jul 18 13:57:56 2005 UTC (4 years, 4 months ago) by thox
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +1 -7 lines
File MIME type: text/x-php
- Renamed autocomplete.css to drupal.css
- Moved the theme_add_style() call
1 <?php
2
3 function ajax_help($section = '') {
4 $output = '';
5
6 switch ($section) {
7 case 'admin/modules/ajax':
8 case 'admin/modules#description':
9 $output = t('Introduces Ajax features to Drupal 4.6.');
10 break;
11 }
12 return $output;
13 }
14
15
16 /**
17 * Add a JavaScript file to the output.
18 *
19 * The first time this function is invoked per page request,
20 * it adds "misc/drupal.js" to the output. Other scripts
21 * depends on the 'killswitch' inside it.
22 */
23 if (!function_exists('drupal_add_js')) {
24 function drupal_add_js($file) {
25 static $sent = array();
26 $module_path = drupal_get_path('module', 'ajax');
27 if (!isset($sent[$module_path.'/drupal.js'])) {
28 drupal_set_html_head('<script type="text/javascript" src="'.$module_path.'/drupal.js"></script>');
29 $sent[$module_path.'/drupal.js'] = true;
30 theme_add_style($module_path.'/drupal.css');
31 }
32 if (!isset($sent[$file])) {
33 drupal_set_html_head('<script type="text/javascript" src="'. check_url($file) .'"></script>');
34 $sent[$file] = true;
35 }
36 }
37 }
38
39 /**
40 * Format a single-line text field that uses Ajax for autocomplete.
41 *
42 * @param $title
43 * The label for the text field.
44 * @param $name
45 * The internal name used to refer to the field.
46 * @param $value
47 * The initial value for the field at page load time.
48 * @param $size
49 * A measure of the visible size of the field (passed directly to HTML).
50 * @param $maxlength
51 * The maximum number of characters that may be entered in the field.
52 * @param $callback_path
53 * A drupal path for the Ajax autocomplete callback.
54 * @param $description
55 * Explanatory text to display after the form item.
56 * @param $attributes
57 * An associative array of HTML attributes to add to the form item.
58 * @param $required
59 * Whether the user must enter some text in the field.
60 * @return
61 * A themed HTML string representing the field.
62 */
63 if (!function_exists('form_autocomplete')) {
64 function form_autocomplete($title, $name, $value, $size, $maxlength, $callback_path, $description = NULL, $attributes = NULL, $required = FALSE) {
65 $module_path = drupal_get_path('module', 'ajax');
66
67 drupal_add_js($module_path.'/autocomplete.js');
68
69 $size = $size ? ' size="'. $size .'"' : '';
70
71 $output = theme('form_element', $title, '<input type="text" maxlength="'. $maxlength .'" class="'. _form_get_class('form-text form-autocomplete', $required, _form_get_error($name)) .'" name="edit['. $name .']" id="edit-'. $name .'"'. $size .' value="'. check_plain($value) .'"'. drupal_attributes($attributes) .' />', $description, 'edit-'. $name, $required, _form_get_error($name));
72 $output .= '<input class="autocomplete" type="hidden" id="edit-'. $name .'-autocomplete" value="'. check_url(url($callback_path, NULL, NULL, TRUE)) .'" disabled="disabled" />';
73
74 return $output;
75 }
76 }
77
78 /**
79 * Format a group of form items.
80 *
81 * @param $legend
82 * The label for the form item group.
83 * @param $group
84 * The form items within the group, as an HTML string.
85 * @param $collapsed
86 * A boolean value decided whether the group starts collapsed.
87 * @param $description
88 * Explanatory text to display after the form item group.
89 * @param $attributes
90 * An associative array of HTML attributes to add to the fieldset tag.
91 * @return
92 * A themed HTML string representing the form item group.
93 */
94 if (!function_exists('form_group_collapsible')) {
95 function form_group_collapsible($legend, $group, $collapsed = FALSE, $description = NULL, $attributes = NULL) {
96 $module_path = drupal_get_path('module', 'ajax');
97 drupal_add_js($module_path . '/collapse.js');
98
99 $attributes['class'] .= ' collapsible';
100 if ($collapsed) {
101 $attributes['class'] .= ' collapsed';
102 }
103
104 return '<fieldset' . drupal_attributes($attributes) .'>' . ($legend ? '<legend>'. $legend .'</legend>' : '') . $group . ($description ? '<div class="description">'. $description .'</div>' : '') . "</fieldset>\n";
105 }
106 }
107
108 /**
109 * Returns the path to a system item (module, theme, etc.).
110 *
111 * @param $type
112 * The type of the item (i.e. theme, theme_engine, module).
113 * @param $name
114 * The name of the item for which the path is requested.
115 *
116 * @return
117 * The path to the requested item.
118 */
119 if (!function_exists('drupal_get_path')) {
120 function drupal_get_path($type, $name) {
121 return dirname(drupal_get_filename($type, $name));
122 }
123 }
124
125 /**
126 * Returns and optionally sets the filename for a system item (module,
127 * theme, etc.). The filename, whether provided, cached, or retrieved
128 * from the database, is only returned if the file exists.
129 *
130 * @param $type
131 * The type of the item (i.e. theme, theme_engine, module).
132 * @param $name
133 * The name of the item for which the filename is requested.
134 * @param $filename
135 * The filename of the item if it is to be set explicitly rather
136 * than by consulting the database.
137 *
138 * @return
139 * The filename of the requested item.
140 */
141 if (!function_exists('drupal_get_filename')) {
142 function drupal_get_filename($type, $name, $filename = NULL) {
143 static $files = array();
144
145 if (!$files[$type]) {
146 $files[$type] = array();
147 }
148
149 if ($filename && file_exists($filename)) {
150 $files[$type][$name] = $filename;
151 }
152 elseif ($files[$type][$name]) {
153 // nothing
154 }
155 elseif (($file = db_result(db_query("SELECT filename FROM {system} WHERE name = '%s' AND type = '%s'", $name, $type))) && file_exists($file)) {
156 $files[$type][$name] = $file;
157 }
158 else {
159 $config = conf_init();
160 $dir = (($type == 'theme_engine') ? 'themes/engines' : "${type}s");
161 $file = (($type == 'theme_engine') ? "$name.engine" : "$name.$type");
162
163 foreach (array("$config/$dir/$file", "$config/$dir/$name/$file", "$dir/$file", "$dir/$name/$file") as $file) {
164 if (file_exists($file)) {
165 $files[$type][$name] = $file;
166 break;
167 }
168 }
169 }
170
171 return $files[$type][$name];
172 }
173 }
174
175 ?>

  ViewVC Help
Powered by ViewVC 1.1.2