summaryrefslogtreecommitdiff
path: root/UI/elements.html
blob: 19570e62f4160c444237008ec113c564da94eb46 (plain)
  1. <?lsmb 
  2. default_keys = ['id', 'class', 'title'] # Defaults for all attributes
  3. input_keys = ['type', 'name', 'disabled', 'size', 'value'] # Defaults for input attributes
  4. # ELEMENT DEFAULTS
  5. #checkbox
  6. checkbox_defaults = {
  7. value = '1'
  8. }
  9. #file
  10. file_defaults = {
  11. size => '60'
  12. }
  13. #password
  14. password_defaults = {
  15. size = '60'
  16. }
  17. # text
  18. text_defaults = {
  19. size = '60',
  20. maxlength = '255'
  21. }
  22. # textarea
  23. textarea_defaults = {
  24. rows = '5',
  25. cols = '60'
  26. }
  27. #button
  28. button_defaults = {
  29. type = 'submit'
  30. }
  31. ?>
  32. <?lsmb # INPUT ELEMENT ?>
  33. <?lsmb BLOCK input ?>
  34. <?lsmb input_defaults = {} # Some inputs have no defaults, so make sure everything is empty to start with. ?>
  35. <?lsmb SWITCH element_data.type; # Merge in type-specific attributes.
  36. CASE 'file';
  37. input_type_keys = input_keys.merge(['accept']);
  38. input_defaults = file_defaults;
  39. CASE 'image';
  40. input_type_keys = input_keys.merge(['alt', 'src']);
  41. CASE ['checkbox'];
  42. input_type_keys = input_keys.merge(['checked']);
  43. input_defaults = checkbox_defaults;
  44. CASE ['radio'];
  45. input_type_keys = input_keys.merge(['checked']);
  46. CASE ['password'];
  47. input_defaults = password_defaults;
  48. CASE 'text';
  49. input_type_keys = input_keys.merge(['maxlength', 'readonly']);
  50. input_defaults = text_defaults;
  51. CASE;
  52. input_type_keys = input_keys;
  53. END;
  54. ?>
  55. <?lsmb PROCESS attributes # Process regular attributes.
  56. attribute_data = element_data
  57. attribute_defaults = input_defaults
  58. element_keys = input_type_keys
  59. element_type = 'input'
  60. ?>
  61. <?lsmb PROCESS custom_attributes # Process custom attributes.
  62. custom_attribute_data=element_data.attributes
  63. ?>
  64. <input<?lsmb all_attributes ?><?lsmb all_custom_attributes ?> />
  65. <?lsmb END ?>
  66. <?lsmb # TEXTAREA ELEMENT ?>
  67. <?lsmb BLOCK textarea ?>
  68. <?lsmb PROCESS attributes # Process regular attributes.
  69. attribute_data=element_data
  70. attribute_defaults = textarea_defaults
  71. element_keys = ['name', 'cols', 'rows', 'disabled', 'readonly', 'tabindex', 'accesskey', 'value'] # Attributes that apply to textareas.
  72. element_type = 'textarea'
  73. ?>
  74. <?lsmb PROCESS custom_attributes # Process custom attributes.
  75. custom_attribute_data=element_data.attributes
  76. ?>
  77. <textarea<?lsmb all_attributes ?><?lsmb all_custom_attributes ?>><?lsmb element_data.text ?></textarea>
  78. <?lsmb END ?>
  79. <?lsmb # SELECT ELEMENT ?>
  80. <?lsmb BLOCK select ?>
  81. <?lsmb PROCESS attributes # Process regular attributes.
  82. attribute_data=element_data
  83. attribute_defaults = {} # Make sure old defaults are cleared out.
  84. element_keys=['name', 'size', 'multiple', 'disabled', 'accesskey', 'tabindex'] # Attributes that apply to selects.
  85. element_type = 'select'
  86. ?>
  87. <?lsmb PROCESS custom_attributes # Process custom attributes.
  88. custom_attribute_data=element_data.attributes
  89. ?>
  90. <select<?lsmb all_attributes ?><?lsmb all_custom_attributes ?>>
  91. <?lsmb # Build options.
  92. FOREACH option_data IN element_data.options;
  93. PROCESS option;
  94. END;
  95. ?>
  96. </select>
  97. <?lsmb END ?>
  98. <?lsmb # OPTION ELEMENT ?>
  99. <?lsmb BLOCK option ?>
  100. <?lsmb # Selected is a special case -- no attribute key, so it's handled here.
  101. IF option_data.defined('selected');
  102. option_data.selected = " selected";
  103. ELSE;
  104. option_data.selected = "";
  105. END;
  106. ?>
  107. <?lsmb PROCESS attributes # Process regular attributes.
  108. attribute_data=option_data
  109. element_keys=['tabindex', 'disabled', 'value'] # Attributes that apply to options.
  110. element_type = 'option'
  111. ?>
  112. <?lsmb PROCESS custom_attributes # Process custom attributes.
  113. custom_attribute_data=option_data.attributes
  114. ?>
  115. <option<?lsmb all_attributes ?><?lsmb all_custom_attributes ?><?lsmb option_data.selected ?>><?lsmb option_data.text ?></option>
  116. <?lsmb END ?>
  117. <?lsmb # BUTTON ELEMENT ?>
  118. <?lsmb BLOCK button ?>
  119. <?lsmb PROCESS attributes # Process regular attributes.
  120. attribute_data=element_data
  121. attribute_defaults = button_defaults
  122. element_keys=['name', 'value', 'accesskey', 'type', 'disabled', 'tabindex'] # Attributes that apply to buttons.
  123. element_type = 'button'
  124. ?>
  125. <?lsmb PROCESS custom_attributes # Process custom attributes.
  126. custom_attribute_data=element_data.attributes
  127. ?>
  128. <button<?lsmb all_attributes ?><?lsmb all_custom_attributes ?>><?lsmb element_data.text ?></button>
  129. <?lsmb END ?>
  130. <?lsmb # LABEL ELEMENT ?>
  131. <?lsmb BLOCK label ?>
  132. <?lsmb PROCESS attributes
  133. attribute_data=element_data
  134. attribute_defaults = {} # Make sure old defaults are cleared out.
  135. element_keys=['for'] # Attributes that apply to labels.
  136. element_type = 'label'
  137. ?>
  138. <?lsmb PROCESS custom_attributes
  139. custom_attribute_data=element_data.attributes
  140. ?>
  141. <label<?lsmb all_attributes ?><?lsmb all_custom_attributes ?>><?lsmb element_data.text ?></label>
  142. <?lsmb END ?>
  143. <?lsmb # REGULAR ATTRIBUTE PROCESSING -- all explicitly allowed attributes are processed here. ?>
  144. <?lsmb BLOCK attributes ?>
  145. <?lsmb
  146. all_attributes = ""
  147. all_keys = default_keys.merge(element_keys) # Merge in attributes that apply to this element.
  148. ?>
  149. <?lsmb FOREACH element_attribute IN all_keys # Loop through each allowed attribute. ?>
  150. <?lsmb
  151. IF attribute_data.defined(element_attribute); # Add the attribute to the element if it's been set.
  152. all_attributes = all_attributes _ " " _ element_attribute _ '="' _ attribute_data.${element_attribute} _ '"';
  153. ELSIF attribute_defaults.defined(element_attribute); # Fall back to default value if one is supplied.
  154. all_attributes = all_attributes _ " " _ element_attribute _ '="' _ attribute_defaults.${element_attribute} _ '"';
  155. END;
  156. ?>
  157. <?lsmb END ?>
  158. <?lsmb UNLESS attribute_data.defined('id') # id attribute should always be set, so auto-set it if it's not defined. ?>
  159. <?lsmb element_id = "" ?>
  160. <?lsmb # Labal id's default to [for]-label.
  161. IF element_type == 'label' AND attribute_data.defined('for');
  162. element_id = attribute_data.for _ "-label";
  163. ELSIF ((element_type == 'input' AND attribute_data.type == 'radio') OR element_type == 'button') AND attribute_data.defined('name') AND attribute_data.defined('value');
  164. element_id = attribute_data.name _ "-" _ attribute_data.value; # radios and buttons get name-value for uniqueness.
  165. ELSIF (element_type == 'input' OR element_type == 'textarea' OR element_type == 'select') AND attribute_data.defined('name');
  166. element_id = attribute_data.name;
  167. END;
  168. ?>
  169. <?lsmb # Add the id if it's been generated. Replace underscores with dashes -- nicer CSS.
  170. IF element_id;
  171. all_attributes = ' id="' _ element_id.replace('[_]', '-') _ '"' _ all_attributes;
  172. END;
  173. ?>
  174. <?lsmb END ?>
  175. <?lsmb END ?>
  176. <?lsmb # CUSTOM ATTRIBUTE PROCESSING -- any other attributes passed in the 'attributes' key are processed here. ?>
  177. <?lsmb BLOCK custom_attributes ?>
  178. <?lsmb all_custom_attributes = "" ?>
  179. <?lsmb # Loop through each attribute and add it to the custom attribute string.
  180. FOREACH element_attribute IN custom_attribute_data;
  181. all_custom_attributes = all_custom_attributes _ " " _ element_attribute.key _ '="' _ element_attribute.value _ '"';
  182. END;
  183. ?>
  184. <?lsmb END ?>