uki 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. data/VERSION +1 -1
  2. data/bin/uki +1 -1
  3. data/frameworks/uki/README.rdoc +1 -1
  4. data/frameworks/uki/examples/core-examples/controls/controls.js +6 -6
  5. data/frameworks/uki/examples/core-examples/flow/flow.js +4 -4
  6. data/frameworks/uki/examples/core-examples/linearGradient/gradient.svg +11 -0
  7. data/frameworks/uki/examples/core-examples/linearGradient/linearGradient.js +87 -0
  8. data/frameworks/uki/examples/core-examples/popup/popup.js +23 -10
  9. data/frameworks/uki/examples/core-examples/resizeToContents/resizeToContents.js +12 -1
  10. data/frameworks/uki/examples/core-examples/slider/slider.js +1 -1
  11. data/frameworks/uki/examples/core-examples/splitPaneExtended/splitPaneExtended.js +1 -1
  12. data/frameworks/uki/examples/core-examples/table/table.js +19 -2
  13. data/frameworks/uki/examples/core-examples/wave/wave-theme.js +1 -1
  14. data/frameworks/uki/examples/core-examples/wave/wave.js +1 -1
  15. data/frameworks/uki/examples/more-examples/radioButton/radioButton.js +3 -3
  16. data/frameworks/uki/examples/more-examples/select/select.js +35 -0
  17. data/frameworks/uki/examples/touch-examples/scrollPane/scrollPane.js +53 -0
  18. data/frameworks/uki/spec/unit/background.spec.js +1 -1
  19. data/frameworks/uki/spec/unit/selector.spec.js +28 -12
  20. data/frameworks/uki/spec/unit/utils.spec.js +14 -0
  21. data/frameworks/uki/src/uki-core.js +3 -1
  22. data/frameworks/uki/src/uki-core/after.js +57 -0
  23. data/frameworks/uki/src/uki-core/attachment.js +15 -6
  24. data/frameworks/uki/src/uki-core/background.js +4 -3
  25. data/frameworks/uki/src/uki-core/background/css.js +1 -0
  26. data/frameworks/uki/src/uki-core/background/cssBox.js +5 -3
  27. data/frameworks/uki/src/uki-core/background/linearGradient.js +112 -0
  28. data/frameworks/uki/src/uki-core/background/multi.js +2 -2
  29. data/frameworks/uki/src/uki-core/background/rows.js +1 -0
  30. data/frameworks/uki/src/uki-core/background/sliced9.js +5 -2
  31. data/frameworks/uki/src/uki-core/builder.js +5 -4
  32. data/frameworks/uki/src/uki-core/collection.js +18 -13
  33. data/frameworks/uki/src/uki-core/dom/browser.js +114 -0
  34. data/frameworks/uki/src/uki-core/dom/event.js +3 -0
  35. data/frameworks/uki/src/uki-core/image.js +1 -26
  36. data/frameworks/uki/src/uki-core/selector.js +5 -0
  37. data/frameworks/uki/src/uki-core/theme.js +24 -23
  38. data/frameworks/uki/src/uki-core/theme/template.js +1 -1
  39. data/frameworks/uki/src/uki-core/uki.js +7 -4
  40. data/frameworks/uki/src/uki-core/utils.js +51 -26
  41. data/frameworks/uki/src/uki-core/view.js +6 -3
  42. data/frameworks/uki/src/uki-core/view/base.js +16 -1
  43. data/frameworks/uki/src/uki-core/view/container.js +15 -5
  44. data/frameworks/uki/src/uki-core/view/focusable.js +17 -4
  45. data/frameworks/uki/src/uki-core/view/observable.js +15 -2
  46. data/frameworks/uki/src/uki-core/view/styleable.js +4 -11
  47. data/frameworks/uki/src/uki-data/ajax.js +4 -30
  48. data/frameworks/uki/src/uki-data/json.js +191 -0
  49. data/frameworks/uki/src/uki-data/localStore.js +37 -0
  50. data/frameworks/uki/src/uki-data/model.js +1 -1
  51. data/frameworks/uki/src/uki-more.js +4 -0
  52. data/frameworks/uki/src/uki-more/more/background.js +2 -0
  53. data/frameworks/uki/src/uki-more/more/color.js +168 -0
  54. data/frameworks/uki/src/uki-more/more/utils.js +5 -12
  55. data/frameworks/uki/src/uki-more/more/view.js +3 -1
  56. data/frameworks/uki/src/uki-more/more/view/form.js +30 -0
  57. data/frameworks/uki/src/uki-more/more/view/hTile.js +59 -0
  58. data/frameworks/uki/src/uki-more/more/view/nativeButton.js +3 -0
  59. data/frameworks/uki/src/uki-more/more/view/nativeCheckbox.js +38 -0
  60. data/frameworks/uki/src/uki-more/more/view/nativeControl.js +40 -0
  61. data/frameworks/uki/src/uki-more/more/view/nativeInput.js +78 -0
  62. data/frameworks/uki/src/uki-more/more/view/nativeSelect.js +29 -0
  63. data/frameworks/uki/src/uki-more/more/view/radioButton.js +1 -1
  64. data/frameworks/uki/src/uki-more/more/view/select-theme.js +55 -0
  65. data/frameworks/uki/src/uki-more/more/view/select.js +208 -0
  66. data/frameworks/uki/src/uki-theme/airport.js +145 -88
  67. data/frameworks/uki/src/uki-theme/airport/i/table/a-down.png +0 -0
  68. data/frameworks/uki/src/uki-theme/airport/i/table/a-up.png +0 -0
  69. data/frameworks/uki/src/uki-touch.js +2 -0
  70. data/frameworks/uki/src/uki-touch/touch.js +1 -0
  71. data/frameworks/uki/src/uki-touch/touch/const.js +24 -0
  72. data/frameworks/uki/src/uki-touch/touch/setup.js +52 -0
  73. data/frameworks/uki/src/uki-touch/touch/view.js +4 -0
  74. data/frameworks/uki/src/uki-touch/touch/view/scrollPane.js +505 -0
  75. data/frameworks/uki/src/uki-touch/touch/view/scrollableList.js +27 -0
  76. data/frameworks/uki/src/uki-view/view/box.js +9 -0
  77. data/frameworks/uki/src/uki-view/view/button.js +36 -1
  78. data/frameworks/uki/src/uki-view/view/checkbox.js +32 -3
  79. data/frameworks/uki/src/uki-view/view/flow.js +37 -9
  80. data/frameworks/uki/src/uki-view/view/image.js +14 -1
  81. data/frameworks/uki/src/uki-view/view/label.js +72 -11
  82. data/frameworks/uki/src/uki-view/view/list.js +143 -13
  83. data/frameworks/uki/src/uki-view/view/list/render.js +1 -0
  84. data/frameworks/uki/src/uki-view/view/popup.js +46 -2
  85. data/frameworks/uki/src/uki-view/view/radio.js +19 -4
  86. data/frameworks/uki/src/uki-view/view/scrollPane.js +91 -33
  87. data/frameworks/uki/src/uki-view/view/slider.js +67 -54
  88. data/frameworks/uki/src/uki-view/view/splitPane.js +102 -9
  89. data/frameworks/uki/src/uki-view/view/table.js +59 -2
  90. data/frameworks/uki/src/uki-view/view/table/column.js +45 -17
  91. data/frameworks/uki/src/uki-view/view/table/header.js +40 -12
  92. data/frameworks/uki/src/uki-view/view/table/render.js +4 -0
  93. data/frameworks/uki/src/uki-view/view/textField.js +75 -21
  94. data/frameworks/uki/src/uki-view/view/toolbar.js +16 -0
  95. data/lib/uki/builder.rb +1 -1
  96. data/lib/uki/include_js.rb +2 -2
  97. data/lib/uki/project.rb +14 -14
  98. data/templates/index.html.erb +2 -2
  99. data/templates/myapp.js.erb +2 -2
  100. data/uki.gemspec +34 -48
  101. metadata +44 -47
  102. data/frameworks/uki/src/uki-core/dom/nativeLayout.js +0 -18
  103. data/frameworks/uki/src/uki-theme/airport/i/button/down-c.gif +0 -0
  104. data/frameworks/uki/src/uki-theme/airport/i/button/down-c.png +0 -0
  105. data/frameworks/uki/src/uki-theme/airport/i/button/down-h.gif +0 -0
  106. data/frameworks/uki/src/uki-theme/airport/i/button/down-h.png +0 -0
  107. data/frameworks/uki/src/uki-theme/airport/i/button/down-m.png +0 -0
  108. data/frameworks/uki/src/uki-theme/airport/i/button/down-v.png +0 -0
  109. data/frameworks/uki/src/uki-theme/airport/i/button/focusRing-c.png +0 -0
  110. data/frameworks/uki/src/uki-theme/airport/i/button/focusRing-h.png +0 -0
  111. data/frameworks/uki/src/uki-theme/airport/i/button/focusRing-m.png +0 -0
  112. data/frameworks/uki/src/uki-theme/airport/i/button/focusRing-v.png +0 -0
  113. data/frameworks/uki/src/uki-theme/airport/i/button/focusRing.png +0 -0
  114. data/frameworks/uki/src/uki-theme/airport/i/button/hover-c.gif +0 -0
  115. data/frameworks/uki/src/uki-theme/airport/i/button/hover-c.png +0 -0
  116. data/frameworks/uki/src/uki-theme/airport/i/button/hover-h.gif +0 -0
  117. data/frameworks/uki/src/uki-theme/airport/i/button/hover-h.png +0 -0
  118. data/frameworks/uki/src/uki-theme/airport/i/button/hover-m.png +0 -0
  119. data/frameworks/uki/src/uki-theme/airport/i/button/hover-v.png +0 -0
  120. data/frameworks/uki/src/uki-theme/airport/i/button/hover.png +0 -0
  121. data/frameworks/uki/src/uki-theme/airport/i/button/normal-c.gif +0 -0
  122. data/frameworks/uki/src/uki-theme/airport/i/button/normal-c.png +0 -0
  123. data/frameworks/uki/src/uki-theme/airport/i/button/normal-h.gif +0 -0
  124. data/frameworks/uki/src/uki-theme/airport/i/button/normal-h.png +0 -0
  125. data/frameworks/uki/src/uki-theme/airport/i/button/normal-m.png +0 -0
  126. data/frameworks/uki/src/uki-theme/airport/i/button/normal-v.png +0 -0
  127. data/frameworks/uki/src/uki-theme/airport/i/button/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/shadow/large-c.png +0 -0
  134. data/frameworks/uki/src/uki-theme/airport/i/shadow/large-h.png +0 -0
  135. data/frameworks/uki/src/uki-theme/airport/i/shadow/large-m.png +0 -0
  136. data/frameworks/uki/src/uki-theme/airport/i/shadow/large-v.png +0 -0
  137. data/frameworks/uki/src/uki-theme/airport/i/shadow/large.png +0 -0
  138. data/frameworks/uki/src/uki-theme/airport/i/slider/bar-m.gif +0 -0
  139. data/frameworks/uki/src/uki-theme/airport/i/slider/bar-m.png +0 -0
  140. data/frameworks/uki/src/uki-theme/airport/i/slider/bar-v.gif +0 -0
  141. data/frameworks/uki/src/uki-theme/airport/i/slider/bar-v.png +0 -0
  142. data/frameworks/uki/src/uki-theme/airport/i/slider/bar.png +0 -0
  143. data/frameworks/uki/src/uki-theme/airport/i/slider/focus.png +0 -0
  144. data/frameworks/uki/src/uki-theme/airport/i/slider/handle.gif +0 -0
