Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

cleaning up. and now middle mouse selects items

  • Loading branch information...
commit d33a15de0de5b59b754d1bacea1dee96b54ac422 1 parent 3ae7c8a
Daniel Ribeiro authored
40 lib/coffee/minecraft.coffee
@@ -20,7 +20,7 @@ class Player
20 20 @halfHeight = @height / 2
21 21 @halfWidth = @width / 2
22 22 @halfDepth = @depth / 2
23   - @pos = vec 850, 300, 35
  23 + @pos = vec 750, 300, 35
24 24 @eyesDelta = @halfHeight * 0.9
25 25
26 26 eyesPosition: ->
@@ -114,9 +114,9 @@ class CollisionHelper
114 114 miny = @toGrid(vmin.y)
115 115 minz = @toGrid(vmin.z)
116 116
117   - maxx = @toGrid(vmax.x) + 1
118   - maxy = @toGrid(vmax.y) + 1
119   - maxz = @toGrid(vmax.z) + 1
  117 + maxx = @toGrid(vmax.x + @rad)
  118 + maxy = @toGrid(vmax.y + @rad)
  119 + maxz = @toGrid(vmax.z + @rad)
120 120 x = minx
121 121 while x <= maxx
122 122 y = miny
@@ -132,7 +132,7 @@ class CollisionHelper
132 132 toGrid: (val) ->
133 133 ret = Math.floor(val / @rad)
134 134 return 0 if ret < 0
135   - return @grid.size if ret > @grid.size
  135 + return @grid.size - 1 if ret > @grid.size - 1
136 136 return ret
137 137
138 138
@@ -175,7 +175,6 @@ class Floor
175 175 class Game
176 176 constructor: ->
177 177 @rad = CubeSize
178   - # @geo = new CubeGeometry(@rad, @rad, @rad, 1, 1, 1)
179 178 @width = window.innerWidth
180 179 @height = window.innerHeight
181 180
@@ -189,8 +188,8 @@ class Game
189 188 grass_dirt, # back
190 189 grass_dirt] #front
191 190 @cubeBlocks = {}
192   - blocks = ["bluewool", "brick", "cobblestone", "diamond",
193   - "glowstone", "obsidian", "plank", "redwool", "whitewool"]
  191 + blocks = ["cobblestone", "plank", "brick", "diamond",
  192 + "glowstone", "obsidian", "whitewool", "bluewool", "redwool", "netherrack"]
194 193 for b in blocks
195 194 texture = TextureHelper.loadTexture "./textures/#{b}.png"
196 195 cube = new THREE.CubeGeometry @rad, @rad, @rad, 1, 1, 1, texture
@@ -198,10 +197,9 @@ class Game
198 197 @selectCubeBlock 'cobblestone'
199 198 @geo = new THREE.CubeGeometry( @rad, @rad, @rad, 1, 1, 1, materials)
200 199
201   - @mat = new MeshLambertMaterial(color: 0xCC0000)
202 200 @move = {x: 0, z: 0, y: 0}
203 201 @keysDown = {}
204   - @grid = new Grid(200)
  202 + @grid = new Grid(100)
205 203 @onGround = true
206 204 @pause = off
207 205 @renderer = @createRenderer()
@@ -283,7 +281,7 @@ class Game
283 281 addLights: (scene) ->
284 282 ambientLight = new AmbientLight(0xaaaaaa)
285 283 scene.add ambientLight
286   - directionalLight = new DirectionalLight(0xffffff, 1.5)
  284 + directionalLight = new DirectionalLight(0xffffff, 1)
287 285 directionalLight.position.set 1, 1, 0.5
288 286 directionalLight.position.normalize()
289 287 scene.add directionalLight
@@ -494,20 +492,28 @@ init_web_app = ->
494 492 game = new Game()
495 493 blockImg = (name) ->
496 494 "<img width='32' height='32' src='./textures/#{name}icon.png' id='#{name}'/>"
497   - blocks = ["bluewool", "brick", "cobblestone", "diamond",
498   - "glowstone", "obsidian", "plank", "redwool", "whitewool"]
  495 + blocks = ["cobblestone", "plank", "brick", "diamond",
  496 + "glowstone", "obsidian", "whitewool", "bluewool", "redwool", "netherrack"]
499 497 blockList = (blockImg(b) for b in blocks)
500 498 $("#blocks").append(blockList.join(''))
501   - current = $("#cobblestone")
502   - current.css(opacity: .9)
  499 + current = "cobblestone"
  500 + $("#" + current).css(opacity: .9)
503 501 $("#blocks").mousedown (e) ->
504 502 return false if e.target == @
505 503 game.selectCubeBlock e.target.id
506 504 newone = $(e.target)
507 505 newone.css(opacity: .9)
508   - current.css(opacity: 1)
509   - current = newone
  506 + $("#" + current).css(opacity: 1)
  507 + current = e.target.id
510 508 return false
  509 + $("body").mousewheel (e, delta) ->
  510 + index = (blocks.indexOf(current) - delta).mod(blocks.length)
  511 + newone = blocks[index]
  512 + game.selectCubeBlock newone
  513 + $("#" + newone).css(opacity: .9)
  514 + $("#" + current).css(opacity: 1)
  515 + current = newone
  516 + return
511 517 game.start()
512 518
513 519 # window.Tracer = new MethodTracer().traceClasses 'Player Grid CollisionHelper TextureHelper Floor Game'
26 public/index.html
@@ -3,17 +3,15 @@
3 3 <head>
4 4 <meta content="text/html;charset=UTF-8" http-equiv="content-type" />
5 5 <title>MineCraftWebGL</title>
6   -<!-- <link href="reset.css" rel="stylesheet"/>-->
  6 + <!-- <link href="reset.css" rel="stylesheet"/>-->
