Source for file BaseElement.class.php

Documentation is available at BaseElement.class.php

  1. <?php
  2. /**
  3. * XOAD HTML DOM Base Element file.
  4. *
  5. * <p>This file defines the {@link XOAD_HTML_DOM_BaseElement} Class.</p>
  6. *
  7. * @author Stanimir Angeloff
  8. *
  9. * @package XOAD
  10. *
  11. * @subpackage XOAD_HTML
  12. *
  13. * @version 0.6.0.0
  14. *
  15. */
  16.  
  17. /**
  18. * XOAD HTML DOM Base Element Class.
  19. *
  20. * <p>This class is used as base class for all {@link XOAD_HTML}
  21. * DOM elements.</p>
  22. *
  23. * @author Stanimir Angeloff
  24. *
  25. * @package XOAD
  26. *
  27. * @subpackage XOAD_HTML
  28. *
  29. * @version 0.6.0.0
  30. *
  31. */
  32. class XOAD_HTML_DOM_BaseElement
  33. {
  34. /**
  35. * Holds attributes collection. This array is not populated
  36. * from the client and it is empty initially.
  37. *
  38. * @access public
  39. *
  40. * @var array
  41. *
  42. */
  43. var $attributes;
  44.  
  45. /**
  46. * Holds style collection. This array is not populated
  47. * from the client and it is empty initially.
  48. *
  49. * @access public
  50. *
  51. * @var array
  52. *
  53. */
  54. var $style;
  55.  
  56. /**
  57. * Holds the keys that will be skipped (like id, clientCode ...).
  58. *
  59. * @access protected
  60. *
  61. * @var array
  62. *
  63. */
  64. var $skipKeys;
  65.  
  66. /**
  67. * Holds the client JavaScript code associated with the element(s).
  68. *
  69. * @access protected
  70. *
  71. * @var string
  72. *
  73. */
  74. var $clientCode;
  75.  
  76. /**
  77. * Creates a new instance of the {@link XOAD_HTML_DOM_BaseElement} class.
  78. *
  79. * @access public
  80. *
  81. */
  82. function XOAD_HTML_DOM_BaseElement()
  83. {
  84. $this->attributes = array();
  85.  
  86. $this->style = array();
  87.  
  88. $this->skipKeys = array('clientCode');
  89.  
  90. $this->clientCode = '';
  91. }
  92.  
  93. /**
  94. * This method removes an attribute from the element(s).
  95. *
  96. * <p>Example:</p>
  97. * <code>
  98. * $content =& XOAD_HTML::getElementById('content');
  99. *
  100. * $content->removeAttribute('disabled');
  101. * </code>
  102. *
  103. * @access public
  104. *
  105. * @param string $attName String that names the attribute to be
  106. * removed from the element(s).
  107. *
  108. * @return void
  109. *
  110. */
  111. function removeAttribute($attName)
  112. {
  113. $this->clientCode .= $this->getElement() . '.removeAttribute(';
  114. $this->clientCode .= XOAD_Client::register($attName) . ');';
  115. }
  116.  
  117. /**
  118. * This method adds a new attribute or changes the
  119. * value of an existing attribute on the element(s).
  120. *
  121. * <p>Example:</p>
  122. * <code>
  123. * $content =& XOAD_HTML::getElementById('content');
  124. *
  125. * $content->setAttribute('disabled', true);
  126. * </code>
  127. *
  128. * @access public
  129. *
  130. * @param string $attName String that names the attribute to be
  131. * removed from the element(s).
  132. *
  133. * @return void
  134. *
  135. */
  136. function setAttribute($name, $value)
  137. {
  138. $this->clientCode .= $this->getElement() . '.setAttribute(';
  139. $this->clientCode .= XOAD_Client::register($name) . ',';
  140. $this->clientCode .= XOAD_Client::register($value) . ');';
  141. }
  142.  
  143. /**
  144. * Returns the JavaScript code of the DOM element.
  145. *
  146. * <p>You should not call this method directly.</p>
  147. *
  148. * @access public
  149. *
  150. * @param string $element The JavaScript element name.
  151. *
  152. * @return string JavaScript source code for the DOM element.
  153. *
  154. * @static
  155. *
  156. */
  157. function process($element = null)
  158. {
  159. $returnValue = '';
  160.  
  161. $objectVars = get_object_vars($this);
  162.  
  163. foreach ($objectVars as $key => $value) {
  164.  
  165. if ((strcasecmp($key, 'skipKeys') == 0) || (in_array($key, $this->skipKeys))) {
  166.  
  167. continue;
  168. }
  169.  
  170. if (strcasecmp($key, 'attributes') == 0) {
  171.  
  172. foreach ($this->attributes as $key => $value) {
  173.  
  174. if ($value === null) {
  175.  
  176. $returnValue .= $element . '.removeAttribute("' . $key . '");';
  177.  
  178. } else {
  179.  
  180. $returnValue .= $element . '.setAttribute("' . $key . '", ' . XOAD_Client::register($value) . ');';
  181. }
  182. }
  183.  
  184. } else if (strcasecmp($key, 'style') == 0) {
  185.  
  186. foreach ($this->style as $key => $value) {
  187.  
  188. $returnValue .= $element . '.style.' . $key . '=' . XOAD_Client::register($value) . ';';
  189. }
  190.  
  191. } else {
  192.  
  193. $assignField = $element . '.' . $key;
  194.  
  195. $assignOperation = $assignField . '=' . XOAD_Client::register($value) . ';';
  196.  
  197. if (strpos($assignOperation, XOAD_HTML_CURRENT_VALUE) !== false) {
  198.  
  199. $assignOperation = str_replace(XOAD_HTML_CURRENT_VALUE, '"+' . $assignField .'+"', $assignOperation);
  200. }
  201.  
  202. $returnValue .= $assignOperation;
  203. }
  204. }
  205.  
  206. $returnValue .= $this->clientCode;
  207.  
  208. return $returnValue;
  209. }
  210. }
  211. ?>

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