annotate popups_test.module @ 6:e02de6b2566e

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