/usr/share/php/xajax/tests/suite/events.php is in php-xajax 0.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | <?php
/*
File: events.php
Test script that uses <xajaxResponse->addHandler> and <xajaxResponse->removeHandler>
to effect the active event handlers on the browser.
*/
require_once("./options.inc.php");
require_once('./testScriptPlugin.inc.php');
function addHandler($sId, $sHandler)
{
$objResponse = new xajaxResponse();
$objResponse->addHandler($sId, "click", $sHandler);
$objResponse->append('log', 'innerHTML', '<div id="handler'.$sHandler.'">*-- '.$sHandler.' (attached)</div>');
return $objResponse;
}
function removeHandler($sId, $sHandler)
{
$objResponse = new xajaxResponse();
$objResponse->removeHandler($sId, "click", $sHandler);
$objResponse->remove('handler'.$sHandler);
return $objResponse;
}
function toggleButtons()
{
$objResponse = new xajaxResponse();
$aArgs = func_get_args();
if (3 < count($aArgs))
{
$aDisable = $aArgs[2];
$aEnable = $aArgs[3];
foreach ($aDisable as $sDisableId)
$objResponse->assign($sDisableId, 'disabled', 'disabled');
foreach ($aEnable as $sEnableId)
$objResponse->assign($sEnableId, 'disabled', '');
}
return $objResponse;
}
$requestAdd = $xajax->register(XAJAX_EVENT, 'add_clicked');
$xajax->register(XAJAX_EVENT_HANDLER, 'add_clicked', 'addHandler');
$xajax->register(XAJAX_EVENT_HANDLER, 'add_clicked', 'toggleButtons');
$requestRemove = $xajax->register(XAJAX_EVENT, 'remove_clicked');
$xajax->register(XAJAX_EVENT_HANDLER, 'remove_clicked', 'removeHandler');
$xajax->register(XAJAX_EVENT_HANDLER, 'remove_clicked', 'toggleButtons');
$xajax->processRequest();
$sRoot = dirname(dirname(dirname(__FILE__)));
if (false == class_exists('xajaxControl')) {
$sCore = '/xajax_core';
include_once($sRoot . $sCore . '/xajaxControl.inc.php');
}
/*
Class: clsMutuallyExclusiveButton
Only one button can be disabled at a given time.
*/
class clsMutuallyExclusiveButton extends xajaxControl
{
var $aPartners;
function clsMutuallyExclusiveButton($sId, $sName, $sValue)
{
xajaxControl::xajaxControl('input', array(
'attributes' => array(
'id' => $sId,
'type' => 'submit',
'name' => $sName,
'value' => $sValue
)
));
$this->aPartners = array();
}
function getId()
{
if (isset($this->aAttributes['id']))
return $this->aAttributes['id'];
trigger_error('An ID is requred for a mux. button.', E_USER_ERROR);
}
function addPartner(&$objPartnerNew)
{
if (false == is_a($objPartnerNew, 'clsMutuallyExclusiveButton'))
trigger_error('Invalid partner specified; should be a clsMutuallyExclusiveButton', E_USER_ERROR);
foreach (array_keys($this->aPartners) as $sKey)
{
$objPartner =& $this->aPartners[$sKey];
$objPartner->privateAddPartner($objPartnerNew);
$objPartnerNew->privateAddPartner($objPartner);
}
$this->privateAddPartner($objPartnerNew);
$objPartnerNew->privateAddPartner($this);
}
function privateAddPartner(&$objPartner)
{
$this->aPartners[] =& $objPartner;
}
function setAttribute($sName, $sValue)
{
if ('disabled' == $sName)
{
if ('disabled' == $sValue)
{
foreach (array_keys($this->aPartners) as $sKey)
{
$objPartner =& $this->aPartners[$sKey];
$objPartner->setAttribute('disabled', 'false');
}
}
}
xajaxControl::setAttribute($sName, $sValue);
}
function printHtml($sIndent='')
{
$sEnable = '[';
$sSeparator = '"';
$sTerminator = ']';
foreach (array_keys($this->aPartners) as $sKey)
{
$objPartner =& $this->aPartners[$sKey];
$sEnable .= $sSeparator;
$sEnable .= $objPartner->getId();
$sSeparator = '", "';
$sTerminator = '"]';
}
$sEnable .= $sTerminator;
$sDisable = '["' . $this->getId() . '"]';
$aRequest =& $this->aEvents['onclick'];
$objRequest =& $aRequest[0];
$objRequest->setParameter(0, XAJAX_QUOTED_VALUE, '');
$objRequest->setParameter(1, XAJAX_QUOTED_VALUE, '');
$objRequest->setParameter(2, XAJAX_JS_VALUE, $sDisable);
$objRequest->setParameter(3, XAJAX_JS_VALUE, $sEnable);
xajaxControl::printHTML($sIndent);
}
}
// one
$inputAddOne =& new clsMutuallyExclusiveButton('add_one', 'add_one', 'Add');
$inputAddOne->setEvent('onclick',
$requestAdd, array(
array(0, XAJAX_QUOTED_VALUE, 'clicker'),
array(1, XAJAX_QUOTED_VALUE, 'clickHandlerOne')
)
);
$inputRemoveOne =& new clsMutuallyExclusiveButton('remove_one', 'remove_one', 'Remove');
$inputRemoveOne->setEvent('onclick',
$requestRemove, array(
array(0, XAJAX_QUOTED_VALUE, 'clicker'),
array(1, XAJAX_QUOTED_VALUE, 'clickHandlerOne')
)
);
$inputAddOne->addPartner($inputRemoveOne);
$inputRemoveOne->setAttribute('disabled', 'disabled');
// two
$inputAddTwo =& new clsMutuallyExclusiveButton('add_two', 'add_two', 'Add');
$inputAddTwo->setEvent('onclick',
$requestAdd, array(
array(0, XAJAX_QUOTED_VALUE, 'clicker'),
array(1, XAJAX_QUOTED_VALUE, 'clickHandlerTwo')
)
);
$inputRemoveTwo =& new clsMutuallyExclusiveButton('remove_two', 'remove_two', 'Remove');
$inputRemoveTwo->setEvent('onclick',
$requestRemove, array(
array(0, XAJAX_QUOTED_VALUE, 'clicker'),
array(1, XAJAX_QUOTED_VALUE, 'clickHandlerTwo')
)
);
$inputAddTwo->addPartner($inputRemoveTwo);
$inputRemoveTwo->setAttribute('disabled', 'disabled');
ob_start();
?>
<script type="text/javascript">
function writeOutput(msg) {
xajax.$('status').innerHTML += msg;
}
function clickHandlerOne() {
writeOutput('message from click handler one<br />');
}
function clickHandlerTwo() {
writeOutput('message from click handler two<br />');
}
function clickDetected() {
writeOutput('<br />');
writeOutput('* click event triggered<br />');
if ('undefined' != typeof clickTimeout)
clearTimeout(clickTimeout);
clickTimeout = setTimeout('clearClick();', 4000);
return true;
}
function clearClick() {
xajax.$('status').innerHTML = '';
clickTimeout = undefined;
}
</script>
<style>
.clicker {
padding: 3px;
display: table;
border: 1px outset black;
font-size: large;
margin-bottom: 10px;
cursor: pointer;
}
.controls {
margin-top: 6px;
margin-bottom: 7px;
}
.description {
margin-top: 4px;
margin-bottom: 4px;
font-size: small;
border: 1px solid #999999;
padding: 3px;
}
.single_line {
white-space: nowrap;
}
</style>
<?
$objTestScriptPlugin->printHeader($xajax, "Client-side Event Handlers", ob_get_clean());
ob_start();
?>
<div id='clicker' class='clicker' onclick='return clickDetected();'>Click here to trigger event</div>
<form id='mainForm' onsubmit='return false;'>
<div id='controls' class='controls'>
<table>
<tr>
<td class='single_line'>Event handler one: </td>
<td align='center'>
<?php $inputAddOne->printHTML(); ?>
</td>
<td align='center'>
<?php $inputRemoveOne->printHTML(); ?>
</td>
<td width='100%'></td>
</tr>
<tr>
<td class='single_line'>Event handler two: </td>
<td align='center'>
<?php $inputAddTwo->printHTML(); ?>
</td>
<td align='center'>
<?php $inputRemoveTwo->printHTML(); ?>
</td>
<td width='100%'></td>
</tr>
</table>
</div>
</form>
<?
$objTestScriptPlugin->printControlPanel(ob_get_clean());
$objTestScriptPlugin->printStatusPanel();
$objTestScriptPlugin->printLogPanel();
$objTestScriptPlugin->printDescriptionPanel("
This page tests the ability to attach event handlers to DOM objects. The DIV above labeled 'Click Here' has an onclick
event that simply appends *click* to the output area. To attach additional even handlers, click 'Add' for either event
handler One, Two or Both. Event handlers attached to the DIV are listed below it.
");
$objTestScriptPlugin->printFooter();
|