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

Diff of /contributions/modules/ticketyboo/ticketyboo.module

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

revision 1.2, Thu Sep 4 17:55:12 2008 UTC revision 1.3, Thu Sep 11 15:49:07 2008 UTC
# Line 60  function _ticketyboo_config($delta) { Line 60  function _ticketyboo_config($delta) {
60        '#type' => 'textarea',        '#type' => 'textarea',
61        '#default_value' => variable_get('ticketyboo_nodes_'.$delta, ''),        '#default_value' => variable_get('ticketyboo_nodes_'.$delta, ''),
62     );     );
63     $form['seconds'] = array(     $form['transition'] = array(
64        '#title' => t('Frequency'),        '#title' => t('Transition time'),
65        '#description' => t('How often the ticker content will change - in seconds'),        '#description' => t('How long, in seconds, for the ticker to move to the next item.'),
66        '#type' => 'select',        '#type' => 'textfield',
67        '#default_value' => variable_get('ticketyboo_seconds_'.$delta, 5),        '#default_value' => variable_get('ticketyboo_transition_'.$delta, 3),
68        '#options' => array(5=>5, 6=>6, 7=>7,8=>8, 9=>9, 10=>10, 15=>15, 20=>20, 30=>30, 40=>40, 50=>50, 60=>60, 90=>90, 120=>120),     );
69       $form['pause'] = array(
70          '#title' => t('Pause time'),
71          '#description' => t('How long, in seconds, for the ticker to remain stationary on each item.'),
72          '#type' => 'textfield',
73          '#default_value' => variable_get('ticketyboo_pause_'.$delta, 1),
74     );     );
75     $form['direction'] = array(     $form['direction'] = array(
76        '#title' => t('Direction'),        '#title' => t('Direction'),
77        '#description' => t('Direction in which the ticker will move'),        '#description' => t('Direction in which the ticker will move'),
78        '#type' => 'select',        '#type' => 'select',
79        '#default_value' => variable_get('ticketyboo_direction_'.$delta, 'vertical'),        '#default_value' => variable_get('ticketyboo_direction_'.$delta, 'vertical'),
80        '#options' => array('vertical'=>'vertical', 'horizontal'=>'horizontal', 'diagonal'=>'diagonal'),        '#options' => array('vertical'=>'vertical', 'horizontal'=>'horizontal'),
81     );     );
82     $form['height'] = array(     $form['style'] = array(
83        '#title' => t('Height'),        '#title' => t('Ticker style'),
84        '#description' => t('The height of the ticker area'),        '#description' => t('CSS style attributes for the ticker area'),
85        '#type' => 'textfield',        '#type' => 'textfield',
86        '#default_value' => variable_get('ticketyboo_height_'.$delta, '100px'),        '#default_value' => variable_get('ticketyboo_style_'.$delta, 'width: 100px; height: 100px;'),
87     );     );
88     $form['width'] = array(     $form['item_width'] = array(
89        '#title' => t('Width'),        '#title' => t('Item width'),
90        '#description' => t('The width of the ticker area'),        '#description' => t('Width of individual ticker items in pixels'),
91        '#type' => 'textfield',        '#type' => 'textfield',
92        '#default_value' => variable_get('ticketyboo_width_'.$delta, '200px'),        '#default_value' => variable_get('ticketyboo_item_width_'.$delta, 100),
93       );
94       $form['item_height'] = array(
95          '#title' => t('Item height'),
96          '#description' => t('Height of individual ticker items in pixels'),
97          '#type' => 'textfield',
98          '#default_value' => variable_get('ticketyboo_item_height_'.$delta, 100),
99       );
100       $form['item_spacing'] = array(
101          '#title' => t('Item spacing'),
102          '#description' => t('Spacing between individual ticker items in pixels'),
103          '#type' => 'textfield',
104          '#default_value' => variable_get('ticketyboo_item_spacing_'.$delta, 10),
105       );
106       $form['item_style'] = array(
107          '#title' => t('Ticker item style'),
108          '#description' => t('CSS style attributes for each ticker item.  Don\'t specify height or width, though.'),
109          '#type' => 'textfield',
110          '#default_value' => variable_get('ticketyboo_item_style_'.$delta, ''),
111       );
112       $form['offset'] = array(
113          '#title' => t('Offset'),
114          '#description' => t('Initial offset, ie starting position for the ticker items, in pixels.'),
115          '#type' => 'textfield',
116          '#default_value' => variable_get('ticketyboo_offset_'.$delta, 0),
117     );     );
118     return $form;     return $form;
119  }  }
# Line 95  function _ticketyboo_config($delta) { Line 124  function _ticketyboo_config($delta) {
124  function _ticketyboo_config_save($delta, $edit) {  function _ticketyboo_config_save($delta, $edit) {
125     variable_set('ticketyboo_nodes_'.$delta, $edit['nodes']);     variable_set('ticketyboo_nodes_'.$delta, $edit['nodes']);
126     variable_set('ticketyboo_text_'.$delta, $edit['text']);     variable_set('ticketyboo_text_'.$delta, $edit['text']);
127     variable_set('ticketyboo_seconds_'.$delta, $edit['seconds']);     variable_set('ticketyboo_transition_'.$delta, $edit['transition']);
128       variable_set('ticketyboo_pause_'.$delta, $edit['pause']);
129     variable_set('ticketyboo_direction_'.$delta, $edit['direction']);     variable_set('ticketyboo_direction_'.$delta, $edit['direction']);
130     variable_set('ticketyboo_height_'.$delta, $edit['height']);     variable_set('ticketyboo_style_'.$delta, $edit['style']);
131     variable_set('ticketyboo_width_'.$delta, $edit['width']);     variable_set('ticketyboo_item_width_'.$delta, $edit['item_width']);
132       variable_set('ticketyboo_item_height_'.$delta, $edit['item_height']);
133       variable_set('ticketyboo_item_spacing_'.$delta, $edit['item_spacing']);
134       variable_set('ticketyboo_item_style_'.$delta, $edit['item_style']);
135       variable_set('ticketyboo_offset_'.$delta, $edit['offset']);
136  }  }
137    
138  /**  /**
# Line 106  function _ticketyboo_config_save($delta, Line 140  function _ticketyboo_config_save($delta,
140  */  */
141  function _ticketyboo_block($delta) {  function _ticketyboo_block($delta) {
142  static $loaded = false;  static $loaded = false;
143    $eps = 50; // events per second, controls the smoothness of the ticker
144    
145       // get the parameters
146     $nodes = variable_get('ticketyboo_nodes_'.$delta, '');     $nodes = variable_get('ticketyboo_nodes_'.$delta, '');
147     $height = variable_get('ticketyboo_height_'.$delta, '100px');     $text = variable_get('ticketyboo_text_'.$delta, '');
148     $ret = '';     $transition = variable_get('ticketyboo_transition_'.$delta, 3);
149     $ret .= variable_get('ticketyboo_text_'.$delta, '');     $pause = variable_get('ticketyboo_pause_'.$delta, 1);
150     $ret .= '<div id="ticketyboo_'.$delta.'" class="ticketyboo_wrapper" style="height: '.$height.'; width: '.variable_get('ticketyboo_width_'.$delta, '200px').';" onMouseover="ticketypause['.$delta.'] = true" onMouseout="ticketypause['.$delta.'] = false">';     $direction = variable_get('ticketyboo_direction_'.$delta, 'vertical');
151       $style = variable_get('ticketyboo_style_'.$delta, 'width: 100px; height: 100px;');
152       $item_width = variable_get('ticketyboo_item_width_'.$delta, 100);
153       $item_height = variable_get('ticketyboo_item_height_'.$delta, 100);
154       $item_spacing = variable_get('ticketyboo_item_spacing_'.$delta, 100);
155       $item_style = variable_get('ticketyboo_item_style_'.$delta, '');
156       $offset = variable_get('ticketyboo_offset_'.$delta, 0);
157    
158       // ticker id
159       $id = "ticketyboo_$delta";
160    
161       // timer interval
162       $interval = (int) 1000/$eps;
163       // distance moved during transition
164       if ($direction == 'horizontal') {
165          $distance = $item_width + $item_spacing;
166       } else {
167          $distance = $item_height + $item_spacing;
168       }
169       // number of events in each transition and size of each event
170       $transition_events = $transition * $eps;
171       $transition_distance = $distance / $transition_events;
172       $pause_events = $pause * $eps;
173    
174       // additional style information for ticker
175       $style = "overflow-x: hidden; overflow-y: hidden; $style";
176       if ($direction == 'horizontal') {
177          $float = 'float: left;';
178          $pad_style="width: {$item_spacing}px; height: {$item_height}px; $float";
179       } else {
180          $float = '';
181          $pad_style="width: {$item_width}px; height: {$item_spacing}px";
182       }
183       $item_style = "overflow-x: hidden; overflow-y: hidden; {$float} width: {$item_width}px; height: {$item_height}px; {$item_style}";
184    
185       // build the ticker contents
186     $nodes = explode(',', $nodes);     $nodes = explode(',', $nodes);
187     $i = 0;     $ret = '';
188       $i=0;
189     foreach ($nodes as $nid) {     foreach ($nodes as $nid) {
       $i++;  
190        $node = node_load(trim($nid));        $node = node_load(trim($nid));
191        $ret .= '<div id="ticketyboo_'.$delta.'_'.$i.'" class="ticketyboo_teaser" style="height: '.$height.'; width: '.variable_get('ticketyboo_width_'.$delta, '200px').';">';        if ($i > 0) {
192             $ret .= '<div style="'.$pad_style.'"></div>';
193          }
194          $ret .= '<div id="ticketyboo_'.$delta.'_'.$i.'" class="ticketyboo_teaser" style="'.$item_style.'">';
195        $ret .= $node->teaser;        $ret .= $node->teaser;
196        $ret .= '</div>';        $ret .= '</div>';
197          $i++;
198       }
199    
200       // build a wrapper for the contents
201       if ($direction == 'horizontal') {
202          $w = count($nodes) * ($item_width + $item_spacing);
203          $h = $item_height;
204       } else {
205          $h = count($nodes) * ($item_height + $item_spacing);
206          $w = $item_width;
207     }     }
208     $ret .= '</div>';     $wrap_style = "width: {$w}px; height: {$h}px;";
209       $ret = '<div id="'.$id.'_wrapper" style="'.$wrap_style.'">'.$ret.'</div>';
210    
211     drupal_add_js('ticketyboo_init('.$delta.', '.variable_get('ticketyboo_seconds_'.$delta, 10).', '.count($nodes).', "'.variable_get('ticketyboo_direction_'.$delta, 'vertical').'")', 'inline', 'footer', true);     // put contents in ticker window
212       $ret = '<div id="'.$id.'" class="ticketyboo_wrapper" style="'.$style.'" onMouseover="ticketypause['.$delta.'] = true" onMouseout="ticketypause['.$delta.'] = false">'.$ret.'</div>';
213    
214       // add scripts etc to page
215       $count = count($nodes);
216       drupal_add_js("tick[$delta] = new ticker($delta, '$id', '$direction', $count, $distance, $interval, $transition_events, $transition_distance, $pause_events, $offset)",
217          'inline', 'footer', true);
218     if (!$loaded) {     if (!$loaded) {
219        drupal_add_js(drupal_get_path('module', 'ticketyboo').'/ticketyboo.js', 'module');        drupal_add_js(drupal_get_path('module', 'ticketyboo').'/ticketyboo.js', 'module');
       drupal_add_css(drupal_get_path('module', 'ticketyboo').'/ticketyboo.css', 'module');  
220        $loaded = true;        $loaded = true;
221     }     }
222    
223     return $ret;     return $text.$ret;
224    
225  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2