-
Notifications
You must be signed in to change notification settings - Fork 1
/
marquee.module
96 lines (84 loc) · 2.24 KB
/
marquee.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* @file
* Provide a marquee element.
*/
/**
* Implements hook_page_alter().
*/
function marquee_page_alter(&$page) {
//dsm($page);
/*
if (drupal_is_front_page()) {
$first_node = array_shift($page['content']['system_main']['nodes']);
$ad = array(
'my_add' => array(
'#markup' => '<div style="padding: 20px; text-align: center; border: 1px solid #000"><img src="http://2011.tcdrupal.org/sites/2011.tcdrupal.org/themes/tcdrupal3/images/logo.png" /></div>',
),
);
array_unshift($page['content']['system_main']['nodes'], $first_node, $ad);
}
*/
$page = _marquee_page_alter($page);
}
/**
* Implements hook_element_info().
*/
function marquee_element_info() {
$types = array();
// The key of the array will become the element #type. For example,
// #type => 'marquee'.
$types['marquee'] = array(
'#theme' => 'marquee_marquee',
);
return $types;
}
/**
* Implements hook_theme().
*/
function marquee_theme() {
return array(
'marquee_marquee' => array(
'render element' => 'element',
),
'marquee_wrapper' => array(
'render element' => 'element',
),
);
}
/**
* Returns HTML for a marquee element.
*
* @param $variables
* An associative array containing:
* - element: A render element representing the marquee.
*
* @ingroup themeable
*/
function theme_marquee_marquee($variables) {
$element = $variables['element'];
$attributes = isset($element['#attributes']) ? $element['#attributes'] : array();
$output = '<marquee' . drupal_attributes($attributes) . '>';
$output .= $element['#value'];
$output .= '</marquee>';
return $output;
}
/**
* Wrap a div around the already-rendered #children.
*/
function theme_marquee_wrapper($variables) {
$amount = abs(rand(1, 50));
$direction = (abs(rand(0, 1)) == 1) ? 'left' : 'right';
$element = $variables['element'];
$output = '<marquee scrollamount="' . $amount . '" direction="'. $direction . '">';
$output .= $element['#children'];
$output .= '</div>';
return $output;
}
function _marquee_page_alter($element) {
$element['#theme_wrappers'][] = 'marquee_wrapper';
foreach (element_children($element) as $key) {
$element[$key] = _marquee_page_alter($element[$key]);
}
return $element;
}