-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjquery_countdown-caching-1901028-plus-layout-1971478.patch
More file actions
156 lines (148 loc) · 5.71 KB
/
Copy pathjquery_countdown-caching-1901028-plus-layout-1971478.patch
File metadata and controls
156 lines (148 loc) · 5.71 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
diff --git a/jquery_countdown.admin.inc b/jquery_countdown.admin.inc
index 114d128..8b23edf 100644
--- a/jquery_countdown.admin.inc
+++ b/jquery_countdown.admin.inc
@@ -56,6 +56,19 @@ function jquery_countdown_admin() {
'#type' => 'textarea',
'#default_value' => check_plain(variable_get('jquery_countdown_msg_format', ''))
);
+
+ $form['jquery_countdown_layout'] = array(
+ '#title' => t('Layout'),
+ '#description' => t(
+ 'Provide a customised layout for more control over the countdown appearance (see !link).<br/>Example (minutes and seconds are with leading zero): <em>%example</em>',
+ array(
+ '!link' => l('documentation', 'http://keith-wood.name/countdownRef.html#layout', array('external' => TRUE)),
+ '%example' => '<span>{dn}</span>:<span>{hn}</span>:<span>{mnn}</span>:<span>{snn}</span>',
+ )
+ ),
+ '#type' => 'textfield',
+ '#default_value' => variable_get('jquery_countdown_layout', ''),
+ );
return system_settings_form($form);
}// end function jquery_countdown_admin;
diff --git a/jquery_countdown.install b/jquery_countdown.install
index b56a894..5f47ee7 100644
--- a/jquery_countdown.install
+++ b/jquery_countdown.install
@@ -33,5 +33,6 @@ function jquery_countdown_uninstall() {
variable_del('jquery_countdown_target');
variable_del('jquery_countdown_exp_txt');
variable_del('jquery_countdown_msg_format');
+ variable_del('jquery_countdown_layout');
}// end function jquery_countdown_uninstall;
diff --git a/jquery_countdown.module b/jquery_countdown.module
index d6dd19b..45aa4fb 100644
--- a/jquery_countdown.module
+++ b/jquery_countdown.module
@@ -38,8 +38,7 @@ function jquery_countdown_block_info() {
$blocks = array();
$blocks['jquery_countdown']['info'] = t('jQuery Countdown Block');
- $blocks['jquery_countdown']['cache'] = DRUPAL_NO_CACHE;
-
+
return $blocks;
}// end function jquery_countdown_block_info;
@@ -93,8 +92,16 @@ function _jquery_countdown_block_content($delta = '') {
'onExpiry' => 'Drupal.jQueryCountdownEvent',
'expiryText' => check_plain(variable_get('jquery_countdown_exp_txt', ''))
);
+ // add "layout" option if provided
+ if ($layout = variable_get('jquery_countdown_layout', '')) {
+ $options['layout'] = $layout;
+ }
- return theme('jquery_countdown', array('options' => $options, 'id' => 'jquery_countdown-' . $delta ));
+ return array(
+ '#theme' => 'jquery_countdown',
+ '#id' => 'jquery_countdown-' . $delta,
+ '#options' => $options,
+ );
}// end function _jquery_countdown_block_content;
/**
@@ -170,11 +177,64 @@ function jquery_countdown_field_formatter_info() {
'jquery_countdown' => array(
'label' => t('jQuery Countdown'),
'field types' => array('date', 'datestamp', 'datetime'),
+ 'settings' => array(
+ 'layout' => '',
+ ),
),
);
return $formatters;
}
+/**
+ * Implements hook_field_formatter_settings_form().
+ */
+function jquery_countdown_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
+ $display = $instance['display'][$view_mode];
+ $settings = $display['settings'];
+
+ $element = array();
+ switch ($display['type']) {
+ case 'jquery_countdown':
+ $element['layout'] = array(
+ '#title' => t('Customise layout'),
+ '#description' => t(
+ 'Provide a customised layout for more control over the countdown appearance (see !link).<br/>Example (minutes and seconds are with leading zero):<br />%example',
+ array(
+ '!link' => l('documentation', 'http://keith-wood.name/countdownRef.html#layout', array('external' => TRUE)),
+ '%example' => '<span>{dn}</span>:<span>{hn}</span>:<span>{mnn}</span>:<span>{snn}</span>',
+ )
+ ),
+ '#type' => 'textfield',
+ '#default_value' => $settings['layout'],
+ );
+ break;
+ }
+
+ return $element;
+}
+
+/**
+ * Implements hook_ield_formatter_settings_summary().
+ */
+function jquery_countdown_field_formatter_settings_summary($field, $instance, $view_mode) {
+ $display = $instance['display'][$view_mode];
+ $settings = $display['settings'];
+
+ $return = array();
+ switch ($display['type']) {
+ case 'jquery_countdown':
+ if (empty($settings['layout'])) {
+ $return[] = t('Using default layout.');
+ }
+ else {
+ $return[] = t('Using customised layout: %layout', array('%layout' => check_plain($settings['layout'])));
+ }
+ break;
+ }
+
+ return implode('<br />', $return);
+}
+
function jquery_countdown_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$settings = $display['settings'];
@@ -216,13 +276,17 @@ function jquery_countdown_field_formatter_view($entity_type, $entity, $field, $i
continue;
}
else {
- $vars['delta'] = $delta;
- $vars['item'] = $item;
- $vars['id'] = $instance['field_name'] . '-' . $instance['id']; // use field as unique id
- $vars['options']['until'] = date("F d, Y g:i a +0000", strtotime($item['value'])); // get date from start field
-
- $element[$delta] = array('#markup' => theme('jquery_countdown', $vars));
+ $element[$delta] = array(
+ '#theme' => 'jquery_countdown',
+ '#delta' => $delta,
+ '#item' => $item,
+ '#id' => $instance['field_name'] . '-' . $instance['id'], // use field as unique id
+ '#options' => array('until' => date("F d, Y g:i a +0000", strtotime($item['value']))), // get date from start field
+ );
+ if (!empty($settings['layout'])) {
+ $element[$delta]['options']['layout'] = $settings['layout'];
+ }
}
}
break;