You are here

marquee_block.module in Marquee Block 6

Same filename and directory in other branches
  1. 7 marquee_block.module

File

marquee_block.module
View source
<?php

function marquee_block_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $blocks[0]['info'] = t('Scrolling Marquee');
      return $blocks;
    case 'view':
      if ($delta == 0) {
        $block['content'] = theme('marquee_block_scroller');
      }
      return $block;
    case 'configure':
      if ($delta == 0) {
        $speed_options = array();
        $speed_options['1'] = t('Very Slow');
        $speed_options['2'] = t('Slow');
        $speed_options['3'] = t('Medium');
        $speed_options['4'] = t('Fast');
        $speed_options['5'] = t('Very Fast');
        $scroll_directions = array();
        $scroll_directions['left'] = t('Left');
        $scroll_directions['right'] = t('Right');
        $scroll_behaviors = array();
        $scroll_behaviors['scroll'] = t('Scroll');
        $scroll_behaviors['slide'] = t('Slide');
        $scroll_behaviors['alternate'] = t('Alternate');
        $form['marquee_block_message'] = array(
          '#type' => 'textarea',
          '#title' => t('Scrolling Message'),
          '#description' => t('Enter your scrolling message here.  HTML tags are allowed.'),
          '#default_value' => variable_get('marquee_block_message', ''),
        );
        $form['marquee_block_scroll_speed'] = array(
          '#type' => 'select',
          '#title' => t('Scroll Speed'),
          '#options' => $speed_options,
          '#default_value' => variable_get('marquee_block_scroll_speed', 3),
        );
        $form['marquee_block_scroll_direction'] = array(
          '#type' => 'radios',
          '#title' => t('Scroll Direction'),
          '#options' => $scroll_directions,
          '#default_value' => variable_get('marquee_block_scroll_direction', 'left'),
        );
        $form['marquee_block_scroll_behavior'] = array(
          '#type' => 'radios',
          '#title' => t('Scroll Behavior'),
          '#options' => $scroll_behaviors,
          '#default_value' => variable_get('marquee_block_scroll_behavior', 'scroll'),
        );
      }
      return $form;
    case 'save':
      if ($delta == 0) {
        variable_set('marquee_block_message', $edit['marquee_block_message']);
        variable_set('marquee_block_scroll_speed', $edit['marquee_block_scroll_speed']);
        variable_set('marquee_block_scroll_direction', $edit['marquee_block_scroll_direction']);
        variable_set('marquee_block_scroll_behavior', $edit['marquee_block_scroll_behavior']);
        drupal_set_message('Your marquee settings have been saved.');
      }
      break;
  }
}
function marquee_block_theme() {
  $items = array();
  $items['marquee_block_scroller'] = array(
    'arguments' => array(),
  );
  return $items;
}
function theme_marquee_block_scroller() {
  $path = drupal_get_path('module', 'marquee_block');
  drupal_add_css($path . '/marquee_block.css');
  drupal_add_js($path . '/jquery.marquee.js');
  drupal_add_js($path . '/marquee_block.js');
  $message = variable_get('marquee_block_message', '');
  $speed = variable_get('marquee_block_scroll_speed', 3);
  $direction = variable_get('marquee_block_scroll_direction', 'left');
  $behavior = variable_get('marquee_block_scroll_direction', 'scroll');
  if (strlen(trim($message)) > 0) {
    $output = '';
    $output .= '<div id="marquee-scroller">';
    $output .= '<div id="marquee-scroller-inner">';
    $output .= sprintf('<marquee class="marquee-block" behavior="%s" scrollamount="%s" direction="%s">', $behavior, $speed, $direction);
    $output .= '<span>' . $message . '</span>';
    $output .= '</marquee>';
    $output .= '</div>';
    $output .= '</div>';
  }
  return $output;
}