You are here

function tableofcontents_init in Table of Contents 7

Same name and namespace in other branches
  1. 6.3 tableofcontents.module \tableofcontents_init()
  2. 6.2 tableofcontents.module \tableofcontents_init()

Implementation of hook_init()

We load the JS/CSS files here so we can cache the filter results.

File

./tableofcontents.module, line 33
This is a filter module to generate a collapsible jquery enabled mediawiki style table of contents based on <h[1-6]> tags. Transforms header tags into named anchors.

Code

function tableofcontents_init() {

  // we probably should not do that on non-node pages!
  // (how do you determine that?)
  // TODO: This can be possibly moved to hook_node_view. Revisit to check if
  // any other JS setting need to be added.
  $path = drupal_get_path('module', 'tableofcontents');
  drupal_add_js($path . '/jquery.scrollTo-min.js');
  drupal_add_js($path . '/jquery.localscroll-min.js');
  drupal_add_js($path . '/tableofcontents.js');
  drupal_add_css($path . '/tableofcontents.css');

  // Add any JS settings needed too.
  $settings = array(
    'tableOfContents' => array(
      'boxSettings' => array(
        'hideText' => variable_get('tableofcontents_hide_show_text_hide', 'hide'),
        'showText' => variable_get('tableofcontents_hide_show_text_show', 'show'),
      ),
    ),
  );
  drupal_add_js($settings, 'setting');
}