You are here

function advagg_mod_fix_js_adminimal_admin_menu in Advanced CSS/JS Aggregation 7.2

Fix admin menu.

Parameters

string $contents: The contents of the js file.

string $filename: The filename.

1 call to advagg_mod_fix_js_adminimal_admin_menu()
advagg_mod_advagg_get_js_file_contents_alter in advagg_mod/advagg_mod.advagg.inc
Implements hook_advagg_get_js_file_contents_alter().

File

advagg_mod/advagg_mod.advagg.inc, line 117
Advanced CSS/JS aggregation modifier module.

Code

function advagg_mod_fix_js_adminimal_admin_menu(&$contents, $filename) {

  // Get adminimal_admin_menu path.
  $adminimal_admin_menu_path = drupal_get_path('module', 'adminimal_admin_menu');

  // Only match slicknav js.
  if ($filename !== "{$adminimal_admin_menu_path}/js/slicknav/jquery.slicknav.js" && $filename !== "{$adminimal_admin_menu_path}/js/slicknav/jquery-no-conflict.slicknav.js") {
    return;
  }

  // Lines to look for.
  $inserted_string_1 = "Drupal.admin = Drupal.admin || {};\n";
  $inserted_string_2 = "Drupal.admin.behaviors = Drupal.admin.behaviors || {};\n";
  if (strpos($contents, $inserted_string_1) !== FALSE && strpos($contents, $inserted_string_2) !== FALSE) {

    // Do nothing if the lines already exist.
    return;
  }

  // Get length of slicknav javascript.
  $strlen = strlen($contents);

  // Get the first occurrence of the problem string.
  $end = strpos($contents, 'Drupal.admin.behaviors.responsivemenu');
  if ($end === FALSE) {
    return;
  }

  // Get the start of this code block.
  $start = strrpos($contents, '(function($)', $end - $strlen);
  if ($start === FALSE) {
    return;
  }

  // Get the lcoation of {.
  $middle = strpos($contents, "{\n", $start);
  if ($middle === FALSE) {
    $middle = strpos($contents, "{", $start);
    if ($middle === FALSE) {
      return;
    }
    else {
      $middle += 1;
    }
  }
  else {
    $middle += 2;
  }

  // Insert new js code.
  $contents = substr_replace($contents, $inserted_string_1 . $inserted_string_2, $middle, 0);
}