/[drupal]/contributions/modules/slider/slider.module
ViewVC logotype

Contents of /contributions/modules/slider/slider.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Wed Oct 15 10:04:25 2008 UTC (13 months, 1 week ago) by marktheunissen
Branch: MAIN
CVS Tags: DRUPAL-6--1-1, HEAD
Branch point for: DRUPAL-6--1
File MIME type: text/x-php
first commit of slider module
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Turns a node into a coda slider
7 *
8 * This module allows the user to select a node type to be transformed into
9 * a coda slider. The node must contain a Nodereference CCK multifield. Each
10 * node referenced becomes a pane of content in the slider.
11 *
12 * CREDIT: http://jqueryfordesigners.com/coda-slider-effect/
13 *
14 */
15
16 /**
17 * Implementation of hook_menu().
18 */
19 function slider_menu() {
20 $items['admin/settings/slider'] = array(
21 'title' => 'Slider',
22 'description' => 'Change the slider node type settings',
23 'page callback' => 'drupal_get_form',
24 'page arguments' => array('slider_admin_settings'),
25 'access arguments' => array('administer site configuration'),
26 'type' => MENU_NORMAL_ITEM,
27 'file' => 'slider.admin.inc',
28 );
29
30 return $items;
31 }
32
33 /**
34 * Implementation of hook_theme().
35 */
36 function slider_theme() {
37 return array(
38 'slider' => array(
39 'template' => 'slider',
40 'arguments' => array('node' => NULL),
41 ),
42 );
43 }
44
45 /**
46 * Implementation of hook_nodeapi().
47 */
48 function slider_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
49 switch ($op) {
50 case 'view':
51 // abort unless we are viewing full page
52 if (!$page) {
53 break;
54 }
55
56 // abort if this is not a slider type
57 $slider_types = variable_get('slider_node_types', array());
58 if (!in_array($node->type, $slider_types)) {
59 break;
60 }
61 $node->content['slider']['#weight'] = 10;
62
63 // if there are no selected node references
64 $numtabs = count($node->field_slider_content);
65 if ($node->field_slider_content[0]['nid'] === NULL) {
66 $empty_slider = t('No content selected for this slider.');
67 $node->content['slider']['#value'] = '<div class="no-slider">' . $empty_slider . '</div>';
68 break;
69 }
70
71 // this is a slider node, so perform modifications!
72 _slider_includes();
73 $node->content['slider']['#value'] = theme('slider', $node);
74 $node->content['slider']['#weight'] = 10;
75 unset($node->content['field_slider_content']);
76 break;
77 }
78 }
79
80 /**
81 * Include necessary files for the slider.
82 */
83 function _slider_includes() {
84 $modulepath = drupal_get_path('module', 'slider');
85 drupal_add_css($modulepath . '/css/slider.css');
86
87 // pass through the dynamic path so it can be accessed from the jquery
88 $js = "var path_to_slider = '". base_path() . $modulepath . "';";
89 drupal_add_js($js, 'inline');
90
91 drupal_add_js($modulepath . '/js/jquery.localscroll-min.js');
92 drupal_add_js($modulepath . '/js/jquery.scrollTo-min.js');
93 drupal_add_js($modulepath . '/js/jquery.serialScroll-min.js');
94 drupal_add_js($modulepath . '/js/slider.js');
95 }
96
97 /**
98 * Preprocess the slider variables.
99 */
100 function template_preprocess_slider(&$vars) {
101 // abort if the slider has no nodes
102 $num_slides = count($vars['node']->field_slider_content);
103 $vars['valid_slider'] = $num_slides ? TRUE : FALSE;
104 if (!$num_slides) {
105 return;
106 }
107
108 $vars['tab'] = array();
109 $vars['slide_content'] = array();
110
111 for ($i = 0; $i < $num_slides; $i++) {
112 $slide_node = node_load($vars['node']->field_slider_content[$i]['nid']);
113 if (!$slide_node) {
114 // node not found!
115 continue;
116 }
117
118 // add the tabs
119 $slide_id = "slider-nid$slide_node->nid";
120 $slide_classes = 'slidetab';
121 if ($i == 0) {
122 $slide_classes .= ' slidetab-active';
123 }
124 $slide_options = array(
125 'attributes' => array('class' => $slide_classes),
126 'fragment' => $slide_id,
127 );
128 $slide_title = check_plain($slide_node->title);
129 $vars['tabs'][] = l($slide_title, $_GET['q'], $slide_options);
130
131 // add the contents of each slide
132 $slide_node_view = node_view($slide_node, FALSE, TRUE, FALSE);
133 $vars['slide_content'][] = "<div class=\"panel\" id=\"$slide_id\">" . $slide_node_view . '</div>';
134 }
135
136 // theme nicely
137 $vars['tabs_formatted'] = theme('item_list', $vars['tabs'], NULL, 'ul', array('class' => 'slidenav'));
138 $vars['slider_content_formatted'] = implode("\n", $vars['slide_content']);
139
140 // above or below
141 $vars['tabs_position'] = variable_get("slider_tabs_position", 0);
142 }

  ViewVC Help
Powered by ViewVC 1.1.2