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 | <?php
function js_example_theme() {
return array(
'my_accordion' => array(
'template' => 'accordion',
'variables' => array('title' => NULL),
),
);
}
function js_example_menu() {
$items = array();
$items['js_example/weights'] = array(
'title' => 'JS Example: see weighting in action',
'page callback' => 'js_example_js_weights',
'access callback' => TRUE,
);
$items['js_example/accordion'] = array(
'title' => 'JS Example: jQuery UI accordion',
'page callback' => 'js_example_accordion',
'access callback' => TRUE,
);
return $items;
}
function js_example_js_weights() {
drupal_add_css(drupal_get_path('module', 'js_example') . '/css/jsweights.css');
$weights = array(
'red' => 100,
'blue' => 23,
'green' => 3,
'brown' => 45,
'black' => 5,
'purple' => 60
);
drupal_add_js(array('js_weights' => $weights), array('type' => 'setting'));
drupal_add_js(drupal_get_path('module', 'js_example') . '/js/red.js', array('weight' => $weights['red']));
drupal_add_js(drupal_get_path('module', 'js_example') . '/js/blue.js', array('weight' => $weights['blue']));
drupal_add_js(drupal_get_path('module', 'js_example') . '/js/green.js', array('weight' => $weights['green']));
drupal_add_js(drupal_get_path('module', 'js_example') . '/js/brown.js', array('weight' => $weights['brown']));
drupal_add_js(drupal_get_path('module', 'js_example') . '/js/black.js', array('weight' => $weights['black']));
drupal_add_js(drupal_get_path('module', 'js_example') . '/js/purple.js', array('weight' => $weights['purple']));
$output = '<div id="js-weights"></div>';
return $output;
}
function js_example_accordion() {
$title = t('Click sections to expand or collapse:');
$build['myelement'] = array(
'#theme' => 'my_accordion',
'#title' => $title,
);
$build['myelement']['#attached']['library'][] = array('system', 'ui.accordion');
$build['myelement']['#attached']['js'][] = array('data' => '(function($){$(function() { $("#accordion").accordion(); })})(jQuery);', 'type' => 'inline');
$output = drupal_render($build);
return $output;
}
|