You are here

twitter_bootstrap_modal.module in Twitter Bootstrap Modal 7

Same filename and directory in other branches
  1. 7.3 twitter_bootstrap_modal.module

Generates a Twitter Bootstrap Modal.

Depends on the jQuery Ajax Load Modules

File

twitter_bootstrap_modal.module
View source
<?php

/**
* @file
* Generates a Twitter Bootstrap Modal.
*
* Depends on the jQuery Ajax Load Modules
*/

/**
 * Implements hook_init().
 */
function twitter_bootstrap_modal_init() {
  $module_path = drupal_get_path('module', 'twitter_bootstrap_modal');
  $tb_trigger = jquery_ajax_load_get_triggers('jquery_ajax_load_trigger_TB', '.twitter_bootstrap_modal');
  $site_name = variable_get('site_name', "Default site name");
  $modal_string = theme('twitter_bootstrap_modal_modal', array(
    'site_name' => $site_name,
    'module_path' => $module_path,
    'replacement_string' => '%s',
  ));
  drupal_add_js(array(
    'jquery_ajax_load' => array(
      'TBtrigger' => $tb_trigger,
      'TBmodal' => $modal_string,
    ),
  ), 'setting');
  drupal_add_js($module_path . '/twitter_bootstrap_modal.js');
}

/**
* Implementation of hook_menu().
*/
function twitter_bootstrap_modal_menu() {

  // Admin settings.
  $items['admin/config/development/jquery_ajax_load/TB'] = array(
    'title' => 'Twitter Bootstrap Modal',
    'description' => 'Shows any page on a Twitter Boostrap AJAX Modal',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'twitter_bootstrap_modal_admin',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'type' => MENU_LOCAL_TASK,
  );
  return $items;
}

/**
 * Callback function for admin setting.
 */
function twitter_bootstrap_modal_admin() {

  // This module will not work if used in overlay paths such as
  // admin/* , node/add etc if user has overlay access.
  $form['jquery_ajax_load_trigger_TB'] = array(
    '#type' => 'textarea',
    '#title' => t('Valid jQuery Classes/IDs to trigger TB Modal via Ajax (One per line)'),
    '#default_value' => variable_get('jquery_ajax_load_trigger_TB', '.twitter_bootstrap_modal' . "\n"),
    '#description' => t('Specify the class/ID of links to convert that link TB Modal, one per line. For example by providing ".twitter_bootstrap_modal" will convert any link with class="twitter_bootstrap_modal"'),
  );
  return system_settings_form($form);
}

/**
 * Implementation of hook_theme().
 *
 * Creates the template for the TB Modal.
 */
function twitter_bootstrap_modal_theme($existing, $type, $theme, $path) {
  $themes = array(
    'twitter_bootstrap_modal_modal' => array(
      'variables' => array(
        'site_name' => NULL,
        'module_path' => NULL,
        'replacement_string' => '%s',
      ),
      'template' => 'twitter_bootstrap_modal_modal',
    ),
  );
  return $themes;
}

Functions

Namesort descending Description
twitter_bootstrap_modal_admin Callback function for admin setting.
twitter_bootstrap_modal_init Implements hook_init().
twitter_bootstrap_modal_menu Implementation of hook_menu().
twitter_bootstrap_modal_theme Implementation of hook_theme().