@@ -87,17 +87,14 @@ function jquery_update_library_alter(&$javascript, $module) {
87
87
$cdn = variable_get('jquery_update_jquery_cdn', 'none');
88
88
89
89
// Replace jQuery with the alternative version.
90
- $admin_version = variable_get('jquery_update_jquery_admin_version', '');
91
-
92
- if (!empty($admin_version) && path_is_admin(current_path())) {
93
- if (version_compare($version, $admin_version, '!=')) {
94
- $version = $admin_version;
95
- }
90
+ $theme_version = theme_get_setting('jquery_update_jquery_version');
91
+ if ($theme_version && version_compare($version, $theme_version, '!=')) {
92
+ $version = $theme_version;
96
93
}
97
94
// If the ajax version is set then that one always win.
98
95
if (!empty($_POST['ajax_page_state']['jquery_version'])) {
99
96
$ajax_version = $_POST['ajax_page_state']['jquery_version'];
100
- if (in_array( $ajax_version, array( 'default', '1.5', '1.6', '1.7', '1.8', '1.9', '1.10' ))) {
97
+ if ($ajax_version == 'default' || in_array($ajax_version, jquery_update_get_versions( ))) {
101
98
$version = $ajax_version;
102
99
}
103
100
}
@@ -172,34 +169,89 @@ function jquery_update_settings_form() {
172
169
'#title' => t('Version options'),
173
170
);
174
171
172
+ $default_version = variable_get('jquery_update_jquery_version', '1.10');
173
+ $version_options = jquery_update_get_version_options(FALSE);
175
174
$form['version_options']['jquery_update_jquery_version'] = array(
176
175
'#type' => 'select',
177
- '#title' => t('Default jQuery Version'),
178
- '#options' => array(
179
- 'default' => t('Default (provided by Drupal)'),
180
- '1.5' => '1.5',
181
- '1.7' => '1.7',
182
- '1.8' => '1.8',
183
- '1.9' => '1.9',
184
- '1.10' => '1.10',
185
- ),
186
- '#default_value' => variable_get('jquery_update_jquery_version', '1.10'),
187
- '#description' => t('Select which jQuery version to use by default.'),
176
+ '#title' => t('Site default jQuery version'),
177
+ '#options' => $version_options,
178
+ '#default_value' => $default_version,
179
+ '#description' => t('Select which version of jQuery to use on the site.'),
188
180
);
189
181
190
- $form['version_options']['jquery_update_jquery_admin_version'] = array(
191
- '#type' => 'select',
192
- '#title' => t('Alternate jQuery version for administrative pages'),
193
- '#options' => array(
194
- '' => t('Default jQuery Version'),
195
- 'default' => t('Default (provided by Drupal)'),
196
- '1.5' => '1.5',
197
- '1.7' => '1.7',
198
- '1.8' => '1.8',
199
- '1.10' => '1.10',
200
- ),
201
- '#default_value' => variable_get('jquery_update_jquery_admin_version', ''),
202
- '#description' => t('Optionally select a different version of jQuery to use on administrative pages.'),
182
+ $themes = list_themes();
183
+ $theme_default = variable_get('theme_default', FALSE);
184
+ $admin_theme = variable_get('admin_theme', FALSE);
185
+ $header = array(t('Theme'), t('jQuery version'), t('Operations'));
186
+ $rows = array();
187
+ $themes_collapsed = TRUE;
188
+ // Go through all themes.
189
+ foreach ($themes as $theme_key => $theme) {
190
+ // Skip disabled themes, but only if they are not configured as admin
191
+ // theme. This is an inconsistency in drupal core, that you can select a
192
+ // disabled theme as admin theme.
193
+ if (!$theme->status && $theme_key !== $admin_theme) {
194
+ continue;
195
+ }
196
+
197
+ // Retrieve the version jQuery for this theme.
198
+ $theme_version = theme_get_setting('jquery_update_jquery_version', $theme_key);
199
+ // Do not collapse the fieldset if a theme has set a jQuery version.
200
+ if ($theme_version) {
201
+ $themes_collapsed = FALSE;
202
+ }
203
+
204
+ // Replace or modify the version name to be displayed.
205
+ if (empty($theme_version)) {
206
+ $theme_version = t('Site Default');
207
+ }
208
+ elseif (in_array($theme_version, array_keys($version_options))) {
209
+ $theme_version = $version_options[$theme_version];
210
+ }
211
+ else {
212
+ $theme_version .= ' (' . t('unknown version') . ')';
213
+ }
214
+
215
+ // Provide additional information for default and admin themes.
216
+ $theme_name = $theme->info['name'];
217
+ if ($theme_key === $theme_default && ($theme_key === $admin_theme || empty($admin_theme))) {
218
+ $theme_name .= ' (' . t('default/admin theme') . ')';
219
+ }
220
+ elseif ($theme_key === $theme_default) {
221
+ $theme_name .= ' (' . t('default theme') . ')';
222
+ }
223
+ elseif ($theme_key === $admin_theme) {
224
+ $theme_name .= ' (' . t('admin theme') . ')';
225
+ }
226
+
227
+ // Construct the table row.
228
+ $rows[] = array(
229
+ $theme_name,
230
+ $theme_version,
231
+ l(t('Configure'), 'admin/appearance/settings/' . $theme_key, array(
232
+ 'attributes' => array(
233
+ 'class' => array(
234
+ 'module-link',
235
+ 'module-link-configure',
236
+ ),
237
+ ),
238
+ 'query' => drupal_get_destination(),
239
+ 'fragment' => 'edit-jquery-update',
240
+ )),
241
+ );
242
+ }
243
+
244
+ $form['version_options']['themes'] = array(
245
+ '#type' => 'fieldset',
246
+ '#title' => t('Theme specific versions'),
247
+ '#description' => t('You can override the default jQuery version above on each themes settings page. This is useful for administrative based themes.'),
248
+ '#collapsible' => TRUE,
249
+ '#collapsed' => $themes_collapsed,
250
+ );
251
+ $form['version_options']['themes']['overrides'] = array(
252
+ '#theme' => 'table',
253
+ '#header' => $header,
254
+ '#rows' => $rows,
203
255
);
204
256
205
257
$form['jquery_update_compression_type'] = array(
@@ -239,6 +291,68 @@ function jquery_update_settings_form() {
239
291
return system_settings_form($form);
240
292
}
241
293
294
+ /**
295
+ * Implements hook_form_FORM_ID_alter().
296
+ */
297
+ function jquery_update_form_system_theme_settings_alter(&$form, $form_state) {
298
+ // Ignore global theme settings.
299
+ if (empty($form_state['build_info']['args'][0])) {
300
+ return;
301
+ }
302
+ $form['jquery_update'] = array(
303
+ '#type' => 'fieldset',
304
+ '#title' => t('jQuery Update'),
305
+ '#description' => t('You can optionally select a different version of jQuery to use for pages that are rendered using this theme. This is useful for administrative based themes.'),
306
+ );
307
+ $form['jquery_update']['jquery_update_jquery_version'] = array(
308
+ '#type' => 'select',
309
+ '#title' => t('Theme specific jQuery version'),
310
+ '#options' => jquery_update_get_version_options(),
311
+ '#default_value' => theme_get_setting('jquery_update_jquery_version', $form_state['build_info']['args'][0]),
312
+ );
313
+ }
314
+
315
+ /**
316
+ * Retrieve the jQuery versions available by this module.
317
+ *
318
+ * @return array
319
+ * The available jQuery versions.
320
+ */
321
+ function jquery_update_get_versions() {
322
+ // Use the advanced drupal_static() pattern, since this has the potential
323
+ // to be called very often.
324
+ static $drupal_static_fast;
325
+ if (!isset($drupal_static_fast)) {
326
+ $drupal_static_fast['versions'] = &drupal_static(__FUNCTION__, drupal_map_assoc(array(
327
+ '1.5', '1.7', '1.8', '1.9', '1.10',
328
+ )));
329
+ }
330
+ return $drupal_static_fast['versions'];
331
+ }
332
+
333
+ /**
334
+ * Retrieve the jQuery versions available by this module as select options.
335
+ *
336
+ * @param bool $empty
337
+ * Toggle on whether or not to return an empty option, which will default
338
+ * to the site wide default setting.
339
+ *
340
+ * @return array
341
+ * The available jQuery versions used to populate a select input.
342
+ */
343
+ function jquery_update_get_version_options($empty = TRUE) {
344
+ $options = array_merge(array(
345
+ '' => t('Site default (!version)', array(
346
+ '!version' => variable_get('jquery_update_jquery_version', '1.10'),
347
+ )),
348
+ 'default' => t('1.4 (Drupal core)'),
349
+ ), jquery_update_get_versions());
350
+ if (!$empty) {
351
+ unset($options['']);
352
+ }
353
+ return $options;
354
+ }
355
+
242
356
/**
243
357
* Update jQuery to the CDN or local path.
244
358
*
0 commit comments