@@ -1,4 +1,14 @@
1
+ /**
2
+ * Horizontal Split Pane
3
+ *
4
+ * @author voloko
5
+ * @name uki.view.HSplitPane
6
+ * @class
7
+ * @extends uki.view.Container
8
+ */
1
9
  uki.view.declare('uki.view.HSplitPane', uki.view.Container, function(Base) {
10
+ this._throttle = 0; // do not try to render more often than every Xms
11
+
2
12
  this._setup = function() {
3
13
  Base._setup.call(this);
4
14
  this._originalRect = this._rect;
@@ -16,14 +26,44 @@ uki.view.declare('uki.view.HSplitPane', uki.view.Container, function(Base) {
16
26
  };
17
27
 
18
28
  /**
19
- * @fires event:handleMove
20
- */
29
+ * @function
30
+ * @name uki.view.HSplitPane#leftMin
31
+ */
32
+ /**
33
+ * @function
34
+ * @name uki.view.HSplitPane#rightMin
35
+ */
36
+ /**
37
+ * @function
38
+ * @name uki.view.HSplitPane#autogrowLeft
39
+ */
40
+ /**
41
+ * @function
42
+ * @name uki.view.HSplitPane#autogrowRight
43
+ */
44
+ /**
45
+ * @function
46
+ * @name uki.view.HSplitPane#throttle
47
+ */
48
+ uki.addProps(this, ['leftMin', 'rightMin', 'autogrowLeft', 'autogrowRight', 'throttle']);
49
+ this.topMin = this.leftMin;
50
+ this.bottomMin = this.rightMin;
51
+
52
+ /**
53
+ * @function
54
+ * @fires event:handleMove
55
+ * @name uki.view.HSplitPane#handlePosition
56
+ */
21
57
  this.handlePosition = uki.newProp('_handlePosition', function(val) {
22
58
  this._handlePosition = this._normalizePosition(val);
23
59
  this.trigger('handleMove', {source: this, handlePosition: this._handlePosition, dragValue: val });
24
60
  this._resizeChildViews();
25
61
  });
26
62
 
63
+ /**
64
+ * @function
65
+ * @name uki.view.HSplitPane#handleWidth
66
+ */
27
67
  this.handleWidth = uki.newProp('_handleWidth', function(val) {
28
68
  if (this._handleWidth != val) {
29
69
  this._handleWidth = val;
@@ -47,10 +87,6 @@ uki.view.declare('uki.view.HSplitPane', uki.view.Container, function(Base) {
47
87
  };
48
88
 
49
89
 
50
- uki.addProps(this, ['leftMin', 'rightMin', 'autogrowLeft', 'autogrowRight']);
51
- this.topMin = this.leftMin;
52
- this.bottomMin = this.rightMin;
53
-
54
90
  this._removeHandle = function() {
55
91
  this._dom.removeChild(this._handle);
56
92
  };
@@ -74,6 +110,7 @@ uki.view.declare('uki.view.HSplitPane', uki.view.Container, function(Base) {
74
110
 
75
111
  this._createDom = function() {
76
112
  this._dom = uki.createElement('div', this.defaultCss);
113
+ this._initClassName();
77
114
  for (var i=0, paneML; i < 2; i++) {
78
115
  paneML = { view: 'Container' };
79
116
  paneML.anchors = i == 1 ? 'left top bottom right' :
@@ -124,26 +161,74 @@ uki.view.declare('uki.view.HSplitPane', uki.view.Container, function(Base) {
124
161
  };
125
162
 
126
163
  this._draggesture = function(e) {
127
- var offset = uki.dom.offset(this.dom());
128
- this.handlePosition(e[this._vertical ? 'pageY' : 'pageX'] - offset[this._vertical ? 'y' : 'x'] - this._posWithinHandle);
129
- this.layout();
164
+ this._updatePositionOnDrag(e);
130
165
  };
131
166
 
132
167
  this._draggestureend = function(e, offset) {
168
+ this._updatePositionOnDrag(e);
133
169
  };
134
170
 
171
+ this._updatePositionOnDrag = function(e) {
172
+ var offset = uki.dom.offset(this.dom());
173
+ this.handlePosition(e[this._vertical ? 'pageY' : 'pageX'] - offset[this._vertical ? 'y' : 'x'] - this._posWithinHandle);
174
+ if (this._throttle) {
175
+ this._throttleHandler = this._throttleHandler || uki.proxy(function() {
176
+ this.layout();
177
+ this._trottling = false;
178
+ }, this);
179
+ if (this._trottling) return;
180
+ this._trottling = true;
181
+ setTimeout(this._throttleHandler, this._throttle);
182
+ } else {
183
+ this.layout();
184
+ }
185
+ };
186
+
187
+
188
+ /**
189
+ * @function
190
+ * @name uki.view.HSplitPane#topPane
191
+ */
192
+ /**
193
+ * @function
194
+ * @name uki.view.HSplitPane#leftPane
195
+ */
135
196
  this.topPane = this.leftPane = function(pane) {
136
197
  return this._paneAt(0, pane);
137
198
  };
138
199
 
200
+ /**
201
+ * @function
202
+ * @name uki.view.HSplitPane#bottomPane
203
+ */
204
+ /**
205
+ * @function
206
+ * @name uki.view.HSplitPane#rightPane
207
+ */
139
208
  this.bottomPane = this.rightPane = function(pane) {
140
209
  return this._paneAt(1, pane);
141
210
  };
142
211
 
212
+ /**
213
+ * @function
214
+ * @name uki.view.HSplitPane#topChildViews
215
+ */
216
+ /**
217
+ * @function
218
+ * @name uki.view.HSplitPane#leftChildViews
219
+ */
143
220
  this.topChildViews = this.leftChildViews = function(views) {
144
221
  return this._childViewsAt(0, views);
145
222
  };
146
223
 
224
+ /**
225
+ * @function
226
+ * @name uki.view.HSplitPane#rightChildViews
227
+ */
228
+ /**
229
+ * @function
230
+ * @name uki.view.HSplitPane#bottomChildViews
231
+ */
147
232
  this.bottomChildViews = this.rightChildViews = function(views) {
148
233
  return this._childViewsAt(1, views);
149
234
  };
@@ -199,6 +284,14 @@ uki.view.declare('uki.view.HSplitPane', uki.view.Container, function(Base) {
199
284
 
200
285
  });
201
286
 
287
+ /**
288
+ * Vertical Split Pane
289
+ *
290
+ * @author voloko
291
+ * @name uki.view.VSplitPane
292
+ * @class
293
+ * @extends uki.view.HSplitPane
294
+ */
202
295
  uki.view.declare('uki.view.VSplitPane', uki.view.HSplitPane, function(Base) {
203
296
  this._setup = function() {
204
297
  Base._setup.call(this);
@@ -2,6 +2,36 @@ include('list.js');
2
2
 
3
3
  uki.view.table = {};
4
4
 
5
+ /**
6
+ * Table
7
+ *
8
+ * Uses uki.view.List to render data. Wraps it into scroll pane and ads a header
9
+ * @author voloko
10
+ * @name uki.view.Table
11
+ * @class
12
+ * @extends uki.view.Container
13
+ *
14
+ * @lends uki.view.List#rowHeight as rowHeight
15
+ * @lends uki.view.List#data as data
16
+ * @lends uki.view.List#packSize as packSize
17
+ * @lends uki.view.List#visibleRectExt as visibleRectExt
18
+ * @lends uki.view.List#render as render
19
+ * @lends uki.view.List#selectedIndex as selectedIndex
20
+ * @lends uki.view.List#selectedIndexes as selectedIndexes
21
+ * @lends uki.view.List#selectedRow as selectedRow
22
+ * @lends uki.view.List#selectedRows as selectedRows
23
+ * @lends uki.view.List#lastClickIndex as lastClickIndex
24
+ * @lends uki.view.List#textSelectable as textSelectable
25
+ * @lends uki.view.List#multiselect as multiselect
26
+ * @lends uki.view.List#redrawRow as redrawRow
27
+ * @lends uki.view.List#addRow as addRow
28
+ * @lends uki.view.List#removeRow as removeRow
29
+ * @lends uki.view.List#focusable as lastClickIndex
30
+ * @lends uki.view.List#focus as focus
31
+ * @lends uki.view.List#blur as blur
32
+ * @lends uki.view.List#hasFocus as hasFocus
33
+ *
34
+ */
5
35
  uki.view.declare('uki.view.Table', uki.view.Container, function(Base) {
6
36
  var propertiesToDelegate = 'rowHeight data packSize visibleRectExt render selectedIndex selectedIndexes selectedRows selectedRow focus blur hasFocus lastClickIndex focusable textSelectable multiselect'.split(' ');
7
37
 
@@ -22,14 +52,29 @@ uki.view.declare('uki.view.Table', uki.view.Container, function(Base) {
22
52
  return Base._style.call(this, name, value);
23
53
  };
24
54
 
55
+ /**
56
+ * @function
57
+ * @return {uki.view.List}
58
+ * @name uki.view.Table#list
59
+ */
25
60
  this.list = function() {
26
61
  return this._list;
27
62
  };
28
63
 
64
+ /**
65
+ * @function
66
+ * @return {uki.view.table.Header}
67
+ * @name uki.view.Table#header
68
+ */
29
69
  this.header = function() {
30
70
  return this._header;
31
71
  };
32
72
 
73
+ /**
74
+ * @function
75
+ * @param {Array.<uki.view.table.Column>} c
76
+ * @name uki.view.Table#columns
77
+ */
33
78
  this.columns = uki.newProp('_columns', function(c) {
34
79
  for (var i = 0; i < this._columns.length; i++) {
35
80
  this._columns[i].unbind();
@@ -47,6 +92,12 @@ uki.view.declare('uki.view.Table', uki.view.Container, function(Base) {
47
92
  this._header.columns(this._columns);
48
93
  });
49
94
 
95
+ /**
96
+ * @function
97
+ * @param {Number} row
98
+ * @param {Number} col
99
+ * @name uki.view.Table#redrawCell
100
+ */
50
101
  this.redrawCell = function(row, col) {
51
102
  var item = this._list._itemAt(row);
52
103
  if (item) {
@@ -67,11 +118,16 @@ uki.view.declare('uki.view.Table', uki.view.Container, function(Base) {
67
118
  this.list()[name].apply(this.list(), arguments);
68
119
  return this;
69
120
  };
70
- }, this)
121
+ }, this);
71
122
 
123
+ /**
124
+ * @function
125
+ * @param {Number} col
126
+ * @name uki.view.Table#redrawColumn
127
+ */
72
128
  this.redrawColumn = function(col) {
73
129
  var from = this._list._packs[0].itemFrom,
74
- to = this._list._packs[1].itemTo
130
+ to = this._list._packs[1].itemTo;
75
131
  for (var i=from; i < to; i++) {
76
132
  this.redrawCell(i, col);
77
133
  };
@@ -91,6 +147,7 @@ uki.view.declare('uki.view.Table', uki.view.Container, function(Base) {
91
147
 
92
148
  this._createDom = function() {
93
149
  Base._createDom.call(this);
150
+ this._initClassName();
94
151
  var scrollPaneRect = new Rect(0, this._headerHeight, this.rect().width, this.rect().height - this._headerHeight),
95
152
  listRect = scrollPaneRect.clone().normalize(),
96
153
  headerRect = new Rect(0, 0, this.rect().width, this._headerHeight),
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @class
3
+ * @extends uki.view.Observable
4
+ */
1
5
  uki.view.table.Column = uki.newClass(uki.view.Observable, new function() {
2
6
  this._width = 100;
3
7
  this._offset = 0;
@@ -6,21 +10,36 @@ uki.view.table.Column = uki.newClass(uki.view.Observable, new function() {
6
10
  this._maxWidth = 0;
7
11
  this._css = 'float:left;white-space:nowrap;text-overflow:ellipsis;';
8
12
  this._inset = new Inset(3, 5);
13
+ this._templatePrefix = 'table-';
9
14
 
10
15
  this.init = function() {};
11
16
 
12
- uki.addProps(this, ['position', 'css', 'formatter', 'label', 'resizable', 'maxWidth', 'minWidth', 'maxWidth', 'key']);
17
+ uki.addProps(this, ['position', 'css', 'formatter', 'label', 'resizable', 'maxWidth', 'minWidth', 'maxWidth', 'key', 'sort']);
13
18
 
14
- this.template = function(v) {
15
- if (v === undefined) return this._template = this._template || uki.theme.template('table-cell');
16
- this._template = v;
17
- return this;
19
+ this.template = function() {
20
+ // cache
21
+ return this._template || (this._template = uki.theme.template(this._templatePrefix + 'cell'));
18
22
  };
19
23
 
20
- this.headerTemplate = function(v) {
21
- if (v === undefined) return this._headerTemplate = this._headerTemplate || uki.theme.template('table-header-cell');
22
- this._headerTemplate = v;
23
- return this;
24
+ this.headerTemplate = function() {
25
+ var suffix = '';
26
+ if (this.sort() == 'ASC') suffix = '-asc';
27
+ if (this.sort() == 'DESC') suffix = '-desc';
28
+ return uki.theme.template(this._templatePrefix + 'header-cell' + suffix);
29
+ };
30
+
31
+ this.sortData = function(data) {
32
+ var _this = this;
33
+ return data.sort(function(a, b) {
34
+ return _this._key ?
35
+ _this.compare(uki.attr(a, _this._key), uki.attr(b, _this._key)) :
36
+ _this.compare(a[_this._position], b[_this._position]);
37
+ });
38
+
39
+ };
40
+
41
+ this.compare = function(a, b) {
42
+ return (a >= b ? 1 : a == b ? 0 : -1) * (this._sort == 'DESC' ? -1 : 1);
24
43
  };
25
44
 
26
45
  /**
@@ -70,8 +89,8 @@ uki.view.table.Column = uki.newClass(uki.view.Observable, new function() {
70
89
  this.renderHeader = function(height) {
71
90
  this._className || this._initStylesheet();
72
91
  var x = this.headerTemplate().render({
73
- data: '<div style="overflow:hidden;text-overflow:ellipsis;*width:100%;height:100%;">' + this.label() + '</div>',
74
- style: '*overflow-y:hidden;' + this._cellStyle(uki.dom.offset.boxModel ? height - 1 : height),
92
+ data: '<div style="overflow:hidden;text-overflow:ellipsis;*width:100%;height:100%;padding-top:' + this._inset.top + 'px">' + this.label() + '</div>',
93
+ style: '*overflow-y:hidden;' + this._cellStyle(true, height),
75
94
  className: this._className
76
95
  });
77
96
  return x;
@@ -81,19 +100,22 @@ uki.view.table.Column = uki.newClass(uki.view.Observable, new function() {
81
100
  this._className || this._initStylesheet();
82
101
  this._prerenderedTemplate = this.template().render({
83
102
  data: '\u0001\u0001',
84
- style: 'overflow:hidden;' + this._cellStyle(rect.height),
103
+ style: 'overflow:hidden;' + this._cellStyle(false, rect.height),
85
104
  className: this._className
86
105
  }).split('\u0001');
87
106
  };
88
107
 
89
- this._cellPadding = function() {
108
+ this._cellPadding = function(skipVertical) {
90
109
  var inset = this._inset;
91
- return ['padding:', inset.top, 'px ', inset.right, 'px ', inset.bottom, 'px ', inset.left, 'px;'].join('');
110
+ return ['padding:', (skipVertical ? '0' : inset.top), 'px ', inset.right, 'px ', (skipVertical ? '0' : inset.bottom), 'px ', inset.left, 'px;'].join('');
92
111
  };
93
112
 
94
- this._cellStyle = function(height) {
95
- var h = 'height:' + (height - (uki.dom.offset.boxModel ? this._inset.height() : 0)) + 'px;';
96
- return this._css + this._cellPadding() + ';' + h;
113
+ this._cellHeight = function(skipVertical, height) {
114
+ return 'height:' + (height - (uki.dom.offset.boxModel && !skipVertical ? this._inset.height() : 0)) + 'px;';
115
+ };
116
+
117
+ this._cellStyle = function(skipVertical, height) {
118
+ return this._css + this._cellPadding(skipVertical) + ';' + this._cellHeight(skipVertical, height);
97
119
  };
98
120
 
99
121
  this._clientWidth = function() {
@@ -114,6 +136,12 @@ uki.view.table.NumberColumn = uki.newClass(uki.view.table.Column, new function()
114
136
  var Base = uki.view.table.Column.prototype;
115
137
 
116
138
  this._css = Base._css + 'text-align:right;';
139
+
140
+ this.compare = function(a, b) {
141
+ a*=1;
142
+ b*=1;
143
+ return (a >= b ? 1 : a == b ? 0 : -1) * (this._sort == 'DESC' ? -1 : 1);
144
+ };
117
145
  });
118
146
 
119
147
  uki.view.table.CustomColumn = uki.view.table.Column;
@@ -1,24 +1,43 @@
1
1
  include('../label.js');
2
2
 
3
- uki.view.table.Header = uki.newClass(uki.view.Label, function(Base) {
3
+ /**
4
+ * @class
5
+ * @extends uki.view.Label
6
+ */
7
+ uki.view.declare('uki.view.table.Header', uki.view.Label, function(Base) {
8
+ this._defaultBackground = 'theme(table-header)';
9
+
4
10
  this._setup = function() {
5
11
  Base._setup.call(this);
6
12
  this._multiline = true;
7
13
  this._resizers = [];
8
14
  };
9
15
 
10
- this.typeName = function() { return 'uki.view.table.Header'; };
11
-
12
16
  this.columns = uki.newProp('_columns', function(v) {
13
17
  this._columns = v;
14
18
  this.html(this._createColumns());
15
19
  this._createResizers();
16
20
  });
17
21
 
18
- this.redrawColumn = function(col) {
19
- if (this._resizers[col]) {
20
- uki.dom.unbind(this._resizers[col]);
22
+ this._createDom = function() {
23
+ Base._createDom.call(this);
24
+ this.bind('click', this._click);
25
+ };
26
+
27
+ this._click = function(e) {
28
+ if (this._dragging) return;
29
+
30
+ var target = e.target;
31
+ if (target == this.dom() || target == this._label) return;
32
+ while (target.parentNode != this._label) target = target.parentNode;
33
+ var i = uki.inArray(target, this._label.childNodes);
34
+ if (i > -1) {
35
+ this.trigger('columnClick', { source: this, columnIndex: i, column: this._columns[i] });
21
36
  }
37
+ };
38
+
39
+ this.redrawColumn = function(col) {
40
+ if (this._resizers[col]) uki.dom.unbind(this._resizers[col]);
22
41
  var container = doc.createElement('div');
23
42
  container.innerHTML = this._columns[col].renderHeader(this.rect().height);
24
43
  this._label.replaceChild(container.firstChild, this._label.childNodes[col]);
@@ -30,7 +49,7 @@ uki.view.table.Header = uki.newClass(uki.view.Label, function(Base) {
30
49
  for(var i = 0, offset = 0, columns = this._columns, l = columns.length; i < l; i++) {
31
50
  html[html.length] = columns[i].renderHeader(this.rect().height);
32
51
  }
33
- return html.join('')
52
+ return html.join('');
34
53
  };
35
54
 
36
55
  this._createResizer = function(i) {
@@ -47,14 +66,23 @@ uki.view.table.Header = uki.newClass(uki.view.Label, function(Base) {
47
66
  };
48
67
 
49
68
  this._bindResizerDrag = function(resizer, columnIndex) {
50
- uki.dom.bind(resizer, 'draggesture', uki.proxy(function(e) {
51
- var headerOffset = uki.dom.offset(this.dom()),
69
+ var _this = this;
70
+
71
+ uki.dom.bind(resizer, 'draggesture', function(e) {
72
+ _this._dragging = true;
73
+ var headerOffset = uki.dom.offset(_this.dom()),
52
74
  offsetWithinHeader = e.pageX - headerOffset.x,
53
- columnOffset = 0, i, column = this._columns[columnIndex];
75
+ columnOffset = 0, i, column = _this._columns[columnIndex];
54
76
  for (i=0; i < columnIndex; i++) {
55
- columnOffset += this._columns[i].width();
77
+ columnOffset += _this._columns[i].width();
56
78
  };
57
79
  column.width(offsetWithinHeader - columnOffset);
58
- }, this));
80
+ });
81
+
82
+ uki.dom.bind(resizer, 'draggestureend', function() {
83
+ setTimeout(function() {
84
+ _this._dragging = false;
85
+ }, 1);
86
+ });
59
87
  };
60
88
  });