You are here

function advagg_mod_get_lists in Advanced CSS/JS Aggregation 7.2

Same name and namespace in other branches
  1. 8.2 advagg_mod/advagg_mod.module \advagg_mod_get_lists()

Generate a list of rules and exceptions for js files and inline.

Controls inline wrapping and defer. Controls no async/defer file list. Controls files that stay in the header.

Parameters

array $js: The JS array.

array $css: The CSS array.

Return value

array A multidimensional array.

9 calls to advagg_mod_get_lists()
advagg_mod_add_loadcss_js_lib in advagg_mod/advagg_mod.module
Adds the loadcss js library if needed.
advagg_mod_advagg_modify_css_pre_render_alter in advagg_mod/advagg_mod.module
Implements hook_advagg_modify_css_pre_render_alter().
advagg_mod_defer_inline_js in advagg_mod/advagg_mod.module
Callback for preg_replace_callback.
advagg_mod_js_async_defer in advagg_mod/advagg_mod.module
Add the defer and or the async tag to js.
advagg_mod_js_move_to_footer in advagg_mod/advagg_mod.module
Move JS to the footer.

... See full list

File

advagg_mod/advagg_mod.module, line 2084
Advanced aggregation modifier module.

Code

function advagg_mod_get_lists(array $js = array(), array $css = array()) {
  $lists =& drupal_static(__FUNCTION__);
  $js_count = count($js);
  $css_count = count($css);
  $key = $js_count . '.' . $css_count;
  if (!isset($lists[$key])) {

    // Do not move to footer file list.
    $header_file_list = array(
      // Modernizr js.
      '/modernizr.',
      // Html5shiv and html5shiv-printshiv.
      '/html5shiv.',
      '/html5shiv-printshiv.',
      // Google Admanager Needs to be in the header.
      '/google_service.',
    );

    // Do not move to footer inline list.
    $header_inline_list = array(
      // Google Analytics should be in the header to verify for Webmaster tools.
      'GoogleAnalyticsObject',
      'window.google_analytics_uacct',
      // Google Admanager Needs to be in the header.
      'GS_googleAddAdSenseService(',
      'GS_googleEnableAllServices(',
      'GA_googleAddSlot(',
      'GA_googleFetchAds(',
    );

    // Do not defer/async list.
    $no_async_defer_list = array(
      // Wistia js.
      '//fast.wistia.',
      // Maps.
      '//dev.virtualearth.net',
      '//api.maps.yahoo.com',
      // Google Admanager can't be forced defer/async.
      '/google_service.',
    );

    // Openlayers.
    if (module_exists('openlayers')) {

      // Openlayers fix; external scripts can not be loaded out of order.
      // Cloudmade.
      $path = variable_get('openlayers_layers_cloudmade_js', '');
      if (valid_url($path, TRUE)) {
        $no_async_defer_list['openlayers_layers_cloudmade'] = $path;
      }

      // Google.
      $mapdomain = variable_get('openlayers_layers_google_mapdomain', 'maps.google.com');
      $no_async_defer_list['openlayers_layers_google'] = $mapdomain . '/maps';
    }

    // Wrap inline js so it does not run until the condition is TRUE.
    // Inline search string => js condition.
    $inline_wrapper_list = array();

    // Get inline wrap js skip list string and convert it to an array.
    $inline_js_wrap_skip_list = array_filter(array_map('trim', explode("\n", variable_get('advagg_mod_wrap_inline_js_skip_list', ADVAGG_MOD_WRAP_INLINE_JS_SKIP_LIST))));
    $inline_js_wrap_skip_list[] = '.write(';
    $inline_js_wrap_skip_list[] = '._fbq';
    $inline_js_wrap_skip_list[] = '.fbq';
    $inline_js_wrap_skip_list[] = 'gtm.start';
    $inline_js_wrap_skip_list[] = '_gaq.push(["_';
    $inline_js_wrap_skip_list[] = 'ga("';
    $inline_js_wrap_skip_list[] = "ga('";
    $inline_js_wrap_skip_list[] = 'GoogleAnalyticsObject';
    $inline_js_wrap_skip_list[] = 'window.google_analytics_uacct';
    $inline_js_wrap_skip_list[] = 'function krumo(';
    $inline_js_wrap_skip_list[] = '// no advagg';
    $inline_js_wrap_skip_list[] = '// noadvagg';
    $inline_js_wrap_skip_list[] = '// no-advagg';
    $inline_js_wrap_skip_list[] = '//no advagg';
    $inline_js_wrap_skip_list[] = '//noadvagg';
    $inline_js_wrap_skip_list[] = '//no-advagg';

    // Google Admanager can not be wrapped in a callback function.
    $inline_js_wrap_skip_list[] = 'GS_googleAddAdSenseService(';
    $inline_js_wrap_skip_list[] = 'GS_googleEnableAllServices(';
    $inline_js_wrap_skip_list[] = 'GA_googleAddSlot(';
    $inline_js_wrap_skip_list[] = 'GA_googleFetchAds(';
    $inline_js_wrap_skip_list[] = 'GA_googleFillSlot(';
    $inline_js_wrap_skip_list[] = 'adsbygoogle';
    $inline_js_wrap_skip_list[] = '_paq.push(["';
    if (module_exists('h5p')) {
      $inline_js_wrap_skip_list[] = 'H5PIntegration';
    }

    // Get inline defer js skip list string and convert it to an array.
    $inline_js_defer_skip_list = array_filter(array_map('trim', explode("\n", variable_get('advagg_mod_defer_inline_js_skip_list', ADVAGG_MOD_DEFER_INLINE_JS_SKIP_LIST))));
    $inline_js_defer_skip_list[] = 'loadCSS(';
    $inline_js_defer_skip_list[] = '._fbq';
    $inline_js_defer_skip_list[] = '.fbq';
    $inline_js_defer_skip_list[] = 'gtm.start';
    $inline_js_defer_skip_list[] = '_gaq.push(["_';
    $inline_js_defer_skip_list[] = 'GoogleAnalyticsObject';
    $inline_js_defer_skip_list[] = 'window.google_analytics_uacct';
    $inline_js_defer_skip_list[] = '// no advagg';
    $inline_js_defer_skip_list[] = '// noadvagg';
    $inline_js_defer_skip_list[] = '// no-advagg';
    $inline_js_defer_skip_list[] = '//no advagg';
    $inline_js_defer_skip_list[] = '//noadvagg';
    $inline_js_defer_skip_list[] = '//no-advagg';

    // Google Admanager can not be wrapped in a callback function.
    $inline_js_defer_skip_list[] = 'GS_googleAddAdSenseService(';
    $inline_js_defer_skip_list[] = 'GS_googleEnableAllServices(';
    $inline_js_defer_skip_list[] = 'GA_googleAddSlot(';
    $inline_js_defer_skip_list[] = 'GA_googleFetchAds(';
    $inline_js_defer_skip_list[] = 'GA_googleFillSlot(';
    $inline_js_defer_skip_list[] = 'adsbygoogle';
    $inline_js_defer_skip_list[] = '_paq.push(["';
    if (module_exists('h5p')) {
      $inline_js_defer_skip_list[] = 'H5PIntegration';
    }

    // If there is a fast clicker, ajax links might not work if ajax.js is
    // loaded in the footer.
    $all_in_footer_list = array(
      'misc/ajax.js' => array(
        '/jquery.js',
        '/jquery.min.js',
        '/jquery.once.js',
        '/ajax.js',
        '/drupal.js',
        'settings',
      ),
    );
    $move_js_to_footer = variable_get('advagg_mod_js_footer', ADVAGG_MOD_JS_FOOTER);
    $defer_setting = variable_get('advagg_mod_js_defer', ADVAGG_MOD_JS_DEFER);
    $async_setting = variable_get('advagg_mod_js_async', ADVAGG_MOD_JS_ASYNC);
    $css_defer = variable_get('advagg_mod_css_defer', ADVAGG_MOD_CSS_DEFER);

    // Allow other modules to add/edit the above lists.
    // Call hook_advagg_mod_get_lists_alter().
    $lists[$key] = array(
      $header_file_list,
      $header_inline_list,
      $no_async_defer_list,
      $inline_wrapper_list,
      $inline_js_wrap_skip_list,
      $inline_js_defer_skip_list,
      $all_in_footer_list,
      $move_js_to_footer,
      $defer_setting,
      $async_setting,
      $css_defer,
    );
    drupal_alter('advagg_mod_get_lists', $lists[$key], $js, $css);
  }
  return $lists[$key];
}