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,130 @@
1
+ include('../dom.js');
2
+
3
+ (function() {
4
+ var self;
5
+
6
+ if ( doc.documentElement["getBoundingClientRect"] ) {
7
+ self = uki.dom.offset = function( elem ) {
8
+ if ( !elem || elem == root ) return new Point();
9
+ if ( elem === elem.ownerDocument.body ) return self.bodyOffset( elem );
10
+ self.boxModel === undefined && self.initializeBoxModel();
11
+ var box = elem.getBoundingClientRect(),
12
+ doc = elem.ownerDocument,
13
+ body = doc.body,
14
+ docElem = doc.documentElement,
15
+ clientTop = docElem.clientTop || body.clientTop || 0,
16
+ clientLeft = docElem.clientLeft || body.clientLeft || 0,
17
+ top = box.top + (self.pageYOffset || self.boxModel && docElem.scrollTop || body.scrollTop ) - clientTop,
18
+ left = box.left + (self.pageXOffset || self.boxModel && docElem.scrollLeft || body.scrollLeft) - clientLeft;
19
+
20
+ return new Point(left, top);
21
+ };
22
+ } else {
23
+ self = uki.dom.offset = function( elem ) {
24
+ if ( !elem || elem == root ) return new Point();
25
+ if ( elem === elem.ownerDocument.body ) return self.bodyOffset( elem );
26
+ self.initialized || self.initialize();
27
+
28
+ var offsetParent = elem.offsetParent,
29
+ prevOffsetParent = elem,
30
+ doc = elem.ownerDocument,
31
+ computedStyle,
32
+ docElem = doc.documentElement,
33
+ body = doc.body,
34
+ defaultView = doc.defaultView,
35
+ prevComputedStyle = defaultView.getComputedStyle(elem, null),
36
+ top = elem.offsetTop,
37
+ left = elem.offsetLeft;
38
+
39
+ while ( (elem = elem.parentNode) && elem !== body && elem !== docElem ) {
40
+ computedStyle = defaultView.getComputedStyle(elem, null);
41
+ top -= elem.scrollTop;
42
+ left -= elem.scrollLeft;
43
+
44
+ if ( elem === offsetParent ) {
45
+ top += elem.offsetTop;
46
+ left += elem.offsetLeft;
47
+
48
+ if ( self.doesNotAddBorder && !(self.doesAddBorderForTableAndCells && (/^t(able|d|h)$/i).test(elem.tagName)) ) {
49
+ top += parseInt( computedStyle.borderTopWidth, 10) || 0;
50
+ left += parseInt( computedStyle.borderLeftWidth, 10) || 0;
51
+ }
52
+ prevOffsetParent = offsetParent;
53
+ offsetParent = elem.offsetParent;
54
+ }
55
+ if ( self.subtractsBorderForOverflowNotVisible && computedStyle.overflow !== "visible" ) {
56
+ top += parseInt( computedStyle.borderTopWidth, 10) || 0;
57
+ left += parseInt( computedStyle.borderLeftWidth, 10) || 0;
58
+ }
59
+ prevComputedStyle = computedStyle;
60
+ }
61
+
62
+ if ( prevComputedStyle.position === "relative" || prevComputedStyle.position === "static" ) {
63
+ top += body.offsetTop;
64
+ left += body.offsetLeft;
65
+ }
66
+
67
+ if ( prevComputedStyle.position === "fixed" ) {
68
+ top += MAX(docElem.scrollTop, body.scrollTop);
69
+ left += MAX(docElem.scrollLeft, body.scrollLeft);
70
+ }
71
+
72
+ return new Point(left, top);
73
+ };
74
+ }
75
+
76
+ uki.extend(self, {
77
+ initialize: function() {
78
+ if ( this.initialized ) return;
79
+ var body = doc.body,
80
+ container = doc.createElement('div'),
81
+ innerDiv, checkDiv, table, td, rules, prop,
82
+ bodyMarginTop = body.style.marginTop,
83
+ html = '<div style="position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;"><div></div></div><table style="position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;" cellpadding="0" cellspacing="0"><tr><td></td></tr></table>';
84
+
85
+ rules = { position: 'absolute', top: 0, left: 0, margin: 0, border: 0, width: '1px', height: '1px', visibility: 'hidden' };
86
+ for ( prop in rules ) container.style[prop] = rules[prop];
87
+
88
+ container.innerHTML = html;
89
+ body.insertBefore(container, body.firstChild);
90
+ innerDiv = container.firstChild;
91
+ checkDiv = innerDiv.firstChild;
92
+ td = innerDiv.nextSibling.firstChild.firstChild;
93
+
94
+ this.doesNotAddBorder = (checkDiv.offsetTop !== 5);
95
+ this.doesAddBorderForTableAndCells = (td.offsetTop === 5);
96
+
97
+ innerDiv.style.overflow = 'hidden';
98
+ innerDiv.style.position = 'relative';
99
+ this.subtractsBorderForOverflowNotVisible = (checkDiv.offsetTop === -5);
100
+
101
+ body.style.marginTop = '1px';
102
+ this.doesNotIncludeMarginInBodyOffset = (body.offsetTop === 0);
103
+ body.style.marginTop = bodyMarginTop;
104
+
105
+ body.removeChild(container);
106
+ this.boxModel === undefined && this.initializeBoxModel();
107
+ this.initialized = true;
108
+ },
109
+
110
+ initializeBoxModel: function() {
111
+ if (this.boxModel !== undefined) return;
112
+ var div = doc.createElement("div");
113
+ div.style.width = div.style.paddingLeft = "1px";
114
+
115
+ doc.body.appendChild( div );
116
+ this.boxModel = div.offsetWidth === 2;
117
+ doc.body.removeChild( div ).style.display = 'none';
118
+ },
119
+
120
+ bodyOffset: function(body) {
121
+ self.initialized || self.initialize();
122
+ var top = body.offsetTop, left = body.offsetLeft;
123
+ if ( uki.dom.doesNotIncludeMarginInBodyOffset ) {
124
+ top += parseInt( uki.dom.elem.currentStyle(body).marginTop, 10 ) || 0;
125
+ left += parseInt( uki.dom.elem.currentStyle(body).marginLeft, 10 ) || 0;
126
+ }
127
+ return new Point(left, top);
128
+ }
129
+ });
130
+ })();
@@ -0,0 +1,333 @@
1
+ include('event.js');
2
+
3
+ (function() {
4
+
5
+ var dnd = uki.dom.dnd,
6
+ retriggering = false;
7
+
8
+ // common properties
9
+ uki.extend(dnd, {
10
+ dragDelta: 5,
11
+ initNativeDnD: function() {
12
+ // moz needs the drag image to be appended to document
13
+ // so create an offscreen container to hold drag images.
14
+ // note that it can't have overflow:hidden, since drag image will be cutted to container
15
+ var container = uki.createElement('div', 'position: absolute;left:-999em;');
16
+ doc.body.appendChild(container);
17
+ dnd.dragImageContainer = container;
18
+ dnd.initNativeDnD = uki.F;
19
+ return true;
20
+ },
21
+ dragImageContainer: null,
22
+ dataTransfer: null,
23
+ target: null,
24
+ dragOver: null
25
+ });
26
+
27
+
28
+ function viewToDom (element) {
29
+ if (uki.isFunction(element.dom)) {
30
+ if (element.parent().length) return element.dom();
31
+ var container = uki.createElement('div', 'width:1px;height:1px;position:absolute;left:-999em;top:0');
32
+ doc.body.appendChild(container);
33
+ element.attachTo(container);
34
+ return container;
35
+ }
36
+ return element;
37
+ }
38
+
39
+ var dataTransferProps = ['dropEffect', 'effectAllowed', 'types', 'files'];
40
+
41
+ uki.dom.DataTransferWrapper = uki.newClass(new function() {
42
+ this.init = function(dataTransfer) {
43
+ this.dataTransfer = dataTransfer;
44
+ for (var i = dataTransferProps.length - 1; i >= 0; i--){
45
+ this[ dataTransferProps[i] ] = dataTransfer[ dataTransferProps[i] ];
46
+ };
47
+ };
48
+
49
+ this.setData = function(format, data) {
50
+ return this.dataTransfer.setData(format, data);
51
+ };
52
+
53
+ this.clearData = function(format) {
54
+ return this.dataTransfer.clearData(format);
55
+ };
56
+
57
+ this.getData = function(format) {
58
+ return this.dataTransfer.getData(format);
59
+ };
60
+
61
+ this.setDragImage = function(image, x, y) {
62
+ dnd.initNativeDnD();
63
+ image = viewToDom(image);
64
+ var clone = image.cloneNode(true),
65
+ style = clone.style;
66
+ style.left = style.right = style.top = style.bottom = '';
67
+ style.position = 'static';
68
+ dnd.dragImageContainer.appendChild(clone);
69
+ setTimeout(function() {
70
+ dnd.dragImageContainer.removeChild(clone);
71
+ }, 1);
72
+ return this.dataTransfer.setDragImage(clone, x, y);
73
+ };
74
+ })
75
+
76
+ // w3c spec based dataTransfer implementation
77
+ uki.dom.DataTransfer = uki.newClass(new function() {
78
+ this.init = function() {
79
+ uki.extend(this, {
80
+ dropEffect: 'none',
81
+ effectAllowed: 'none',
82
+ types: [],
83
+ files: [],
84
+ dragImage: new Image(),
85
+ imagePosition: new Point(),
86
+ data: {}
87
+ });
88
+ };
89
+
90
+ this.setData = function(format, data) {
91
+ this.data[format] = data;
92
+ if (uki.inArray(format, this.types) == -1) this.types.push(format);
93
+ };
94
+
95
+ this.clearData = function(format) {
96
+ if (format) {
97
+ delete this.data[format];
98
+ this.types = uki.grep(this.types, function(x) { return x != format; });
99
+ } else {
100
+ this.data = {};
101
+ this.types = [];
102
+ }
103
+ };
104
+
105
+ this.getData = function(format) {
106
+ return this.data[format];
107
+ };
108
+
109
+ this.setDragImage = function(image, x, y) {
110
+ this._dragImage = this._initDragImage(image);
111
+ this._imagePosition = new Point(x || 0, y || 0);
112
+ };
113
+
114
+ this.update = function(e) {
115
+ if (!this._dragImage) return;
116
+ this._dragImage.style.left = e.pageX - this._imagePosition.x + 'px';
117
+ this._dragImage.style.top = e.pageY - this._imagePosition.y + 'px';
118
+ };
119
+
120
+ this.cleanup = function() {
121
+ this._dragImage && this._dragImage.parentNode.removeChild(this._dragImage);
122
+ this._dragImage = undefined;
123
+ };
124
+
125
+ this._initDragImage = function(image) {
126
+ image = viewToDom(image);
127
+ var clone = image.cloneNode(true),
128
+ style = clone.style;
129
+
130
+ style.left = style.right = style.top = style.bottom = '';
131
+ style.position = 'absolute';
132
+ style.left = '-999em';
133
+ style.zIndex = '9999';
134
+ doc.body.appendChild(clone);
135
+ return clone;
136
+ };
137
+ });
138
+
139
+
140
+ var bindW3CDrag = {
141
+ setup: function() {
142
+ if (this.__w3cdragbound) {
143
+ this.__w3cdragbound++;
144
+ } else {
145
+ this.__w3cdragbound = 1;
146
+ uki.dom.bind( this, 'draggesture', drag );
147
+ }
148
+ },
149
+ teardown: function() {
150
+ this.__w3cdragbound--;
151
+ if (!this.__draggesturebound) uki.dom.unbind( this, 'draggesture', drag );
152
+ }
153
+ };
154
+
155
+ if (dnd.nativeDnD) {
156
+ uki.extend(uki.dom.special, {
157
+ dragstart: {
158
+ setup: function() {
159
+ this.addEventListener('dragstart', nativeDragWrapper, false);
160
+ },
161
+ teardown: function() {
162
+ this.removeEventListener('dragstart', nativeDragWrapper, false);
163
+ }
164
+ }
165
+ })
166
+
167
+ } else {
168
+ uki.extend(uki.dom.special, {
169
+ dragstart: bindW3CDrag,
170
+ drag: bindW3CDrag,
171
+ dragend: bindW3CDrag
172
+ });
173
+
174
+ uki.each({
175
+ dragover: 'mousemove',
176
+ drop: 'mouseup'
177
+ }, function( source, target ){
178
+
179
+ var handler = function(e) {
180
+ if (dnd.dataTransfer && retriggering) {
181
+ e.type = source;
182
+ e.dataTransfer = dnd.dataTransfer;
183
+ uki.dom.handler.apply(this, arguments);
184
+ }
185
+ };
186
+
187
+ uki.dom.special[ source ] = {
188
+ setup: function() {
189
+ uki.dom.bind( this, target, handler );
190
+ },
191
+ teardown: function(){
192
+ uki.dom.unbind( this, target, handler );
193
+ }
194
+ };
195
+ });
196
+
197
+ uki.dom.special.dragenter = {
198
+ setup: function() {
199
+ uki.dom.bind( this, 'mousemove', dragenter );
200
+ },
201
+ teardown: function(){
202
+ uki.dom.unbind( this, 'mousemove', dragenter );
203
+ }
204
+ };
205
+ uki.dom.special.dragleave = { setup: function() {}, teardown: function() {} }
206
+ }
207
+
208
+ function nativeDragWrapper (e) {
209
+ e = new uki.dom.Event(e);
210
+ var dataTransfer = e.dataTransfer;
211
+ e.dataTransfer = new uki.dom.DataTransferWrapper(dataTransfer);
212
+ uki.dom.handler.apply(this, arguments);
213
+ dataTransfer.effectAllowed = e.dataTransfer.effectAllowed;
214
+ }
215
+
216
+ function startW3Cdrag (element) {
217
+ uki.dom.bind( element, 'draggestureend', dragend );
218
+ }
219
+
220
+ function stopW3Cdrag (element) {
221
+ dnd.dataTransfer.cleanup();
222
+ dnd.dragOver = dnd.dataTransfer = dnd.target = null;
223
+ uki.dom.unbind( element, 'draggestureend', dragend );
224
+ }
225
+
226
+ function dragenter (e) {
227
+ if (!dnd.dataTransfer || e.domEvent.__dragOver) return;
228
+ e.domEvent.__dragOver = true;
229
+ if (dnd.dragOver == this) return;
230
+ dnd.dragOver = this;
231
+ e.type = 'dragenter';
232
+ uki.dom.handler.apply(this, arguments);
233
+ }
234
+
235
+ function drag (e) {
236
+ if (retriggering) {
237
+ if (!e.domEvent.__dragOver && dnd.dragOver) {
238
+ e.type = 'dragleave';
239
+ uki.dom.handler.apply(dnd.dragOver, arguments);
240
+ dnd.dragOver = null;
241
+ }
242
+ return;
243
+ };
244
+
245
+ if (dnd.dataTransfer) { // dragging
246
+ e.type = 'drag';
247
+ e.target = dnd.target;
248
+ } else if (e.dragOffset.x > dnd.dragDelta || e.dragOffset.y > dnd.dragDelta) { // start drag
249
+ var target = e.target,
250
+ parent = this.parentNode;
251
+ try {
252
+ while (target && target != parent && !target.getAttribute('draggable')) target = target.parentNode;
253
+ } catch (ex) { target = null; }
254
+ if (target && target.getAttribute('draggable')) {
255
+ dnd.target = e.target = target;
256
+ e.type = 'dragstart';
257
+ dnd.dataTransfer = e.dataTransfer = new uki.dom.DataTransfer(e.domEvent.dataTransfer);
258
+ startW3Cdrag(this);
259
+ } else {
260
+ return;
261
+ }
262
+ } else {
263
+ return;
264
+ }
265
+ uki.dom.handler.apply(this, arguments);
266
+ if (e.isDefaultPrevented()) {
267
+ stopW3Cdrag(this);
268
+ } else {
269
+ retriggerMouseEvent(e);
270
+ }
271
+
272
+ }
273
+
274
+ var props = 'detail screenX screenY clientX clientY ctrlKey altKey shiftKey metaKey button'.split(' ');
275
+
276
+ function retriggerMouseEvent (e) {
277
+ var imageStyle = dnd.dataTransfer._dragImage.style,
278
+ type = e.domEvent.type, target;
279
+ e.stopPropagation();
280
+ e.preventDefault();
281
+ imageStyle.left = '-999em';
282
+ target = doc.elementFromPoint(e.pageX, e.pageY);
283
+ dnd.dataTransfer.update(e);
284
+
285
+ try {
286
+ var newEvent;
287
+ retriggering = true;
288
+ try {
289
+ if (doc.createEventObject) {
290
+ newEvent = doc.createEventObject();
291
+ for ( var i = props.length, prop; i; ){
292
+ prop = uki.dom.props[ --i ];
293
+ newEvent[ prop ] = e.domEvent[ prop ];
294
+ }
295
+ target.fireEvent('on' + type, newEvent)
296
+ } else {
297
+ newEvent = doc.createEvent('MouseEvents');
298
+ newEvent.initMouseEvent(
299
+ type,
300
+ true,
301
+ true,
302
+ doc.defaultView,
303
+ e.detail,
304
+ e.screenX,
305
+ e.screenY,
306
+ e.clientX,
307
+ e.clientY,
308
+ e.ctrlKey,
309
+ e.altKey,
310
+ e.shiftKey,
311
+ e.metaKey,
312
+ e.button,
313
+ null
314
+ );
315
+ target.dispatchEvent(newEvent)
316
+ }
317
+ } catch (e) {}
318
+ retriggering = false;
319
+ } catch (e) {}
320
+ }
321
+
322
+ function dragend (e) {
323
+ if (retriggering) return;
324
+ if (dnd.dataTransfer) { // drag started
325
+ e.type = 'dragend';
326
+ e.target = dnd.target;
327
+ e.dataTransfer = dnd.dataTransfer;
328
+ uki.dom.handler.apply(this, arguments);
329
+ retriggerMouseEvent(e);
330
+ stopW3Cdrag(this);
331
+ }
332
+ }
333
+ })();
@@ -0,0 +1,109 @@
1
+ include('const.js');
2
+ include('uki.js');
3
+ include('utils.js');
4
+
5
+ /**
6
+ * Basic utils to work with the dom tree
7
+ * @namespace
8
+ * @author voloko
9
+ */
10
+ uki.dom = {
11
+ guid: 1,
12
+
13
+ /**
14
+ * Convenience wrapper around document.createElement
15
+ * Creates dom element with given tagName, cssText and innerHTML
16
+ *
17
+ * @param {string} tagName
18
+ * @param {string=} cssText
19
+ * @param {string=} innerHTML
20
+ * @returns {Element} created element
21
+ */
22
+ createElement: function(tagName, cssText, innerHTML) {
23
+ var e = doc.createElement(tagName);
24
+ if (cssText) e.style.cssText = cssText;
25
+ if (innerHTML) e.innerHTML = innerHTML;
26
+ e[expando] = uki.dom.guid++;
27
+ return e;
28
+ },
29
+
30
+ /**
31
+ * Adds a probe element to page dom tree, callbacks, removes the element
32
+ *
33
+ * @param {Element} dom Probing dom element
34
+ * @param {function(Element)} callback
35
+ */
36
+ probe: function(dom, callback) {
37
+ var target = doc.body;
38
+ target.appendChild(dom);
39
+ var result = callback(dom);
40
+ target.removeChild(dom);
41
+ return result;
42
+ },
43
+
44
+ /**
45
+ * Assigns layout style properties to an element
46
+ *
47
+ * @param {CSSStyleDeclaration} style Target declaration
48
+ * @param {object} layout Properties to assign
49
+ * @param {object=} prevLayout If given assigns only difference between layout and prevLayout
50
+ */
51
+ layout: function(style, layout, prevLayout) {
52
+ prevLayout = prevLayout || {};
53
+ if (prevLayout.left != layout.left) style.left = layout.left + PX;
54
+ if (prevLayout.top != layout.top) style.top = layout.top + PX;
55
+ if (prevLayout.right != layout.right) style.right = layout.right + PX;
56
+ if (prevLayout.bottom != layout.bottom) style.bottom = layout.bottom + PX;
57
+ if (prevLayout.width != layout.width) style.width = MAX(layout.width, 0) + PX;
58
+ if (prevLayout.height != layout.height) style.height = MAX(layout.height, 0) + PX;
59
+ return layout;
60
+ },
61
+
62
+ /**
63
+ * Computed style for a give element
64
+ *
65
+ * @param {Element} el
66
+ * @returns {CSSStyleDeclaration} style declaration
67
+ */
68
+ computedStyle: function(el) {
69
+ if (doc && doc.defaultView && doc.defaultView.getComputedStyle) {
70
+ return doc.defaultView.getComputedStyle( el, null );
71
+ } else if (el.currentStyle) {
72
+ return el.currentStyle;
73
+ }
74
+ },
75
+
76
+ /**
77
+ * Checks if parent contains child
78
+ *
79
+ * @param {Element} parent
80
+ * @param {Element} child
81
+ * @return {Boolean}
82
+ */
83
+ contains: function(parent, child) {
84
+ try {
85
+ if (parent.contains) return parent.contains(child);
86
+ if (parent.compareDocumentPosition) return !!(parent.compareDocumentPosition(child) & 16);
87
+ } catch (e) {}
88
+ while ( child && child != parent ) {
89
+ try { child = child.parentNode } catch(e) { child = null };
90
+ }
91
+ return parent == child;
92
+ },
93
+
94
+ createStylesheet: function(code) {
95
+ var style = doc.createElement('style');
96
+ doc.getElementsByTagName('head')[0].appendChild(style);
97
+ if (style.styleSheet) { //IE
98
+ style.styleSheet.cssText = code;
99
+ } else {
100
+ style.appendChild(document.createTextNode(code));
101
+ }
102
+ return style;
103
+ }
104
+
105
+ };
106
+
107
+ uki.each(['createElement'], function(i, name) {
108
+ uki[name] = uki.dom[name];
109
+ });