7 7 <script src='./jquery/jquery-1.6.4.js' type='text/javascript'></script>
8 8 <script src='./lib/rbcoffee.js' type='text/javascript'></script>
9 9 <script src='./coreExtensions.js' type='text/javascript'></script>
10 10 <script src='./lib/jquery.hotkeys.js' type='text/javascript'></script>
11   -<!-- <script src='./lib/jsclass/core.js' type='text/javascript'></script>
12   - <script src='./lib/jsclass/stdlib.js' type='text/javascript'></script>
13   -<!-- <script src='/dynamic_css.js' type='text/javascript'></script>-->
14   -<script src='./lib/RequestAnimationFrame.js' type='text/javascript'></script>
  11 + <script src='./lib/jquery.mousewheel.js' type='text/javascript'></script>
  12 + <script src='./lib/RequestAnimationFrame.js' type='text/javascript'></script>
15 13 <script src='./lib/Three.js' type='text/javascript'></script>
16   -
  14 +
17 15 <script src='./camera.js' type='text/javascript'></script>
18 16 <script src='./collision.js' type='text/javascript'></script>
19 17 <script src='./minecraft.js' type='text/javascript'></script>
@@ -28,7 +26,7 @@
28 26 margin: 0;
29 27 padding: 0;
30 28 overflow: hidden;
31   -}
  29 + }
32 30 #blocks {
33 31 position: relative;
34 32 bottom: 37px;
@@ -38,17 +36,17 @@
38 36 height: 32px;
39 37 }
40 38 #blocks img {
41   - margin: 0;
42   - padding: 0;
  39 + margin: 0;
  40 + padding: 0;
43 41 }
44 42 </style>
45 43 </head>
46 44 <body>
47   -<!-- <div id="debug">
48   - <div>x: <span id="posx">0</span></div>
49   - <div>y: <span id="posy">0</span></div>
50   - <div>z: <span id="posz">0</span></div>
51   - </div>-->
  45 + <!-- <div id="debug">
  46 + <div>x: <span id="posx">0</span></div>
  47 + <div>y: <span id="posy">0</span></div>
  48 + <div>z: <span id="posz">0</span></div>
  49 + </div>-->
