uki 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (235) hide show
  1. data/.gitignore +7 -0
  2. data/.gitmodules +3 -0
  3. data/LICENSE +20 -0
  4. data/Rakefile +23 -0
  5. data/Readme.rdoc +9 -0
  6. data/VERSION +1 -0
  7. data/bin/uki +102 -0
  8. data/frameworks/jspec/lib/images/bg.png +0 -0
  9. data/frameworks/jspec/lib/images/hr.png +0 -0
  10. data/frameworks/jspec/lib/images/loading.gif +0 -0
  11. data/frameworks/jspec/lib/images/sprites.bg.png +0 -0
  12. data/frameworks/jspec/lib/images/sprites.png +0 -0
  13. data/frameworks/jspec/lib/images/vr.png +0 -0
  14. data/frameworks/jspec/lib/jspec.css +149 -0
  15. data/frameworks/jspec/lib/jspec.growl.js +115 -0
  16. data/frameworks/jspec/lib/jspec.jquery.js +72 -0
  17. data/frameworks/jspec/lib/jspec.js +1756 -0
  18. data/frameworks/jspec/lib/jspec.shell.js +39 -0
  19. data/frameworks/jspec/lib/jspec.timers.js +90 -0
  20. data/frameworks/jspec/lib/jspec.xhr.js +195 -0
  21. data/frameworks/uki/README.rdoc +179 -0
  22. data/frameworks/uki/compiler.jar +0 -0
  23. data/frameworks/uki/run.rb +2 -0
  24. data/frameworks/uki/spec/commands/example_command.rb +19 -0
  25. data/frameworks/uki/spec/dom.html +39 -0
  26. data/frameworks/uki/spec/support/images/bg.png +0 -0
  27. data/frameworks/uki/spec/support/images/hr.png +0 -0
  28. data/frameworks/uki/spec/support/images/loading.gif +0 -0
  29. data/frameworks/uki/spec/support/images/sprites.bg.png +0 -0
  30. data/frameworks/uki/spec/support/images/sprites.png +0 -0
  31. data/frameworks/uki/spec/support/images/vr.png +0 -0
  32. data/frameworks/uki/spec/support/jspec.css +149 -0
  33. data/frameworks/uki/spec/support/jspec.js +1773 -0
  34. data/frameworks/uki/spec/support/jspec.xhr.js +193 -0
  35. data/frameworks/uki/spec/support/spec.helper.js +1 -0
  36. data/frameworks/uki/spec/unit/background.spec.js +29 -0
  37. data/frameworks/uki/spec/unit/builder.spec.js +51 -0
  38. data/frameworks/uki/spec/unit/data/model.spec.js +29 -0
  39. data/frameworks/uki/spec/unit/dom/dnd.spec.js +71 -0
  40. data/frameworks/uki/spec/unit/dom/event.spec.js +78 -0
  41. data/frameworks/uki/spec/unit/dom.spec.js +28 -0
  42. data/frameworks/uki/spec/unit/geometry.spec.js +79 -0
  43. data/frameworks/uki/spec/unit/selector.spec.js +140 -0
  44. data/frameworks/uki/spec/unit/theme/template.spec.js +31 -0
  45. data/frameworks/uki/spec/unit/utils.spec.js +176 -0
  46. data/frameworks/uki/spec/unit/view/base.spec.js +86 -0
  47. data/frameworks/uki/spec/unit/view/container.spec.js +73 -0
  48. data/frameworks/uki/spec/unit/view.spec.js +13 -0
  49. data/frameworks/uki/src/airport.js +1 -0
  50. data/frameworks/uki/src/uki-core/attachment.js +175 -0
  51. data/frameworks/uki/src/uki-core/background/css.js +37 -0
  52. data/frameworks/uki/src/uki-core/background/cssBox.js +73 -0
  53. data/frameworks/uki/src/uki-core/background/multi.js +20 -0
  54. data/frameworks/uki/src/uki-core/background/null.js +10 -0
  55. data/frameworks/uki/src/uki-core/background/rows.js +77 -0
  56. data/frameworks/uki/src/uki-core/background/sliced9.js +206 -0
  57. data/frameworks/uki/src/uki-core/background.js +35 -0
  58. data/frameworks/uki/src/uki-core/builder.js +68 -0
  59. data/frameworks/uki/src/uki-core/collection.js +278 -0
  60. data/frameworks/uki/src/uki-core/const.js +17 -0
  61. data/frameworks/uki/src/uki-core/dom/dnd.js +93 -0
  62. data/frameworks/uki/src/uki-core/dom/event.js +194 -0
  63. data/frameworks/uki/src/uki-core/dom/nativeLayout.js +18 -0
  64. data/frameworks/uki/src/uki-core/dom/offset.js +130 -0
  65. data/frameworks/uki/src/uki-core/dom/w3cdnd.js +333 -0
  66. data/frameworks/uki/src/uki-core/dom.js +109 -0
  67. data/frameworks/uki/src/uki-core/geometry.js +658 -0
  68. data/frameworks/uki/src/uki-core/image.js +90 -0
  69. data/frameworks/uki/src/uki-core/selector.js +201 -0
  70. data/frameworks/uki/src/uki-core/theme/base.js +39 -0
  71. data/frameworks/uki/src/uki-core/theme/template.js +26 -0
  72. data/frameworks/uki/src/uki-core/theme.js +45 -0
  73. data/frameworks/uki/src/uki-core/uki.js +45 -0
  74. data/frameworks/uki/src/uki-core/utils.js +399 -0
  75. data/frameworks/uki/src/uki-core/view/base.js +480 -0
  76. data/frameworks/uki/src/uki-core/view/container.js +155 -0
  77. data/frameworks/uki/src/uki-core/view/focusable.js +93 -0
  78. data/frameworks/uki/src/uki-core/view/observable.js +66 -0
  79. data/frameworks/uki/src/uki-core/view/styleable.js +70 -0
  80. data/frameworks/uki/src/uki-core/view/utils.js +66 -0
  81. data/frameworks/uki/src/uki-core/view.js +21 -0
  82. data/frameworks/uki/src/uki-core.js +36 -0
  83. data/frameworks/uki/src/uki-data/data.js +1 -0
  84. data/frameworks/uki/src/uki-data/model.js +28 -0
  85. data/frameworks/uki/src/uki-data/observable.js +34 -0
  86. data/frameworks/uki/src/uki-data.js +1 -0
  87. data/frameworks/uki/src/uki-more/more/utils.js +20 -0
  88. data/frameworks/uki/src/uki-more/more/view/listContainer.js +4 -0
  89. data/frameworks/uki/src/uki-more/more/view/multiselectList.js +196 -0
  90. data/frameworks/uki/src/uki-more/more/view/radioButton.js +27 -0
  91. data/frameworks/uki/src/uki-more/more/view/splitTable.js +79 -0
  92. data/frameworks/uki/src/uki-more/more/view/toggleButton.js +24 -0
  93. data/frameworks/uki/src/uki-more/more/view/treeList/render.js +53 -0
  94. data/frameworks/uki/src/uki-more/more/view/treeList.js +110 -0
  95. data/frameworks/uki/src/uki-more/more/view.js +2 -0
  96. data/frameworks/uki/src/uki-more/more.js +1 -0
  97. data/frameworks/uki/src/uki-more.js +4 -0
  98. data/frameworks/uki/src/uki-theamless.js +15 -0
  99. data/frameworks/uki/src/uki-theme/airport/i/button/down-c.gif +0 -0
  100. data/frameworks/uki/src/uki-theme/airport/i/button/down-c.png +0 -0
  101. data/frameworks/uki/src/uki-theme/airport/i/button/down-h.gif +0 -0
  102. data/frameworks/uki/src/uki-theme/airport/i/button/down-h.png +0 -0
  103. data/frameworks/uki/src/uki-theme/airport/i/button/down-m.png +0 -0
  104. data/frameworks/uki/src/uki-theme/airport/i/button/down-v.png +0 -0
  105. data/frameworks/uki/src/uki-theme/airport/i/button/focusRing-c.png +0 -0
  106. data/frameworks/uki/src/uki-theme/airport/i/button/focusRing-h.png +0 -0
  107. data/frameworks/uki/src/uki-theme/airport/i/button/focusRing-m.png +0 -0
  108. data/frameworks/uki/src/uki-theme/airport/i/button/focusRing-v.png +0 -0
  109. data/frameworks/uki/src/uki-theme/airport/i/button/focusRing.png +0 -0
  110. data/frameworks/uki/src/uki-theme/airport/i/button/hover-c.gif +0 -0
  111. data/frameworks/uki/src/uki-theme/airport/i/button/hover-c.png +0 -0
  112. data/frameworks/uki/src/uki-theme/airport/i/button/hover-h.gif +0 -0
  113. data/frameworks/uki/src/uki-theme/airport/i/button/hover-h.png +0 -0
  114. data/frameworks/uki/src/uki-theme/airport/i/button/hover-m.png +0 -0
  115. data/frameworks/uki/src/uki-theme/airport/i/button/hover-v.png +0 -0
  116. data/frameworks/uki/src/uki-theme/airport/i/button/hover.png +0 -0
  117. data/frameworks/uki/src/uki-theme/airport/i/button/normal-c.gif +0 -0
  118. data/frameworks/uki/src/uki-theme/airport/i/button/normal-c.png +0 -0
  119. data/frameworks/uki/src/uki-theme/airport/i/button/normal-h.gif +0 -0
  120. data/frameworks/uki/src/uki-theme/airport/i/button/normal-h.png +0 -0
  121. data/frameworks/uki/src/uki-theme/airport/i/button/normal-m.png +0 -0
  122. data/frameworks/uki/src/uki-theme/airport/i/button/normal-v.png +0 -0
  123. data/frameworks/uki/src/uki-theme/airport/i/button/normal.png +0 -0
  124. data/frameworks/uki/src/uki-theme/airport/i/checkbox/checkbox.png +0 -0
  125. data/frameworks/uki/src/uki-theme/airport/i/checkbox/focus.png +0 -0
  126. data/frameworks/uki/src/uki-theme/airport/i/checkbox/normal.gif +0 -0
  127. data/frameworks/uki/src/uki-theme/airport/i/checkbox/normal.png +0 -0
  128. data/frameworks/uki/src/uki-theme/airport/i/panel/dark-h.gif +0 -0
  129. data/frameworks/uki/src/uki-theme/airport/i/panel/dark-h.png +0 -0
  130. data/frameworks/uki/src/uki-theme/airport/i/panel/dark-m.png +0 -0
  131. data/frameworks/uki/src/uki-theme/airport/i/panel/dark.png +0 -0
  132. data/frameworks/uki/src/uki-theme/airport/i/popup/normal.png +0 -0
  133. data/frameworks/uki/src/uki-theme/airport/i/radio/focus.png +0 -0
  134. data/frameworks/uki/src/uki-theme/airport/i/radio/normal.gif +0 -0
  135. data/frameworks/uki/src/uki-theme/airport/i/radio/normal.png +0 -0
  136. data/frameworks/uki/src/uki-theme/airport/i/radio/radio.png +0 -0
  137. data/frameworks/uki/src/uki-theme/airport/i/shadow/large-c.png +0 -0
  138. data/frameworks/uki/src/uki-theme/airport/i/shadow/large-h.png +0 -0
  139. data/frameworks/uki/src/uki-theme/airport/i/shadow/large-m.png +0 -0
  140. data/frameworks/uki/src/uki-theme/airport/i/shadow/large-v.png +0 -0
  141. data/frameworks/uki/src/uki-theme/airport/i/shadow/large.png +0 -0
  142. data/frameworks/uki/src/uki-theme/airport/i/slider/bar-m.gif +0 -0
  143. data/frameworks/uki/src/uki-theme/airport/i/slider/bar-m.png +0 -0
  144. data/frameworks/uki/src/uki-theme/airport/i/slider/bar-v.gif +0 -0
  145. data/frameworks/uki/src/uki-theme/airport/i/slider/bar-v.png +0 -0
  146. data/frameworks/uki/src/uki-theme/airport/i/slider/bar.png +0 -0
  147. data/frameworks/uki/src/uki-theme/airport/i/slider/focus.png +0 -0
  148. data/frameworks/uki/src/uki-theme/airport/i/slider/handle.gif +0 -0
  149. data/frameworks/uki/src/uki-theme/airport/i/splitPane/horizontal.gif +0 -0
  150. data/frameworks/uki/src/uki-theme/airport/i/splitPane/horizontal.png +0 -0
  151. data/frameworks/uki/src/uki-theme/airport/i/splitPane/vertical.gif +0 -0
  152. data/frameworks/uki/src/uki-theme/airport/i/x.gif +0 -0
  153. data/frameworks/uki/src/uki-theme/airport.js +322 -0
  154. data/frameworks/uki/src/uki-theme/aristo/i/button/down-c.gif +0 -0
  155. data/frameworks/uki/src/uki-theme/aristo/i/button/down-c.png +0 -0
  156. data/frameworks/uki/src/uki-theme/aristo/i/button/down-h.png +0 -0
  157. data/frameworks/uki/src/uki-theme/aristo/i/button/down-m.png +0 -0
  158. data/frameworks/uki/src/uki-theme/aristo/i/button/down-v.png +0 -0
  159. data/frameworks/uki/src/uki-theme/aristo/i/button/down.png +0 -0
  160. data/frameworks/uki/src/uki-theme/aristo/i/button/focusRing-c.png +0 -0
  161. data/frameworks/uki/src/uki-theme/aristo/i/button/focusRing-h.png +0 -0
  162. data/frameworks/uki/src/uki-theme/aristo/i/button/focusRing-m.png +0 -0
  163. data/frameworks/uki/src/uki-theme/aristo/i/button/focusRing-v.png +0 -0
  164. data/frameworks/uki/src/uki-theme/aristo/i/button/focusRing.png +0 -0
  165. data/frameworks/uki/src/uki-theme/aristo/i/button/normal-c.gif +0 -0
  166. data/frameworks/uki/src/uki-theme/aristo/i/button/normal-c.png +0 -0
  167. data/frameworks/uki/src/uki-theme/aristo/i/button/normal-h.png +0 -0
  168. data/frameworks/uki/src/uki-theme/aristo/i/button/normal-m.png +0 -0
  169. data/frameworks/uki/src/uki-theme/aristo/i/button/normal-v.png +0 -0
  170. data/frameworks/uki/src/uki-theme/aristo/i/button/normal.png +0 -0
  171. data/frameworks/uki/src/uki-theme/aristo/i/checkbox/focus.png +0 -0
  172. data/frameworks/uki/src/uki-theme/aristo/i/checkbox/normal.gif +0 -0
  173. data/frameworks/uki/src/uki-theme/aristo/i/checkbox/normal.png +0 -0
  174. data/frameworks/uki/src/uki-theme/aristo/i/panel/normal-h.png +0 -0
  175. data/frameworks/uki/src/uki-theme/aristo/i/panel/normal-m.png +0 -0
  176. data/frameworks/uki/src/uki-theme/aristo/i/panel/normal.png +0 -0
  177. data/frameworks/uki/src/uki-theme/aristo/i/popup/normal.png +0 -0
  178. data/frameworks/uki/src/uki-theme/aristo/i/radio/focus.png +0 -0
  179. data/frameworks/uki/src/uki-theme/aristo/i/radio/normal.gif +0 -0
  180. data/frameworks/uki/src/uki-theme/aristo/i/radio/normal.png +0 -0
  181. data/frameworks/uki/src/uki-theme/aristo/i/shadow/large-c.png +0 -0
  182. data/frameworks/uki/src/uki-theme/aristo/i/shadow/large-h.png +0 -0
  183. data/frameworks/uki/src/uki-theme/aristo/i/shadow/large-m.png +0 -0
  184. data/frameworks/uki/src/uki-theme/aristo/i/shadow/large-v.png +0 -0
  185. data/frameworks/uki/src/uki-theme/aristo/i/shadow/large.png +0 -0
  186. data/frameworks/uki/src/uki-theme/aristo/i/slider/bar-m.gif +0 -0
  187. data/frameworks/uki/src/uki-theme/aristo/i/slider/bar-m.png +0 -0
  188. data/frameworks/uki/src/uki-theme/aristo/i/slider/bar-v.gif +0 -0
  189. data/frameworks/uki/src/uki-theme/aristo/i/slider/bar-v.png +0 -0
  190. data/frameworks/uki/src/uki-theme/aristo/i/slider/bar.png +0 -0
  191. data/frameworks/uki/src/uki-theme/aristo/i/slider/handle.gif +0 -0
  192. data/frameworks/uki/src/uki-theme/aristo/i/slider/handle.png +0 -0
  193. data/frameworks/uki/src/uki-theme/aristo/i/splitPane/horizontal.gif +0 -0
  194. data/frameworks/uki/src/uki-theme/aristo/i/splitPane/horizontal.png +0 -0
  195. data/frameworks/uki/src/uki-theme/aristo/i/splitPane/vertical.gif +0 -0
  196. data/frameworks/uki/src/uki-theme/aristo/i/x.gif +0 -0
  197. data/frameworks/uki/src/uki-theme/aristo.js +217 -0
  198. data/frameworks/uki/src/uki-view/view/box.js +1 -0
  199. data/frameworks/uki/src/uki-view/view/button.js +126 -0
  200. data/frameworks/uki/src/uki-view/view/checkbox.js +36 -0
  201. data/frameworks/uki/src/uki-view/view/flow.js +48 -0
  202. data/frameworks/uki/src/uki-view/view/image.js +9 -0
  203. data/frameworks/uki/src/uki-view/view/label.js +123 -0
  204. data/frameworks/uki/src/uki-view/view/list/render.js +23 -0
  205. data/frameworks/uki/src/uki-view/view/list.js +442 -0
  206. data/frameworks/uki/src/uki-view/view/popup.js +113 -0
  207. data/frameworks/uki/src/uki-view/view/radio.js +57 -0
  208. data/frameworks/uki/src/uki-view/view/scrollPane.js +139 -0
  209. data/frameworks/uki/src/uki-view/view/slider.js +154 -0
  210. data/frameworks/uki/src/uki-view/view/splitPane.js +213 -0
  211. data/frameworks/uki/src/uki-view/view/table/column.js +96 -0
  212. data/frameworks/uki/src/uki-view/view/table/header.js +53 -0
  213. data/frameworks/uki/src/uki-view/view/table/render.js +25 -0
  214. data/frameworks/uki/src/uki-view/view/table.js +71 -0
  215. data/frameworks/uki/src/uki-view/view/textField.js +145 -0
  216. data/frameworks/uki/src/uki-view/view/toolbar.js +93 -0
  217. data/frameworks/uki/src/uki-view.js +15 -0
  218. data/frameworks/uki/src/uki.js +2 -0
  219. data/frameworks/uki/thin.yaml +11 -0
  220. data/frameworks/uki/uki.rb +38 -0
  221. data/frameworks/uki/uki.ru +2 -0
  222. data/lib/uki/include_js.rb +50 -0
  223. data/lib/uki/project.rb +207 -0
  224. data/lib/uki/routes.rb +20 -0
  225. data/lib/uki/server.rb +42 -0
  226. data/lib/uki.rb +9 -0
  227. data/templates/index.html.erb +10 -0
  228. data/templates/model.js.erb +5 -0
  229. data/templates/myapp.js.erb +44 -0
  230. data/templates/package.js.erb +3 -0
  231. data/templates/spec.html.erb +23 -0
  232. data/templates/spec.js.erb +6 -0
  233. data/templates/view.js.erb +10 -0
  234. data/uki.gemspec +281 -0
  235. metadata +317 -0
