You are here

function superfish_library in Superfish 7

Add require JavaScript and CSS files from the Superfish library.

1 call to superfish_library()
superfish_block_view in ./superfish.module
Implements hook_block_view().

File

./superfish.module, line 1820
Enables the use of jQuery Superfish plugin for Drupal menus.

Code

function superfish_library($type = NULL, $name = NULL, $action = 'add') {
  $directory = superfish_get_path('superfish');
  $directory_easing = superfish_get_path('easing');
  $sf_library = $directory . "/jquery.hoverIntent.minified.js\n" . $directory . "/jquery.bgiframe.min.js\n" . $directory . "/superfish.js\n" . $directory . "/supersubs.js\n" . $directory . "/supposition.js\n" . $directory . "/sftouchscreen.js\n" . $directory . "/sfsmallscreen.js\n" . $directory . "/sfautomaticwidth.js";
  $sf_library = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", "\n", trim($sf_library));
  $sf_library = explode("\n", $sf_library);
  if ($action == 'check') {
    switch ($type) {
      case 'javascript':
        switch ($name) {
          case 'drupal_behavior':
            $name = 'superfish.js';
            $sf_library = array(
              drupal_get_path('module', 'superfish') . '/' . $name,
            );
            break;
          case 'jquery.easing.js':
            $name = 'jquery.easing.js';
            $sf_library = array(
              $directory_easing . '/' . $name,
            );
            break;
        }
        $in_library = FALSE;
        foreach ($sf_library as $s) {
          if (strpos($s, $name) !== FALSE) {
            $in_library = TRUE;
            if (file_exists($s)) {
              return TRUE;
            }
            else {
              watchdog('page not found', '%file', array(
                '%file' => $directory . '/' . $name,
              ), WATCHDOG_ERROR);
              return FALSE;
            }
          }
        }
        if (!$in_library) {
          watchdog('page not found', '%path missing from Superfish library configuration, please add it immediately.', array(
            '%path' => $directory . '/' . $name,
          ), WATCHDOG_WARNING, l(t('Superfish library configuration'), 'admin/config/user-interface/superfish'));
          return FALSE;
        }
        break;
      case 'CSS':
        $directory .= '/css';
        switch ($name) {
          case 'superfish':
          case 'horizontal':
            if (file_exists($directory . '/superfish.css')) {
              return TRUE;
            }
            else {
              watchdog('page not found', '%directory/superfish.css', array(
                '%directory' => $directory,
              ), WATCHDOG_WARNING);
              return FALSE;
            }
            break;
          case 'navbar':
          case 'vertical':
          case 'smallscreen':
            if (file_exists($directory . '/superfish-' . $name . '.css')) {
              return TRUE;
            }
            else {
              watchdog('page not found', '%directory/superfish-%name.css', array(
                '%directory' => $directory,
                '%name' => $name,
              ), WATCHDOG_WARNING);
              return FALSE;
            }
            break;
        }
        break;
    }
  }
  if ($action == 'add') {
    switch ($type) {
      case 'javascript':
        switch ($name) {
          case 'easing':
            $output = array(
              $directory_easing . '/jquery.easing.js' => array(
                'type' => 'file',
                'weight' => 490,
              ),
            );
            return $output;
          case 'drupal_behavior':
            $output = array(
              drupal_get_path('module', 'superfish') . '/superfish.js' => array(
                'type' => 'file',
                'weight' => 495,
              ),
            );
            return $output;
          default:
            if (file_exists($directory . '/superfish.js')) {
              foreach ($sf_library as $s) {
                if (strpos($s, $name) !== FALSE) {
                  switch ($name) {
                    case 'superfish':
                      $weight = 480;
                      break;
                    case 'supersubs':
                      $weight = 490;
                      break;
                    default:
                      $weight = 470;
                  }
                  $output = array(
                    $s => array(
                      'type' => 'file',
                      'weight' => $weight,
                    ),
                  );
                  return $output;
                }
              }

              // If the required file did not exist in the library files list.
              if (empty($output)) {
                watchdog('page not found', '%name cannot be found.', array(
                  '%name' => $name,
                ), WATCHDOG_WARNING);
              }
            }
            else {
              watchdog('page not found', '%directory/superfish.js', array(
                '%directory' => $directory,
              ), WATCHDOG_ERROR);
            }
        }
        break;
      case 'CSS':
        $directory .= '/css';
        switch ($name) {
          case 'superfish':
          case 'horizontal':
            $output = array(
              $directory . '/superfish.css' => array(
                'type' => 'file',
                'weight' => 480,
              ),
            );
            return $output;
          case 'navbar':
          case 'vertical':
          case 'smallscreen':
            $output = array(
              $directory . '/superfish-' . $name . '.css' => array(
                'type' => 'file',
                'weight' => 490,
              ),
            );
            return $output;
        }
        break;
    }
  }
}