52 50 <div id="container"></div>
53 51 <div id="blocks">
54 52 </div>
1,193 public/lib/erectorjs/erectorjs.js
... ... @@ -1,1193 +0,0 @@
1   -(function() {
2   - var AbstractPart, AttrBuilder, Collection, ComponentsCounter, Erector, ErectorJS, ErectorPart, Event, Events, IdsCounter, JqueryExceptionHandlerProxy, JqueryFlippingProxy, MethodsStore, Pair, TextPart, UIComponent, _extend, _i, _j, _len, _ref, asList, camelToDashes, capitalize, createDisplayName, defineComponentName, dsl, eql, extendedErectorPart, fullTags, handleInvoke, isEmpty, isEmptyObject, isNumber, isStr, log, n, name, objToHash, root, scopeIt, strip, text, uncapitalize, words;
3   - var __slice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
4   - var ctor = function(){};
5   - ctor.prototype = parent.prototype;
6   - child.prototype = new ctor();
7   - child.prototype.constructor = child;
8   - if (typeof parent.extended === "function") parent.extended(child);
9   - child.__super__ = parent.prototype;
10   - }, __bind = function(func, context) {
11   - return function(){ return func.apply(context, arguments); };
12   - };
13   - root = window;
14   - if (root.app_development) {
15   - log = function(arg) {
16   - if (console) {
17   - return console.log(arg + "\n");
18   - }
19   - };
20   - } else {
21   - log = function() {};
22   - }
23   - scopeIt = function(args, f) {
24   - return f.apply(this, args);
25   - };
26   - ErectorJS = {};
27   - capitalize = function(string) {
28   - if (isEmpty(string)) {
29   - return string;
30   - }
31   - return string.charAt(0).toUpperCase() + string.slice(1);
32   - };
33   - uncapitalize = function(string) {
34   - if (isEmpty(string)) {
35   - return string;
36   - }
37   - return string.charAt(0).toLowerCase() + string.slice(1);
38   - };
39   - camelToDashes = function(string) {
40   - return string.replace(/[A-Z]/g, function(ch) {
41   - return '-' + ch.toLowerCase();
42   - });
43   - };
44   - strip = function(str) {
45   - return str.replace(/^\s+/, '').replace(/\s+$/, '');
46   - };
47   - eql = function(thi, that) {
48   - return thi == that;
49   - };
50   - dsl = function() {
51   - return new Erector();
52   - };
53   - words = function() {
54   - var args;
55   - args = __slice.call(arguments, 0);
56   - return args.join(' ');
57   - };
58   - text = function() {
59   - var args;
60   - args = __slice.call(arguments, 0);
61   - return args.join('');
62   - };
63   - asList = function(args) {
64   - return JS.array(args);
65   - };
66   - isEmpty = function(array) {
67   - return array.length === 0;
68   - };
69   - isNumber = function(value) {
70   - return typeof value === 'number';
71   - };
72   - isStr = function(value) {
73   - return typeof value === 'string' || value instanceof String;
74   - };
75   - objToHash = function(obj) {
76   - var _i, _ref, key, ret;
77   - ret = new JS.Hash();
78   - _ref = obj;
79   - for (key in _ref) {
80   - if (!__hasProp.call(_ref, key)) continue;
81   - _i = _ref[key];
82   - ret.put(key, obj[key]);
83   - }
84   - return ret;
85   - };
86   - isEmptyObject = function(obj) {
87   - var _i, _ref, name;
88   - _ref = obj;
89   - for (name in _ref) {
90   - if (!__hasProp.call(_ref, name)) continue;
91   - _i = _ref[name];
92   - return false;
93   - }
94   - return true;
95   - };
96   - defineComponentName = function(clas, name) {
97   - clas.prototype._class = name;
98   - return (clas.className = name);
99   - };
100   - createDisplayName = function(target) {
101   - var _i, _ref, _ref2, _result, clas, name, needsName;
102   - if (!target) {
103   - target = window;
104   - }
105   - _result = []; _ref = target;
106   - for (name in _ref) {
107   - if (!__hasProp.call(_ref, name)) continue;
108   - _i = _ref[name];
109   - try {
110   - clas = target[name];
111   - needsName = (typeof clas === "undefined" || clas === null) ? undefined : clas.prototype;
112   - needsName && (needsName = (!isEmptyObject(clas.prototype)));
113   - needsName && (needsName = (!(typeof (_ref2 = clas.className) !== "undefined" && _ref2 !== null)));
114   - if (needsName) {
115   - defineComponentName(clas, name);
116   - log("Name for class " + (name));
117   - }
118   - } catch (exception) {
119   - return null;
120   - }
121   - }
122   - return _result;
123   - };
124   - _extend = function(obj, mixin) {
125   - var _ref, _result, method, name;
126   - _result = []; _ref = mixin;
127   - for (name in _ref) {
128   - if (!__hasProp.call(_ref, name)) continue;
129   - method = _ref[name];
130   - _result.push(obj[name] = method);
131   - }
132   - return _result;
133   - };
134   - Pair = function(key, value) {
135   - this.key = key;
136   - this.value = value;
137   - return this;
138   - };
139   - Pair.fromList = function(list) {
140   - return new Pair(list[0], list[1]);
141   - };
142   - Collection = (ErectorJS.Collection = new JS.Class({
143   - include: JS.Enumerable,
144   - extend: JS.Forwardable,
145   - initialize: function(args) {
146   - var _i, _len, _ref, arg;
147   - if (args instanceof Array) {
148   - this._list = args;
149   - return null;
150   - }
151   - this._list = [];
152   - if (!(args)) {
153   - return null;
154   - }
155   - _ref = args;
156   - for (_i = 0, _len = _ref.length; _i < _len; _i++) {
157   - arg = _ref[_i];
158   - this._list.push(arg);
159   - }
160   - return this;
161   - },
162   - length: function() {
163   - return this._list.length;
164   - },
165   - isEmpty: function() {
166   - return this.length() === 0;
167   - },
168   - forEach: function(block, context) {
169   - var _i, _len, _ref, arg;
170   - if (!(block)) {
171   - return this.enumFor('forEach');
172   - }
173   - _ref = this._list;
174   - for (_i = 0, _len = _ref.length; _i < _len; _i++) {
175   - arg = _ref[_i];
176   - block.call(context || null, arg);
177   - }
178   - return this;
179   - },
180   - addAll: function(array) {
181   - var _i, _len, _ref, arg;
182   - _ref = asList(array);
183   - for (_i = 0, _len = _ref.length; _i < _len; _i++) {
184   - arg = _ref[_i];
185   - this._list.push(arg);
186   - }
187   - return this;
188   - },
189   - unshiftAll: function(array) {
190   - var _i, _len, _ref, arg;
191   - _ref = asList(array);
192   - for (_i = 0, _len = _ref.length; _i < _len; _i++) {
193   - arg = _ref[_i];
194   - this._list.unshift(arg);
195   - }
196   - return this;
197   - },
198   - toArray: function() {
199   - return this._list;
200   - },
201   - sum: function() {
202   - return this.inject(0, function(memo, x) {
203   - return memo + x;
204   - });
205   - },
206   - grep: function(pattern) {
207   - return this.select(function(i) {
208   - return i.match(pattern);
209   - });
210   - }
211   - }));
212   - Collection.defineDelegators('_list', 'pop', 'push', 'reverse', 'shift', 'slice', 'splice', 'unshift', 'concat', 'join');
213   - MethodsStore = function() {
214   - this._storeMethods = [];
215   - return this;
216   - };
217   - MethodsStore.prototype._store = function(method, args) {
218   - return this._storeMethods.push(new Pair(method, args));
219   - };
220   - MethodsStore.prototype._fireAt = function(instance) {
221   - var _i, _len, _ref, pair;
222   - _ref = this._storeMethods;
223   - for (_i = 0, _len = _ref.length; _i < _len; _i++) {
224   - pair = _ref[_i];
225   - instance[pair.key].apply(instance, pair.value);
226   - }
227   - return null;
228   - };
229   - ErectorJS.DelayProxy = function(clas) {
230   - var _, _i, _j, _ref, n;
231   - this.AnonClass = (function() {
232   - _ = function() {
233   - return MethodsStore.apply(this, arguments);
234   - };
235   - __extends(_, MethodsStore);
236   - return _;
237   - })();
238   - defineComponentName(this.AnonClass, "MethodStore instance");
239   - _ref = clas.prototype;
240   - for (_j in _ref) {
241   - if (!__hasProp.call(_ref, _j)) continue;
242   - (function() {
243   - var n = _j;
244   - var _i = _ref[_j];
245   - return n !== 'initialize' ? scopeIt([n], __bind(function(name) {
246   - return define(this.AnonClass, name, function() {
247   - return this._store(name, arguments);
248   - });
249   - }, this)) : null;
250   - }).call(this);
251   - }
252   - return this;
253   - };
254   - ErectorJS.DelayProxy.prototype.instance = function() {
255   - return new this.AnonClass();
256   - };
257   - AttrBuilder = function() {
258   - this.lastAttributeName = null;
259   - this.attributes = {};
260   - this.id_attribute = null;
261   - return this;
262   - };
263   - AttrBuilder.prototype.getAttributes = function() {
264   - return this.attributes;
265   - };
266   - AttrBuilder.prototype.getId = function() {
267   - return this.id_attribute;
268   - };
269   - AttrBuilder.prototype.parseArguments = function(args) {
270   - var first;
271   - if (args.length === 0) {
272   - args;
273   - }
274   - first = args[0];
275   - if (first instanceof Object && !(first instanceof AbstractPart) && !isStr(first)) {
276   - return this._buildAttributesFromLiteralObject(args);
277   - }
278   - return this._buildAttributesFromSplatStrings(args);
279   - };
280   - AttrBuilder.prototype._buildAttributesFromSplatStrings = function(args) {
281   - var _len, _ref, arg, i;
282   - _ref = args;
283   - for (i = 0, _len = _ref.length; i < _len; i++) {
284   - arg = _ref[i];
285   - if (!(isStr(arg))) {
286   - break;
287   - }
288   - this.push(arg);
289   - }
290   - return this._normalizeRest(args.slice(i));
291   - };
292   - AttrBuilder.prototype._buildAttributesFromLiteralObject = function(args) {
293   - var _i, _ref, first, key;
294   - first = args[0];
295   - _ref = first;
296   - for (key in _ref) {
297   - if (!__hasProp.call(_ref, key)) continue;
298   - _i = _ref[key];
299   - this._include_atribute(key, first[key]);
300   - }
301   - return this._normalizeRest(args.slice(1));
302   - };
303   - AttrBuilder.prototype._normalizeRest = function(args) {
304   - var _i, _len, _ref, ar, list, ret, x;
305   - list = [];
306   - if (this.lastAttributeName !== null) {
307   - list.push(this.lastAttributeName);
308   - }
309   - ar = [];
310   - _ref = list.concat(args);
311   - for (_i = 0, _len = _ref.length; _i < _len; _i++) {
312   - x = _ref[_i];
313   - if (isStr(x)) {
314   - ret = new TextPart(x);
315   - ret.parent = this;
316   - ar.push(ret);
317   - } else {
318   - ar.push(x);
319   - }
320   - }
321   - return ar;
322   - };
323   - AttrBuilder.prototype._include_atribute = function(key, value) {
324   - return key === 'id' ? (this.id_attribute = value) : (this.attributes[key] = value);
325   - };
326   - AttrBuilder.prototype.push = function(arg) {
327   - if (this.lastAttributeName === null) {
328   - this.lastAttributeName = arg;
329   - return null;
330   - }
331   - this._include_atribute(this.lastAttributeName, arg);
332   - return (this.lastAttributeName = null);
333   - };
334   - AbstractPart = (function() {
335   - ErectorJS.AbstractPart = function() {
336   - this.parent = null;
337   - return this;
338   - };
339   - ErectorJS.AbstractPart.prototype.to_html = function() {
340   - return abstract_method();
341   - };
342   - ErectorJS.AbstractPart.prototype.owns = function(list) {
343   - var _i, _len, _ref, x;
344   - _ref = list;
345   - for (_i = 0, _len = _ref.length; _i < _len; _i++) {
346   - x = _ref[_i];
347   - this.owns_child(x);
348   - }
349   - return null;
350   - };
351   - ErectorJS.AbstractPart.prototype.owns_child = function(child) {
352   - child.parent = this;
353   - return child;
354   - };
355   - ErectorJS.AbstractPart.prototype.id_of = function(name) {
356   - return null;
357   - };
358   - ErectorJS.AbstractPart.prototype.pre_render = function() {};
359   - return ErectorJS.AbstractPart;
360   - })();
361   - ErectorJS.JQueryProxy = new ErectorJS.DelayProxy(jQuery);
362   - JqueryExceptionHandlerProxy = function(_arg) {
363   - this.erectorPart = _arg;
364   - return this;
365   - };
366   - JqueryExceptionHandlerProxy.prototype.target = function() {
367   - return jQuery('#' + this.erectorPart.id());
368   - };
369   - JqueryExceptionHandlerProxy.prototype.handleError = function(name, arglist, exception) {
370   - var args;
371   - args = asList(arglist).join(", ");
372   - log(("error trying to send jquery method '" + (name) + "(" + (args) + ")'") + " to part: " + this.erectorPart.fullPath());
373   - return log(exception);
374   - };
375   - handleInvoke = function(name) {
376   - return function() {
377   - var t;
378   - try {
379   - t = this.target();
380   - return t[name].apply(t, arguments);
381   - } catch (exception) {
382   - return this.handleError(name, arguments, exception);
383   - }
384   - };
385   - };
386   - _ref = jQuery.prototype;
387   - for (name in _ref) {
388   - if (!__hasProp.call(_ref, name)) continue;
389   - _i = _ref[name];
390   - if (name !== 'initialize') {
391   - define(JqueryExceptionHandlerProxy, name, handleInvoke(name));
392   - }
393   - }
394   - JqueryFlippingProxy = function(erectorPart) {
395   - this.erectorPart = erectorPart;
396   - this.delayedProxy = ErectorJS.JQueryProxy.instance();
397   - this.handlingProxy = new JqueryExceptionHandlerProxy(erectorPart);
398   - return this;
399   - };
400   - JqueryFlippingProxy.prototype._invoke_jquery = function(name, arglist) {
401   - return this.erectorPart._on_dom ? this.handlingProxy[name].apply(this.handlingProxy, arglist) : this.delayedProxy[name].apply(this.delayedProxy, arglist);
402   - };
403   - JqueryFlippingProxy.prototype._unfreeze = function() {
404   - return this.delayedProxy._fireAt(this.handlingProxy);
405   - };
406   - _ref = jQuery.prototype;
407   - for (_j in _ref) {
408   - if (!__hasProp.call(_ref, _j)) continue;
409   - (function() {
410   - var n = _j;
411   - var _i = _ref[_j];
412   - return scopeIt([n], __bind(function(name) {
413   - return define(JqueryFlippingProxy, name, function() {
414   - return this._invoke_jquery(name, arguments);
415   - });
416   - }, this));
417   - }).call(this);
418   - }
419   - Events = (ErectorJS.Events = new JS.Hash());
420   - Events.setDefault(function() {
421   - return [];
422   - });
423   - Event = {};
424   - Event.fire = function(eventName) {
425   - var _k, _len, _ref2, _result, args, mName, params, target;
426   - args = __slice.call(arguments, 1);
427   - params = {
428   - parameters: args
429   - };
430   - mName = 'respondTo' + capitalize(eventName);
431   - _result = []; _ref2 = Events.get(eventName);
432   - for (_k = 0, _len = _ref2.length; _k < _len; _k++) {
433   - target = _ref2[_k];
434   - _result.push(target[mName].call(target, params));
435   - }
436   - return _result;
437   - };
438   - extendedErectorPart = function(child) {
439   - ErectorPart.subclasses.push(child);
440   - return (child.extended = extendedErectorPart);
441   - };
442   - ErectorPart = (function() {
443   - ErectorJS.ErectorPart = function(name, args) {
444   - var _k, _len, _ref2, _result, c, eventCallbacks, eventName, methodName, methods;
445   - ErectorJS.ErectorPart.__super__.constructor.call(this);
446   - this._name = name;
447   - this.children = [];
448   - this.attributes = {};
449   - this._id = null;
450   - this.alias = null;
451   - this._classes = new JS.HashSet();
452   - this.add_list(args);
453   - this._style = {};
454   - this._proxy = new JqueryFlippingProxy(this);
455   - this._on_dom = false;
456   - this._pre_rendered = false;
457   - methods = methodsOfInstanceWhile(this, function(clas) {
458   - return clas !== ErectorPart;
459   - });
460   - eventCallbacks = (function() {
461   - _result = []; _ref2 = methods;
462   - for (_k = 0, _len = _ref2.length; _k < _len; _k++) {
463   - c = _ref2[_k];
464   - if (c.match(/respondTo/)) {
465   - _result.push(c);
466   - }
467   - }
468   - return _result;
469   - })();
470   - _ref2 = eventCallbacks;
471   - for (_k = 0, _len = _ref2.length; _k < _len; _k++) {
472   - methodName = _ref2[_k];
473   - eventName = uncapitalize(methodName.slice('respondTo'.length));
474   - if (!(Events.hasKey(eventName))) {
475   - Events.put(eventName, []);
476   - }
477   - Events.get(eventName).push(this);
478   - }
479   - return this;
480   - };
481   - __extends(ErectorJS.ErectorPart, AbstractPart);
482   - ErectorJS.ErectorPart.subclasses = [];
483   - ErectorJS.ErectorPart.extended = extendedErectorPart;
484   - ErectorJS.ErectorPart.prototype.deregisterEvents = function() {
485   - var _k, _len, _ref2, _result, c, eventCallbacks, eventName, methodName, methods;
486   - methods = methodsOfInstanceWhile(this, function(clas) {
487   - return clas !== ErectorPart;
488   - });
489   - eventCallbacks = (function() {
490   - _result = []; _ref2 = methods;
491   - for (_k = 0, _len = _ref2.length; _k < _len; _k++) {
492   - c = _ref2[_k];
493   - if (c.match(/respondTo/)) {
494   - _result.push(c);
495   - }
496   - }
497   - return _result;
498   - })();
499   - _result = []; _ref2 = eventCallbacks;
500   - for (_k = 0, _len = _ref2.length; _k < _len; _k++) {
501   - methodName = _ref2[_k];
502   - _result.push((function() {
503   - eventName = uncapitalize(methodName.slice('respondTo'.length));
504   - return Events.remove(eventName);
505   - })());
506   - }
507   - return _result;
508   - };
509   - ErectorJS.ErectorPart.prototype.id = function(value) {
510   - if (value) {
511   - this._id = value;
512   - return value;
513   - }
514   - if (!(ui.genIds)) {
515   - return this._id;
516   - }
517   - if (this._id === null) {
518   - this._id = ComponentsCounter.counter(this);
519   - }
520   - return this._id;
521   - };
522   - ErectorJS.ErectorPart.prototype.child = function(index) {
523   - return this.children[index];
524   - };
525   - ErectorJS.ErectorPart.prototype.add = function() {
526   - return this.add_list(arguments);
527   - };
528   - ErectorJS.ErectorPart.prototype.add_list = function(args) {
529   - var _ref2, attrBuilder, k, possibleAlias, v;
530   - attrBuilder = new AttrBuilder();
531   - this.add_children(attrBuilder.parseArguments(asList(args)));
532   - _ref2 = attrBuilder.getAttributes();
533   - for (k in _ref2) {
534   - if (!__hasProp.call(_ref2, k)) continue;
535   - v = _ref2[k];
536   - if (k === 'class') {
537   - this._classes.add(v);
538   - } else {
539   - this.attributes[k] = v;
540   - }
541   - }
542   - possibleAlias = attrBuilder.getId();
543   - if (possibleAlias) {
544   - this.alias = possibleAlias;
545   - }
546   - return this;
547   - };
548   - ErectorJS.ErectorPart.prototype._keyValueStr = function(k, v) {
549   - return k + '="' + v + '"';
550   - };
551   - ErectorJS.ErectorPart.prototype.initialTag = function() {
552   - var _ref2, _result, k, ret, v;
553   - ret = (function() {
554   - _result = []; _ref2 = this.attributes;
555   - for (k in _ref2) {
556   - if (!__hasProp.call(_ref2, k)) continue;
557   - v = _ref2[k];
558   - _result.push(this._keyValueStr(k, v));
559   - }
560   - return _result;
561   - }).call(this);
562   - if (!(this._classes.isEmpty())) {
563   - ret.push(this._keyValueStr('class', this._classes.toArray().join(" ")));
564   - }
565   - if (this.id()) {
566   - ret.push('id="' + this.id() + '"');
567   - }
568   - if (isEmpty(ret)) {
569   - return '<' + this._name;
570   - }
571   - return '<' + this._name + ' ' + ret.join(' ');
572   - };
573   - ErectorJS.ErectorPart.prototype.to_html = function() {
574   - var _k, _len, _ref2, child, fromChildren, ret;
575   - if (!(typeof (_ref2 = this._name) !== "undefined" && _ref2 !== null)) {
576   - raise("Name of a erector part must be a valid string");
577   - }
578   - if (!isEmptyObject(this._style) && this.id() === null) {
579   - raise("Please enable ui.genIds, or set id for elements with style");
580   - }
581   - if (isEmpty(this.children)) {
582   - this._on_dom = true;
583   - return this.initialTag() + '/>';
584   - }
585   - fromChildren = [];
586   - _ref2 = this.children;
587   - for (_k = 0, _len = _ref2.length; _k < _len; _k++) {
588   - child = _ref2[_k];
589   - if (!(child.to_html)) {
590   - raise("Child must have to_html method");
591   - }
592   - fromChildren.push(child.to_html());
593   - }
594   - ret = this.initialTag() + '>' + fromChildren.join('') + '</' + this._name + '>';
595   - this._on_dom = true;
596   - return ret;
597   - };
598   - ErectorJS.ErectorPart.prototype.hidden_html = function() {
599   - return this.hidden_style().to_html();
600   - };
601   - ErectorJS.ErectorPart.prototype.hidden_style = function() {
602   - return this.add('style', 'display: none"');
603   - };
604   - ErectorJS.ErectorPart.prototype.remove = function(child) {
605   - if (this._on_dom) {
606   - child.get_self().remove();
607   - return this;
608   - }
609   - return raise("Remove not implemented outside dom");
610   - };
611   - ErectorJS.ErectorPart.prototype.removeSelf = function() {
612   - if (this._on_dom) {
613   - this.get_self().remove();
614   - return this;
615   - }
616   - return raise("Remove not implemented outside dom");
617   - };
618   - ErectorJS.ErectorPart.prototype.onEnter = function(func) {
619   - return this.get_self().bind('keydown', 'return', func);
620   - };
621   - ErectorJS.ErectorPart.prototype.fadeIn = function(time) {
622   - return this.get_self().fadeIn(time);
623   - };
624   - ErectorJS.ErectorPart.prototype.fadeOut = function(time) {
625   - return this.get_self().fadeOut(time);
626   - };
627   - ErectorJS.ErectorPart.prototype.add_children = function(array) {
628   - var _k, _len, _ref2, i;
629   - _ref2 = array;
630   - for (_k = 0, _len = _ref2.length; _k < _len; _k++) {
631   - i = _ref2[_k];
632   - this.add_child(i);
633   - if (this._on_dom) {
634   - this.get_self().append(i.to_html());
635   - i.pre_render();
636   - }
637   - }
638   - return this;
639   - };
640   - ErectorJS.ErectorPart.prototype.add_child = function(element) {
641   - if (!(element.to_html)) {
642   - raise("Can't add a non abstract part as a child:" + element);
643   - }
644   - this.children.push(element);
645   - return this.owns_child(element);
646   - };
647   - ErectorJS.ErectorPart.prototype.partWithId = function(name) {
648   - var _k, _len, _ref2, c, ret;
649   - _ref2 = this.children;
650   - for (_k = 0, _len = _ref2.length; _k < _len; _k++) {
651   - c = _ref2[_k];
652   - if (c.alias === name) {
653   - return c;
654   - }
655   - }
656   - _ref2 = this.children;
657   - for (_k = 0, _len = _ref2.length; _k < _len; _k++) {
658   - c = _ref2[_k];
659   - if (c instanceof ErectorPart) {
660   - ret = c.partWithId(name);
661   - if (ret) {
662   - return ret;
663   - }
664   - }
665   - }
666   - return null;
667   - };
668   - ErectorJS.ErectorPart.prototype._proxy_or_jquery_object = function() {
669   - return this._proxy;
670   - };
671   - ErectorJS.ErectorPart.prototype.get = function(name) {
672   - var part;
673   - part = this.partWithId(name);
674   - if (part === null) {
675   - raise("No Component with id of: " + name);
676   - }
677   - return part._proxy_or_jquery_object();
678   - };
679   - ErectorJS.ErectorPart.prototype.get_self = function() {
680   - if (this.id() === null) {
681   - raise("Can't get_self if the Part is not a component with id");
682   - }
683   - return this._proxy_or_jquery_object();
684   - };
685   - ErectorJS.ErectorPart.prototype.hide = function() {
686   - this.get_self().hide();
687   - return this;
688   - };
689   - ErectorJS.ErectorPart.prototype.slideUp = function() {
690   - this.get_self().slideUp();
691   - return this;
692   - };
693   - ErectorJS.ErectorPart.prototype.slideDown = function() {
694   - this.get_self().slideDown();
695   - return this;
696   - };
697   - ErectorJS.ErectorPart.prototype.toggle = function() {
698   - this.get_self().toggle();
699   - return this;
700   - };
701   - ErectorJS.ErectorPart.prototype.show = function() {
702   - this.get_self().show();
703   - return this;
704   - };
705   - ErectorJS.ErectorPart.prototype.click = function(func, context) {
706   - if (typeof context !== "undefined" && context !== null) {
707   - this.get_self().click(func);
708   - } else {
709   - this.get_self().click(__bind(function() {
710   - return func.call(this);
711   - }, this));
712   - }
713   - this._classes.add('clickable');
714   - return this;
715   - };
716   - ErectorJS.ErectorPart.prototype.remove_self = function() {
717   - return this.get_self().remove();
718   - };
719   - ErectorJS.ErectorPart.prototype.devMode = function() {
720   - this._devMode = true;
721   - return this;
722   - };
723   - ErectorJS.ErectorPart.prototype.xtyle = function(name, value) {
724   - var _k, _len, _ref2, prefix, prefixes, ret;
725   - ret = {};
726   - prefixes = ['-webkit-', '-moz-', '-o-', '-ms-', ''];
727   - _ref2 = prefixes;
728   - for (_k = 0, _len = _ref2.length; _k < _len; _k++) {
729   - prefix = _ref2[_k];
730   - ret[prefix + name] = value;
731   - }
732   - this.style(ret);
733   - return this;
734   - };
735   - ErectorJS.ErectorPart.prototype.shadow = function(arg) {
736   - return this.xtyle('box-shadow', arg);
737   - };
738   - ErectorJS.ErectorPart.prototype.addStyle = function(obj) {
739   - var params;
740   - params = this._styleParams(obj);
741   - return params.target._addCssClass(params.name);
742   - };
743   - ErectorJS.ErectorPart.prototype.addSelfStyle = function() {
744   - var args, styleName;
745   - args = __slice.call(arguments, 0);
746   - if (args.length === 0) {
747   - return this.addStyle(this);
748   - }
749   - styleName = args[0];
750   - args = {};
751   - args[styleName] = this;
752   - return this.addStyle(args);
753   - };
754   - ErectorJS.ErectorPart.prototype.removeSelfStyle = function() {
755   - var args, styleName;
756   - args = __slice.call(arguments, 0);
757   - if (args.length === 0) {
758   - return this.removeStyle(this);
759   - }
760   - styleName = args[0];
761   - args = {};
762   - args[styleName] = this;
763   - return this.removeStyle(args);
764   - };
765   - ErectorJS.ErectorPart.prototype.removeStyle = function(obj) {
766   - var params;
767   - params = this._styleParams(obj);
768   - return params.target._removeCssClass(params.name);
769   - };
770   - ErectorJS.ErectorPart.prototype._styleParams = function(obj) {
771   - var _ref2, styleName, value;
772   - if (obj instanceof ErectorPart) {
773   - return {
774   - target: obj,
775   - name: this._styleName()
776   - };
777   - }
778   - _ref2 = obj;
779   - for (styleName in _ref2) {
780   - if (!__hasProp.call(_ref2, styleName)) continue;
781   - value = _ref2[styleName];
782   - if (!(value instanceof ErectorPart)) {
783   - raise("Cannot set style to a non Erector Part");
784   - }
785   - return {
786   - target: value,
787   - name: this._multipleStyleName(styleName)
788   - };
789   - }
790   - return raise("Can't add non existing style");
791   - };
792   - ErectorJS.ErectorPart.prototype._styleName = function() {
793   - if (this.constructor.style) {
794   - return ("" + (this._class) + "-style");
795   - }
796   - return raise("" + (this._class) + " must have a style property defined in order to add style");
797   - };
798   - ErectorJS.ErectorPart.prototype._multipleStyleName = function(styleName) {
799   - var _ref2;
800   - if (!((typeof (_ref2 = this.constructor.styles) !== "undefined" && _ref2 !== null) && (typeof (_ref2 = this.constructor.styles[styleName]) !== "undefined" && _ref2 !== null))) {
801   - raise("" + (this._class) + " must have a multiple style property '" + (styleName) + "' defined");
802   - }
803   - return ("" + (this._class) + "-" + (styleName) + "-style");
804   - };
805   - ErectorJS.ErectorPart.prototype._addCssClass = function(clas) {
806   - if (this._on_dom) {
807   - this.get_self().addClass(clas);
808   - return this;
809   - }
810   - this._classes.add(clas);
811   - return this;
812   - };
813   - ErectorJS.ErectorPart.prototype._removeCssClass = function(clas) {
814   - if (this._on_dom) {
815   - this.get_self().removeClass(clas);
816   - return this;
817   - }
818   - this._classes.remove(clas);
819   - return this;
820   - };
821   - ErectorJS.ErectorPart.prototype.style = function() {
822   - var args, jq;
823   - if (this._on_dom) {
824   - jq = this.get_self();
825   - jq.css.apply(jq, arguments);
826   - return this;
827   - }
828   - args = asList(arguments);
829   - if (args.length === 1) {
830   - _extend(this._style, args.shift());
831   - return this;
832   - }
833   - if (args.length % 2 !== 0) {
834   - raise("Style argument lists must be even, or a sinlge object");
835   - }
836   - new Collection(args).forEachSlice(2, __bind(function(pair) {
837   - return (this._style[pair[0]] = pair[1]);
838   - }, this));
839   - return this;
840   - };
841   - ErectorJS.ErectorPart.prototype.pre_render = function() {
842   - var _k, _len, _ref2, c;
843   - if (!(this._on_dom)) {
844   - raise("Invoke to_html before invoking pre_render on " + this.debugString());
845   - }
846   - if (this._pre_rendered) {
847   - raise("Do not invoke prerender more than once on " + this.debugString());
848   - }
849   - this._pre_rendered = true;
850   - if (this.id()) {
851   - this.get_self().css(this._style);
852   - }
853   - if (this.id()) {
854   - this._proxy._unfreeze();
855   - }
856   - _ref2 = this.children;
857   - for (_k = 0, _len = _ref2.length; _k < _len; _k++) {
858   - c = _ref2[_k];
859   - c.pre_render();
860   - }
861   - this.do_prerender();
862   - if (this._devMode) {
863   - return this.get_self().css('border', 'solid red').draggable().resizable();
864   - }
865   - };
866   - ErectorJS.ErectorPart.prototype.debugString = function() {
867   - var ret;
868   - if (!(this._name)) {
869   - return "Very strange. Unamed part";
870   - }
871   - ret = "Part named: " + this._name;
872   - if (this._class) {
873   - ret += words(", with class:", this._class);
874   - }
875   - if (this.alias) {
876   - ret += words(", with original id:", this.alias);
877   - }
878   - if (this.id()) {
879   - ret += words(", with id:", this.id());
880   - }
881   - return ret;
882   - };
883   - ErectorJS.ErectorPart.prototype.fullPath = function() {
884   - var _ref2;
885   - if (!(typeof (_ref2 = this.parent) !== "undefined" && _ref2 !== null)) {
886   - return this.id();
887   - }
888   - return this.parent.fullPath() + ' ' + this.id();
889   - };
890   - ErectorJS.ErectorPart.prototype.onKey = function(expresionString, callback) {
891   - this.get_self().bind('keydown', expresionString, callback);
892   - return this;
893   - };
894   - ErectorJS.ErectorPart.prototype.do_prerender = function() {};
895   - ErectorJS.ErectorPart.prototype.fire = function(eventName) {
896   - var _k, _len, _ref2, _result, args, mName, p, params, target;
897   - args = __slice.call(arguments, 1);
898   - params = {
899   - parameters: args
900   - };
901   - p = this.parent;
902   - mName = 'respondTo' + capitalize(eventName);
903   - while (p) {
904   - if (p[mName]) {
905   - p[mName].call(p, params);
906   - return null;
907   - }
908   - p = p.parent;
909   - }
910   - _result = []; _ref2 = Events.get(eventName);
911   - for (_k = 0, _len = _ref2.length; _k < _len; _k++) {
912   - target = _ref2[_k];
913   - _result.push(target[mName].call(target, params));
914   - }
915   - return _result;
916   - };
917   - return ErectorJS.ErectorPart;
918   - }).call(this);
919   - UIComponent = (function() {
920   - ErectorJS.UIComponent = function(name) {
921   - ErectorJS.UIComponent.__super__.constructor.call(this, name, []);
922   - if (!(ui.genIds)) {
923   - raise("Must enable ui.idsGen to use Ui Componentes");
924   - }
925   - return this;
926   - };
927   - __extends(ErectorJS.UIComponent, ErectorPart);
928   - ErectorJS.UIComponent.prototype.as = function(arg) {
929   - this._name = arg;
930   - return this;
931   - };
932   - return ErectorJS.UIComponent;
933   - })();
934   - TextPart = (function() {
935   - ErectorJS.TextPart = function(text) {
936   - ErectorJS.TextPart.__super__.constructor.call(this);
937   - this.text = text;
938   - return this;
939   - };
940   - __extends(ErectorJS.TextPart, AbstractPart);
941   - ErectorJS.TextPart.prototype.to_html = function() {
942   - return this.text;
943   - };
944   - return ErectorJS.TextPart;
945   - })();
946   - IdsCounter = function() {
947   - this.reset();
948   - return this;
949   - };
950   - IdsCounter.prototype.reset = function() {
951   - return (this.counterHash = new JS.Hash(0));
952   - };
953   - IdsCounter.prototype.counterByName = function(name) {
954   - this.counterHash.put(name, this.counterHash.get(name) + 1);
955   - return this.counterHash.get(name);
956   - };
957   - IdsCounter.prototype.counter = function(target) {
958   - var _ref2, c;
959   - name = target._class && target._class !== 'ErectorPart' ? target._class : 'part-erc';
960   - if (typeof (_ref2 = target.alias) !== "undefined" && _ref2 !== null) {
961   - name = target.alias + '-' + name;
962   - }
963   - c = this.counterByName(name);
964   - return "" + (name) + "-" + (c);
965   - };
966   - ComponentsCounter = (ErectorJS.ComponentsCounter = new IdsCounter());
967   - Erector = (function() {
968   - ErectorJS.Erector = function() {
969   - this.children = [];
970   - return this;
971   - };
972   - ErectorJS.Erector.prototype.text = function() {
973   - return this.initPart(new TextPart(asList(arguments).join('')));
974   - };
975   - ErectorJS.Erector.prototype.words = function() {
976   - return this.initPart(new TextPart(asList(arguments).join(' ')));
977   - };
978   - ErectorJS.Erector.prototype.alink = function(href, text) {
979   - var realText;
980   - realText = (typeof text !== "undefined" && text !== null) ? text : href;
981   - return this.a('href', href, realText);
982   - };
983