/usr/share/php/xajax/tests/suite/iframe.php is in php-xajax 0.5-1ubuntu1.
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 | <?php
/**
* iframe.php
*
* xajax test script to test the ability to modify the contents
* of iframe documents within the main document.
*/
require_once("./options.inc.php");
require_once('./testScriptPlugin.inc.php');
$aFunctions = $xajax->register(XAJAX_CALLABLE_OBJECT, new clsFunctions());
$aFunctions['showformvalues']->addParameter(XAJAX_FORM_VALUES, 'theForm');
$objResponse = new xajaxResponse();
$xajax->processRequest();
class clsContext {
function begin($iframe) {
global $objResponse;
$objResponse->script("var theFrame = xajax.$('".$iframe."'); xajax.config.baseDocument = (theFrame.contentDocument || theFrame.contentWindow.document);");
}
function end() {
global $objResponse;
$objResponse->script("xajax.config.baseDocument = document;");
}
}
class clsFunctions {
function clsFunctions() {
}
function showIsLoaded() {
global $objResponse;
clsContext::begin("theFrame");
$objResponse->script('try { if (iframe.code.loaded) xajax.$("outputDIV").innerHTML += "<br />iframe.js loaded"; } catch (e) { xajax.$("outputDIV").innerHTML += "<br />iframe.js *NOT* loaded"; }');
clsContext::end();
$objResponse->script('try { if (iframe.code.loaded) xajax.$("outputDIV").innerHTML += "<br />iframe.js loaded in iframe context"; } catch (e) { xajax.$("outputDIV").innerHTML += "<br />iframe.js *NOT* loaded in iframe context"; }');
}
function showFormValues($aFormValues) {
global $objResponse;
clsContext::begin("theFrame");
$objResponse->assign("outputDIV", "innerHTML", print_r($aFormValues, true));
$objResponse->includeScriptOnce("iframe.js");
clsContext::end();
$objResponse->assign("outputDIV", "innerHTML", print_r($aFormValues, true));
$objResponse->waitFor("iframe.code.loaded", 90);
$this->showIsLoaded();
return $objResponse;
}
function clear() {
global $objResponse;
clsContext::begin('theFrame');
$objResponse->assign('outputDIV', 'innerHTML', '');
$objResponse->removeScript('iframe.js', 'iframe.code.unload();');
clsContext::end();
$objResponse->assign('outputDIV', 'innerHTML', '');
$this->showIsLoaded();
return $objResponse;
}
}
$objTestScriptPlugin->printHeader($xajax, "Iframe",'','');
?>
<form id='theForm' method='post' action='#' onsubmit='<?php $aFunctions['showformvalues']->printScript(); ?>; return false;'>
<input type='text' id='theText' name='theText' value='some text'><br />
<input type='submit' id='theSubmit' name='theSubmit' value='Submit'>
</form>
<button onclick='<?php $aFunctions['clear']->printScript(); ?>'>Clear</button><br />
<iframe id='theFrame' src='theFrame.php' style='width: 360px; height: 240px;'></iframe>
<div id='outputDIV'></div>
<br />
<div>
This test application demonstrates a number of features:
<ul>
<li>The ability to create and manipulate elements within an iframe.</li>
<li>The ability to load a javascript file(s) inside an iframe</li>
<li>The ability for iframes to have their own instance of xajax</li>
<li>The ability for an iframe to communicate back to the parent</li>
<li>The response command waitFor... which can wait for a custom condition to evaluate to true.</li>
</ul>
When you click the submit button, it will send a xajax request which in turn triggers the following:<br />
The form values are displayed in the iframe and the main document.<br />
The iframe is instructed to load a javascript file (iframe.js)<br />
The main document frame waits until the javascript file is fully loaded (using waitFor)<br />
The iframe.js invokes a xajax request (in the iframe to theFrame.php) which sleeps for 2 seconds, then returns 'iframe.js loaded'.<br />
The iframe.js waits 4 seconds, then notifies the parent (main document) that the iframe.js file is fully loaded.<br />
The main document displays that the iframe.js file is loaded in the iframe context.
</div>
<?php
$objTestScriptPlugin->printControlPanel();
$objTestScriptPlugin->printStatusPanel();
$objTestScriptPlugin->printLogPanel();
$objTestScriptPlugin->printDescriptionPanel();
$objTestScriptPlugin->printFooter();
|