| 1 |
<?php
|
| 2 |
// $Id: greybox.module,v 1.1.2.5 2007/07/14 17:53:00 Gurpartap Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_perm().
|
| 6 |
*/
|
| 7 |
function greybox_perm() {
|
| 8 |
return array('administer greybox');
|
| 9 |
}
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Implementation of hook_init().
|
| 13 |
*/
|
| 14 |
function greybox_init() {
|
| 15 |
static $files_added = FALSE;
|
| 16 |
if (!$files_added) {
|
| 17 |
greybox_add_files();
|
| 18 |
$files_added = TRUE;
|
| 19 |
}
|
| 20 |
}
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Implementation of hook_menu().
|
| 24 |
*/
|
| 25 |
function greybox_menu() {
|
| 26 |
$items = array();
|
| 27 |
|
| 28 |
$items['admin/settings/greybox'] = array(
|
| 29 |
'title' => t('Greybox'),
|
| 30 |
'description' => t('Configure the appearance of Greybox popup window.'),
|
| 31 |
'page callback' => 'drupal_get_form',
|
| 32 |
'page arguments' => array('greybox_settings'),
|
| 33 |
'access callback' => 'user_access',
|
| 34 |
'access arguments' => array('administer greybox'),
|
| 35 |
'type' => MENU_NORMAL_ITEM
|
| 36 |
);
|
| 37 |
|
| 38 |
return $items;
|
| 39 |
}
|
| 40 |
|
| 41 |
/**
|
| 42 |
* Menu callback; Returns settings form..
|
| 43 |
*/
|
| 44 |
function greybox_settings() {
|
| 45 |
$form = array();
|
| 46 |
|
| 47 |
$form['greybox_options'] = array(
|
| 48 |
'#type' => 'fieldset',
|
| 49 |
'#title' => t('Basic configuration'),
|
| 50 |
'#description' => t('<em>Open <a href="http://google.com" class="greybox" title="My caption" rel="">Example Popup</a> ( <code><a href="http://google.com" class="greybox" title="My caption" rel="">Example Popup</a></code> )</em>'),
|
| 51 |
'#collapsible' => FALSE,
|
| 52 |
'#collapsed' => FALSE,
|
| 53 |
);
|
| 54 |
$form['greybox_options']['greybox_class_text'] = array(
|
| 55 |
'#type' => 'textfield',
|
| 56 |
'#title' => t('Class name'),
|
| 57 |
'#description' => t('The class name of the elements, to associate Greybox with. Example: Enter <em>greybox</em> if your element HTML code is: <code><a class="greybox"></code>.'),
|
| 58 |
'#default_value' => variable_get('greybox_class_text', 'greybox'),
|
| 59 |
);
|
| 60 |
$form['greybox_options']['greybox_window_height'] = array(
|
| 61 |
'#type' => 'textfield',
|
| 62 |
'#title' => t('Window height (in pixels)'),
|
| 63 |
'#description' => t('600 recommended. Enter 0 for automatic height.'),
|
| 64 |
'#size' => 5,
|
| 65 |
'#required' => TRUE,
|
| 66 |
'#default_value' => variable_get('greybox_window_height', 0),
|
| 67 |
);
|
| 68 |
$form['greybox_options']['greybox_window_width'] = array(
|
| 69 |
'#type' => 'textfield',
|
| 70 |
'#title' => t('Window width (in pixels)'),
|
| 71 |
'#description' => t('800 recommended. Enter 0 for automatic width.'),
|
| 72 |
'#size' => 5,
|
| 73 |
'#required' => TRUE,
|
| 74 |
'#default_value' => variable_get('greybox_window_width', 0),
|
| 75 |
);
|
| 76 |
|
| 77 |
return system_settings_form($form);
|
| 78 |
}
|
| 79 |
|
| 80 |
/**
|
| 81 |
* Load required JS and CSS files.
|
| 82 |
*/
|
| 83 |
function greybox_add_files() {
|
| 84 |
$path = drupal_get_path('module', 'greybox');
|
| 85 |
$height = variable_get('greybox_window_height', 0);
|
| 86 |
$width = variable_get('greybox_window_width', 0);
|
| 87 |
// Add the required CSS file.
|
| 88 |
drupal_add_css($path . '/greybox.css');
|
| 89 |
// Add the Javascript settings.
|
| 90 |
drupal_add_js(array(
|
| 91 |
'greybox' => array(
|
| 92 |
'class_text' => variable_get('greybox_class_text', 'greybox'),
|
| 93 |
'gbheight' => $height == 0 ? NULL : $height,
|
| 94 |
'gbwidth' => $width == 0 ? NULL : $width,
|
| 95 |
'path' => base_path() . $path,
|
| 96 |
),
|
| 97 |
), 'setting');
|
| 98 |
// Add the required Javascript.
|
| 99 |
drupal_add_js($path . '/js/greybox.js');
|
| 100 |
}
|
| 101 |
|