0

This is an answer how to unset js from specific page types: https://stackoverflow.com/questions/10138660/how-to-remove-css-and-js-from-a-certain-content-type-in-drupal-7 And I've made it for Syntax Highlighter module's js:

function tlito_theme_js_alter(&$js) {
  if (arg(0) != 'node') {
    unset($js['sites/all/libraries/syntaxhighlighter/scripts/shCore.js']);
    unset($js['sites/all/libraries/syntaxhighlighter/scripts/shAutoloader.js']);
    unset($js['sites/all/modules/syntaxhighlighter/syntaxhighlighter.min.js']);
    unset($js['images/syntaxhighlighter.autoloader.js']);
  }
}

And everything is ok but also module adds inline JS that gives error on pages where js ar removed. Inline js is this:

<script type="text/javascript">
<!--//--><![CDATA[//><!--
SyntaxHighlighter.defaults.toolbar = false;
//--><!]]>
</script>

How can I remove inline js from $scripts in my template.php ?

1

Put this inside tlito_theme_js_alter().

foreach ($js as $key => $value) {
  // Skip if data is not a string or is not inline.
  if (!is_string($value['data']) || $value['type'] !== 'inline') {
    continue;
  }
  // Remove SyntaxHighlighter.defaults.toolbar inline js.
  if (strpos($value['data'], 'SyntaxHighlighter.defaults.toolbar') !== FALSE) {
    // Remove from the js array & exit loop.
    unset($js[$key]);
    break;
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.