riojs 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/VERSION +1 -1
  2. data/public/javascripts/components/grid_view.js +88 -27
  3. data/public/javascripts/components/input.js +7 -4
  4. data/public/javascripts/components/label.js +5 -1
  5. data/public/javascripts/components/list_item.js +14 -13
  6. data/public/javascripts/components/list_view.js +15 -1
  7. data/public/javascripts/components/popup.js +1 -1
  8. data/public/javascripts/components/textarea.js +14 -11
  9. data/public/javascripts/lib/attr.js +1 -1
  10. data/public/javascripts/lib/boot.js +2 -0
  11. data/public/javascripts/lib/console/console_commands.js +59 -9
  12. data/public/javascripts/lib/console/docs/files.html +25 -1
  13. data/public/javascripts/lib/console/docs/index.html +1 -1
  14. data/public/javascripts/lib/console/docs/symbols/Object.html +1 -1
  15. data/public/javascripts/lib/console/docs/symbols/_global_.html +1 -1
  16. data/public/javascripts/lib/console/docs/symbols/rio.Application.html +1 -1
  17. data/public/javascripts/lib/console/docs/symbols/rio.Attr.html +1 -1
  18. data/public/javascripts/lib/console/docs/symbols/rio.Binding.html +1 -1
  19. data/public/javascripts/lib/console/docs/symbols/rio.Component.html +1 -1
  20. data/public/javascripts/lib/console/docs/symbols/rio.Cookie.html +1 -1
  21. data/public/javascripts/lib/console/docs/symbols/rio.DelayedTask#initialize.html +1 -1
  22. data/public/javascripts/lib/console/docs/symbols/rio.DelayedTask.html +1 -1
  23. data/public/javascripts/lib/console/docs/symbols/rio.JsTemplate.html +1 -1
  24. data/public/javascripts/lib/console/docs/symbols/rio.Juggernaut.html +1 -1
  25. data/public/javascripts/lib/console/docs/symbols/rio.Model.html +1 -1
  26. data/public/javascripts/lib/console/docs/symbols/rio.Page.html +1 -1
  27. data/public/javascripts/lib/console/docs/symbols/rio.Utils.html +1 -1
  28. data/public/javascripts/lib/console/docs/symbols/rio.html +1 -1
  29. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_attr.js.html +1 -1
  30. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_boot.js.html +32 -30
  31. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_event_delegator.js.html +66 -0
  32. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_page.js.html +189 -179
  33. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_protohack.js.html +258 -241
  34. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_tag.js.html +10 -9
  35. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_thread.js.html +128 -0
  36. data/public/javascripts/lib/event_delegator.js +58 -0
  37. data/public/javascripts/lib/page.js +11 -1
  38. data/public/javascripts/lib/protohack.js +17 -0
  39. data/public/javascripts/lib/rio.build +2 -0
  40. data/public/javascripts/lib/spec.js +19 -0
  41. data/public/javascripts/lib/tag.js +2 -1
  42. data/public/javascripts/lib/thread.js +120 -0
  43. data/public/javascripts/specs/lib/spec_spec.js +42 -0
  44. metadata +6 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -10,27 +10,38 @@ rio.components.GridView = rio.Component.create(rio.components.ListView, "GridVie
10
10
  ["rowClassName", ""],
11
11
  ["rowHoverClassName", "gridItemHover"],
12
12
  ["rowSelectedClassName", "gridItemSelected"],
13
- ["handleContextMenu", false]
13
+ ["handleContextMenu", false],
14
+
15
+ /**
16
+ The item object must have a unique toString value to be used as a cache key
17
+ */
18
+ ["cacheGridItems", false]
14
19
  ],
15
20
  attrHtmls: ["header"],
16
21
  attrEvents: ["contextMenu"],
