You are here

jstools.module in Javascript Tools 5

Same filename and directory in other branches
  1. 6 jstools.module

Provide common methods used by jstools package modules.

File

jstools.module
View source
<?php

/**
 * @file
 * Provide common methods used by jstools package modules.
 */

/**
 * Implementation of hook_footer().
 *
 * Override collapse.js to make it reattachable.
 */
function jstools_footer() {
  $javascript = drupal_add_js();
  $path = drupal_get_path('module', 'jstools');
  if (isset($javascript['module']) && isset($javascript['module'][$path . '/jstools.js']) && isset($javascript['module']['misc/collapse.js']) && !module_exists('jquery_update')) {
    drupal_add_js(drupal_get_path('module', 'jstools') . '/collapse.js');
  }
}

/**
 * Add a JavaScript file to the output.
 *
 * The first time this function is invoked per page request,
 * it adds jstools files to the output. Other jstools scripts
 * depend on the methods and css in them.
 */
function jstools_add_js($files) {
  static $core_sent;
  if (!$core_sent) {
    $path = drupal_get_path('module', 'jstools');
    drupal_add_js($path . '/jstools.js');
    drupal_add_js(array(
      'jstools' => array(
        'cleanurls' => (bool) variable_get('clean_url', '0'),
        'basePath' => base_path(),
      ),
    ), 'setting');
    $core_sent = TRUE;
  }
  if (is_array($files)) {
    foreach ($files as $file) {
      drupal_add_js($file);
    }
  }
  else {
    drupal_add_js($files);
  }
}

/**
 * Load an include file for the current theme.
 *
 * To avoid having to prematurely initialize the theme, call
 * this function from a hook_footer() implementation. hook_footer()
 * typically is called after the theme has been initiated, but
 * before the header has been generated.
 */
function jstools_theme_include($module) {
  global $theme;

  // Initialize theme if necessary.
  if (!isset($theme)) {
    init_theme();
  }
  $file = drupal_get_path('module', $module) . '/theme/' . $theme . '.inc';
  if (file_exists($file)) {
    include_once $file;
    return TRUE;
  }
  return FALSE;
}

/**
 * Load theme-specific data.
 *
 * Allows loading e.g. of theme-specific jQuery selectors.
 * To avoid having to prematurely initialize the theme, call
 * this function from a hook_footer() implementation. hook_footer()
 * typically is called after the theme has been initiated, but
 * before the header has been generated.
 */
function jstools_theme_data($module) {
  return jstools_theme_include($module) ? module_invoke($module, 'theme_data') : array();
}

/**
 * Load available types by module.
 */
function jstools_modules_includes($module) {
  $path = drupal_get_path('module', $module) . '/modules';
  $files = file_scan_directory($path, '\\.inc$');
  foreach ($files as $file) {
    if (module_exists($file->name)) {
      include_once $file->filename;
    }
  }
}

Functions

Namesort descending Description
jstools_add_js Add a JavaScript file to the output.
jstools_footer Implementation of hook_footer().
jstools_modules_includes Load available types by module.
jstools_theme_data Load theme-specific data.
jstools_theme_include Load an include file for the current theme.