Source for file HTML.class.php

Documentation is available at HTML.class.php

  1. <?php
  2. /**
  3. * XOAD HTML Class file.
  4. *
  5. * <p>This file defines the {@link XOAD_HTML} Class.</p>
  6. * <p>Example:</p>
  7. * <code>
  8. * <?php
  9. *
  10. * class Update
  11. * {
  12. * function ui()
  13. * {
  14. * sleep(1);
  15. *
  16. * $content =& XOAD_HTML::getElementById('content');
  17. *
  18. * $content->innerHTML = 'Hello World! How are you?';
  19. * }
  20. * }
  21. *
  22. * define('XOAD_AUTOHANDLE', true);
  23. *
  24. * require_once('xoad.php');
  25. *
  26. * ?>
  27. * <?= XOAD_Utilities::header('.') ?>
  28. *
  29. * <div id="content">Hello!</div>
  30. *
  31. * <script type="text/javascript">
  32. *
  33. * var obj = <?= XOAD_Client::register(new Update()) ?>;
  34. *
  35. * obj.ui(xoad.asyncCall);
  36. *
  37. * </script>
  38. * </code>
  39. *
  40. * @author Stanimir Angeloff
  41. *
  42. * @package XOAD
  43. *
  44. * @subpackage XOAD_HTML
  45. *
  46. * @version 0.6.0.0
  47. *
  48. */
  49.  
  50. /**
  51. * Defines the string that is replaced with the current value
  52. * of the field.
  53. *
  54. * <p>Example:</p>
  55. * <code>
  56. * <?php
  57. *
  58. * class Update
  59. * {
  60. * function ui()
  61. * {
  62. * sleep(1);
  63. *
  64. * $content =& XOAD_HTML::getElementById('content');
  65. *
  66. * $content->innerHTML = XOAD_HTML_CURRENT_VALUE . ' How are you?';
  67. * }
  68. * }
  69. *
  70. * define('XOAD_AUTOHANDLE', true);
  71. *
  72. * require_once('xoad.php');
  73. *
  74. * ?>
  75. * <?= XOAD_Utilities::header('.') ?>
  76. * <div id="content">Hello!</div>
  77. * <script type="text/javascript">
  78. *
  79. * var obj = <?= XOAD_Client::register(new Update()) ?>;
  80. *
  81. * obj.ui(xoad.asyncCall);
  82. *
  83. * </script>
  84. * </code>
  85. */
  86. define('XOAD_HTML_CURRENT_VALUE', '<![xoadHtml:currentValue[');
  87.  
  88. /**
  89. * @global Contains all XOAD_HTML DOM objects.
  90. */
  91. $GLOBALS['_XOAD_HTML_DATA'] = array();
  92.  
  93. /**
  94. * XOAD HTML Class.
  95. *
  96. * <p>This class is used to update the content and the
  97. * style of a page.</p>
  98. * <p>Example:</p>
  99. * <code>
  100. * <?php
  101. *
  102. * class Update
  103. * {
  104. * function ui()
  105. * {
  106. * sleep(1);
  107. *
  108. * $content =& XOAD_HTML::getElementById('content');
  109. *
  110. * $content->innerHTML = 'Hello World! How are you?';
  111. * }
  112. * }
  113. *
  114. * define('XOAD_AUTOHANDLE', true);
  115. *
  116. * require_once('xoad.php');
  117. *
  118. * ?>
  119. * <?= XOAD_Utilities::header('.') ?>
  120. *
  121. * <div id="content">Hello!</div>
  122. *
  123. * <script type="text/javascript">
  124. *
  125. * var obj = <?= XOAD_Client::register(new Update()) ?>;
  126. *
  127. * obj.ui(xoad.asyncCall);
  128. *
  129. * </script>
  130. * </code>
  131. *
  132. * @author Stanimir Angeloff
  133. *
  134. * @package XOAD
  135. *
  136. * @subpackage XOAD_HTML
  137. *
  138. * @version 0.6.0.0
  139. *
  140. */
  141. class XOAD_HTML
  142. {
  143. /**
  144. * Returns the element whose ID is specified.
  145. *
  146. * <p>Note that you must use the '&' operator in order
  147. * to get a reference to the element.</p>
  148. * <p>Example:</p>
  149. * <code>
  150. * $content =& XOAD_HTML::getElementById('content');
  151. * </code>
  152. *
  153. * @access public
  154. *
  155. * @param string $id String representing the unique id of
  156. * the element being sought.
  157. *
  158. * @return object The DOM element with the specified ID.
  159. * Note that the server has no idea whether
  160. * the element exists on the client or not.
  161. *
  162. * @static
  163. *
  164. */
  165. function &getElementById($id)
  166. {
  167. /**
  168. * Loads the class that defines the DOM element by ID class.
  169. */
  170. require_once(XOAD_HTML_BASE . '/classes/DOM/ElementById.class.php');
  171.  
  172. $element = new XOAD_HTML_DOM_ElementById($id);
  173.  
  174. $GLOBALS['_XOAD_HTML_DATA'][] =& $element;
  175.  
  176. return $element;
  177. }
  178.  
  179. /**
  180. * Returns an object representing a list of elements
  181. * of a given name in the document.
  182. *
  183. * <p>Note that you must use the '&' operator in order
  184. * to get a reference to the list.</p>
  185. * <p>Example:</p>
  186. * <code>
  187. * $messages =& XOAD_HTML::getElementsByName('message');
  188. * </code>
  189. *
  190. * @access public
  191. *
  192. * @param string $name String representing the value of
  193. * the name attribute on the element.
  194. *
  195. * @return object The DOM elements list with the specified name.
  196. * Note that the server has no idea whether
  197. * any elements exists on the client or not.
  198. *
  199. * @static
  200. *
  201. */
  202. function &getElementsByName($name)
  203. {
  204. /**
  205. * Loads the class that defines the DOM elements by name class.
  206. */
  207. require_once(XOAD_HTML_BASE . '/classes/DOM/ElementsByName.class.php');
  208.  
  209. $elements = new XOAD_HTML_DOM_ElementsByName($name);
  210.  
  211. $GLOBALS['_XOAD_HTML_DATA'][] =& $elements;
  212.  
  213. return $elements;
  214. }
  215.  
  216. /**
  217. * Returns an object representing a list of elements
  218. * of a given tag name in the document.
  219. *
  220. * <p>Note that you must use the '&' operator in order
  221. * to get a reference to the list.</p>
  222. * <p>Example:</p>
  223. * <code>
  224. * $inputs =& XOAD_HTML::getElementsByTagName('input');
  225. * </code>
  226. *
  227. * @access public
  228. *
  229. * @param string $tagName String representing the name of
  230. * the tag on the element.
  231. *
  232. * @return object The DOM elements list with the specified tag name.
  233. * Note that the server has no idea whether
  234. * any elements exists on the client or not.
  235. *
  236. * @static
  237. *
  238. */
  239. function &getElementsByTagName($tagName)
  240. {
  241. /**
  242. * Loads the class that defines the DOM elements by tag name class.
  243. */
  244. require_once(XOAD_HTML_BASE . '/classes/DOM/ElementsByTagName.class.php');
  245.  
  246. $elements = new XOAD_HTML_DOM_ElementsByTagName($tagName);
  247.  
  248. $GLOBALS['_XOAD_HTML_DATA'][] =& $elements;
  249.  
  250. return $elements;
  251. }
  252.  
  253. /**
  254. * Returns an object representing a list of elements
  255. * that match a given cssQuery in the document.
  256. *
  257. * <p>Note that you must use the '&' operator in order
  258. * to get a reference to the list.</p>
  259. * <p>Example:</p>
  260. * <code>
  261. * $messages =& XOAD_HTML::cssQuery('#message, .message-body');
  262. * </code>
  263. *
  264. * @access public
  265. *
  266. * @param string $query String representing the value of
  267. * the cssQuery.
  268. *
  269. * @return object The DOM elements list matching the cssQuery.
  270. * Note that the server has no idea whether
  271. * any elements exists on the client or not.
  272. *
  273. * @static
  274. *
  275. */
  276. function &cssQuery($query)
  277. {
  278. /**
  279. * Loads the class that defines the DOM cssQuery.
  280. */
  281. require_once(XOAD_HTML_BASE . '/classes/DOM/CssQuery.class.php');
  282.  
  283. $elements = new XOAD_HTML_DOM_CssQuery($query);
  284.  
  285. $GLOBALS['_XOAD_HTML_DATA'][] =& $elements;
  286.  
  287. return $elements;
  288. }
  289.  
  290. /**
  291. * Adds a given JavaScript code to the output.
  292. *
  293. * <p>Note that you must use the '&' operator in order
  294. * to get a reference to the script block.</p>
  295. * <p>You should add ';' at the end of the script.</p>
  296. * <p>Example:</p>
  297. * <code>
  298. * XOAD_HTML::addScriptBlock('alert("Hello World!");');
  299. * </code>
  300. *
  301. * @access public
  302. *
  303. * @param string $script JavaScript source code.
  304. *
  305. * @return object The DOM element that represents the script block.
  306. *
  307. * @static
  308. *
  309. */
  310. function &addScriptBlock($script)
  311. {
  312. /**
  313. * Loads the class that defines the DOM script block class.
  314. */
  315. require_once(XOAD_HTML_BASE . '/classes/DOM/ScriptBlock.class.php');
  316.  
  317. $scriptBlock = new XOAD_HTML_DOM_ScriptBlock($script);
  318.  
  319. $GLOBALS['_XOAD_HTML_DATA'][] =& $scriptBlock;
  320.  
  321. return $scriptBlock;
  322. }
  323.  
  324. /**
  325. * Imports an associative array to the corresponding form elements.
  326. *
  327. * <p>Example:</p>
  328. * <code>
  329. * XOAD_HTML::importForm('mainForm', array('firstName' => 'First', 'lastName' => 'Last'));
  330. * </code>
  331. *
  332. * @access public
  333. *
  334. * @param string $id The client ID of the form.
  335. *
  336. * @param string $formData Associative array that contains the
  337. * values to import.
  338. *
  339. * @return void
  340. *
  341. * @static
  342. *
  343. */
  344. function importForm($id, $formData)
  345. {
  346. $script = 'xoad.html.importForm(';
  347. $script .= XOAD_Client::register($id);
  348. $script .= ', ';
  349. $script .= XOAD_Client::register($formData);
  350. $script .= ');';
  351.  
  352. XOAD_HTML::addScriptBlock($script);
  353. }
  354.  
  355. /**
  356. * Returns the JavaScript code of all DOM elements.
  357. *
  358. * <p>You should not call this method directly.</p>
  359. *
  360. * @access public
  361. *
  362. * @return string JavaScript source code for each DOM element
  363. * or null if no DOM elements were created.
  364. *
  365. * @static
  366. *
  367. */
  368. function process()
  369. {
  370. if ( ! empty($GLOBALS['_XOAD_HTML_DATA'])) {
  371.  
  372. $returnValue = '';
  373.  
  374. foreach ($GLOBALS['_XOAD_HTML_DATA'] as $domObject) {
  375.  
  376. $returnValue .= $domObject->process();
  377. }
  378.  
  379. return $returnValue;
  380. }
  381.  
  382. return null;
  383. }
  384. }
  385. ?>

Documentation generated on Sat, 12 Nov 2005 20:24:14 +0200 by phpDocumentor 1.3.0RC3