Projet

Général

Profil

Révision 503b3f7b

Ajouté par Assos Assos il y a environ 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/jquery_update/jquery_update.module
10 10
 */
11 11
function jquery_update_help($path, $arg) {
12 12
  switch ($path) {
13
      // Help for another path in the block module
13
    // Help for another path in the block module.
14 14
    case 'admin/config/development/jquery_update':
15 15
      return '<p>' . t('Configure how <a href="@jquery">jQuery</a> behaves on the site. Select which jQuery version, the compression level and whether or not to use a CDN.', array(
16 16
        '@jquery' => 'http://jquery.com',
......
35 35
    'css' => array(
36 36
      $path . '/qunit.css' => array(),
37 37
    ),
38
    'version' => '1.11.0',
39
  );
40
  $libraries['jquery_update.ajax.fix'] = array(
41
    'title' => 'jQuery Update Version Fix',
42
    'js' => array(
43
      drupal_get_path('module', 'jquery_update') . '/js/jquery_update.js' => array(
44
        'group' => JS_LIBRARY,
45
        'weight' => 3,
46
      ),
47
    ),
48
    'version' => '0.0.1',
38 49
  );
39 50
  $libraries['jquery.metadata'] = array(
40 51
    'title' => 'QUnit',
......
61 72
}
62 73

  
63 74
/**
64
 * Implementation of hook_library_alter().
75
 * Implements hook_library_alter().
65 76
 */
66 77
function jquery_update_library_alter(&$javascript, $module) {
78
  $path = drupal_get_path('module', 'jquery_update');
79
  $version = variable_get('jquery_update_jquery_version', '1.10');
67 80

  
68
  // We are updating just the system module. For all other cases we return.
69
  if ($module != 'system') {
70
    return;
71
  }
72 81

  
73
  $path = drupal_get_path('module', 'jquery_update');
82
  // Modified System Library.
83
  if ($module === 'system') {
84

  
85
    // Make sure we inject either the minified or uncompressed version as desired.
86
    $min = variable_get('jquery_update_compression_type', 'min') == 'none' ? '' : '.min';
87
    $cdn = variable_get('jquery_update_jquery_cdn', 'none');
74 88

  
75
  // Make sure we inject either the minified or uncompressed version as desired.
76
  $min = variable_get('jquery_update_compression_type', 'min') == 'none' ? '' : '.min';
77
  $cdn = variable_get('jquery_update_jquery_cdn', 'none');
89
    // Replace jQuery with the alternative version.
90
    $admin_version = variable_get('jquery_update_jquery_admin_version', '');
78 91

  
79
  // Replace jQuery with the latest version.
80
  $version = variable_get('jquery_update_jquery_version', '1.5');
81
  jquery_update_jquery_replace($javascript, $cdn, $path, $min, $version);
92
    if (!empty($admin_version) && path_is_admin(current_path())) {
93
      if (version_compare($version, $admin_version, '!=')) {
94
        $version = $admin_version;
95
      }
96
    }
82 97

  
83
  // Replace jQuery UI with CDN or local files. If from a CDN include all of jQuery UI.
84
  jquery_update_jqueryui_replace($javascript, $cdn, $path, $min);
98
    // Always add a new jquery_version array to ajaxPageState.
99
    // This is what we used to determine which version to use
100
    // for any ajax callback.
101
    $javascript['drupal.ajax']['js'][] = array(
102
      'data' => array('ajaxPageState' => array('jquery_version' => $version)),
103
      'type' => 'setting',
104
    );
105
    $javascript['drupal.ajax']['dependencies'][] = array('jquery_update', 'jquery_update.ajax.fix');
106
    jquery_update_jquery_replace($javascript, $cdn, $path, $min, $version);
85 107

  
86
  // Replace the jQuery Cookie plugin.
87
  $javascript['cookie']['js']['misc/jquery.cookie.js']['data'] = $path . '/replace/ui/external/jquery.cookie.js';
88
  // Noting the version based on git commit as no version number is available.
89
  $javascript['cookie']['version'] = '67fb34f6a866c40d0570';
108
    // Replace jQuery UI with CDN or local files. If from a CDN include all of
109
    // jQuery UI.
110
    if (version_compare($version, '1.6', '>=')) {
111
      jquery_update_jqueryui_replace($javascript, $cdn, $path, $min);
112
    }
90 113

  
91
  // Replace jQuery Form plugin.
92
  $javascript['jquery.form']['js']['misc/jquery.form.js']['data'] = $path . '/replace/misc/jquery.form' . $min . '.js';
93
  $javascript['jquery.form']['version'] = '2.69';
114
    // Replace the jQuery Cookie plugin.
115
    $javascript['cookie']['js']['misc/jquery.cookie.js']['data'] = $path . '/replace/ui/external/jquery.cookie.js';
116
    // Noting the version based on git commit as no version number is available.
117
    $javascript['cookie']['version'] = '67fb34f6a866c40d0570';
94 118

  
95
  // Replace files for jQuery 1.7 and up
96
  if (version_compare($version, '1.7', '>=')) {
97
    $javascript['drupal.states']['js']['misc/states.js']['data'] = $path . '/replace/misc/1.7/states.js';
119
    // Replace jQuery Form plugin.
120
    $javascript['jquery.form']['js']['misc/jquery.form.js']['data'] = $path . '/replace/misc/jquery.form' . $min . '.js';
121
    $javascript['jquery.form']['version'] = '2.69';
122

  
123
    // Replace files for Jquery 1.9 and up
124
    if (version_compare($version, '1.9', '>=')) {
125
      $javascript['jquery.bbq']['js']['misc/jquery.ba-bbq.js']['data'] = $path . '/replace/misc/1.9/jquery.ba-bbq' . $min . '.js';
126
    }
127
  }
128

  
129
  if ($module == 'overlay') {
130
    if (version_compare($version, '1.9', '>=')) {
131
      $javascript['parent']['js']['modules/overlay/overlay-parent.js']['data'] = $path . '/replace/misc/1.9/overlay-parent.js';
132
    }
98 133
  }
99 134
}
100 135

  
......
114 149
}
115 150

  
116 151
/**
117
 * Implementation of hook_form_FORM_ID().
152
 * Admin settings menu callback.
153
 *
154
 * @see jquery_update_menu()
118 155
 */
119 156
function jquery_update_settings_form() {
120
  $form['jquery_update_jquery_version'] = array(
157
  $form['version_options'] = array(
158
    '#type' => 'fieldset',
159
    '#title' => t('Version options'),
160
  );
161

  
162
  $form['version_options']['jquery_update_jquery_version'] = array(
121 163
    '#type' => 'select',
122
    '#title' => t('jQuery Version'),
164
    '#title' => t('Default jQuery Version'),
123 165
    '#options' => array(
124 166
      '1.5' => '1.5',
125 167
      '1.7' => '1.7',
126 168
      '1.8' => '1.8',
169
      '1.9' => '1.9',
170
      '1.10' => '1.10',
127 171
    ),
128
    '#default_value' => variable_get('jquery_update_jquery_version', '1.5'),
129
    '#description' => t('Select which jQuery version branch to use.'),
172
    '#default_value' => variable_get('jquery_update_jquery_version', '1.10'),
173
    '#description' => t('Select which jQuery version to use by default.'),
130 174
  );
175

  
176
  $form['version_options']['jquery_update_jquery_admin_version'] = array(
177
    '#type' => 'select',
178
    '#title' => t('Alternate jQuery version for administrative pages'),
179
    '#options' => array(
180
      '' => t('Use the default'),
181
      '1.5' => '1.5',
182
      '1.7' => '1.7',
183
      '1.8' => '1.8',
184
      '1.10' => '1.10',
185
    ),
186
    '#default_value' => variable_get('jquery_update_jquery_admin_version', ''),
187
    '#description' => t('Optionally select a different version of jQuery to use on administrative pages.'),
188
  );
189

  
131 190
  $form['jquery_update_compression_type'] = array(
132 191
    '#type' => 'radios',
133 192
    '#title' => t('jQuery compression level'),
......
163 222
 *   - none
164 223
 *   - google
165 224
 *   - microsoft
225
 * @param string $path
226
 *   The path to the module where replacements can be found.
227
 * @param string $min
228
 *   The '.min' to include in the file name if we are requesting a minified
229
 *   version.
166 230
 * @param string $version
167 231
 *   The version of jQuery to use.
168 232
 */
169 233
function jquery_update_jquery_replace(&$javascript, $cdn, $path, $min, $version) {
234
  // If the ajax version is set then that one always win.
235
  if (!empty($_POST['ajax_page_state']['jquery_version'])) {
236
    $ajax_version = $_POST['ajax_page_state']['jquery_version'];
237
    if (in_array($ajax_version, array('1.5', '1.6', '1.7', '1.8', '1.9', '1.10'))) {
238
      $version = $ajax_version;
239
    }
240
  }
241

  
170 242
  // Make sure to use the latest version in given branch.
171 243
  $trueversion = NULL;
172 244
  switch ($version) {
173 245
    case '1.5':
174 246
      $trueversion = '1.5.2';
175 247
      break;
248

  
176 249
    case '1.7':
177 250
      $trueversion = '1.7.1';
178 251
      break;
252

  
179 253
    case '1.8':
180 254
      $trueversion = '1.8.2';
181 255
      break;
256

  
257
    case '1.9':
258
      $trueversion = '1.9.1';
259
      break;
260

  
261
    case '1.10':
262
      $trueversion = '1.10.2';
263
      break;
182 264
  }
183 265
  $javascript['jquery']['version'] = $trueversion;
184 266

  
185 267
  // Check for CDN support.
186
  switch($cdn) {
268
  switch ($cdn) {
187 269
    case 'google':
188
      $javascript['jquery']['js']['misc/jquery.js']['data'] = 'https://ajax.googleapis.com/ajax/libs/jquery/'. $trueversion . '/jquery' . $min . '.js';
270
      $javascript['jquery']['js']['misc/jquery.js']['data'] = 'https://ajax.googleapis.com/ajax/libs/jquery/' . $trueversion . '/jquery' . $min . '.js';
189 271
      $javascript['jquery']['js']['misc/jquery.js']['type'] = 'external';
190 272
      jquery_update_jquery_backup($javascript, $path, $min, $version);
191 273
      break;
274

  
192 275
    case 'microsoft':
193
      $javascript['jquery']['js']['misc/jquery.js']['data'] = 'http://ajax.aspnetcdn.com/ajax/jQuery/jquery-'. $trueversion . $min . '.js';
276
      $javascript['jquery']['js']['misc/jquery.js']['data'] = 'http://ajax.aspnetcdn.com/ajax/jQuery/jquery-' . $trueversion . $min . '.js';
194 277
      $javascript['jquery']['js']['misc/jquery.js']['type'] = 'external';
195 278
      jquery_update_jquery_backup($javascript, $path, $min, $version);
196 279
      break;
280

  
197 281
    case 'jquery':
198
      $javascript['jquery']['js']['misc/jquery.js']['data'] = 'http://code.jquery.com/jquery-'. $trueversion . $min . '.js';
282
      $javascript['jquery']['js']['misc/jquery.js']['data'] = 'http://code.jquery.com/jquery-' . $trueversion . $min . '.js';
199 283
      $javascript['jquery']['js']['misc/jquery.js']['type'] = 'external';
200 284
      jquery_update_jquery_backup($javascript, $path, $min, $version);
201 285
      break;
286

  
202 287
    case 'none':
203 288
    default:
204
      $javascript['jquery']['js']['misc/jquery.js']['data'] = $path . '/replace/jquery/'. $version . '/jquery' . $min . '.js';
289
      $javascript['jquery']['js']['misc/jquery.js']['data'] = $path . '/replace/jquery/' . $version . '/jquery' . $min . '.js';
205 290
      break;
206 291
  }
207 292
}
......
214 299
 * @param string $path
215 300
 *   The path to the module where replacements can be found.
216 301
 * @param string $min
217
 *   The '.min' to include in the file name if we are requesting a minified version.
302
 *   The '.min' to include in the file name if we are requesting a minified
303
 *   version.
218 304
 * @param string $version
219 305
 *   The verison of jQuery to use.
220 306
 */
221 307
function jquery_update_jquery_backup(&$javascript, $path, $min, $version) {
222 308
  $javascript['jquery']['js'][] = array(
223
    'data' => 'window.jQuery || document.write("<script src=\'' . base_path() . $path . '/replace/jquery/'. $version . '/jquery' . $min . '.js\'>\x3C/script>")',
309
    'data' => 'window.jQuery || document.write("<script src=\'' . base_path() . $path . '/replace/jquery/' . $version . '/jquery' . $min . '.js\'>\x3C/script>")',
224 310
    'type' => 'inline',
225 311
    'group' => JS_LIBRARY,
226 312
    'weight' => -19.999999999,
......
237 323
 *   - none
238 324
 *   - google
239 325
 *   - microsoft
326
 * @param string $path
327
 *   The path to the module where replacements can be found.
328
 * @param string $min
329
 *   The '.min' to include in the file name if we are requesting a minified
330
 *   version.
240 331
 */
241 332
function jquery_update_jqueryui_replace(&$javascript, $cdn, $path, $min) {
333
  // Add new components
334
  $javascript['ui.menu'] = array(
335
    'title' => 'jQuery UI: Menu',
336
    'website' => 'http://jqueryui.com/demos/menu/',
337
    'version' => '1.10.2',
338
    'js' => array('misc/ui/jquery.ui.menu.min.js' => array()),
339
    'css' => array('misc/ui/jquery.ui.menu.css' => array()),
340
    'dependencies' => array(array('system', 'ui.widget'), array('system', 'ui.position')),
341
  );
342
  $javascript['ui.spinner'] = array(
343
    'title' => 'jQuery UI: Spinner',
344
    'website' => 'http://jqueryui.com/demos/spinner/',
345
    'version' => '1.10.2',
346
    'js' => array('misc/ui/jquery.ui.spinner.min.js' => array()),
347
    'css' => array('misc/ui/jquery.ui.spinner.css' => array()),
348
    'dependencies' => array(array('system', 'ui.widget'), array('system', 'ui.button')),
349
  );
350
  $javascript['ui.tooltip'] = array(
351
    'title' => 'jQuery UI: Spinner',
352
    'website' => 'http://jqueryui.com/demos/tooltip/',
353
    'version' => '1.10.2',
354
    'js' => array('misc/ui/jquery.ui.tooltip.min.js' => array()),
355
    'css' => array('misc/ui/jquery.ui.tooltip.css' => array()),
356
    'dependencies' => array(array('system', 'ui.widget'), array('system', 'ui.position')),
357
  );
358

  
359
  // fix dependencies
360
  $javascript['ui.autocomplete']['dependencies'][] = array('system', 'ui.menu');
242 361
  // Replace all CSS files.
243 362
  $names = drupal_map_assoc(array(
244
    'ui.accordion', 'ui.autocomplete', 'ui.button', 'ui.datepicker',
245
    'ui.dialog', 'ui.progressbar', 'ui.resizable', 'ui.selectable',
246
    'ui.slider', 'ui.tabs',
363
    'ui.accordion', 'ui.autocomplete', 'ui.button', 'ui.datepicker', 'ui.dialog',
364
    'ui.progressbar', 'ui.resizable', 'ui.selectable', 'ui.slider', 'ui.tabs',
365
    'ui.menu', 'ui.spinner', 'ui.tooltip',
247 366
  ));
248 367
  $names['ui'] = 'ui.core';
249 368
  $csspath = $path . '/replace/ui/themes/base/' . (($min == '.min') ? 'minified/' : '');
......
255 374

  
256 375
  // Replace jQuery UI's JavaScript, beginning by defining the mapping.
257 376
  $names = drupal_map_assoc(array(
258
    'ui.accordion', 'ui.autocomplete', 'ui.button', 'ui.datepicker',
259
    'ui.dialog', 'ui.draggable', 'ui.droppable', 'ui.mouse', 'ui.position',
260
    'ui.progressbar', 'ui.resizable', 'ui.selectable', 'ui.slider',
261
    'ui.sortable', 'ui.tabs', 'ui.widget', 'effects.blind', 'effects.bounce',
262
    'effects.clip', 'effects.drop', 'effects.explode', 'effects.fade',
263
    'effects.fold', 'effects.highlight', 'effects.pulsate', 'effects.scale',
264
    'effects.shake', 'effects.slide', 'effects.transfer',
377
    'ui.accordion', 'ui.autocomplete', 'ui.button', 'ui.datepicker', 'ui.dialog', 'ui.draggable',
378
    'ui.droppable', 'ui.mouse', 'ui.position', 'ui.progressbar', 'ui.resizable', 'ui.selectable',
379
    'ui.slider', 'ui.sortable', 'ui.tabs', 'ui.widget', 'ui.spinner', 'ui.menu', 'ui.tooltip',
380
    'effects.blind', 'effects.bounce', 'effects.clip', 'effects.drop', 'effects.explode', 'effects.fade',
381
    'effects.fold', 'effects.highlight', 'effects.pulsate', 'effects.scale', 'effects.shake', 'effects.slide',
382
    'effects.transfer',
265 383
  ));
266 384
  $names['ui'] = 'ui.core';
267
  $names['effects'] = 'effects.core';
385
  $names['effects'] = 'ui.effect';
268 386

  
269
  switch($cdn) {
387
  switch ($cdn) {
270 388
    case 'google':
271
      $cdn = 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui' . $min . '.js';
389
      $cdn = 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui' . $min . '.js';
272 390
      jquery_update_jqueryui_cdn($cdn, $javascript, $path, $min, $names);
273 391
      jquery_update_jqueryui_backup($javascript, $path, $min);
274 392
      break;
393

  
275 394
    case 'microsoft':
276
      $cdn = 'http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.11/jquery-ui' . $min . '.js';
395
      $cdn = 'http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.2/jquery-ui' . $min . '.js';
277 396
      jquery_update_jqueryui_cdn($cdn, $javascript, $path, $min, $names);
278 397
      jquery_update_jqueryui_backup($javascript, $path, $min);
279 398
      break;
399

  
280 400
    case 'none':
281 401
      jquery_update_jqueryui_local($javascript, $path, $min, $names);
282 402
      break;
......
291 411
 * @param string $path
292 412
 *   The path to the module where replacements can be found.
293 413
 * @param string $min
294
 *   The '.min' to include in the file name if we are requesting a minified version.
414
 *   The '.min' to include in the file name if we are requesting a minified
415
 *   version.
295 416
 */
296 417
function jquery_update_jqueryui_backup(&$javascript, $path, $min) {
297 418
  $js_path = ($min == '.min') ? '/replace/ui/ui/minified/jquery-ui.min.js' : '/replace/ui/ui/jquery-ui.js';
......
306 427
/**
307 428
 * Handle when jQuery UI is updated to the cdn version.
308 429
 *
430
 * @param string $cdn
431
 *   The name of the CDN option to use. Possible options are:
432
 *   - none
433
 *   - google
434
 *   - microsoft
309 435
 * @param array $javascript
310 436
 *   The $libraries array as seen in hook_library_alter()
311 437
 * @param string $path
312 438
 *   The path to the module where replacements can be found.
313 439
 * @param string $min
314
 *   The '.min' to include in the file name if we are requesting a minified version.
315
 * @param array $names
440
 *   The '.min' to include in the file name if we are requesting a minified
441
 *   version.
442
 * * @param array $names
316 443
 *   An array mapping jquery ui parts to their file names.
317 444
 */
318 445
function jquery_update_jqueryui_cdn($cdn, &$javascript, $path, $min, $names) {
......
323 450
    $corefile = 'misc/ui/jquery.' . $file . '.min.js';
324 451
    // Remove the core files.
325 452
    unset($javascript[$name]['js'][$corefile]);
326
    $javascript[$name]['version'] = '1.8.11';
453
    $javascript[$name]['version'] = '1.10.2';
327 454
  }
328 455

  
329 456
  // UI is used by all of UI. Add the js cdn here.
......
333 460
    'group' => JS_LIBRARY,
334 461
    'weight' => -11,
335 462
  );
463

  
464
  // The cdn puts jQuery UI core and the jQuery UI Effects library in the same
465
  // file, but the latter can normally be used without the former. So we need
466
  // to add a dependency to guarantee that code which uses the Effects library
467
  // has the file loaded regardless of whether they are also using jQuery UI
468
  // core.
469
  $javascript['effects']['dependencies'][] = array('system', 'ui');
336 470
}
337 471

  
338 472
/**
......
343 477
 * @param string $path
344 478
 *   The path to the module where replacements can be found.
345 479
 * @param string $min
346
 *   The '.min' to include in the file name if we are requesting a minified version.
480
 *   The '.min' to include in the file name if we are requesting a minified
481
 *   version.
347 482
 * @param array $names
348 483
 *   An array mapping jquery ui parts to their file names.
349 484
 */
......
354 489
  foreach ($names as $name => $file) {
355 490
    $corefile = 'misc/ui/jquery.' . $file . '.min.js';
356 491
    $javascript[$name]['js'][$corefile]['data'] = $jspath . 'jquery.' . $file . $min . '.js';
357
    $javascript[$name]['version'] = '1.8.11';
492
    $javascript[$name]['version'] = '1.10.2';
358 493
  }
359 494
}

Formats disponibles : Unified diff