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