You are here

function tablesorter_page_build in Tablesorter 7

File

./tablesorter.module, line 338
Tablesorter.

Code

function tablesorter_page_build() {
  $attach = variable_get('tablesorter_page_init_action', 'page_enable') == 'page_enable';
  if (!$attach) {

    // Check if the current path is allowed to have sorted tables.
    $paths = variable_get('tablesorter_page_list') ?: '';
    $attach = drupal_match_path(drupal_get_path_alias(), $paths) || drupal_match_path(current_path(), $paths);
  }
  if ($attach) {
    libraries_load('tablesorter');

    // Add this module's javascript.
    drupal_add_js(drupal_get_path('module', 'tablesorter') . '/tablesortervar.js');
    $settings = array();
    $theme = variable_get('tablesorter_theme');
    if ($theme) {
      $settings['tablesorter']['theme'] = $theme;
    }

    // Add widgets.
    $widgets = variable_get('tablesorter_widgets');
    foreach ($widgets as $widget => $value) {
      if (!$value) {
        unset($widgets[$widget]);
      }
    }
    if ($widgets) {
      $settings['tablesorter']['widgets'] = array_keys($widgets);

      // Get stripe classes.
      if (in_array('zebra', $widgets)) {
        $settings['tablesorter']['zebra']['odd'] = variable_get('tablesorter_zebra_odd_class', 'odd');
        $settings['tablesorter']['zebra']['even'] = variable_get('tablesorter_zebra_even_class', 'even');
      }
    }

    // Add settings.
    drupal_add_js($settings, 'setting');
  }
}