comparison popups.module @ 2:c076d54409cb

Popus: Version RF
author Franck Deroche <franck@defr.org>
date Fri, 31 Dec 2010 13:46:12 +0100
parents 76f9b43738f2
children
comparison
equal deleted inserted replaced
0:76f9b43738f2 2:c076d54409cb
151 $js = array_merge_recursive(drupal_add_js(), drupal_add_js(NULL, NULL, 'footer')); 151 $js = array_merge_recursive(drupal_add_js(), drupal_add_js(NULL, NULL, 'footer'));
152 $query_string = '?'. substr(variable_get('css_js_query_string', '0'), 0, 1); 152 $query_string = '?'. substr(variable_get('css_js_query_string', '0'), 0, 1);
153 153
154 $popup_js = array(); 154 $popup_js = array();
155 155
156 // Allow modules to specifically alter the JS used in a popup.
157 drupal_alter('popups_js', $js);
158 if (module_exists('jquery_update')) {
159 $replacements = jquery_update_get_replacements();
160 $path = drupal_get_path('module', 'jquery_update') .'/replace/';
161 foreach($replacements as $type => $data) {
162 foreach($data as $src => $dst) {
163 $replacements[$type][$src] = $path . $dst;
164 }
165 }
166 // The behavior got called, so we're pretty sure that jQuery is already
167 // loaded.
168 unset($js['core']['misc/jquery.js']);
169 unset($js['core']['misc/drupal.js']);
170 }
171 else {
172 $replacements = array();
173 }
174
156 foreach ($js as $type => $data) { 175 foreach ($js as $type => $data) {
157 if (!$data) continue; 176 if (!$data) continue;
158 switch ($type) { 177 switch ($type) {
159 case 'setting': 178 case 'setting':
160 // Why not just array_merge_recursive($data); 179 // Why not just array_merge_recursive($data);
165 $popup_js['inline'][] = '<script type="text/javascript"' . ($info['defer'] ? ' defer="defer"' : '') . '>' . $info['code'] . "</script>\n"; 184 $popup_js['inline'][] = '<script type="text/javascript"' . ($info['defer'] ? ' defer="defer"' : '') . '>' . $info['code'] . "</script>\n";
166 } 185 }
167 break; 186 break;
168 default: 187 default:
169 foreach ($data as $path => $info) { 188 foreach ($data as $path => $info) {
189 $path = isset($replacements[$type][$path]) ? $replacements[$type][$path] : $path;
170 $popup_js[$type][$path] = '<script type="text/javascript"'. ($info['defer'] ? ' defer="defer"' : '') .' src="'. base_path() . $path . $query_string ."\"></script>\n"; 190 $popup_js[$type][$path] = '<script type="text/javascript"'. ($info['defer'] ? ' defer="defer"' : '') .' src="'. base_path() . $path . $query_string ."\"></script>\n";
171 } 191 }
172 break; 192 break;
173 } 193 }
174 } 194 }
271 * @param array $rules: Array of rules to apply to the page or form, keyed by jQuery link selector. 291 * @param array $rules: Array of rules to apply to the page or form, keyed by jQuery link selector.
272 * See README.txt for a listing of the options, and popups_admin.module for examples. 292 * See README.txt for a listing of the options, and popups_admin.module for examples.
273 */ 293 */
274 function popups_add_popups($rules=NULL) { 294 function popups_add_popups($rules=NULL) {
275 static $added = FALSE; 295 static $added = FALSE;
296 static $shouldAdd = NULL;
297 if (is_null($shouldAdd)) {
298 $shouldAdd = !isset($_SERVER['HTTP_X_REQUESTED_WITH']) || $_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest' || $_SESSION['page_override'];
299 }
276 $settings = array('popups' => array()); 300 $settings = array('popups' => array());
277 301
278 if (is_array($rules)) { 302 if (is_array($rules)) {
279 $settings['popups']['links'] = array(); 303 $settings['popups']['links'] = array();
280 foreach ($rules as $popup_selector => $options) { 304 foreach ($rules as $popup_selector => $options) {
287 } 311 }
288 if($added) { 312 if($added) {
289 drupal_add_js( $settings, 'setting' ); 313 drupal_add_js( $settings, 'setting' );
290 } 314 }
291 } 315 }
292 if (!$added) { 316 if (!$added && $shouldAdd) {
293 // Determing if we are showing the default theme or a custom theme. 317 // Determing if we are showing the default theme or a custom theme.
294 global $custom_theme; 318 global $custom_theme;
295 $theme = $custom_theme; 319 $theme = $custom_theme;
296 if (!$theme) { 320 if (!$theme) {
297 $theme = variable_get('theme_default','none'); 321 $theme = variable_get('theme_default','none');