-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopups_test.module
More file actions
226 lines (198 loc) · 10.7 KB
/
popups_test.module
File metadata and controls
226 lines (198 loc) · 10.7 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
/**
* @file
* Page for testing the Popups API.
*/
// **************************************************************************
// CORE HOOK FUNCTIONS ****************************************************
// **************************************************************************
/**
* Implementation of hook_menu().
*
* @return array of new menu items.
*/
function popups_test_menu() {
// Items for testing.
$items['popups/test'] = array(
'title' => 'Popup Test',
'page callback' => '_popups_test_popups',
'type' => MENU_CALLBACK,
'access callback' => TRUE,
);
$items['popups/test/response'] = array(
'page callback' => '_popups_test_response',
'type' => MENU_CALLBACK,
'access callback' => TRUE,
);
$items['popups/test/namechange'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array('_popups_test_namechange'),
'type' => MENU_CALLBACK,
'access callback' => TRUE,
);
$items['popups/test/old'] = array(
'title' => 'Popup Test',
'page callback' => '_popups_test_popups_old',
'type' => MENU_CALLBACK,
'access callback' => TRUE,
);
return $items;
}
/**
* Implementation of hook_popups().
*
* This implements hook_popups, defined in popups_get_popups.
* See the comments in popups_add_popups for explination of the options.
* Adding popup behavior to the core admin pages has been moved to popups_admin.
*
* @return: Array of link selectors to apply popup behavior to.
* Keyed by path or form_id.
*/
function popups_test_popups() {
return array(
'popups/test' => array( // test page.
// '*' => array( // test page.
'#test-popup' => array(
// 'additionalJavascript' => array('misc/collapse.js'),
// 'forceReturn' => 'node/add/story',
),
),
);
}
// **************************************************************************
// TESTING ****************************************************************
// **************************************************************************
function _popups_test_popups() {
popups_add_popups();
$output = '<ol id="test-list">';
$output .= '<li>'. l("Pop up entire local page.", 'popups/test/response',
array('attributes' => array('class' => 'popups')));
$output .= "<li>". l("Pop with options (href override).", 'popups/test/',
array('attributes' => array('class' => 'popups', 'on-popups-options' => '{href: "test/response"}')));
$output .= "<li>". l("Pop with options (width=200px).", 'popups/test/response',
array('attributes' => array('class' => 'popups', 'on-popups-options' => '{width: "200px"}')));
$output .= "<li class=\"popups\" on-popups-options=\"{href: 'test/response'}\">Non-link popup</li>";
$output .= '<li>'. l("Add Story (hook)", 'node/add/story',
array( 'attributes' => array('id' => 'test-popup')));
$output .= '<li>'. l("Add Story (attribute).", 'node/add/story',
array( 'attributes' => array('class' => 'popups-form')));
$output .= '<li>'. l("Change Settings and ajax update entire content area: ",
'admin/settings/popups',
array( 'attributes' => array('class' => 'popups-form'),
));
$output .= " (Auto Fade checkbox is: " . (variable_get('popups_autoclose_final_message', 1) ? 'on' : 'off') . ')';
$output .= '<li>'. l("Change Settings and ajax update only single target.", 'admin/settings/popups',
array( 'attributes' => array('id' => 'reload-target'),
));
$output .= "<span id='response2'> (Auto Fade checkbox is: " . (variable_get('popups_autoclose_final_message', 1) ? 'on' : 'off') . ')</span>';
popups_add_popups(array('#reload-target' => array('targetSelectors' => array('#response2'))));
$output .= '<li>'. l("Change Settings and ajax update multiple targets with data from other page (tricky!).", 'admin/settings/popups',
array( 'attributes' => array(
'id' => 'foo',
'class' => 'popups-form',
'on-popups-options' => '{targetSelectors: {"#edit-popups-always-scan-wrapper": "#foo", "#edit-popups-popup-final-message-wrapper": "#test-list li:first"}, forceReturn: "admin/settings/popups"}')));
$output .= '<li>'. l("Change Settings and reload entire page.",
'admin/settings/popups',
array( 'attributes' => array('class' => 'popups-form-reload'),
));
$output .= '<li>'. l("Pop up defined by popups_add_popups rule.", 'popups/test/response',
array('attributes' => array('id' => 'rule-test')));
popups_add_popups(array('#rule-test' => array('width' => '300px')));
$output .= '<li>'. l('Ajax update just Page Title (only works if you theme uses id="page-title")', 'popups/test/namechange',
array('attributes' => array('id' => 'title-test')));
popups_add_popups(array('#title-test' => array('titleSelectors' => array('#page-title'), 'noUpdate' => TRUE, 'forceReturn' => 'popups/test/namechange')));
global $user;
$output .= "<li>You are user number $user->uid</li>";
if ($user->uid == 0) {
$output .= '<li>'. l("Login and ajax refresh content area.", 'user',
array('attributes' => array('class' => 'popups-form')));
$output .= '<li>'. l("Login and reload entire page.", 'user',
array('attributes' => array('class' => 'popups-form-reload')));
$output .= '<li>'. l("Login and do not reload anything.", 'user',
array('attributes' => array('class' => 'popups-form-noupdate')));
}
else {
$output .= '<li>'. l("Logout (need to surpress warning b/c session is dumped)", 'logout',
array('attributes' => array('id' => 'logout')));
}
// Need to have the rule outside the else, or it won't get loaded on ajax reload.
popups_add_popups(array('#logout' => array('noUpdate' => TRUE, 'reloadOnError' => TRUE)));
$output .= '<li>'. l("Add Poll (test inline)", 'node/add/poll',
array('attributes' => array('class' => 'popups-form')));
$output .= "</ol>";
return $output;
}
function _popups_test_popups_old() {
// drupal_set_message('Popup Test Page: If you edit your page.tpl.php to wrap the print $messages in a div with id="popit", this message will popup on page load');
popups_add_popups();
$output = '<ul id="test-list">';
$output .= '<li>'. l("Pop up entire local page.", 'popups/test/response',
array('attributes' => array('class' => 'popups')));
$output .= "<li>". l("Pop with options (href override).", 'popups/test/',
array('attributes' => array('class' => 'popups', 'on-popups-options' => '{href: "test/response"}')));
$output .= "<li>". l("Pop with options (width=200px).", 'popups/test/response',
array('attributes' => array('class' => 'popups', 'on-popups-options' => '{width: "200px"}')));
$output .= "<li class=\"popups\" on-popups-options=\"{href: 'test/response'}\">Non-link popup</li>";
$output .= '<li>'. l("Add Story (hook)", 'node/add/story',
array( 'attributes' => array('id' => 'test-popup')));
$output .= '<li>'. l("Add Story (attribute).", 'node/add/story',
array( 'attributes' => array('class' => 'popups-form')));
$output .= '<li>'. l("Change Settings and ajax update entire content area: ",
'admin/settings/popups',
array( 'attributes' => array('class' => 'popups-form'),
));
$output .= " (Auto Fade checkbox is: " . (variable_get('popups_popup_final_message', 1) ? 'on' : 'off') . ')';
$output .= '<li>'. l("Change Settings and ajax update only single target.", 'admin/settings/popups',
array( 'attributes' => array('id' => 'reload-target'),
));
$output .= "<span id='response2'> (Auto Fade checkbox is: " . (variable_get('popups_popup_final_message', 1) ? 'on' : 'off') . ')</span>';
popups_add_popups(array('#reload-target' => array('targetSelectors' => array('#response2'))));
$output .= '<li>'. l("Change Settings and ajax update multiple targets with data from other page (tricky!).", 'admin/settings/popups',
array( 'attributes' => array(
'id' => 'foo',
'class' => 'popups-form',
'on-popups-options' => '{targetSelectors: {"#edit-popups-always-scan-wrapper": "#foo", "#edit-popups-popup-final-message-wrapper": "#test-list li:first"}, forceReturn: "admin/settings/popups"}')));
$output .= '<li>'. l("Change Settings and reload entire page.",
'admin/settings/popups',
array( 'attributes' => array('class' => 'popups-form-reload'),
));
$output .= '<li>'. l("Pop up defined by popups_add_popups rule.", 'popups/test/response',
array('attributes' => array('id' => 'rule-test')));
popups_add_popups(array('#rule-test' => array('width' => '300px')));
$output .= '<li>'. l('Ajax update just Page Title (only works if you theme uses id="page-title")', 'popups/test/namechange',
array('attributes' => array('id' => 'title-test')));
popups_add_popups(array('#title-test' => array('titleSelectors' => array('#page-title'), 'noUpdate' => TRUE, 'forceReturn' => 'popups/test/namechange')));
global $user;
$output .= "<li>You are user number $user->uid</li>";
if ($user->uid == 0) {
$output .= '<li>'. l("Login and ajax refresh content area.", 'user',
array('attributes' => array('class' => 'popups-form')));
$output .= '<li>'. l("Login and reload entire page.", 'user',
array('attributes' => array('class' => 'popups-form-reload')));
$output .= '<li>'. l("Login and do not reload anything.", 'user',
array('attributes' => array('class' => 'popups-form-noupdate')));
}
else {
$output .= '<li>'. l("Logout (need to surpress warning b/c session is dumped)", 'logout',
array('attributes' => array('id' => 'logout')));
}
// Need to have the rule outside the else, or it won't get loaded on ajax reload.
popups_add_popups(array('#logout' => array('noUpdate' => TRUE, 'reloadOnError' => TRUE)));
$output .= '<li>'. l("Add Poll (test inline)", 'node/add/poll',
array('attributes' => array('class' => 'popups-form')));
$output .= "</ul>";
return $output;
}
function _popups_test_response() {
drupal_set_title("Popup Test Two");
return '<div>Hello World</div><a href="#" class="popups">Popup chaining test</a>';
}
function _popups_test_namechange() {
drupal_set_title("New Name for Test Page");
$form = array();
$form['popups_popup_final_message'] = array(
'#type' => 'submit',
'#value' => t('Test Name Change'),
);
return $form;
}