| 1 |
<?php
|
| 2 |
// $Id
|
| 3 |
/**
|
| 4 |
* implementation of hook_panels_styles
|
| 5 |
*/
|
| 6 |
function panels_accordion_panels_styles() {
|
| 7 |
return array(
|
| 8 |
'accordion' => array(
|
| 9 |
'title' => t('Accordian'),
|
| 10 |
'description' => t('Apply accordion styles to multiple panes'),
|
| 11 |
'panels implementations' => array(),
|
| 12 |
'render panel' => 'panels_accordion_style_render_panel',
|
| 13 |
'settings form' => 'panels_accordion_style_settings_form',
|
| 14 |
),
|
| 15 |
);
|
| 16 |
}
|
| 17 |
|
| 18 |
/**
|
| 19 |
* Panel style render callback.
|
| 20 |
*/
|
| 21 |
function theme_panels_accordion_style_render_panel($display, $panel_id, $panes, $settings) {
|
| 22 |
$output = '';
|
| 23 |
$style = panels_get_style('accordion');
|
| 24 |
$reverse_action = array('slideDown'=> 'slideUp', 'fadeIn' => 'fadeOut', 'show' => 'hide' );
|
| 25 |
|
| 26 |
drupal_add_js(drupal_get_path('module', 'panels_accordion') . '/js/jquery.cookie.js', 'module');
|
| 27 |
drupal_add_js('$(document).ready(function(){
|
| 28 |
//Hide all submenus
|
| 29 |
$("#panels_accordion-' .$panel_id .' .content").hide();
|
| 30 |
//Get cookie value or set to 0 if not found
|
| 31 |
var cid = parseInt($.cookie("accordion_cookie"));
|
| 32 |
if(isNaN(cid))
|
| 33 |
{
|
| 34 |
cid =0;
|
| 35 |
}
|
| 36 |
//show corresponding menu
|
| 37 |
$("#panels_accordion-' .$panel_id .' .content:eq("+cid+")").show();
|
| 38 |
|
| 39 |
//Loop through all menu header and assign click action to set cookie with correct index number
|
| 40 |
$("#panels_accordion-' .$panel_id .' span a").each(
|
| 41 |
function(i) {
|
| 42 |
$(this).click(
|
| 43 |
function(e)
|
| 44 |
{
|
| 45 |
var date = new Date();
|
| 46 |
|
| 47 |
date.setTime(date.getTime() + (60 * 60 * 1000));
|
| 48 |
|
| 49 |
$.cookie("accordion_cookie", i.toString(), { path: "/", expires: date });
|
| 50 |
}
|
| 51 |
)
|
| 52 |
});
|
| 53 |
|
| 54 |
$("#panels_accordion-' .$panel_id .' span a").' .$settings['action']. '(function(){
|
| 55 |
$("#panels_accordion-' .$panel_id .' span a").removeClass("active");
|
| 56 |
$(this).addClass("active");
|
| 57 |
$("#panels_accordion-' .$panel_id .' .content:visible").' .$reverse_action[$settings['effect']]. '("' .$settings['speed'].'");
|
| 58 |
$(this).parent().parent().next().' .$settings['effect']. '("' .$settings['speed'].'").scrollTo( $("#panels_accordion-' .$panel_id .' "), 800 );
|
| 59 |
return false;
|
| 60 |
});
|
| 61 |
});', 'inline');
|
| 62 |
|
| 63 |
|
| 64 |
// Render the items of the accordion.
|
| 65 |
$output .= '<div id="panels_accordion-' . $panel_id . '">';
|
| 66 |
$class = 'class="active"';
|
| 67 |
foreach ($panes as $pane_id => $pane) {
|
| 68 |
$pane->subject = '<span><a href="#"' .$class. '>' .strip_tags($pane->title, '<p><h1><h2><h3><strong><img>'). '</a></span>';
|
| 69 |
$pane->title = '<span><a href="#"' .$class. '>' .strip_tags($pane->title, '<p><h1><h2><h3><strong><img>'). '</a></span>';
|
| 70 |
$output .= theme('panels_pane', $pane, $display->content[$pane_id], $display);
|
| 71 |
$class = '';
|
| 72 |
}
|
| 73 |
$output .= '</div>';
|
| 74 |
|
| 75 |
return $output;
|
| 76 |
|
| 77 |
}
|
| 78 |
|
| 79 |
/**
|
| 80 |
* Settings form for this style
|
| 81 |
*/
|
| 82 |
function panels_accordion_style_settings_form($style_settings) {
|
| 83 |
// need to see if not(:first) has more alternative
|
| 84 |
/*$form['expanded'] = array(
|
| 85 |
'#type' => 'textfield',
|
| 86 |
'#title' => t('Expanded'),
|
| 87 |
'#default_value' => isset($style_settings['expanded']) ? $style_settings['expanded'] : 'first',
|
| 88 |
'#description' => t('Choose which panel will be expanded by default'),
|
| 89 |
);*/
|
| 90 |
$form['action'] = array(
|
| 91 |
'#type' => 'radios',
|
| 92 |
'#title' => t('Action'),
|
| 93 |
'#options' => array('click' => t('Click'), 'mouseover' => t('Mouse Over')),
|
| 94 |
'#default_value' => isset($style_settings['action']) ? $style_settings['action'] : $style_settings['action'] = 'click',
|
| 95 |
'#description' => t('Choose what event will make the action occur'),
|
| 96 |
);
|
| 97 |
$form['effect'] = array(
|
| 98 |
'#type' => 'radios',
|
| 99 |
'#title' => t('Effect'),
|
| 100 |
'#options' => array('slideDown' => t('Slide Down'), 'fadeIn' => t('Fade In'), 'show' => t('Show')),
|
| 101 |
'#default_value' => isset($style_settings['effect']) ? $style_settings['effect'] : $style_settings['effect'] = 'slideDown',
|
| 102 |
'#description' => t('Choose what effect will occur when focus area is triggered'),
|
| 103 |
);
|
| 104 |
$form['speed'] = array(
|
| 105 |
'#type' => 'radios',
|
| 106 |
'#title' => t('Speed'),
|
| 107 |
'#options' => array('slow' => t('Slow'), 'normal' => t('Normal'), 'fast' => t('Fast')),
|
| 108 |
'#default_value' => isset($style_settings['speed']) ? $style_settings['speed'] : $style_settings['speed'] = 'normal',
|
| 109 |
'#description' => t('Choose the speed at which the effects will occur'),
|
| 110 |
);
|
| 111 |
// need to check for alternative to this method of MouseOver Delays
|
| 112 |
/*
|
| 113 |
$form['delay'] = array(
|
| 114 |
'#type' => 'textfield',
|
| 115 |
'#title' => t('Delay'),
|
| 116 |
'#default_value' => isset($style_settings['delay']) ? $style_settings['delay'] : '1',
|
| 117 |
'#description' => t('OPTIONAL : Set a Delay for the Mouse Over Action'),
|
| 118 |
);
|
| 119 |
*/
|
| 120 |
|
| 121 |
return $form;
|
| 122 |
}
|