You are here

function advagg_mod_js_inline_processor in Advanced CSS/JS Aggregation 7.2

Given html, do some processing on the script tags included inside it.

Parameters

string $html: String containing html markup.

1 call to advagg_mod_js_inline_processor()
advagg_mod_process_move_js in advagg_mod/advagg_mod.module
Implements hook_process().

File

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

Code

function advagg_mod_js_inline_processor(&$html) {

  // Add src script to dns-prefetch.
  if (variable_get('advagg_mod_js_inline_resource_hints', ADVAGG_MOD_JS_INLINE_RESOURCE_HINTS)) {
    advagg_mod_xpath_script_external_dns($html);
  }

  // Setting is enabled.
  // All JS is in the footer.
  // OR All JS is defer.
  // OR All JS is async.
  if (variable_get('advagg_mod_js_footer_inline_alter', ADVAGG_MOD_JS_FOOTER_INLINE_ALTER) && (variable_get('advagg_mod_js_footer', ADVAGG_MOD_JS_FOOTER) >= 1 || variable_get('advagg_mod_js_defer', ADVAGG_MOD_JS_DEFER) || variable_get('advagg_mod_js_async', ADVAGG_MOD_JS_ASYNC))) {
    $pattern = '/<script(?![^<>]*src=)(?:(?![^<>]*type=)|(?=[^<>]*type="?[^<>"]*javascript))(.*?)>(.*?)<\\/script>/smix';
    $callback = 'advagg_mod_wrap_inline_js';

    // Wrap inline JS with a check so that it only runs once Drupal.settings &
    // jQuery are not undefined.
    if (variable_get('advagg_mod_wrap_inline_js_xpath', ADVAGG_MOD_WRAP_INLINE_JS_XPATH)) {
      $html = advagg_mod_xpath_script_wrapper($html);
    }
    else {
      $html = preg_replace_callback($pattern, $callback, $html);
    }
  }
}