@@ -0,0 +1,140 @@
1
+ describe 'uki.Selector'
2
+ it 'should tokenize expression'
3
+ tokens = uki.Selector.tokenize('label > * > project.views.CustomView Label[name^="wow"]')[0];
4
+ tokens.should_eql ['label', '>', '*', '>', 'project.views.CustomView', 'Label[name^="wow"]']
5
+ end
6
+
7
+ it 'should copy find to uki'
8
+ uki.find.should.not.be_undefined
9
+ end
10
+
11
+ describe 'filtering'
12
+ before_each
13
+ tree = uki.build([
14
+ { view: 'Box', rect: '0 0 1000 1000', name: 'top', childViews: [
15
+ { view: 'Box', rect: '0 0 1000 1000', name: 'second', childViews: [
16
+ { view: 'Box', rect: '10 10 100 100', name: 'third', someAttribute: true, childViews: [
17
+ { view: 'Label', rect: '10 10 100 100', name: 'label1', someAttribute: false }
18
+ ]},
19
+ { view: 'Label', rect: '200 10 100 100', name: 'label2' }
20
+ ]}
21
+ ]}
22
+ ]);
23
+
24
+ end
25
+
26
+ it 'by *'
27
+ elements = uki.Selector.find('*', tree);
28
+ elements.length.should.be 4
29
+ uki.attr(elements[0], 'name').should.be 'second'
30
+ uki.attr(elements[1], 'name').should.be 'third'
31
+ uki.attr(elements[2], 'name').should.be 'label1'
32
+ uki.attr(elements[3], 'name').should.be 'label2'
33
+ end
34
+
35
+ it 'by * *'
36
+ elements = uki.Selector.find('* *', tree);
37
+ elements.length.should.be 3
38
+ uki.attr(elements[0], 'name').should.be 'third'
39
+ uki.attr(elements[1], 'name').should.be 'label1'
40
+ uki.attr(elements[2], 'name').should.be 'label2'
41
+ end
42
+
43
+ it 'by full typeName()'
44
+ elements = uki.Selector.find('uki.view.Label', tree);
45
+ elements.length.should.be 2
46
+ uki.attr(elements[0], 'name').should.be 'label1'
47
+ uki.attr(elements[1], 'name').should.be 'label2'
48
+ end
49
+
50
+ it 'by contracted typeName()'
51
+ elements = uki.Selector.find('Box', tree);
52
+ elements.length.should.be 2
53
+ uki.attr(elements[0], 'name').should.be 'second'
54
+ uki.attr(elements[1], 'name').should.be 'third'
55
+ end
56
+
57
+ it 'by attribute'
58
+ elements = uki.Selector.find('[name=second]', tree);
59
+ elements.length.should.be 1
60
+ uki.attr(elements[0], 'name').should.be 'second'
61
+ end
62
+
63
+ it 'by attribute in brackets'
64
+ elements = uki.Selector.find('[name="second"]', tree);
65
+ elements.length.should.be 1
66
+ uki.attr(elements[0], 'name').should.be 'second'
67
+ end
68
+
69
+ it 'by attribute and typeName()'
70
+ elements = uki.Selector.find('Box[name=second]', tree);
71
+ elements.length.should.be 1
72
+ uki.attr(elements[0], 'name').should.be 'second'
73
+ end
74
+
75
+ it 'by ^= attribute'
76
+ elements = uki.Selector.find('[name^="label"]', tree);
77
+ elements.length.should.be 2
78
+ uki.attr(elements[0], 'name').should.be 'label1'
79
+ uki.attr(elements[1], 'name').should.be 'label2'
80
+ end
81
+
82
+ it 'by $= attribute'
83
+ elements = uki.Selector.find('*[name$="bel1"]', tree);
84
+ elements.length.should.be 1
85
+ uki.attr(elements[0], 'name').should.be 'label1'
86
+ end
87
+
88
+ it 'by ~= attribute'
89
+ elements = uki.Selector.find('*[name~="abe"]', tree);
90
+ elements.length.should.be 2
91
+ uki.attr(elements[0], 'name').should.be 'label1'
92
+ uki.attr(elements[1], 'name').should.be 'label2'
93
+ end
94
+
95
+ it 'by attribute presence'
96
+ elements = uki.Selector.find('*[someAttribute]', tree);
97
+ elements.length.should.be 1
98
+ uki.attr(elements[0], 'name').should.be 'third'
99
+ end
100
+
101
+ it 'direct children with >'
102
+ elements = uki.Selector.find('>', [tree[0].childViews()[0]]);
103
+ elements.length.should.be 2
104
+ uki.attr(elements[0], 'name').should.be 'third'
105
+ uki.attr(elements[1], 'name').should.be 'label2'
106
+ end
107
+
108
+ it 'direct children with > *'
109
+ elements = uki.Selector.find('> *', [tree[0].childViews()[0]]);
110
+ elements.length.should.be 2
111
+ uki.attr(elements[0], 'name').should.be 'third'
112
+ uki.attr(elements[1], 'name').should.be 'label2'
113
+ end
114
+
115
+ it 'right after with +'
116
+ elements = uki.Selector.find('Box + Label', tree);
117
+ elements.length.should.be 1
118
+ uki.attr(elements[0], 'name').should.be 'label2'
119
+ end
120
+
121
+ it 'direct children within container >'
122
+ elements = uki.Selector.find('Box > Label', tree);
123
+ elements.length.should.be 2
124
+ uki.attr(elements[0], 'name').should.be 'label2'
125
+ uki.attr(elements[1], 'name').should.be 'label1'
126
+ end
127
+
128
+ it 'by :eq modifier'
129
+ elements = uki.Selector.find('Box:eq(0) > Label:eq(0)', tree);
130
+ elements.length.should.be 1
131
+ uki.attr(elements[0], 'name').should.be 'label2'
132
+ end
133
+
134
+ it 'by :gt modifier'
135
+ elements = uki.Selector.find('Box:gt(0)', tree);
136
+ elements.length.should.be 1
137
+ uki.attr(elements[0], 'name').should.be 'third'
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,31 @@
1
+ describe 'uki.theme.Template'
2
+ it 'should replace single value'
3
+ var t = new uki.theme.Template('<code>${value}</code>')
4
+ t.render({value: '111'}).should.be '<code>111</code>'
5
+ end
6
+
7
+ it 'should replace at the beggining of a string'
8
+ var t = new uki.theme.Template('${before}<code>${value}</code>')
9
+ t.render({before: '000', value: '111'}).should.be '000<code>111</code>'
10
+ end
11
+
12
+ it 'should replace at the end of a string'
13
+ var t = new uki.theme.Template('<code>${value}</code>${after}')
14
+ t.render({value: '111', after: '222'}).should.be '<code>111</code>222'
15
+ end
16
+
17
+ it 'should replace several same values'
18
+ var t = new uki.theme.Template('<code>${value} ${value}</code>');
19
+ t.render({value: '111'}).should.be '<code>111 111</code>'
20
+ end
21
+
22
+ it 'should replace adjacent values'
23
+ var t = new uki.theme.Template('<code>${a}${b}</code>');
24
+ t.render({a: '111', b: '222'}).should.be '<code>111222</code>'
25
+ end
26
+
27
+ it 'should work with brackets'
28
+ var t = new uki.theme.Template('<code>${a} {something} ${b} .css { some code }</code>');
29
+ t.render({a: '111', b: '222'}).should.be '<code>111 {something} 222 .css { some code }</code>'
30
+ end
31
+ end
@@ -0,0 +1,176 @@
1
+ describe 'uki.utils'
2
+ utils = uki.utils;
3
+
4
+ it 'should test isFunction'
5
+ var f1 = function() {};
6
+ function f2 () {};
7
+ utils.isFunction(function() {}).should.be_true('anonimous function')
8
+ utils.isFunction(f1).should.be_true('var f = function')
9
+ utils.isFunction(f2).should.be_true('function f')
10
+ utils.isFunction({}).should.not.be_true('object')
11
+ end
12
+
13
+ it 'should test isArray'
14
+ var x = [1, 2]
15
+ utils.isArray([]).should.be_true('anonimous array')
16
+ utils.isArray(x).should.be_true('x = []')
17
+ utils.isArray({}).should.not.be_true('object')
18
+ end
19
+
20
+ describe '.each()'
21
+ it 'should iterate over array'
22
+ var count = 0;
23
+ utils.each([1, 1, 1], function() {
24
+ count ++;
25
+ });
26
+ count.should.be 3
27
+ end
28
+
29
+ it 'should set this to current element'
30
+ utils.each([1, 1, 1], function() {
31
+ this.valueOf().should.eql 1
32
+ });
33
+ end
34
+
35
+ it 'should iterate with given context'
36
+ var context = {};
37
+ utils.each([1, 1, 1], function() {
38
+ this.should.be context
39
+ }, context);
40
+ end
41
+
42
+ it 'should iterave over hash'
43
+ utils.each({a: 1, b: 1, c: 1}, function() {
44
+ this.valueOf().should.be 1
45
+ });
46
+ end
47
+
48
+ it 'should iterate over hash with given context'
49
+ var context = {};
50
+ utils.each({a: 1, b: 1, c: 1}, function() {
51
+ this.should.be context
52
+ }, context);
53
+ end
54
+ end
55
+
56
+ it 'should trim text'
57
+ utils.trim(' TEST TEST ').should.be 'TEST TEST'
58
+ end
59
+
60
+ it 'should escape html'
61
+ utils.escapeHTML('<span class="a">1</span>').should.be '&lt;span class=&quot;a&quot;&gt;1&lt;/span&gt;'
62
+ end
63
+
64
+ it 'should test if is inArray'
65
+ utils.inArray(1, [0, 1, 2]).should.be 1
66
+ utils.inArray(3, [0, 1, 2]).should.be -1
67
+ end
68
+
69
+ it 'should make uniq array'
70
+ utils.unique([1, 1, 2, 3]).should.eql [1, 2, 3]
71
+ end
72
+
73
+ it 'should grep array for items'
74
+ var result = utils.grep([1, 2, 3, 4], function(v) {
75
+ return v > 2;
76
+ });
77
+ result.should.eql [3, 4]
78
+ end
79
+
80
+ it 'should map array'
81
+ var result = utils.map([1, 2, 3, 4], function(v) {
82
+ return -v;
83
+ });
84
+ result.should.eql [-1, -2, -3, -4]
85
+ end
86
+
87
+ it 'should reduce array'
88
+ var result = utils.reduce(1, [1,2,3,4], function(x, e) { return e*x; });
89
+ result.should.be 2*3*4
90
+ end
91
+
92
+ it 'should map in given context'
93
+ var context = {};
94
+ var result = utils.map([1, 2, 3, 4], function(v) {
95
+ this.should.be context
96
+ }, context);
97
+ end
98
+
99
+ it 'should map by field name (shortcut)'
100
+ var result = utils.map([{a: 1}, {a: 2}, {a: 3}], 'a');
101
+ result.should.eql [1, 2, 3]
102
+ end
103
+
104
+ it 'should map extend objects'
105
+ var e = utils.extend({a: 1}, {b: 2}, {c: 3, d: undefined});
106
+ e.should.eql {a: 1, b: 2, c: 3}
107
+ end
108
+
109
+ it 'should extend uki with utils'
110
+ var functions = ['isFunction', 'isArray', 'trim', 'escapeHTML', 'each', 'inArray', 'unique', 'grep', 'map', 'extend'];
111
+ utils.each(functions, function() {
112
+ uki[this].should.not.be_null
113
+ });
114
+ end
115
+
116
+ it 'should extend new class with base class'
117
+ base = function() {};
118
+ called = {};
119
+ base.prototype = {
120
+ a: function() {
121
+ called.a = true;
122
+ }
123
+ }
124
+ var sub = uki.newClass(base, { init: uki.F });
125
+ (new sub()).a();
126
+ called.a.should.be_true
127
+ end
128
+
129
+ it 'should extend new class with mixins'
130
+ base = function() {};
131
+ called = {};
132
+ base.prototype = {
133
+ a: function() {
134
+ called.a = true;
135
+ }
136
+ }
137
+ var sub = uki.newClass(base, { b: function() { called.b = true} }, { init: uki.F });
138
+ (new sub()).a();
139
+ (new sub()).b();
140
+ called.a.should.be_true
141
+ called.b.should.be_true
142
+ end
143
+
144
+ it 'should use function as a last parameter passing base classes to it'
145
+ base = function() {};
146
+ called = false;
147
+ base.prototype = {
148
+ a: function() {
149
+ called.a = true;
150
+ }
151
+ }
152
+ var sub = uki.newClass(base, { b: function() { called.b = true} }, function(b, mixin) {
153
+ called = true;
154
+ b.should.be base.prototype
155
+ mixin.b.should.not.be_null
156
+ this.init = uki.F;
157
+ this.b = uki.F;
158
+ });
159
+ (new sub()).b.should.not.be_null
160
+ called.should.be_true
161
+ end
162
+
163
+ it 'should filter unique elements in array'
164
+ a = [1, 2, 3, 1, 4]
165
+ uki.unique(a).should.eql [1, 2, 3, 4]
166
+ end
167
+
168
+ it 'should filter unique elements in array of objects'
169
+ x = {a: 1}
170
+ y = {b: 1}
171
+ z = {c: 1}
172
+ a = [x, y, x, y, z]
173
+ uki.unique(a).should.eql [x, y, z]
174
+ end
175
+
176
+ end
@@ -0,0 +1,86 @@
1
+ describe 'uki.view.Base'
2
+
3
+ before_each
4
+ v = new uki.view.Base('100 100');
5
+ end
6
+
7
+ it 'should create a dom node upon construction'
8
+ v.dom().should.not.be_null
9
+ end
10
+
11
+ it 'should delegate className to dom'
12
+ v.className('test')
13
+ v.className().should.be 'test'
14
+ v.dom().className.should.be 'test'
15
+ end
16
+
17
+ it 'should delegate id to dom'
18
+ v.id('test')
19
+ v.id().should.be 'test'
20
+ v.dom().id.should.be 'test'
21
+ end
22
+
23
+ it 'should register id in a hash'
24
+ called = false
25
+ stub(uki, 'registerId').and_return(function(view) {
26
+ view.id().should.be 'test1'
27
+ called = true
28
+ });
29
+ v.id('test1')
30
+ called.should.be_true
31
+ end
32
+
33
+ it 'should unregister id from hash on change'
34
+ called = false
35
+ stub(uki, 'unregisterId').and_return(function(view) {
36
+ view.id().should.be 'test2'
37
+ called = true
38
+ });
39
+ v.id('test2')
40
+ v.id('test3')
41
+ called.should.be_true
42
+ end
43
+
44
+ it 'should attach background'
45
+ var bg = new uki.background.Null()
46
+ called = false
47
+ stub(bg, 'attachTo').and_return(function(view) {
48
+ view.should.be v
49
+ called = true
50
+ })
51
+ v.background(bg)
52
+ called.should.be_true
53
+ end
54
+
55
+ it 'should return default background if none specified'
56
+ v._defaultBackground = '#CCC'
57
+ v.background().should.be_an_instance_of uki.background.Css
58
+ end
59
+
60
+ it 'should set rect property'
61
+ v.rect('0 10 20 30')
62
+ v.rect().should.be_an_instance_of uki.geometry.Rect
63
+ end
64
+
65
+ it 'should set minSize and maxSize properties'
66
+ v.minSize('10 20').maxSize('100 200')
67
+ v.dom().style.minWidth.should.be '10px'
68
+ v.dom().style.minHeight.should.be '20px'
69
+ v.dom().style.maxWidth.should.be '100px'
70
+ v.dom().style.maxHeight.should.be '200px'
71
+ v.minSize().should.eql new uki.geometry.Size(10, 20)
72
+ v.maxSize().should.eql new uki.geometry.Size(100, 200)
73
+ end
74
+
75
+ it 'should normailze rect according to min and max sizes'
76
+ v.minSize('110 10')
77
+ v.rect().width.should.be 110
78
+ v.maxSize('200 50')
79
+ v.rect().height.should.be 50
80
+ end
81
+
82
+ it 'should return null for next/prev views'
83
+ v.nextView().should.be_null
84
+ v.prevView().should.be_null
85
+ end
86
+ end
@@ -0,0 +1,73 @@
1
+ describe 'uki.view.Container'
2
+ before_each
3
+ parentView = new uki.view.Container('100 200')
4
+ end
5
+
6
+ it 'should append child views'
7
+ child = new uki.view.Base('10 10')
8
+ parentView.appendChild(child)
9
+ parentView.childViews().length.should.be 1
10
+ parentView.childViews().should.eql [child]
11
+ end
12
+
13
+ it 'should insert child before'
14
+ firstChild = new uki.view.Base('10 10')
15
+ secondChild = new uki.view.Base('10 10')
16
+ parentView.appendChild(secondChild)
17
+ parentView.insertBefore(firstChild, secondChild)
18
+ parentView.childViews().should.eql [firstChild, secondChild]
19
+ end
20
+
21
+ it 'should set correct parent'
22
+ child = new uki.view.Base('10 10')
23
+ parentView.appendChild(child)
24
+ child.parent().should.be parentView
25
+ end
26
+
27
+ it 'should remove children'
28
+ child = new uki.view.Base('10 10')
29
+ parentView.appendChild(child)
30
+ parentView.removeChild(child)
31
+ child.parent().should.be_null
32
+ end
33
+
34
+ it 'should allow childViews() writing'
35
+ child = new uki.view.Base('10 10')
36
+ parentView.childViews([child])
37
+ parentView.childViews().should.eql [child]
38
+ end
39
+
40
+ it 'should remove children on childViews() write'
41
+ firstChild = new uki.view.Base('10 10')
42
+ secondChild = new uki.view.Base('10 10')
43
+ thirdChild = new uki.view.Base('10 10')
44
+ parentView.childViews([firstChild, secondChild])
45
+ parentView.childViews([secondChild, thirdChild])
46
+ firstChild.parent().should.be_null
47
+ secondChild.parent().should.be parentView
48
+ thirdChild.parent().should.be parentView
49
+ end
50
+
51
+ it 'should allow nextView, prevView accessors for children'
52
+ secondChild = new uki.view.Base('10 10')
53
+ firstChild = new uki.view.Base('10 10')
54
+ parentView.appendChild(firstChild)
55
+ parentView.appendChild(secondChild)
56
+ firstChild.nextView().should.be secondChild
57
+ secondChild.prevView().should.be firstChild
58
+ firstChild.prevView().should.be_null
59
+ secondChild.nextView().should.be_null
60
+ end
61
+
62
+ it 'should resize children on rect resize'
63
+ child = new uki.view.Base('10 10')
64
+ called = 0
65
+ stub(child, 'parentResized').and_return(function() {
66
+ called++;
67
+ });
68
+ parentView.appendChild(child)
69
+ parentView.rect('200 200')
70
+ called.should.be 1
71
+ end
72
+
73
+ end
@@ -0,0 +1,13 @@
1
+ describe 'uki.view'
2
+ it 'should declare new views'
3
+ called = false
4
+ uki.view.declare('tmp.view.TestView', uki.view.Base, function(base) {
5
+ base.should.be uki.view.Base.prototype
6
+ called = true
7
+ });
8
+ tmp.view.TestView.should.not.be_null
9
+ called.should.be_true
10
+ (new tmp.view.TestView()).typeName().should.be 'tmp.view.TestView'
11
+ end
12
+
13
+ end
@@ -0,0 +1 @@
1
+ include('uki-theme/airport.js');
@@ -0,0 +1,175 @@
1
+ include('const.js');
2
+ include('utils.js');
3
+ include('dom.js');
4
+ include('geometry.js');
5
+ include('view/observable.js');
6
+
7
+ (function() {
8
+ var self = uki.Attachment = uki.newClass(uki.view.Observable, /** @lends uki.Attachment.prototype */ {
9
+ /**
10
+ * Attachment serves as a connection between a uki view and a dom container.
11
+ * It notifies its view with parentResized on window resize.
12
+ * Attachment supports part of uki.view.Base API like #domForChild or #rectForChild
13
+ *
14
+ * @param {Element} dom Container element
15
+ * @param {uki.view.Base} view Attached view
16
+ * @param {uki.geometry.Rect} rect Initial size
17
+ *
18
+ * @see uki.view.Base#parentResized
19
+ * @name uki.Attachment
20
+ * @augments uki.view.Observable
21
+ * @constructor
22
+ */
23
+ init: function( dom, view, rect ) {
24
+ uki.initNativeLayout();
25
+
26
+ this._dom = dom = dom || root;
27
+ this._view = view;
28
+ this._rect = Rect.create(rect) || this.rect();
29
+
30
+ uki.dom.offset.initialize();
31
+
32
+ view.parent(this);
33
+ this.domForChild().appendChild(view.dom());
34
+
35
+ if (dom != root && dom.tagName != 'BODY') {
36
+ var computedStyle = dom.runtimeStyle || dom.ownerDocument.defaultView.getComputedStyle(dom, null);
37
+ if (!computedStyle.position || computedStyle.position == 'static') dom.style.position = 'relative';
38
+ }
39
+ self.register(this);
40
+
41
+ this.layout();
42
+ },
43
+
44
+ /**
45
+ * Returns document.body if attached to window. Otherwise returns dom
46
+ * uki.view.Base api
47
+ *
48
+ * @type Element
49
+ */
50
+ domForChild: function() {
51
+ return this._dom === root ? doc.body : this._dom;
52
+ },
53
+
54
+ /**
55
+ * uki.view.Base api
56
+ *
57
+ * @type uki.geometry.Rect
58
+ */
59
+ rectForChild: function(child) {
60
+ return this.rect();
61
+ },
62
+
63
+ /**
64
+ * uki.view.Base api
65
+ */
66
+ scroll: function() {
67
+ // TODO: support window scrolling
68
+ },
69
+
70
+ /**
71
+ * uki.view.Base api
72
+ */
73
+ scrollTop: function() {
74
+ // TODO: support window scrolling
75
+ return this._dom.scrollTop || 0;
76
+ },
77
+
78
+ /**
79
+ * uki.view.Base api
80
+ */
81
+ scrollLeft: function() {
82
+ // TODO: support window scrolling
83
+ return this._dom.scrollLeft || 0;
84
+ },
85
+
86
+ /**
87
+ * uki.view.Base api
88
+ */
89
+ parent: function() {
90
+ return null;
91
+ },
92
+
93
+ /**
94
+ * On window resize resizes and layout its child view
95
+ * @fires event:layout
96
+ */
97
+ layout: function() {
98
+ var oldRect = this._rect;
99
+
100
+ // if (rect.eq(this._rect)) return;
101
+ var newRect = this._rect = this.rect();
102
+ this._view.parentResized(oldRect, newRect);
103
+ if (this._view._needsLayout) this._view.layout();
104
+ this.trigger('layout', {source: this, rect: newRect});
105
+ },
106
+
107
+ /**
108
+ * @return {Element} Container dom
109
+ */
110
+ dom: function() {
111
+ return this._dom;
112
+ },
113
+
114
+ /**
115
+ * @return {Element} Child view
116
+ */
117
+ view: function() {
118
+ return this._view;
119
+ },
120
+
121
+ /**
122
+ * @private
123
+ * @return {uki.geometry.Rect} Size of the container
124
+ */
125
+ rect: function() {
126
+ var width = this._dom === root || this._dom === doc.body ?
127
+ MAX(getRootElement().clientWidth, this._dom.offsetWidth || 0) :
128
+ this._dom.offsetWidth,
129
+ height = this._dom === root || this._dom === doc.body ?
130
+ MAX(getRootElement().clientHeight, this._dom.offsetHeight || 0) :
131
+ this._dom.offsetHeight;
132
+
133
+ return new Rect(width, height);
134
+ }
135
+ });
136
+
137
+ function getRootElement() {
138
+ return doc.compatMode == "CSS1Compat" && doc.documentElement || doc.body;
139
+ }
140
+
141
+ self.instances = [];
142
+
143
+ /**
144
+ * @memberOf uki.Attachment
145
+ */
146
+ self.register = function(a) {
147
+ if (self.instances.length == 0) {
148
+ var timeout = false;
149
+ uki.dom.bind(root, 'resize', function() {
150
+ if (!timeout) {
151
+ timeout = true;
152
+ setTimeout(function() {
153
+ timeout = false;
154
+ uki.each(self.instances, function() { this.layout(); });
155
+ }, 1)
156
+ }
157
+ });
158
+ }
159
+ self.instances.push(a);
160
+ };
161
+
162
+ /**
163
+ * @memberOf uki.Attachment
164
+ */
165
+ self.childViews = function() {
166
+ return uki.map(self.instances, 'view');
167
+ };
168
+
169
+ /**
170
+ * @memberOf uki.Attachment
171
+ */
172
+ uki.top = function() {
173
+ return [self];
174
+ };
175
+ })();