17
22
  methods: {
18
23
  initialize: function($super, options) {
19
24
  $super(options);
25
+
26
+ var cacheGridItems = this.getCacheGridItems();
27
+ if (cacheGridItems) {
28
+ this._gridItemCache = {};
29
+ }
20
30
  this._listItemBuilder = function(item, renderer) {
31
+ if (cacheGridItems && this._gridItemCache[item]) { return this._gridItemCache[item]; }
21
32
  var gridItem = new rio.components.GridItem({
22
33
  item: item,
23
34
  columns: this.getColumns(),
24
35
  rowClassName: this.getRowClassName(),
25
36
  hoverClassName: this.getRowHoverClassName(),
26
- selectedClassName: this.getRowSelectedClassName(),
27
- handleContextMenu: this.getHandleContextMenu()
37
+ selectedClassName: this.getRowSelectedClassName()
28
38
  });
29
39
 
30
40
  if (this.getHandleContextMenu()) {
31
41
  gridItem.observe("contextMenu", this.fire.bind(this, "contextMenu"));
32
42
  }
33
43
 
44
+ if (cacheGridItems) { this._gridItemCache[item] = gridItem; }
34
45
  return gridItem;
35
46
  }.bind(this);
36
47
  },
@@ -51,6 +62,31 @@ rio.components.GridView = rio.Component.create(rio.components.ListView, "GridVie
51
62
  boxHtml.insert(gridHtml);
52
63
 
53
64
  boxHtml.addClassName("gridView");
65
+
66
+ boxHtml.observe("click", function(e) {
67
+ var target = e.target;
68
+ while(target && target != boxHtml) {
69
+ if (target.rioComponent && Object.isFunction(target.rioComponent.click)) {
70
+ target.rioComponent.click(e);
71
+ }
72
+ target = target.parentNode;
73
+ }
74
+ }.bindAsEventListener(this));
75
+
76
+ if (this.getHandleContextMenu()) {
77
+ boxHtml.observe("contextmenu", function(e) {
78
+ var target = e.target;
79
+ while(target && target != boxHtml) {
80
+ if (target.rioComponent && Object.isFunction(target.rioComponent.contextMenu)) {
81
+ target.rioComponent.contextMenu(e);
82
+ e.stop();
83
+ return;
84
+ }
85
+ target = target.parentNode;
86
+ }
87
+ }.bindAsEventListener(this));
88
+ }
89
+
54
90
 
55
91
  return boxHtml;
56
92
  },
@@ -75,45 +111,70 @@ rio.components.GridView = rio.Component.create(rio.components.ListView, "GridVie
75
111
 
76
112
  rio.components.GridItem = rio.Component.create(rio.components.ListItem, "GridItem", {
77
113
  attrAccessors: [["columns", []], ["selected", false]],
78
- attrReaders: ["rowClassName", "handleContextMenu"],
114
+ attrReaders: ["rowClassName"],
79
115
  attrEvents: ["click", "contextMenu"],
80
116
  methods: {
81
117
  buildHtml: function() {
82
118
  var rowClassName = this.getRowClassName();
83
119
  var className = Object.isFunction(rowClassName) ? rowClassName(this.getItem()) : rowClassName;
84
- var html = rio.Tag.tr(
85
- this.getColumns().map(function(column) {
86
- var cell = rio.Tag.td(column.renderer(this.getItem(), this));
87
- cell.setStyle({
88
- width: column.width,
89
- textAlign: column.align || "left",
90
- padding: (column.padding != undefined) ? column.padding : this.padding
120
+
121
+
122
+ var columns = this.getColumns();
123
+ var column, cell;
124
+ var html = rio.Tag.tr("", { className: className });
125
+
126
+ html.rioComponent = this;
127
+
128
+ var deferRendering = function(cell, column) {
129
+ var contents = column.renderer(this.getItem(), this, html);
130
+ if (Object.isArray(contents)) {
131
+ cell.update();
132
+ contents.each(function(content) {
133
+ cell.insert(content);
91
134
  });
92
- return cell;
93
- }.bind(this)),
94
- {
95
- className: className
135
+ } else {
136
+ cell.update();
137
+ cell.insert(contents);
96
138
  }
97
- );
139
+ };
98
140
 
99
- html.addHoverClass(this.getHoverClassName());
100
- html.observe("click", function(e) {
101
- this.fire("click", e);
102
- }.bindAsEventListener(this));
103
-
104
- if (this.getHandleContextMenu()) {
105
- html.observe("contextmenu", function(e) {
106
- this.fire("contextMenu", this, e);
107
- e.stop();
108
- }.bindAsEventListener(this));
141
+ for (var i=0, length=columns.length; i<length; i++) {
142
+ column = columns[i];
143
+
144
+ if (column.deferRendering) {
145
+ cell = rio.Tag.td(" ");
146
+ rio.Thread.fork(deferRendering.bind(this, cell, column), column.deferOptions);
147
+ } else {
148
+ cell = rio.Tag.td(column.renderer(this.getItem(), this, html));
149
+ }
150
+
151
+ cell.setStyle({
152
+ width: column.width,
153
+ textAlign: column.align || "left",
154
+ padding: (column.padding != undefined) ? column.padding : this.padding
155
+ });
156
+ html.insert(cell);
109
157
  }
110
-
158
+
159
+ var hoverClassName = this.getHoverClassName();
160
+ if (hoverClassName) {
161
+ html.addHoverClass(hoverClassName);
162
+ }
163
+
111
164
  this.bind("selected", function(selected) {
112
165
  html[selected ? "addClassName" : "removeClassName"](this.getSelectedClassName());
113
166
  }.bind(this));
114
167
 
115
168
 
116
169
  return html;
170
+ },
171
+
172
+ click: function(e) {
173
+ this.fire("click", e);
174
+ },
175
+
176
+ contextMenu: function(e) {
177
+ this.fire("contextMenu", this, e)
117
178
  }
118
179
  }
119
180
  });
@@ -22,7 +22,7 @@ rio.components.Input = rio.Component.create(rio.components.Box, "Input", {
22
22
  ["focus", false],
23
23
  ["enabled", true]
24
24
  ],
25
- attrEvents: ["enter", "keyPress", "keyDown", "keyUp", "focus", "blur"],
25
+ attrEvents: ["enter", "escape", "keyPress", "keyDown", "keyUp", "focus", "blur"],
26
26
  methods: {
27
27
  buildHtml: function() {
28
28
  var inputHtml = rio.Tag.input("", {
@@ -131,9 +131,12 @@ rio.components.Input = rio.Component.create(rio.components.Box, "Input", {
131
131
  }, this);
132
132
  }
133
133
 
134
- if (e.keyCode == Event.KEY_ESC && this.getRevertOnEscape()) {
135
- inputHtml.value = this.getValue();
136
- inputHtml.blur();
134
+ if (e.keyCode == Event.KEY_ESC) {
135
+ if (this.getRevertOnEscape()) {
136
+ inputHtml.value = this.getValue();
137
+ inputHtml.blur();
138
+ }
139
+ this.fire("escape");
137
140
  }
138
141
 
139
142
  this.fire("keyDown", e);
@@ -8,8 +8,12 @@ rio.components.Label = rio.Component.create(rio.components.Base, {
8
8
  this.content.bind(function(content) {
9
9
  labelHtml.update(content);
10
10
  });
11
- labelHtml.observe("dblclick", this.fire.curry("dblClick").bind(this));
11
+ labelHtml.rioComponent = this;
12
12
  return labelHtml;
13
+ },
14
+
15
+ dblClick: function(e) {
16
+ this.fire("dblClick", e);
13
17
  }
14
18
  }
15
19
  });
@@ -12,19 +12,17 @@ rio.components.ListItem = rio.Component.create(rio.components.Base, "ListItem",
12
12
  methods: {
13
13
  buildHtml: function() {
14
14
  var listItemHtml = this.getRenderer()(this.getItem());
15
+ listItemHtml.rioComponent = this;
15
16
 
16
- listItemHtml.observe("mouseover", function() {
17
- listItemHtml.addClassName(this.getHoverClassName());
18
- }.bind(this));
19
- listItemHtml.observe("mouseout", function() {
20
- listItemHtml.removeClassName(this.getHoverClassName());
21
- }.bind(this));
22
- listItemHtml.observe("click", function(e) {
23
- this.click();
24
- if (this.getStopClickPropogation()) {
25
- e.stop();
26
- }
27
- }.bindAsEventListener(this));
17
+ var hoverClass = this.getHoverClassName();
18
+ if (hoverClass && !hoverClass.blank()) {
19
+ listItemHtml.observe("mouseover", function() {
20
+ listItemHtml.addClassName(hoverClass);
21
+ });
22
+ listItemHtml.observe("mouseout", function() {
23
+ listItemHtml.removeClassName(hoverClass);
24
+ });
25
+ }
28
26
 
29
27
  this.bind("selected", function(selected) {
30
28
  listItemHtml[selected ? "addClassName" : "removeClassName"](this.getSelectedClassName());
@@ -33,8 +31,11 @@ rio.components.ListItem = rio.Component.create(rio.components.Base, "ListItem",
33
31
  return listItemHtml;
34
32
  },
35
33
 
36
- click: function() {
34
+ click: function(e) {
37
35
  this.fire("click");
36
+ if (this.getStopClickPropogation()) {
37
+ e.stop();
38
+ }
38
39
  },
39
40
 
40
41
  scrollTo: function() {
@@ -29,7 +29,17 @@ rio.components.ListView = rio.Component.create(rio.components.Box, "ListView", {
29
29
  addBindings: function(listHtml) {
30
30
  if (!this._unbindings) { this._unbindings = []; }
31
31
  var unbindItems = this.bind("items", {
32
- set: function(items) {
32
+ set: function(items, oldItems) {
33
+ if ((oldItems == undefined || oldItems.length == 0) && (items && items.empty())) {
34
+ return;
35
+ }
36
+
37
+ var manageReflow = listHtml && listHtml.parentNode;
38
+ var reinserter;
39
+ if (manageReflow) {
40
+ reinserter = listHtml.removeToInsertLater();
41
+ }
42
+
33
43
  listHtml.update();
34
44
  this.setListItems([]);
35
45
  if (items) {
@@ -37,6 +47,10 @@ rio.components.ListView = rio.Component.create(rio.components.Box, "ListView", {
37
47
  this.insertItem(items[i], this.getListItems().size(), listHtml);
38
48
  }
39
49
  }
50
+
51
+ if (manageReflow) {
52
+ reinserter();
53
+ }
40
54
  }.bind(this),
41
55
  insert: function(val, atIndex) {
42
56
  this.insertItem(val, atIndex, listHtml);
@@ -8,7 +8,7 @@ rio.components.Popup = rio.Component.create("Popup", {
8
8
  ["opacity", 0.8],
9
9
  ["autoCenter", true],
10
10
  ["wrapContent", true],
11
- ["animateOverlay", true]
11
+ ["animateOverlay", false]
12
12
  ],
13
13
  attrReaders: [],
14
14
  attrHtmls: ["overlay"],
@@ -19,16 +19,17 @@ rio.components.Textarea = rio.Component.create(rio.components.Base, "Textarea",
19
19
  ],
20
20
  attrEvents: ["enter", "keyPress", "keyDown", "keyUp", "focus", "blur", "resize"],
21
21
  attrHtmls: ["textarea"],
22
- styles: ["height"],
23
22
  methods: {
24
23
  buildHtml: function() {
25
- var html = rio.Tag.div("", {
24
+ var html = rio.Tag.div(this.textareaHtml(), {
26
25
  className: this.getClassName(),
27
- style: "padding-bottom: 1px"
26
+ style: "padding-bottom: 1px;"
28
27
  });
29
- html.addHoverClass(this.getHoverClassName());
30
- html.insert(this.textareaHtml());
31
- html.applyStyle({ height: this.height });
28
+ var hoverClass = this.getHoverClassName();
29
+ if (hoverClass && !hoverClass.blank()) {
30
+ html.addHoverClass(hoverClass);
31
+ }
32
+ html.rioComponent = this;
32
33
  return html;
33
34
  },
34
35
 
@@ -150,13 +151,15 @@ rio.components.Textarea = rio.Component.create(rio.components.Base, "Textarea",
150
151
  updateHeight();
151
152
  this.fire("keyDown", e);
152
153
  }.bindAsEventListener(this));
153
- textareaHtml.observe('keyup', function() {
154
- updateHeight();
155
- this.fire("keyUp");
156
- }.bind(this));
157
-
154
+
158
155
  return textareaHtml;
159
156
  },
157
+
158
+ keyUp: function() {
159
+ this.resize(this.textareaHtml());
160
+ this.fire("keyUp");
161
+ },
162
+
160
163
  clear: function() {
161
164
  this.setValue("");
162
165
  },
@@ -235,7 +235,7 @@ rio.Attr = {
235
235
  if (binding.empty) { binding.empty(value.length == 0); }
236
236
  }
237
237
  if (binding.set) {
238
- binding.set(value);
238
+ binding.set(value, oldValue);
239
239
  }
240
240
  }
241
241
  },
@@ -284,6 +284,8 @@ var w = window;
284
284
  }
285
285
 
286
286
  document.observe('dom:loaded', function() {
287
+ rio.EventDelegator.enable();
288
+
287
289
  var app = rio.apps[rio.boot.appName.camelize()];
288
290
  var pushOverride = app.environment().push == undefined ? true : app.environment().push;
289
291
  if ((rio.environment.push && pushOverride) && !rio.push) {
@@ -80,6 +80,34 @@ rio.ConsoleCommands = {
80
80
  opener.rio.app.reboot();
81
81
  }
82
82
  },
83
+
84
+ y: {
85
+ description: "Dump an object as yaml",
86
+ action: function(prompt) {
87
+ yaml = rio.Yaml.dump(opener.eval(prompt.match(/^y (.*)$/)[1]));
88
+ this.log(yaml, "", "");
89
+ }
90
+ },
91
+
92
+ ec: {
93
+ description: "Show a count of event observations",
94
+ action: function() {
95
+ var eventCounts = opener.rio.eventCounts || {};
96
+ var total = Object.values(eventCounts).inject(0, function(acc, c) { return acc + c });
97
+
98
+ yaml = rio.Yaml.dump(eventCounts);
99
+ yaml += "\n----------------\ntotal: " + total;
100
+ this.log(yaml, "", "");
101
+ }
102
+ },
103
+
104
+ rec: {
105
+ description: "Reset the count of event observations",
106
+ action: function() {
107
+ opener.rio.eventCounts = {};
108
+ this.log("Event counts reset");
109
+ }
110
+ },
83
111
 
84
112
  bind: {
85
113
  description: "Set the execution binding to something other than window",
@@ -150,10 +178,10 @@ rio.ConsoleCommands = {
150
178
  }
151
179
  },
152
180
 
153
- // perf: {
154
- // description: "Check the status of, turn on, and turn off autocss",
155
- // action: function(prompt) {
156
- // this.log("Benchmarking...");
181
+ perf: {
182
+ description: "Check the status of, turn on, and turn off autocss",
183
+ action: function(prompt) {
184
+ this.log("Benchmarking...");
157
185
  // var stub = function(obj, method) {
158
186
  // return new opener.rio.Stub(obj, method);
159
187
  // };
@@ -166,7 +194,7 @@ rio.ConsoleCommands = {
166
194
  // stubs.push(stub(opener.rio.components.LineItem, "_lineItemCache").withValue({}));
167
195
  //
168
196
  // // var count = "Model#initialize";
169
- // opener.rio.Benchmark.start();
197
+ // opener.rio.Benchmark.start();
170
198
  //
171
199
  // try {
172
200
  // // TODO: remove method
@@ -174,7 +202,7 @@ rio.ConsoleCommands = {
174
202
  // items: opener.rio.models.Outline.find(41).getRootNodes().sortedLineItems
175
203
  // });
176
204
  //
177
- // var startTime = new Date();
205
+ var startTime = new Date();
178
206
  // // opener.rio.models.LineItem.findAll({ parameters: { outlineId: 196 } });
179
207
  // // opener.rio.models.Outline.find(196).getLineItems()
180
208
  // // opener.rio.models.Outline.find(196).getRootNodes().getSortedLineItems();
@@ -192,7 +220,29 @@ rio.ConsoleCommands = {
192
220
  // // new opener.rio.models.LineItem({ outline: o });
193
221
  // // });
194
222
  //
195
- // this.log(new Date() - startTime + " ms");
223
+
224
+ // opener.rio.Benchmark.start();
225
+ var runs = 1;
226
+ (runs).times(function() {
227
+ try {
228
+ opener.rio.app.getCurrentPage().getOutlineListPage().closePopup();
229
+ } catch(e) {
230
+ }
231
+ opener.rio.app.getCurrentPage().getOutlineListPage().popup();
232
+ });
233
+ this.log((new Date() - startTime)/runs + " ms");
234
+
235
+ // opener.rio.Benchmark.stop();
236
+ // opener.rio.Benchmark.getInstallations().each(function(installation) {
237
+ // this.log(
238
+ // installation.getObjectString() + "#" +
239
+ // installation.getMethodName() + " - " +
240
+ // installation.getInvocations() / 5 + ", " +
241
+ // installation.getTime() / 5
242
+ // );
243
+ // }.bind(this));
244
+
245
+ // this.log(new Date() - startTime + " ms");
196
246
  //
197
247
  // opener.rio.Benchmark.stop();
198
248
  // opener.rio.Benchmark.getInstallations().each(function(installation) {
@@ -209,8 +259,8 @@ rio.ConsoleCommands = {
209
259
  // } finally {
210
260
  // stubs.invoke("release");
211
261
  // }
212
- // }
213
- // },
262
+ }
263
+ },
214
264
 
215
265
  fixtures: {
216
266
  description: "Force the fixtures to reload",