View source
<?php
define('ITOGGLE_VERSION', '7.x-3.x-dev');
function itoggle_library() {
return array(
'itoggle' => array(
'title' => 'iToggle',
'website' => 'http://drupal.org/project/itoggle',
'version' => ITOGGLE_VERSION,
'js' => array(
drupal_get_path('module', 'itoggle') . '/misc/itoggle.js' => array(),
),
'css' => array(
drupal_get_path('module', 'itoggle') . '/misc/itoggle.css' => array(),
),
),
);
}
function itoggle_element_info() {
return array(
'itoggle' => array(
'#input' => TRUE,
'#base_type' => 'checkbox',
'#process' => array(
'itoggle_element_process',
'ajax_process_form',
),
'#theme' => 'itoggle',
'#theme_wrappers' => array(
'itoggle_wrapper',
),
'#pre_render' => array(
'form_pre_render_conditional_form_element',
),
'#title_display' => 'before',
'#itoggle_type' => 'yesno',
),
);
}
function itoggle_element_process($element, $form_state) {
$element['#attached']['js'][] = drupal_get_path('module', 'itoggle') . '/misc/itoggle.js';
$element['#attached']['js'][] = drupal_get_path('module', 'itoggle') . '/misc/itoggle-element.js';
$element['#attached']['css'][] = drupal_get_path('module', 'itoggle') . '/misc/itoggle.css';
if (isset($element['#options'])) {
return form_process_checkboxes($element);
}
else {
$element['#return_value'] = 1;
return form_process_checkbox($element, $form_state);
}
}
function itoggle_theme() {
return array(
'itoggle' => array(
'render element' => 'element',
),
'itoggle_wrapper' => array(
'render element' => 'element',
),
);
}
function theme_itoggle($variables) {
return theme_checkbox($variables);
}
function theme_itoggle_wrapper($variables) {
$element =& $variables['element'];
$display_types = array(
'yesno',
'onoff',
'onezero',
);
if (!in_array($element['#itoggle_type'], $display_types)) {
$element['#itoggle_type'] = 'yesno';
}
$element += array(
'#title_display' => 'before',
);
$attributes['id'] = $element['#id'];
$attributes['class'] = array(
'form-item',
'itoggle-wrapper',
"itoggle-display-{$element['#itoggle_type']}",
);
if (!empty($element['#type'])) {
$attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
}
if (!empty($element['#name'])) {
$attributes['class'][] = 'form-item-' . strtr($element['#name'], array(
' ' => '-',
'_' => '-',
'[' => '-',
']' => '',
));
}
if (!empty($element['#attributes']['disabled'])) {
$attributes['class'][] = 'form-disabled';
}
$output = '<div' . drupal_attributes($attributes) . '>' . "\n";
$output .= $element['#children'];
if (!empty($element['#description'])) {
$output .= '<div class="description">' . $element['#description'] . "</div>\n";
}
$output .= "</div>\n";
return $output;
}