Mercurial > defr > drupal > popups
comparison popups_test.module @ 0:76f9b43738f2
Popups 2.0-alpha5
author | Franck Deroche <franck@defr.org> |
---|---|
date | Fri, 31 Dec 2010 13:41:08 +0100 |
parents | |
children | 4215c43e74eb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:76f9b43738f2 |
---|---|
1 <?php | |
2 // $Id: popups_test.module,v 1.1.4.6 2009/03/19 15:53:44 starbow Exp $ | |
3 | |
4 /** | |
5 * @file | |
6 * Page for testing the Popups API. | |
7 */ | |
8 | |
9 | |
10 // ************************************************************************** | |
11 // CORE HOOK FUNCTIONS **************************************************** | |
12 // ************************************************************************** | |
13 | |
14 /** | |
15 * Implementation of hook_menu(). | |
16 * | |
17 * @return array of new menu items. | |
18 */ | |
19 function popups_test_menu() { | |
20 // Items for testing. | |
21 $items['popups/test'] = array( | |
22 'title' => 'Popup Test', | |
23 'page callback' => '_popups_test_popups', | |
24 'type' => MENU_CALLBACK, | |
25 'access callback' => TRUE, | |
26 ); | |
27 $items['popups/test/response'] = array( | |
28 'page callback' => '_popups_test_response', | |
29 'type' => MENU_CALLBACK, | |
30 'access callback' => TRUE, | |
31 ); | |
32 $items['popups/test/namechange'] = array( | |
33 'page callback' => 'drupal_get_form', | |
34 'page arguments' => array('_popups_test_namechange'), | |
35 'type' => MENU_CALLBACK, | |
36 'access callback' => TRUE, | |
37 ); | |
38 $items['popups/test/old'] = array( | |
39 'title' => 'Popup Test', | |
40 'page callback' => '_popups_test_popups_old', | |
41 'type' => MENU_CALLBACK, | |
42 'access callback' => TRUE, | |
43 ); | |
44 return $items; | |
45 } | |
46 | |
47 /** | |
48 * Implementation of hook_popups(). | |
49 * | |
50 * This implements hook_popups, defined in popups_get_popups. | |
51 * See the comments in popups_add_popups for explination of the options. | |
52 * Adding popup behavior to the core admin pages has been moved to popups_admin. | |
53 * | |
54 * @return: Array of link selectors to apply popup behavior to. | |
55 * Keyed by path or form_id. | |
56 */ | |
57 function popups_test_popups() { | |
58 return array( | |
59 'popups/test' => array( // test page. | |
60 // '*' => array( // test page. | |
61 '#test-popup' => array( | |
62 // 'additionalJavascript' => array('misc/collapse.js'), | |
63 // 'forceReturn' => 'node/add/story', | |
64 ), | |
65 ), | |
66 ); | |
67 } | |
68 | |
69 // ************************************************************************** | |
70 // TESTING **************************************************************** | |
71 // ************************************************************************** | |
72 | |
73 function _popups_test_popups() { | |
74 popups_add_popups(); | |
75 $output = '<ol id="test-list">'; | |
76 $output .= '<li>'. l("Pop up entire local page.", 'popups/test/response', | |
77 array('attributes' => array('class' => 'popups'))); | |
78 $output .= "<li>". l("Pop with options (href override).", 'popups/test/', | |
79 array('attributes' => array('class' => 'popups', 'on-popups-options' => '{href: "test/response"}'))); | |
80 $output .= "<li>". l("Pop with options (width=200px).", 'popups/test/response', | |
81 array('attributes' => array('class' => 'popups', 'on-popups-options' => '{width: "200px"}'))); | |
82 $output .= "<li class=\"popups\" on-popups-options=\"{href: 'test/response'}\">Non-link popup</li>"; | |
83 $output .= '<li>'. l("Add Story (hook)", 'node/add/story', | |
84 array( 'attributes' => array('id' => 'test-popup'))); | |
85 $output .= '<li>'. l("Add Story (attribute).", 'node/add/story', | |
86 array( 'attributes' => array('class' => 'popups-form'))); | |
87 | |
88 $output .= '<li>'. l("Change Settings and ajax update entire content area: ", | |
89 'admin/settings/popups', | |
90 array( 'attributes' => array('class' => 'popups-form'), | |
91 )); | |
92 $output .= " (Auto Fade checkbox is: " . (variable_get('popups_autoclose_final_message', 1) ? 'on' : 'off') . ')'; | |
93 | |
94 $output .= '<li>'. l("Change Settings and ajax update only single target.", 'admin/settings/popups', | |
95 array( 'attributes' => array('id' => 'reload-target'), | |
96 )); | |
97 $output .= "<span id='response2'> (Auto Fade checkbox is: " . (variable_get('popups_autoclose_final_message', 1) ? 'on' : 'off') . ')</span>'; | |
98 popups_add_popups(array('#reload-target'=>array('targetSelectors'=>array('#response2')))); | |
99 | |
100 $output .= '<li>'. l("Change Settings and ajax update multiple targets with data from other page (tricky!).", 'admin/settings/popups', | |
101 array( 'attributes' => array( | |
102 'id' => 'foo', | |
103 'class' => 'popups-form', | |
104 'on-popups-options' => '{targetSelectors: {"#edit-popups-always-scan-wrapper": "#foo", "#edit-popups-popup-final-message-wrapper": "#test-list li:first"}, forceReturn: "admin/settings/popups"}'))); | |
105 | |
106 $output .= '<li>'. l("Change Settings and reload entire page.", | |
107 'admin/settings/popups', | |
108 array( 'attributes' => array('class' => 'popups-form-reload'), | |
109 )); | |
110 | |
111 $output .= '<li>'. l("Pop up defined by popups_add_popups rule.", 'popups/test/response', | |
112 array('attributes' => array('id' => 'rule-test'))); | |
113 popups_add_popups(array('#rule-test'=>array('width'=>'300px'))); | |
114 $output .= '<li>'. l('Ajax update just Page Title (only works if you theme uses id="page-title")', 'popups/test/namechange', | |
115 array('attributes' => array('id' => 'title-test'))); | |
116 popups_add_popups(array('#title-test'=>array('titleSelectors'=>array('#page-title'), 'noUpdate'=> TRUE, 'forceReturn'=>'popups/test/namechange'))); | |
117 | |
118 global $user; | |
119 $output .= "<li>You are user number $user->uid</li>"; | |
120 if ($user->uid == 0) { | |
121 $output .= '<li>'. l("Login and ajax refresh content area.", 'user', | |
122 array('attributes' => array('class' => 'popups-form'))); | |
123 $output .= '<li>'. l("Login and reload entire page.", 'user', | |
124 array('attributes' => array('class' => 'popups-form-reload'))); | |
125 $output .= '<li>'. l("Login and do not reload anything.", 'user', | |
126 array('attributes' => array('class' => 'popups-form-noupdate'))); | |
127 } | |
128 else { | |
129 $output .= '<li>'. l("Logout (need to surpress warning b/c session is dumped)", 'logout', | |
130 array('attributes' => array('id' => 'logout'))); | |
131 } | |
132 // Need to have the rule outside the else, or it won't get loaded on ajax reload. | |
133 popups_add_popups(array('#logout'=>array('noUpdate'=>TRUE, 'reloadOnError'=>TRUE))); | |
134 | |
135 $output .= '<li>'. l("Add Poll (test inline)", 'node/add/poll', | |
136 array('attributes' => array('class' => 'popups-form'))); | |
137 | |
138 $output .= "</ol>"; | |
139 return $output; | |
140 } | |
141 | |
142 function _popups_test_popups_old() { | |
143 // 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'); | |
144 popups_add_popups(); | |
145 $output = '<ul id="test-list">'; | |
146 $output .= '<li>'. l("Pop up entire local page.", 'popups/test/response', | |
147 array('attributes' => array('class' => 'popups'))); | |
148 $output .= "<li>". l("Pop with options (href override).", 'popups/test/', | |
149 array('attributes' => array('class' => 'popups', 'on-popups-options' => '{href: "test/response"}'))); | |
150 $output .= "<li>". l("Pop with options (width=200px).", 'popups/test/response', | |
151 array('attributes' => array('class' => 'popups', 'on-popups-options' => '{width: "200px"}'))); | |
152 $output .= "<li class=\"popups\" on-popups-options=\"{href: 'test/response'}\">Non-link popup</li>"; | |
153 $output .= '<li>'. l("Add Story (hook)", 'node/add/story', | |
154 array( 'attributes' => array('id' => 'test-popup'))); | |
155 $output .= '<li>'. l("Add Story (attribute).", 'node/add/story', | |
156 array( 'attributes' => array('class' => 'popups-form'))); | |
157 | |
158 $output .= '<li>'. l("Change Settings and ajax update entire content area: ", | |
159 'admin/settings/popups', | |
160 array( 'attributes' => array('class' => 'popups-form'), | |
161 )); | |
162 $output .= " (Auto Fade checkbox is: " . (variable_get('popups_popup_final_message', 1) ? 'on' : 'off') . ')'; | |
163 | |
164 $output .= '<li>'. l("Change Settings and ajax update only single target.", 'admin/settings/popups', | |
165 array( 'attributes' => array('id' => 'reload-target'), | |
166 )); | |
167 $output .= "<span id='response2'> (Auto Fade checkbox is: " . (variable_get('popups_popup_final_message', 1) ? 'on' : 'off') . ')</span>'; | |
168 popups_add_popups(array('#reload-target'=>array('targetSelectors'=>array('#response2')))); | |
169 | |
170 $output .= '<li>'. l("Change Settings and ajax update multiple targets with data from other page (tricky!).", 'admin/settings/popups', | |
171 array( 'attributes' => array( | |
172 'id' => 'foo', | |
173 'class' => 'popups-form', | |
174 'on-popups-options' => '{targetSelectors: {"#edit-popups-always-scan-wrapper": "#foo", "#edit-popups-popup-final-message-wrapper": "#test-list li:first"}, forceReturn: "admin/settings/popups"}'))); | |
175 | |
176 $output .= '<li>'. l("Change Settings and reload entire page.", | |
177 'admin/settings/popups', | |
178 array( 'attributes' => array('class' => 'popups-form-reload'), | |
179 )); | |
180 | |
181 $output .= '<li>'. l("Pop up defined by popups_add_popups rule.", 'popups/test/response', | |
182 array('attributes' => array('id' => 'rule-test'))); | |
183 popups_add_popups(array('#rule-test'=>array('width'=>'300px'))); | |
184 $output .= '<li>'. l('Ajax update just Page Title (only works if you theme uses id="page-title")', 'popups/test/namechange', | |
185 array('attributes' => array('id' => 'title-test'))); | |
186 popups_add_popups(array('#title-test'=>array('titleSelectors'=>array('#page-title'), 'noUpdate'=> TRUE, 'forceReturn'=>'popups/test/namechange'))); | |
187 | |
188 global $user; | |
189 $output .= "<li>You are user number $user->uid</li>"; | |
190 if ($user->uid == 0) { | |
191 $output .= '<li>'. l("Login and ajax refresh content area.", 'user', | |
192 array('attributes' => array('class' => 'popups-form'))); | |
193 $output .= '<li>'. l("Login and reload entire page.", 'user', | |
194 array('attributes' => array('class' => 'popups-form-reload'))); | |
195 $output .= '<li>'. l("Login and do not reload anything.", 'user', | |
196 array('attributes' => array('class' => 'popups-form-noupdate'))); | |
197 } | |
198 else { | |
199 $output .= '<li>'. l("Logout (need to surpress warning b/c session is dumped)", 'logout', | |
200 array('attributes' => array('id' => 'logout'))); | |
201 } | |
202 // Need to have the rule outside the else, or it won't get loaded on ajax reload. | |
203 popups_add_popups(array('#logout'=>array('noUpdate'=>TRUE, 'reloadOnError'=>TRUE))); | |
204 | |
205 $output .= '<li>'. l("Add Poll (test inline)", 'node/add/poll', | |
206 array('attributes' => array('class' => 'popups-form'))); | |
207 | |
208 $output .= "</ul>"; | |
209 return $output; | |
210 } | |
211 | |
212 function _popups_test_response() { | |
213 drupal_set_title("Popup Test Two"); | |
214 return '<div>Hello World</div><a href="#" class="popups">Popup chaining test</a>'; | |
215 } | |
216 | |
217 function _popups_test_namechange() { | |
218 drupal_set_title("New Name for Test Page"); | |
219 $form = array(); | |
220 | |
221 $form['popups_popup_final_message'] = array( | |
222 '#type' => 'submit', | |
223 '#value' => t('Test Name Change'), | |
224 ); | |
225 | |
226 return $form; | |
227 } |