Projet

Général

Profil

Révision 6ff32cea

Ajouté par Florent Torregrosa il y a environ 9 ans

Update core to 7.36

Voir les différences:

drupal7/includes/common.inc
4162 4162
 *       else being the same, JavaScript added by a call to drupal_add_js() that
4163 4163
 *       happened later in the page request gets added to the page after one for
4164 4164
 *       which drupal_add_js() happened earlier in the page request.
4165
 *   - requires_jquery: Set this to FALSE if the JavaScript you are adding does
4166
 *     not have a dependency on jQuery. Defaults to TRUE, except for JavaScript
4167
 *     settings where it defaults to FALSE. This is used on sites that have the
4168
 *     'javascript_always_use_jquery' variable set to FALSE; on those sites, if
4169
 *     all the JavaScript added to the page by drupal_add_js() does not have a
4170
 *     dependency on jQuery, then for improved front-end performance Drupal
4171
 *     will not add jQuery and related libraries and settings to the page.
4165 4172
 *   - defer: If set to TRUE, the defer attribute is set on the <script>
4166 4173
 *     tag. Defaults to FALSE.
4167 4174
 *   - cache: If set to FALSE, the JavaScript file is loaded anew on every page
......
4179 4186
 */
4180 4187
function drupal_add_js($data = NULL, $options = NULL) {
4181 4188
  $javascript = &drupal_static(__FUNCTION__, array());
4189
  $jquery_added = &drupal_static(__FUNCTION__ . ':jquery_added', FALSE);
4190

  
4191
  // If the $javascript variable has been reset with drupal_static_reset(),
4192
  // jQuery and related files will have been removed from the list, so set the
4193
  // variable back to FALSE to indicate they have not yet been added.
4194
  if (empty($javascript)) {
4195
    $jquery_added = FALSE;
4196
  }
4182 4197

  
4183 4198
  // Construct the options, taking the defaults into consideration.
4184 4199
  if (isset($options)) {
......
4189 4204
  else {
4190 4205
    $options = array();
4191 4206
  }
4207
  if (isset($options['type']) && $options['type'] == 'setting') {
4208
    $options += array('requires_jquery' => FALSE);
4209
  }
4192 4210
  $options += drupal_js_defaults($data);
4193 4211

  
4194 4212
  // Preprocess can only be set if caching is enabled.
......
4199 4217
  $options['weight'] += count($javascript) / 1000;
4200 4218

  
4201 4219
  if (isset($data)) {
4202
    // Add jquery.js and drupal.js, as well as the basePath setting, the
4203
    // first time a JavaScript file is added.
4204
    if (empty($javascript)) {
4220
    // Add jquery.js, drupal.js, and related files and settings if they have
4221
    // not been added yet. However, if the 'javascript_always_use_jquery'
4222
    // variable is set to FALSE (indicating that the site does not want jQuery
4223
    // automatically added on all pages) then only add it if a file or setting
4224
    // that requires jQuery is being added also.
4225
    if (!$jquery_added && (variable_get('javascript_always_use_jquery', TRUE) || $options['requires_jquery'])) {
4226
      $jquery_added = TRUE;
4205 4227
      // url() generates the prefix using hook_url_outbound_alter(). Instead of
4206 4228
      // running the hook_url_outbound_alter() again here, extract the prefix
4207 4229
      // from url().
4208 4230
      url('', array('prefix' => &$prefix));
4209
      $javascript = array(
4231
      $default_javascript = array(
4210 4232
        'settings' => array(
4211 4233
          'data' => array(
4212 4234
            array('basePath' => base_path()),
......
4225 4247
          'group' => JS_LIBRARY,
4226 4248
          'every_page' => TRUE,
4227 4249
          'weight' => -1,
4250
          'requires_jquery' => TRUE,
4228 4251
          'preprocess' => TRUE,
4229 4252
          'cache' => TRUE,
4230 4253
          'defer' => FALSE,
4231 4254
        ),
4232 4255
      );
4256
      $javascript = drupal_array_merge_deep($javascript, $default_javascript);
4233 4257
      // Register all required libraries.
4234 4258
      drupal_add_library('system', 'jquery', TRUE);
4235 4259
      drupal_add_library('system', 'jquery.once', TRUE);
......
4270 4294
    'group' => JS_DEFAULT,
4271 4295
    'every_page' => FALSE,
4272 4296
    'weight' => 0,
4297
    'requires_jquery' => TRUE,
4273 4298
    'scope' => 'header',
4274 4299
    'cache' => TRUE,
4275 4300
    'defer' => FALSE,
......
4316 4341
  if (!isset($javascript)) {
4317 4342
    $javascript = drupal_add_js();
4318 4343
  }
4319
  if (empty($javascript)) {
4344

  
4345
  // If no JavaScript items have been added, or if the only JavaScript items
4346
  // that have been added are JavaScript settings (which don't do anything
4347
  // without any JavaScript code to use them), then no JavaScript code should
4348
  // be added to the page.
4349
  if (empty($javascript) || (isset($javascript['settings']) && count($javascript) == 1)) {
4320 4350
    return '';
4321 4351
  }
4322 4352

  
......
4470 4500
 *
4471 4501
 * Libraries, JavaScript, CSS and other types of custom structures are attached
4472 4502
 * to elements using the #attached property. The #attached property is an
4473
 * associative array, where the keys are the the attachment types and the values
4474
 * are the attached data. For example:
4503
 * associative array, where the keys are the attachment types and the values are
4504
 * the attached data. For example:
4475 4505
 * @code
4476 4506
 * $build['#attached'] = array(
4477 4507
 *   'js' => array(drupal_get_path('module', 'taxonomy') . '/taxonomy.js'),

Formats disponibles : Unified diff