imba-source 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 78d5692153fa7283b919eb5ab123d13085ff3ad3
4
+ data.tar.gz: 3c903a2987e976114027a5ace2fae26b517da622
5
+ SHA512:
6
+ metadata.gz: cdaae55b3f977b61a8860595c387e9b499d7a9fd28bab62f55fcf5c969823bac9d98041dcfe0e45b623d4ce6d65d641b05803c7a18fa076ff808801c1f389dda
7
+ data.tar.gz: 9a22608f5a260cf26c37faa81666043ec83f28e1decb0fdb7997c6d5260f7b7d41b05ac9148f95772e8ce08dcf2239308af5945a5d433b0c982d1a612475f5fc
@@ -0,0 +1,41 @@
1
+ # Imba::Source
2
+
3
+ JavaScript source code for the [Imba](https://github.com/somebee/imba) compiler and runtime library.
4
+
5
+ ## Usage (public API)
6
+
7
+ ```ruby
8
+ require 'imba/source'
9
+
10
+ # The Imba runtime:
11
+ Imba::Source.path_for("imba.js")
12
+ Imba::Source.path_for("imba.min.js")
13
+
14
+ # The Imba compiler:
15
+ Imba::Source.path_for("imbac.js")
16
+ Imba::Source.path_for("imbac.min.js")
17
+
18
+ # Path to the directory which contains the files above
19
+ Imba::Source::BROWSER_PATH # => Pathname instance
20
+ ```
21
+
22
+ ## Installation
23
+
24
+ Add this line to your application's Gemfile:
25
+
26
+ ```ruby
27
+ gem 'imba-source'
28
+ ```
29
+
30
+ And then execute:
31
+
32
+ $ bundle
33
+
34
+ Or install it yourself as:
35
+
36
+ $ gem install imba-source
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,13 @@
1
+ require "imba/source/version"
2
+ require "pathname"
3
+
4
+ module Imba
5
+ module Source
6
+ VENDOR_PATH = Pathname.new(__FILE__).expand_path + "../../../vendor/imba"
7
+ BROWSER_PATH = VENDOR_PATH + "lib/browser"
8
+
9
+ def self.path_for(name)
10
+ (BROWSER_PATH + name).to_s
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Imba
2
+ module Source
3
+ VERSION = "0.12.1"
4
+ end
5
+ end
@@ -0,0 +1,2713 @@
1
+ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.imba = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2
+ (function(){
3
+
4
+ if (typeof Imba === 'undefined') {
5
+ require('./imba');
6
+ require('./core.events');
7
+ require('./dom');
8
+ require('./dom.client');
9
+ require('./dom.html');
10
+ require('./dom.legacy');
11
+ require('./dom.events');
12
+ require('./dom.static');
13
+ require('./selector');
14
+ };
15
+
16
+ })()
17
+ },{"./core.events":2,"./dom":6,"./dom.client":3,"./dom.events":4,"./dom.html":5,"./dom.legacy":7,"./dom.static":8,"./imba":9,"./selector":10}],2:[function(require,module,exports){
18
+ (function(){
19
+
20
+
21
+ function emit__(event,args,node){
22
+ // var node = cbs[event]
23
+ var prev,cb,ret;
24
+
25
+ while ((prev = node) && (node = node.next)){
26
+ if (cb = node.listener) {
27
+ if (node.path && cb[node.path]) {
28
+ ret = args ? (cb[node.path].apply(cb,args)) : (cb[node.path]());
29
+ } else {
30
+ // check if it is a method?
31
+ ret = args ? (cb.apply(node,args)) : (cb.call(node));
32
+ };
33
+ };
34
+
35
+ if (node.times && --node.times <= 0) {
36
+ prev.next = node.next;
37
+ node.listener = null;
38
+ };
39
+ };
40
+ return;
41
+ };
42
+
43
+ // method for registering a listener on object
44
+ Imba.listen = function (obj,event,listener,path){
45
+ var $1;
46
+ var cbs,list,tail;
47
+ cbs = obj.__listeners__ || (obj.__listeners__ = {});
48
+ list = cbs[($1=event)] || (cbs[$1] = {});
49
+ tail = list.tail || (list.tail = (list.next = {}));
50
+ tail.listener = listener;
51
+ tail.path = path;
52
+ list.tail = tail.next = {};
53
+ return tail;
54
+ };
55
+
56
+ Imba.once = function (obj,event,listener){
57
+ var tail = Imba.listen(obj,event,listener);
58
+ tail.times = 1;
59
+ return tail;
60
+ };
61
+
62
+ Imba.unlisten = function (obj,event,cb,meth){
63
+ var node,prev;
64
+ var meta = obj.__listeners__;
65
+ if (!meta) { return };
66
+
67
+ if (node = meta[event]) {
68
+ while ((prev = node) && (node = node.next)){
69
+ if (node == cb || node.listener == cb) {
70
+ prev.next = node.next;
71
+ // check for correct path as well?
72
+ node.listener = null;
73
+ break;
74
+ };
75
+ };
76
+ };
77
+ return;
78
+ };
79
+
80
+ Imba.emit = function (obj,event,params){
81
+ var cb;
82
+ if (cb = obj.__listeners__) {
83
+ if (cb[event]) { emit__(event,params,cb[event]) };
84
+ if (cb.all) { emit__(event,[event,params],cb.all) }; // and event != 'all'
85
+ };
86
+ return;
87
+ };
88
+
89
+ Imba.observeProperty = function (observer,key,trigger,target,prev){
90
+ if (prev && typeof prev == 'object') {
91
+ Imba.unlisten(prev,'all',observer,trigger);
92
+ };
93
+ if (target && typeof target == 'object') {
94
+ Imba.listen(target,'all',observer,trigger);
95
+ };
96
+ return this;
97
+ };
98
+
99
+ })()
100
+ },{}],3:[function(require,module,exports){
101
+ (function(){
102
+ function iter$(a){ return a ? (a.toArray ? a.toArray() : a) : []; };
103
+
104
+
105
+ var prefixes = ['-webkit-','-ms-','-moz-','-o-','-blink-'];
106
+ var props = ['transform','transition','animation'];
107
+ var styles = window.getComputedStyle(document.documentElement,'');
108
+ Imba.CSSKeyMap = {};
109
+
110
+ for (var i=0, ary=iter$(styles), len=ary.length, prefixed; i < len; i++) {
111
+ // really? this must be for the client ---
112
+ // there is no way to set this otherwise?
113
+ prefixed = ary[i];
114
+ var unprefixed = prefixed.replace(/^-(webkit|ms|moz|o|blink)-/,'');
115
+ var camelCase = unprefixed.replace(/-(\w)/g,function(m,a) { return a.toUpperCase(); });
116
+
117
+ // if there exists an unprefixed version -- always use this
118
+ if (prefixed != unprefixed) {
119
+ if (styles.hasOwnProperty(unprefixed)) { continue };
120
+ };
121
+
122
+ // register the prefixes
123
+ Imba.CSSKeyMap[unprefixed] = Imba.CSSKeyMap[camelCase] = prefixed;
124
+ };
125
+
126
+ Imba.extendTag('htmlelement', function(tag){
127
+
128
+ // override the original css method
129
+ tag.prototype.css = function (key,val){
130
+ if (key instanceof Object) {
131
+ for (var i=0, keys=Object.keys(key), l=keys.length; i < l; i++){
132
+ this.css(keys[i],key[keys[i]]);
133
+ };
134
+ return this;
135
+ };
136
+
137
+ key = Imba.CSSKeyMap[key] || key;
138
+
139
+ if (val == null) {
140
+ this.dom().style.removeProperty(key);
141
+ } else if (val == undefined) {
142
+ return this.dom().style[key];
143
+ } else {
144
+ if ((typeof val=='number'||val instanceof Number) && key.match(/width|height|left|right|top|bottom/)) {
145
+ val = val + "px";
146
+ };
147
+ this.dom().style[key] = val;
148
+ };
149
+ return this;
150
+ };
151
+ });
152
+
153
+ })()
154
+ },{}],4:[function(require,module,exports){
155
+ (function(){
156
+ function iter$(a){ return a ? (a.toArray ? a.toArray() : a) : []; };
157
+ var doc = document;
158
+ var win = window;
159
+
160
+ // typeof ontouchstart instead?
161
+ var hasTouchEvents = window && window.ontouchstart !== undefined; // .hasOwnProperty('ontouchstart')
162
+
163
+ // Ringbuffer for events?
164
+
165
+ Imba.RingBuffer = function RingBuffer(len){
166
+ if(len === undefined) len = 10;
167
+ this._array = [];
168
+ this._keep = len;
169
+ this._head = 0;
170
+ this;
171
+ };
172
+
173
+
174
+ Imba.RingBuffer.prototype.__head = {name: 'head'};
175
+ Imba.RingBuffer.prototype.head = function(v){ return this._head; }
176
+ Imba.RingBuffer.prototype.setHead = function(v){ this._head = v; return this; };
177
+
178
+ Imba.RingBuffer.prototype.push = function (obj){
179
+ var i = this._head++;
180
+ this._array[i % this._keep] = obj;
181
+ return i;
182
+ };
183
+
184
+ Imba.RingBuffer.prototype.last = function (){
185
+ return this._array[this._head % this._keep];
186
+ };
187
+
188
+ // really more like a pointer?
189
+ Imba.Pointer = function Pointer(){
190
+ this.setButton(-1);
191
+ this.setEvents(new Imba.RingBuffer(10));
192
+ this.setEvent({x: 0,y: 0,type: 'uninitialized'});
193
+ this;
194
+ };
195
+
196
+
197
+ Imba.Pointer.prototype.__phase = {name: 'phase'};
198
+ Imba.Pointer.prototype.phase = function(v){ return this._phase; }
199
+ Imba.Pointer.prototype.setPhase = function(v){ this._phase = v; return this; }; // change: update
200
+
201
+ Imba.Pointer.prototype.__prevEvent = {name: 'prevEvent'};
202
+ Imba.Pointer.prototype.prevEvent = function(v){ return this._prevEvent; }
203
+ Imba.Pointer.prototype.setPrevEvent = function(v){ this._prevEvent = v; return this; };
204
+
205
+ Imba.Pointer.prototype.__button = {name: 'button'};
206
+ Imba.Pointer.prototype.button = function(v){ return this._button; }
207
+ Imba.Pointer.prototype.setButton = function(v){ this._button = v; return this; };
208
+
209
+ Imba.Pointer.prototype.__event = {name: 'event'};
210
+ Imba.Pointer.prototype.event = function(v){ return this._event; }
211
+ Imba.Pointer.prototype.setEvent = function(v){ this._event = v; return this; };
212
+
213
+ Imba.Pointer.prototype.__dirty = {name: 'dirty'};
214
+ Imba.Pointer.prototype.dirty = function(v){ return this._dirty; }
215
+ Imba.Pointer.prototype.setDirty = function(v){ this._dirty = v; return this; };
216
+
217
+ Imba.Pointer.prototype.__events = {name: 'events'};
218
+ Imba.Pointer.prototype.events = function(v){ return this._events; }
219
+ Imba.Pointer.prototype.setEvents = function(v){ this._events = v; return this; };
220
+
221
+ Imba.Pointer.prototype.__touch = {name: 'touch'};
222
+ Imba.Pointer.prototype.touch = function(v){ return this._touch; }
223
+ Imba.Pointer.prototype.setTouch = function(v){ this._touch = v; return this; };
224
+
225
+ Imba.Pointer.prototype.update = function (e){
226
+ // console.log(e)
227
+ this.setEvent(e);
228
+ // normalize the event / touch?
229
+ this.events().push(e);
230
+ this.setDirty(true);
231
+ return this;
232
+ };
233
+
234
+ // this is just for regular mouse now
235
+ Imba.Pointer.prototype.process = function (){
236
+ var phase = this.phase();
237
+ var e0 = this.prevEvent();
238
+ var e1 = this.event();
239
+
240
+ if (this.dirty()) {
241
+ this.setPrevEvent(e1);
242
+ this.setDirty(false);
243
+ // button should only change on mousedown etc
244
+ if (e1.type == 'mousedown') {
245
+ this.setButton(e1.button);
246
+ this.setTouch(new Imba.Touch(e1,this));
247
+ this.touch().mousedown(e1,e1);
248
+ } else if (e1.type == 'mousemove') {
249
+ if (this.touch()) { this.touch().mousemove(e1,e1) };
250
+ } else if (e1.type == 'mouseup') {
251
+ this.setButton(-1);
252
+ if (this.touch()) { this.touch().mouseup(e1,e1) };
253
+ this.setTouch(null); // reuse?
254
+ // trigger pointerup
255
+ };
256
+ } else {
257
+ // set type to stationary?
258
+ // update always?
259
+ if (this.touch()) { this.touch().idle() };
260
+ };
261
+
262
+
263
+ return this;
264
+ };
265
+
266
+ Imba.Pointer.prototype.emit = function (name,target,pars){
267
+ if(!pars||pars.constructor !== Object) pars = {};
268
+ var bubble = pars.bubble !== undefined ? pars.bubble : true;
269
+ return true;
270
+ };
271
+
272
+ Imba.Pointer.prototype.cleanup = function (){
273
+ return Imba.POINTERS;
274
+ };
275
+
276
+ Imba.Pointer.prototype.x = function (){
277
+ return this.event().x;
278
+ };
279
+ Imba.Pointer.prototype.y = function (){
280
+ return this.event().y;
281
+ };
282
+
283
+ Imba.Pointer.update = function (){
284
+ // console.log('update touch')
285
+ for (var i=0, ary=iter$(Imba.POINTERS), len=ary.length; i < len; i++) {
286
+ ary[i].process();
287
+ };
288
+ // need to be able to prevent the default behaviour of touch, no?
289
+ win.requestAnimationFrame(Imba.Pointer.update);
290
+ return this;
291
+ };
292
+
293
+
294
+ // Imba.Touch
295
+ // Began A finger touched the screen.
296
+ // Moved A finger moved on the screen.
297
+ // Stationary A finger is touching the screen but hasn't moved.
298
+ // Ended A finger was lifted from the screen. This is the final phase of a touch.
299
+ // Canceled The system cancelled tracking for the touch.
300
+ Imba.Touch = function Touch(e,ptr){
301
+ // @native = false
302
+ this.setEvent(e);
303
+ this.setData({});
304
+ this.setActive(true);
305
+ this._suppress = false;
306
+ this.setBubble(false);
307
+ this.setPointer(ptr);
308
+ this.setUpdates(0);
309
+ };
310
+
311
+ var multi = true;
312
+ var touches = [];
313
+ var count = 0;
314
+ var identifiers = {};
315
+
316
+ Imba.Touch.count = function (){
317
+ return count;
318
+ };
319
+
320
+ Imba.Touch.lookup = function (item){
321
+ // return touch if var touch = item:__touch__
322
+ return item && (item.__touch__ || identifiers[item.identifier]);
323
+ // look for lookup
324
+ // var id = item:identifier
325
+ // if id != undefined and (touch = IMBA_TOUCH_IDENTIFIERS{id})
326
+ // return touch
327
+ };
328
+
329
+ Imba.Touch.release = function (item,touch){
330
+ var v_, $1;
331
+ (((v_ = identifiers[item.identifier]),delete identifiers[item.identifier], v_));
332
+ ((($1 = item.__touch__),delete item.__touch__, $1));
333
+ return;
334
+ };
335
+
336
+ Imba.Touch.ontouchstart = function (e){
337
+ for (var i=0, ary=iter$(e.changedTouches), len=ary.length, t; i < len; i++) {
338
+ t = ary[i];
339
+ if (this.lookup(t)) { continue };
340
+ var touch = identifiers[t.identifier] = new this(e); // (e)
341
+ t.__touch__ = touch;
342
+ touches.push(touch);
343
+ count++;
344
+ touch.touchstart(e,t);
345
+ };
346
+ return this;
347
+ };
348
+
349
+ Imba.Touch.ontouchmove = function (e){
350
+ var touch;
351
+ for (var i=0, ary=iter$(e.changedTouches), len=ary.length, t; i < len; i++) {
352
+ t = ary[i];
353
+ if (touch = this.lookup(t)) {
354
+ touch.touchmove(e,t);
355
+ };
356
+ };
357
+
358
+ return this;
359
+ };
360
+
361
+ Imba.Touch.ontouchend = function (e){
362
+ var touch;
363
+ for (var i=0, ary=iter$(e.changedTouches), len=ary.length, t; i < len; i++) {
364
+ t = ary[i];
365
+ if (touch = this.lookup(t)) {
366
+ touch.touchend(e,t);
367
+ this.release(t,touch);
368
+ count--;
369
+ // not always supported!
370
+ // touches = touches.filter(||)
371
+ };
372
+ };
373
+ return this;
374
+ };
375
+
376
+ Imba.Touch.ontouchcancel = function (e){
377
+ var touch;
378
+ for (var i=0, ary=iter$(e.changedTouches), len=ary.length, t; i < len; i++) {
379
+ t = ary[i];
380
+ if (touch = this.lookup(t)) {
381
+ touch.touchcancel(e,t);
382
+ this.release(t,touch);
383
+ count--;
384
+ };
385
+ };
386
+ return this;
387
+ };
388
+
389
+
390
+
391
+
392
+ Imba.Touch.prototype.__phase = {name: 'phase'};
393
+ Imba.Touch.prototype.phase = function(v){ return this._phase; }
394
+ Imba.Touch.prototype.setPhase = function(v){ this._phase = v; return this; };
395
+
396
+ Imba.Touch.prototype.__active = {name: 'active'};
397
+ Imba.Touch.prototype.active = function(v){ return this._active; }
398
+ Imba.Touch.prototype.setActive = function(v){ this._active = v; return this; };
399
+
400
+ Imba.Touch.prototype.__event = {name: 'event'};
401
+ Imba.Touch.prototype.event = function(v){ return this._event; }
402
+ Imba.Touch.prototype.setEvent = function(v){ this._event = v; return this; };
403
+
404
+ Imba.Touch.prototype.__pointer = {name: 'pointer'};
405
+ Imba.Touch.prototype.pointer = function(v){ return this._pointer; }
406
+ Imba.Touch.prototype.setPointer = function(v){ this._pointer = v; return this; };
407
+
408
+ Imba.Touch.prototype.__target = {name: 'target'};
409
+ Imba.Touch.prototype.target = function(v){ return this._target; }
410
+ Imba.Touch.prototype.setTarget = function(v){ this._target = v; return this; }; // if 'safe' we can cache multiple uses
411
+
412
+ Imba.Touch.prototype.__handler = {name: 'handler'};
413
+ Imba.Touch.prototype.handler = function(v){ return this._handler; }
414
+ Imba.Touch.prototype.setHandler = function(v){ this._handler = v; return this; };
415
+
416
+ Imba.Touch.prototype.__updates = {name: 'updates'};
417
+ Imba.Touch.prototype.updates = function(v){ return this._updates; }
418
+ Imba.Touch.prototype.setUpdates = function(v){ this._updates = v; return this; };
419
+
420
+ Imba.Touch.prototype.__suppress = {name: 'suppress'};
421
+ Imba.Touch.prototype.suppress = function(v){ return this._suppress; }
422
+ Imba.Touch.prototype.setSuppress = function(v){ this._suppress = v; return this; };
423
+
424
+ Imba.Touch.prototype.__data = {name: 'data'};
425
+ Imba.Touch.prototype.data = function(v){ return this._data; }
426
+ Imba.Touch.prototype.setData = function(v){ this._data = v; return this; };
427
+
428
+ Imba.Touch.prototype.__bubble = {chainable: true,name: 'bubble'};
429
+ Imba.Touch.prototype.bubble = function(v){ return v !== undefined ? (this.setBubble(v),this) : this._bubble; }
430
+ Imba.Touch.prototype.setBubble = function(v){ this._bubble = v; return this; };
431
+
432
+
433
+ Imba.Touch.prototype.__gestures = {name: 'gestures'};
434
+ Imba.Touch.prototype.gestures = function(v){ return this._gestures; }
435
+ Imba.Touch.prototype.setGestures = function(v){ this._gestures = v; return this; };
436
+ // prop preventDefault
437
+
438
+
439
+ Imba.Touch.prototype.__x0 = {name: 'x0'};
440
+ Imba.Touch.prototype.x0 = function(v){ return this._x0; }
441
+ Imba.Touch.prototype.setX0 = function(v){ this._x0 = v; return this; };
442
+
443
+ Imba.Touch.prototype.__y0 = {name: 'y0'};
444
+ Imba.Touch.prototype.y0 = function(v){ return this._y0; }
445
+ Imba.Touch.prototype.setY0 = function(v){ this._y0 = v; return this; };
446
+
447
+ // duration etc -- important
448
+
449
+ Imba.Touch.prototype.preventDefault = function (){
450
+ this._preventDefault = true;
451
+ this.event() && this.event().preventDefault();
452
+ // pointer.event.preventDefault
453
+ return this;
454
+ };
455
+
456
+ Imba.Touch.prototype.extend = function (gesture){
457
+ // console.log "added gesture!!!"
458
+ this._gestures || (this._gestures = []);
459
+ this._gestures.push(gesture);
460
+ return this;
461
+ };
462
+
463
+ Imba.Touch.prototype.redirect = function (target){
464
+ this._redirect = target;
465
+ return this;
466
+ };
467
+
468
+ Imba.Touch.prototype.suppress = function (){
469
+ // collision with the suppress property
470
+ this._active = false;
471
+ return this;
472
+ };
473
+
474
+ Imba.Touch.prototype.touchstart = function (e,t){
475
+ this._event = e;
476
+ this._touch = t;
477
+ this._x = t.clientX;
478
+ this._y = t.clientY;
479
+ this.began();
480
+ if (e && this._suppress) { e.preventDefault() };
481
+ return this;
482
+ };
483
+
484
+ Imba.Touch.prototype.touchmove = function (e,t){
485
+ this._event = e;
486
+ this._x = t.clientX;
487
+ this._y = t.clientY;
488
+ this.update();
489
+ if (e && this._suppress) { e.preventDefault() };
490
+ return this;
491
+ };
492
+
493
+ Imba.Touch.prototype.touchend = function (e,t){
494
+ this._event = e;
495
+ // log "touchend"
496
+ this._x = t.clientX;
497
+ this._y = t.clientY;
498
+ this.ended();
499
+ if (e && this._suppress) { e.preventDefault() };
500
+ return this;
501
+ };
502
+
503
+ Imba.Touch.prototype.touchcancel = function (e,t){
504
+ // log "touchcancel"
505
+ return this;
506
+ };
507
+
508
+
509
+ Imba.Touch.prototype.mousedown = function (e,t){
510
+ // log "mousedown"
511
+ this._x = t.clientX;
512
+ this._y = t.clientY;
513
+ this.began();
514
+ return this;
515
+ };
516
+
517
+ Imba.Touch.prototype.mousemove = function (e,t){
518
+ // log "mousemove"
519
+ this._x = t.clientX;
520
+ this._y = t.clientY;
521
+ // how does this work with touches?
522
+ this._event = e;
523
+ if (this._suppress) { e.preventDefault() };
524
+ this.update();
525
+ this.move();
526
+ return this;
527
+ };
528
+
529
+ Imba.Touch.prototype.mouseup = function (e,t){
530
+ // log "mousemove"
531
+ this._x = t.clientX;
532
+ this._y = t.clientY;
533
+ this.ended();
534
+ return this;
535
+ };
536
+
537
+ Imba.Touch.prototype.idle = function (){
538
+ return this.update();
539
+ };
540
+
541
+ Imba.Touch.prototype.began = function (){
542
+ // console.log "begaN??"
543
+ this._x0 = this._x;
544
+ this._y0 = this._y;
545
+
546
+ var e = this.event();
547
+ // var ptr = pointer
548
+ var dom = this.event().target;
549
+ var node = null;
550
+
551
+ this._sourceTarget = dom && tag$wrap(dom);
552
+ // need to find the
553
+ while (dom){
554
+ node = tag$wrap(dom);
555
+ if (node && node.ontouchstart) {
556
+ this._bubble = false;
557
+ this.setTarget(node);
558
+ this.target().ontouchstart(this);
559
+ if (!this._bubble) { break };
560
+ };
561
+ dom = dom.parentNode;
562
+ };
563
+
564
+ // console.log('target??',target)
565
+ this._updates++;
566
+ // if target
567
+ // target.ontouchstart(self)
568
+ // # ptr.event.preventDefault unless @native
569
+ // # prevent default?
570
+
571
+ // = e:clientX
572
+ // = e:clientY
573
+ return this;
574
+ };
575
+
576
+ Imba.Touch.prototype.update = function (){
577
+ if (!this._active) { return this };
578
+ // catching a touch-redirect?!?
579
+ if (this._redirect) {
580
+ if (this._target && this._target.ontouchcancel) {
581
+ this._target.ontouchcancel(this);
582
+ };
583
+ this.setTarget(this._redirect);
584
+ this._redirect = null;
585
+ if (this.target().ontouchstart) { this.target().ontouchstart(this) };
586
+ };
587
+
588
+
589
+ this._updates++;
590
+ if (this._gestures) {
591
+ for (var i=0, ary=iter$(this._gestures), len=ary.length; i < len; i++) {
592
+ ary[i].ontouchupdate(this);
593
+ };
594
+ };
595
+
596
+ if (this.target() && this.target().ontouchupdate) { this.target().ontouchupdate(this) };
597
+ return this;
598
+ };
599
+
600
+ Imba.Touch.prototype.move = function (){
601
+ if (!this._active) { return this };
602
+
603
+ if (this._gestures) {
604
+ for (var i=0, ary=iter$(this._gestures), len=ary.length, g; i < len; i++) {
605
+ g = ary[i];
606
+ if (g.ontouchmove) { g.ontouchmove(this,this._event) };
607
+ };
608
+ };
609
+
610
+ if (this.target() && this.target().ontouchmove) { this.target().ontouchmove(this,this._event) };
611
+ return this;
612
+ };
613
+
614
+ Imba.Touch.prototype.ended = function (){
615
+ if (!this._active) { return this };
616
+
617
+ this._updates++;
618
+
619
+ if (this._gestures) {
620
+ for (var i=0, ary=iter$(this._gestures), len=ary.length; i < len; i++) {
621
+ ary[i].ontouchend(this);
622
+ };
623
+ };
624
+
625
+ if (this.target() && this.target().ontouchend) { this.target().ontouchend(this) };
626
+
627
+ // simulate tap -- need to be careful about this(!)
628
+ // must look at timing and movement(!)
629
+ if (this._touch) {
630
+ ED.trigger('tap',this.event().target);
631
+ };
632
+ return this;
633
+ };
634
+
635
+ Imba.Touch.prototype.cancelled = function (){
636
+ return this;
637
+ };
638
+
639
+ Imba.Touch.prototype.dx = function (){
640
+ return this._x - this._x0;
641
+ // pointer.x - @x0
642
+ };
643
+
644
+ Imba.Touch.prototype.dy = function (){
645
+ return this._y - this._y0;
646
+ // pointer.y - @y0
647
+ };
648
+
649
+ Imba.Touch.prototype.x = function (){
650
+ return this._x;
651
+ }; // pointer.x
652
+ Imba.Touch.prototype.y = function (){
653
+ return this._y;
654
+ }; // pointer.y
655
+
656
+ Imba.Touch.prototype.button = function (){
657
+ return this._pointer ? (this._pointer.button()) : (0);
658
+ };
659
+
660
+ Imba.Touch.prototype.sourceTarget = function (){
661
+ return this._sourceTarget;
662
+ };
663
+
664
+
665
+ Imba.TouchGesture = function TouchGesture(){ };
666
+
667
+
668
+ Imba.TouchGesture.prototype.__active = {'default': false,name: 'active'};
669
+ Imba.TouchGesture.prototype.active = function(v){ return this._active; }
670
+ Imba.TouchGesture.prototype.setActive = function(v){ this._active = v; return this; }
671
+ Imba.TouchGesture.prototype._active = false;
672
+
673
+ Imba.TouchGesture.prototype.ontouchstart = function (e){
674
+ return this;
675
+ };
676
+
677
+ Imba.TouchGesture.prototype.ontouchupdate = function (e){
678
+ return this;
679
+ };
680
+
681
+ Imba.TouchGesture.prototype.ontouchend = function (e){
682
+ return this;
683
+ };
684
+
685
+
686
+ // A Touch-event is created on mousedown (always)
687
+ // and while it exists, mousemove and mouseup will
688
+ // be delegated to this active event.
689
+ Imba.POINTER = new Imba.Pointer();
690
+ Imba.POINTERS = [Imba.POINTER];
691
+
692
+
693
+ // regular event stuff
694
+ Imba.KEYMAP = {
695
+ "8": 'backspace',
696
+ "9": 'tab',
697
+ "13": 'enter',
698
+ "16": 'shift',
699
+ "17": 'ctrl',
700
+ "18": 'alt',
701
+ "19": 'break',
702
+ "20": 'caps',
703
+ "27": 'esc',
704
+ "32": 'space',
705
+ "35": 'end',
706
+ "36": 'home',
707
+ "37": 'larr',
708
+ "38": 'uarr',
709
+ "39": 'rarr',
710
+ "40": 'darr',
711
+ "45": 'insert',
712
+ "46": 'delete',
713
+ "107": 'plus',
714
+ "106": 'mult',
715
+ "91": 'meta'
716
+ };
717
+
718
+ Imba.CHARMAP = {
719
+ "%": 'modulo',
720
+ "*": 'multiply',
721
+ "+": 'add',
722
+ "-": 'sub',
723
+ "/": 'divide',
724
+ ".": 'dot'
725
+ };
726
+
727
+
728
+ Imba.Event = function Event(e){
729
+ this.setEvent(e);
730
+ this.setBubble(true);
731
+ };
732
+
733
+
734
+ Imba.Event.prototype.__event = {name: 'event'};
735
+ Imba.Event.prototype.event = function(v){ return this._event; }
736
+ Imba.Event.prototype.setEvent = function(v){ this._event = v; return this; };
737
+
738
+ Imba.Event.prototype.__target = {name: 'target'};
739
+ Imba.Event.prototype.target = function(v){ return this._target; }
740
+ Imba.Event.prototype.setTarget = function(v){ this._target = v; return this; };
741
+
742
+ Imba.Event.prototype.__prefix = {name: 'prefix'};
743
+ Imba.Event.prototype.prefix = function(v){ return this._prefix; }
744
+ Imba.Event.prototype.setPrefix = function(v){ this._prefix = v; return this; };
745
+
746
+ Imba.Event.prototype.__data = {name: 'data'};
747
+ Imba.Event.prototype.data = function(v){ return this._data; }
748
+ Imba.Event.prototype.setData = function(v){ this._data = v; return this; };
749
+
750
+ Imba.Event.prototype.__source = {name: 'source'};
751
+ Imba.Event.prototype.source = function(v){ return this._source; }
752
+ Imba.Event.prototype.setSource = function(v){ this._source = v; return this; };
753
+
754
+ Imba.Event.prototype.__bubble = {name: 'bubble'};
755
+ Imba.Event.prototype.bubble = function(v){ return this._bubble; }
756
+ Imba.Event.prototype.setBubble = function(v){ this._bubble = v; return this; }; // getset: yes
757
+
758
+ Imba.Event.wrap = function (e){
759
+ return new this(e);
760
+ };
761
+
762
+ Imba.Event.prototype.name = function (){
763
+ return this.event().type.toLowerCase().replace(/\:/g,'');
764
+ };
765
+
766
+ // mimc getset
767
+ Imba.Event.prototype.bubble = function (v){
768
+ if (v != undefined) {
769
+ this.setBubble(v);
770
+ return this;
771
+ };
772
+ return this._bubble;
773
+ };
774
+
775
+ Imba.Event.prototype.halt = function (){
776
+ this.setBubble(false);
777
+ return this;
778
+ };
779
+
780
+ Imba.Event.prototype.cancel = function (){
781
+ if (this.event().preventDefault) { this.event().preventDefault() };
782
+ return this;
783
+ };
784
+
785
+ Imba.Event.prototype.target = function (){
786
+ return tag$wrap(this.event()._target || this.event().target);
787
+ };
788
+
789
+ Imba.Event.prototype.redirect = function (node){
790
+ this._redirect = node;
791
+ return this;
792
+ };
793
+
794
+ Imba.Event.prototype.keychar = function (){
795
+ if (this.event() instanceof TextEvent) {
796
+ return this.event().data;
797
+ };
798
+
799
+ if (this.event() instanceof KeyboardEvent) {
800
+ var ki = this.event().keyIdentifier;
801
+ var sym = Imba.KEYMAP[this.event().keyCode];
802
+
803
+ // p 'keysym!',ki,sym
804
+
805
+ if (!sym && ki.substr(0,2) == "U+") {
806
+ sym = String.fromCharCode(parseInt(ki.substr(2),16));
807
+ };
808
+ return sym;
809
+ };
810
+
811
+ return null;
812
+ };
813
+
814
+ Imba.Event.prototype.keycombo = function (){
815
+ var sym;
816
+ if (!(sym = this.keychar())) { return };
817
+ sym = Imba.CHARMAP[sym] || sym;
818
+ var combo = [],e = this.event();
819
+ if (e.ctrlKey) { combo.push('ctrl') };
820
+ if (e.shiftKey) { combo.push('shift') };
821
+ if (e.altKey) { combo.push('alt') };
822
+ if (e.metaKey) { combo.push('cmd') };
823
+ combo.push(sym);
824
+ return combo.join("_").toLowerCase();
825
+ };
826
+
827
+ Imba.Event.prototype.process = function (){
828
+ var node;
829
+ var meth = ("on" + (this._prefix || '') + this.name());
830
+ var args = null;
831
+ var domtarget = this.event()._target || this.event().target;
832
+ // var node = <{domtarget:_responder or domtarget}>
833
+
834
+ var domnode = domtarget._responder || domtarget;
835
+ var rerouter = null;
836
+ var rerouted = false;
837
+ // need to stop infinite redirect-rules here??!?
838
+ var $1;while (domnode){
839
+ this._redirect = null;
840
+ if (node = tag$wrap(domnode)) { // not only tag
841
+
842
+ if ((typeof node[($1=meth)]=='string'||node[$1] instanceof String)) {
843
+ // should remember the receiver of the event
844
+ meth = node[meth];
845
+ continue;
846
+ };
847
+
848
+ if (node[meth] instanceof Array) {
849
+ args = node[meth].concat(node);
850
+ meth = args.shift();
851
+ continue;
852
+ };
853
+
854
+ if (node[meth] instanceof Function) {
855
+ var res = args ? (node[meth].apply(node,args)) : (node[meth](this,this.data()));
856
+ };
857
+ };
858
+
859
+ // log "hit?",domnode
860
+ // add node.nextEventResponder as a separate method here?
861
+ if (!(this.bubble() && (domnode = (this._redirect || (node ? (node.parent()) : (domnode.parentNode)))))) { break };
862
+ };
863
+
864
+ return this;
865
+ };
866
+
867
+ Imba.Event.prototype.x = function (){
868
+ return this.event().x;
869
+ };
870
+ Imba.Event.prototype.y = function (){
871
+ return this.event().y;
872
+ };
873
+ Imba.Event.prototype.which = function (){
874
+ return this.event().which;
875
+ };
876
+
877
+ Imba.EventManager = function EventManager(node,pars){
878
+ var self=this;
879
+ if(!pars||pars.constructor !== Object) pars = {};
880
+ var events = pars.events !== undefined ? pars.events : [];
881
+ self.setRoot(node);
882
+ self.setListeners([]);
883
+ self.setDelegators({});
884
+ self.setDelegator(function(e) {
885
+ // console.log "delegating event?! {e}"
886
+ self.delegate(e);
887
+ return true;
888
+ });
889
+
890
+ for (var i=0, ary=iter$(events), len=ary.length; i < len; i++) {
891
+ self.register(ary[i]);
892
+ };
893
+ self;
894
+ };
895
+
896
+
897
+ Imba.EventManager.prototype.__root = {name: 'root'};
898
+ Imba.EventManager.prototype.root = function(v){ return this._root; }
899
+ Imba.EventManager.prototype.setRoot = function(v){ this._root = v; return this; };
900
+
901
+ Imba.EventManager.prototype.__enabled = {'default': false,watch: 'enabledDidSet',name: 'enabled'};
902
+ Imba.EventManager.prototype.enabled = function(v){ return this._enabled; }
903
+ Imba.EventManager.prototype.setEnabled = function(v){
904
+ var a = this.enabled();
905
+ if(v != a) { v = this._enabled = v; }
906
+ if(v != a) { this.enabledDidSet && this.enabledDidSet(v,a,this.__enabled) }
907
+ return this;
908
+ }
909
+ Imba.EventManager.prototype._enabled = false;
910
+
911
+ Imba.EventManager.prototype.__listeners = {name: 'listeners'};
912
+ Imba.EventManager.prototype.listeners = function(v){ return this._listeners; }
913
+ Imba.EventManager.prototype.setListeners = function(v){ this._listeners = v; return this; };
914
+
915
+ Imba.EventManager.prototype.__delegators = {name: 'delegators'};
916
+ Imba.EventManager.prototype.delegators = function(v){ return this._delegators; }
917
+ Imba.EventManager.prototype.setDelegators = function(v){ this._delegators = v; return this; };
918
+
919
+ Imba.EventManager.prototype.__delegator = {name: 'delegator'};
920
+ Imba.EventManager.prototype.delegator = function(v){ return this._delegator; }
921
+ Imba.EventManager.prototype.setDelegator = function(v){ this._delegator = v; return this; };
922
+
923
+ Imba.EventManager.prototype.enabledDidSet = function (bool){
924
+ bool ? (this.onenable()) : (this.ondisable());
925
+ return this;
926
+ };
927
+
928
+
929
+ Imba.EventManager.prototype.register = function (name,handler){
930
+ if(handler === undefined) handler = true;
931
+ if (name instanceof Array) {
932
+ for (var i=0, ary=iter$(name), len=ary.length; i < len; i++) {
933
+ this.register(ary[i],handler);
934
+ };
935
+ return this;
936
+ };
937
+
938
+ if (this.delegators()[name]) { return this };
939
+ // console.log("register for event {name}")
940
+ var fn = this.delegators()[name] = handler instanceof Function ? (handler) : (this.delegator());
941
+ if (this.enabled()) { return this.root().addEventListener(name,fn,true) };
942
+ };
943
+
944
+ Imba.EventManager.prototype.listen = function (name,handler,capture){
945
+ if(capture === undefined) capture = true;
946
+ this.listeners().push([name,handler,capture]);
947
+ if (this.enabled()) { this.root().addEventListener(name,handler,capture) };
948
+ return this;
949
+ };
950
+
951
+ Imba.EventManager.prototype.delegate = function (e){
952
+ // console.log "delegate event {e and e:type}"
953
+ // really? wrap all events? Quite expensive unless we reuse them
954
+ var event = Imba.Event.wrap(e);
955
+ // console.log "delegate event {e:type}"
956
+ event.process();
957
+ // name = e:type.toLowerCase.replace(/\:/g,'')
958
+ // create our own event here?
959
+ return this;
960
+ };
961
+
962
+ Imba.EventManager.prototype.create = function (type,target,pars){
963
+ if(!pars||pars.constructor !== Object) pars = {};
964
+ var data = pars.data !== undefined ? pars.data : null;
965
+ var source = pars.source !== undefined ? pars.source : null;
966
+ var event = Imba.Event.wrap({type: type,target: target});
967
+ if (data) { (event.setData(data),data) };
968
+ if (source) { (event.setSource(source),source) };
969
+ return event;
970
+ };
971
+
972
+ // use create instead?
973
+ Imba.EventManager.prototype.trigger = function (type,target,pars){
974
+ if(!pars||pars.constructor !== Object) pars = {};
975
+ var data = pars.data !== undefined ? pars.data : null;
976
+ var source = pars.source !== undefined ? pars.source : null;
977
+ var event = Imba.Event.wrap({type: type,target: target});
978
+ if (data) { (event.setData(data),data) };
979
+ if (source) { (event.setSource(source),source) };
980
+ return event.process();
981
+ };
982
+
983
+ Imba.EventManager.prototype.emit = function (obj,event,data,pars){
984
+ // log "emit event for",obj,event,data
985
+ if(!pars||pars.constructor !== Object) pars = {};
986
+ var dom = pars.dom !== undefined ? pars.dom : true;
987
+ var ns = pars.ns !== undefined ? pars.ns : 'object';
988
+ var fn = ("on" + ns);
989
+ var nodes = DOC.querySelectorAll(("." + (obj.uid())));
990
+ for (var i=0, ary=iter$(nodes), len=ary.length, node; i < len; i++) {
991
+ // log "found node {node:className}"
992
+ node = ary[i];
993
+ if (node._tag && node._tag[fn]) {
994
+ node._tag[fn](event,data);
995
+ };
996
+ // now we simply link to onobject event
997
+ };
998
+ return this;
999
+ };
1000
+
1001
+ Imba.EventManager.prototype.onenable = function (){
1002
+ for (var o=this.delegators(), i=0, keys=Object.keys(o), l=keys.length; i < l; i++){
1003
+ this.root().addEventListener(keys[i],o[keys[i]],true);
1004
+ };
1005
+
1006
+ for (var j=0, ary=iter$(this.listeners()), len=ary.length, item; j < len; j++) {
1007
+ item = ary[j];
1008
+ this.root().addEventListener(item[0],item[1],item[2]);
1009
+ };
1010
+ return this;
1011
+ };
1012
+
1013
+ Imba.EventManager.prototype.ondisable = function (){
1014
+ for (var o=this.delegators(), i=0, keys=Object.keys(o), l=keys.length; i < l; i++){
1015
+ this.root().removeEventListener(keys[i],o[keys[i]],true);
1016
+ };
1017
+
1018
+ for (var j=0, ary=iter$(this.listeners()), len=ary.length, item; j < len; j++) {
1019
+ item = ary[j];
1020
+ this.root().removeEventListener(item[0],item[1],item[2]);
1021
+ };
1022
+ return this;
1023
+ };
1024
+
1025
+
1026
+ ED = Imba.Events = new Imba.EventManager(document,{events: [
1027
+ 'keydown','keyup','keypress','textInput','input','change','submit',
1028
+ 'focusin','focusout','blur','contextmenu',
1029
+ 'mousedown','mouseup','mousewheel',
1030
+ 'dblclick'
1031
+ ]});
1032
+
1033
+ if (hasTouchEvents) {
1034
+ ED.listen('touchstart',function(e) { return Imba.Touch.ontouchstart(e); });
1035
+ ED.listen('touchmove',function(e) { return Imba.Touch.ontouchmove(e); });
1036
+ ED.listen('touchend',function(e) { return Imba.Touch.ontouchend(e); });
1037
+ ED.listen('touchcancel',function(e) { return Imba.Touch.ontouchcancel(e); });
1038
+ } else {
1039
+ ED.listen('click',function(e) {
1040
+ return ED.trigger('tap',e.target); // no
1041
+ });
1042
+
1043
+ ED.listen('mousedown',function(e) {
1044
+ if (Imba.POINTER) { return Imba.POINTER.update(e).process() };
1045
+ });
1046
+
1047
+ ED.listen('mousemove',function(e) {
1048
+ if (Imba.POINTER) { return Imba.POINTER.update(e).process() }; // .process if touch # should not happen? We process through
1049
+ });
1050
+
1051
+ ED.listen('mouseup',function(e) {
1052
+ if (Imba.POINTER) { return Imba.POINTER.update(e).process() };
1053
+ });
1054
+ };
1055
+
1056
+ // enable immediately by default
1057
+ Imba.Events.setEnabled(true);
1058
+
1059
+ })()
1060
+ },{}],5:[function(require,module,exports){
1061
+ (function(){
1062
+
1063
+ // predefine all supported html tags
1064
+ Imba.extendTag('htmlelement', function(tag){
1065
+
1066
+
1067
+ tag.prototype.__id = {name: 'id'};
1068
+ tag.prototype.id = function(v){ return this.getAttribute('id'); }
1069
+ tag.prototype.setId = function(v){ this.setAttribute('id',v); return this; };
1070
+
1071
+ tag.prototype.__tabindex = {name: 'tabindex'};
1072
+ tag.prototype.tabindex = function(v){ return this.getAttribute('tabindex'); }
1073
+ tag.prototype.setTabindex = function(v){ this.setAttribute('tabindex',v); return this; };
1074
+
1075
+ tag.prototype.__title = {name: 'title'};
1076
+ tag.prototype.title = function(v){ return this.getAttribute('title'); }
1077
+ tag.prototype.setTitle = function(v){ this.setAttribute('title',v); return this; };
1078
+
1079
+ tag.prototype.__role = {name: 'role'};
1080
+ tag.prototype.role = function(v){ return this.getAttribute('role'); }
1081
+ tag.prototype.setRole = function(v){ this.setAttribute('role',v); return this; };
1082
+ });
1083
+
1084
+
1085
+ Imba.defineTag('fragment','htmlelement', function(tag){
1086
+
1087
+ tag.createNode = function (){
1088
+ return Imba.document().createDocumentFragment();
1089
+ };
1090
+ });
1091
+
1092
+ Imba.defineTag('a', function(tag){
1093
+
1094
+ tag.prototype.__href = {dom: true,name: 'href'};
1095
+ tag.prototype.href = function(v){ return this.getAttribute('href'); }
1096
+ tag.prototype.setHref = function(v){ this.setAttribute('href',v); return this; };
1097
+ });
1098
+
1099
+ Imba.defineTag('abbr');
1100
+ Imba.defineTag('address');
1101
+ Imba.defineTag('area');
1102
+ Imba.defineTag('article');
1103
+ Imba.defineTag('aside');
1104
+ Imba.defineTag('audio');
1105
+ Imba.defineTag('b');
1106
+ Imba.defineTag('base');
1107
+ Imba.defineTag('bdi');
1108
+ Imba.defineTag('bdo');
1109
+ Imba.defineTag('big');
1110
+ Imba.defineTag('blockquote');
1111
+ Imba.defineTag('body');
1112
+ Imba.defineTag('br');
1113
+
1114
+ Imba.defineTag('button', function(tag){
1115
+
1116
+ tag.prototype.__autofocus = {name: 'autofocus'};
1117
+ tag.prototype.autofocus = function(v){ return this.getAttribute('autofocus'); }
1118
+ tag.prototype.setAutofocus = function(v){ this.setAttribute('autofocus',v); return this; };
1119
+
1120
+ tag.prototype.__type = {dom: true,name: 'type'};
1121
+ tag.prototype.type = function(v){ return this.getAttribute('type'); }
1122
+ tag.prototype.setType = function(v){ this.setAttribute('type',v); return this; };
1123
+
1124
+ tag.prototype.__disabled = {dom: true,name: 'disabled'};
1125
+ tag.prototype.disabled = function(v){ return this.getAttribute('disabled'); }
1126
+ tag.prototype.setDisabled = function(v){ this.setAttribute('disabled',v); return this; };
1127
+ });
1128
+
1129
+ Imba.defineTag('canvas');
1130
+ Imba.defineTag('caption');
1131
+ Imba.defineTag('cite');
1132
+ Imba.defineTag('code');
1133
+ Imba.defineTag('col');
1134
+ Imba.defineTag('colgroup');
1135
+ Imba.defineTag('data');
1136
+ Imba.defineTag('datalist');
1137
+ Imba.defineTag('dd');
1138
+ Imba.defineTag('del');
1139
+ Imba.defineTag('details');
1140
+ Imba.defineTag('dfn');
1141
+ Imba.defineTag('div');
1142
+ Imba.defineTag('dl');
1143
+ Imba.defineTag('dt');
1144
+ Imba.defineTag('em');
1145
+ Imba.defineTag('embed');
1146
+ Imba.defineTag('fieldset');
1147
+ Imba.defineTag('figcaption');
1148
+ Imba.defineTag('figure');
1149
+ Imba.defineTag('footer');
1150
+
1151
+ Imba.defineTag('form', function(tag){
1152
+
1153
+ tag.prototype.__method = {dom: true,name: 'method'};
1154
+ tag.prototype.method = function(v){ return this.getAttribute('method'); }
1155
+ tag.prototype.setMethod = function(v){ this.setAttribute('method',v); return this; };
1156
+
1157
+ tag.prototype.__action = {dom: true,name: 'action'};
1158
+ tag.prototype.action = function(v){ return this.getAttribute('action'); }
1159
+ tag.prototype.setAction = function(v){ this.setAttribute('action',v); return this; };
1160
+ });
1161
+
1162
+ Imba.defineTag('h1');
1163
+ Imba.defineTag('h2');
1164
+ Imba.defineTag('h3');
1165
+ Imba.defineTag('h4');
1166
+ Imba.defineTag('h5');
1167
+ Imba.defineTag('h6');
1168
+ Imba.defineTag('head');
1169
+ Imba.defineTag('header');
1170
+ Imba.defineTag('hr');
1171
+ Imba.defineTag('html');
1172
+ Imba.defineTag('i');
1173
+
1174
+ Imba.defineTag('iframe', function(tag){
1175
+
1176
+ tag.prototype.__src = {name: 'src'};
1177
+ tag.prototype.src = function(v){ return this.getAttribute('src'); }
1178
+ tag.prototype.setSrc = function(v){ this.setAttribute('src',v); return this; };
1179
+ });
1180
+
1181
+ Imba.defineTag('img', function(tag){
1182
+
1183
+ tag.prototype.__src = {name: 'src'};
1184
+ tag.prototype.src = function(v){ return this.getAttribute('src'); }
1185
+ tag.prototype.setSrc = function(v){ this.setAttribute('src',v); return this; };
1186
+ });
1187
+
1188
+ Imba.defineTag('input', function(tag){
1189
+ // can use attr instead
1190
+
1191
+ tag.prototype.__name = {dom: true,name: 'name'};
1192
+ tag.prototype.name = function(v){ return this.getAttribute('name'); }
1193
+ tag.prototype.setName = function(v){ this.setAttribute('name',v); return this; };
1194
+
1195
+ tag.prototype.__type = {dom: true,name: 'type'};
1196
+ tag.prototype.type = function(v){ return this.getAttribute('type'); }
1197
+ tag.prototype.setType = function(v){ this.setAttribute('type',v); return this; };
1198
+
1199
+ tag.prototype.__value = {dom: true,name: 'value'};
1200
+ tag.prototype.value = function(v){ return this.getAttribute('value'); }
1201
+ tag.prototype.setValue = function(v){ this.setAttribute('value',v); return this; }; // dom property - NOT attribute
1202
+
1203
+ tag.prototype.__required = {dom: true,name: 'required'};
1204
+ tag.prototype.required = function(v){ return this.getAttribute('required'); }
1205
+ tag.prototype.setRequired = function(v){ this.setAttribute('required',v); return this; };
1206
+
1207
+ tag.prototype.__disabled = {dom: true,name: 'disabled'};
1208
+ tag.prototype.disabled = function(v){ return this.getAttribute('disabled'); }
1209
+ tag.prototype.setDisabled = function(v){ this.setAttribute('disabled',v); return this; };
1210
+
1211
+ tag.prototype.__placeholder = {dom: true,name: 'placeholder'};
1212
+ tag.prototype.placeholder = function(v){ return this.getAttribute('placeholder'); }
1213
+ tag.prototype.setPlaceholder = function(v){ this.setAttribute('placeholder',v); return this; };
1214
+
1215
+
1216
+ tag.prototype.__autofocus = {name: 'autofocus'};
1217
+ tag.prototype.autofocus = function(v){ return this.getAttribute('autofocus'); }
1218
+ tag.prototype.setAutofocus = function(v){ this.setAttribute('autofocus',v); return this; };
1219
+
1220
+ tag.prototype.value = function (){
1221
+ return this.dom().value;
1222
+ };
1223
+
1224
+ tag.prototype.setValue = function (v){
1225
+ if (v != this.dom().value) { this.dom().value = v };
1226
+ return this;
1227
+ };
1228
+
1229
+ tag.prototype.checked = function (){
1230
+ return this.dom().checked;
1231
+ };
1232
+
1233
+ tag.prototype.setChecked = function (bool){
1234
+ if (bool != this.dom().checked) { this.dom().checked = bool };
1235
+ return this;
1236
+ };
1237
+ });
1238
+
1239
+ Imba.defineTag('ins');
1240
+ Imba.defineTag('kbd');
1241
+ Imba.defineTag('keygen');
1242
+ Imba.defineTag('label');
1243
+ Imba.defineTag('legend');
1244
+ Imba.defineTag('li');
1245
+
1246
+ Imba.defineTag('link', function(tag){
1247
+
1248
+ tag.prototype.__rel = {dom: true,name: 'rel'};
1249
+ tag.prototype.rel = function(v){ return this.getAttribute('rel'); }
1250
+ tag.prototype.setRel = function(v){ this.setAttribute('rel',v); return this; };
1251
+
1252
+ tag.prototype.__type = {dom: true,name: 'type'};
1253
+ tag.prototype.type = function(v){ return this.getAttribute('type'); }
1254
+ tag.prototype.setType = function(v){ this.setAttribute('type',v); return this; };
1255
+
1256
+ tag.prototype.__href = {dom: true,name: 'href'};
1257
+ tag.prototype.href = function(v){ return this.getAttribute('href'); }
1258
+ tag.prototype.setHref = function(v){ this.setAttribute('href',v); return this; };
1259
+
1260
+ tag.prototype.__media = {dom: true,name: 'media'};
1261
+ tag.prototype.media = function(v){ return this.getAttribute('media'); }
1262
+ tag.prototype.setMedia = function(v){ this.setAttribute('media',v); return this; };
1263
+ });
1264
+
1265
+ Imba.defineTag('main');
1266
+ Imba.defineTag('map');
1267
+ Imba.defineTag('mark');
1268
+ Imba.defineTag('menu');
1269
+ Imba.defineTag('menuitem');
1270
+
1271
+ Imba.defineTag('meta', function(tag){
1272
+
1273
+ tag.prototype.__name = {dom: true,name: 'name'};
1274
+ tag.prototype.name = function(v){ return this.getAttribute('name'); }
1275
+ tag.prototype.setName = function(v){ this.setAttribute('name',v); return this; };
1276
+
1277
+ tag.prototype.__content = {dom: true,name: 'content'};
1278
+ tag.prototype.content = function(v){ return this.getAttribute('content'); }
1279
+ tag.prototype.setContent = function(v){ this.setAttribute('content',v); return this; };
1280
+
1281
+ tag.prototype.__charset = {dom: true,name: 'charset'};
1282
+ tag.prototype.charset = function(v){ return this.getAttribute('charset'); }
1283
+ tag.prototype.setCharset = function(v){ this.setAttribute('charset',v); return this; };
1284
+ });
1285
+
1286
+ Imba.defineTag('meter');
1287
+ Imba.defineTag('nav');
1288
+ Imba.defineTag('noscript');
1289
+ Imba.defineTag('object');
1290
+ Imba.defineTag('ol');
1291
+ Imba.defineTag('optgroup');
1292
+
1293
+ Imba.defineTag('option', function(tag){
1294
+
1295
+ tag.prototype.__value = {dom: true,name: 'value'};
1296
+ tag.prototype.value = function(v){ return this.getAttribute('value'); }
1297
+ tag.prototype.setValue = function(v){ this.setAttribute('value',v); return this; };
1298
+ });
1299
+
1300
+ Imba.defineTag('output');
1301
+ Imba.defineTag('p');
1302
+ Imba.defineTag('param');
1303
+ Imba.defineTag('pre');
1304
+ Imba.defineTag('progress');
1305
+ Imba.defineTag('q');
1306
+ Imba.defineTag('rp');
1307
+ Imba.defineTag('rt');
1308
+ Imba.defineTag('ruby');
1309
+ Imba.defineTag('s');
1310
+ Imba.defineTag('samp');
1311
+
1312
+ Imba.defineTag('script', function(tag){
1313
+
1314
+ tag.prototype.__src = {dom: true,name: 'src'};
1315
+ tag.prototype.src = function(v){ return this.getAttribute('src'); }
1316
+ tag.prototype.setSrc = function(v){ this.setAttribute('src',v); return this; };
1317
+
1318
+ tag.prototype.__type = {dom: true,name: 'type'};
1319
+ tag.prototype.type = function(v){ return this.getAttribute('type'); }
1320
+ tag.prototype.setType = function(v){ this.setAttribute('type',v); return this; };
1321
+ });
1322
+
1323
+ Imba.defineTag('section');
1324
+
1325
+ Imba.defineTag('select', function(tag){
1326
+
1327
+ tag.prototype.__multiple = {dom: true,name: 'multiple'};
1328
+ tag.prototype.multiple = function(v){ return this.getAttribute('multiple'); }
1329
+ tag.prototype.setMultiple = function(v){ this.setAttribute('multiple',v); return this; };
1330
+
1331
+ tag.prototype.value = function (){
1332
+ return this.dom().value;
1333
+ };
1334
+
1335
+ tag.prototype.setValue = function (v){
1336
+ if (v != this.dom().value) { this.dom().value = v };
1337
+ return this;
1338
+ };
1339
+ });
1340
+
1341
+
1342
+ Imba.defineTag('small');
1343
+ Imba.defineTag('source');
1344
+ Imba.defineTag('span');
1345
+ Imba.defineTag('strong');
1346
+ Imba.defineTag('style');
1347
+ Imba.defineTag('sub');
1348
+ Imba.defineTag('summary');
1349
+ Imba.defineTag('sup');
1350
+ Imba.defineTag('table');
1351
+ Imba.defineTag('tbody');
1352
+ Imba.defineTag('td');
1353
+
1354
+ Imba.defineTag('textarea', function(tag){
1355
+
1356
+ tag.prototype.__name = {dom: true,name: 'name'};
1357
+ tag.prototype.name = function(v){ return this.getAttribute('name'); }
1358
+ tag.prototype.setName = function(v){ this.setAttribute('name',v); return this; };
1359
+
1360
+ tag.prototype.__disabled = {dom: true,name: 'disabled'};
1361
+ tag.prototype.disabled = function(v){ return this.getAttribute('disabled'); }
1362
+ tag.prototype.setDisabled = function(v){ this.setAttribute('disabled',v); return this; };
1363
+
1364
+ tag.prototype.__required = {dom: true,name: 'required'};
1365
+ tag.prototype.required = function(v){ return this.getAttribute('required'); }
1366
+ tag.prototype.setRequired = function(v){ this.setAttribute('required',v); return this; };
1367
+
1368
+ tag.prototype.__placeholder = {dom: true,name: 'placeholder'};
1369
+ tag.prototype.placeholder = function(v){ return this.getAttribute('placeholder'); }
1370
+ tag.prototype.setPlaceholder = function(v){ this.setAttribute('placeholder',v); return this; };
1371
+
1372
+ tag.prototype.__value = {dom: true,name: 'value'};
1373
+ tag.prototype.value = function(v){ return this.getAttribute('value'); }
1374
+ tag.prototype.setValue = function(v){ this.setAttribute('value',v); return this; };
1375
+
1376
+ tag.prototype.__rows = {dom: true,name: 'rows'};
1377
+ tag.prototype.rows = function(v){ return this.getAttribute('rows'); }
1378
+ tag.prototype.setRows = function(v){ this.setAttribute('rows',v); return this; };
1379
+
1380
+ tag.prototype.__cols = {dom: true,name: 'cols'};
1381
+ tag.prototype.cols = function(v){ return this.getAttribute('cols'); }
1382
+ tag.prototype.setCols = function(v){ this.setAttribute('cols',v); return this; };
1383
+
1384
+
1385
+ tag.prototype.__autofocus = {name: 'autofocus'};
1386
+ tag.prototype.autofocus = function(v){ return this.getAttribute('autofocus'); }
1387
+ tag.prototype.setAutofocus = function(v){ this.setAttribute('autofocus',v); return this; };
1388
+
1389
+ tag.prototype.value = function (){
1390
+ return this.dom().value;
1391
+ };
1392
+
1393
+ tag.prototype.setValue = function (v){
1394
+ if (v != this.dom().value) { this.dom().value = v };
1395
+ return this;
1396
+ };
1397
+ });
1398
+
1399
+ Imba.defineTag('tfoot');
1400
+ Imba.defineTag('th');
1401
+ Imba.defineTag('thead');
1402
+ Imba.defineTag('time');
1403
+ Imba.defineTag('title');
1404
+ Imba.defineTag('tr');
1405
+ Imba.defineTag('track');
1406
+ Imba.defineTag('u');
1407
+ Imba.defineTag('ul');
1408
+ Imba.defineTag('video');
1409
+ Imba.defineTag('wbr');
1410
+
1411
+ })()
1412
+ },{}],6:[function(require,module,exports){
1413
+ (function (global){
1414
+ (function(){
1415
+ function idx$(a,b){
1416
+ return (b && b.indexOf) ? b.indexOf(a) : [].indexOf.call(a,b);
1417
+ };
1418
+
1419
+ // helper for subclassing
1420
+ function subclass$(obj,sup) {
1421
+ for (var k in sup) {
1422
+ if (sup.hasOwnProperty(k)) obj[k] = sup[k];
1423
+ };
1424
+ // obj.__super__ = sup;
1425
+ obj.prototype = Object.create(sup.prototype);
1426
+ obj.__super__ = obj.prototype.__super__ = sup.prototype;
1427
+ obj.prototype.initialize = obj.prototype.constructor = obj;
1428
+ };
1429
+
1430
+ function iter$(a){ return a ? (a.toArray ? a.toArray() : a) : []; };
1431
+
1432
+ var svgSupport = typeof SVGElement !== 'undefined';
1433
+
1434
+ Imba.document = function (){
1435
+ return window.document;
1436
+ };
1437
+
1438
+ Imba.static = function (items,nr){
1439
+ items.static = nr;
1440
+ return items;
1441
+ };
1442
+
1443
+
1444
+ function ElementTag(dom){
1445
+ this.setDom(dom);
1446
+ this;
1447
+ };
1448
+
1449
+ global.ElementTag = ElementTag; // global class
1450
+
1451
+ ElementTag.prototype.__object = {name: 'object'};
1452
+ ElementTag.prototype.object = function(v){ return this._object; }
1453
+ ElementTag.prototype.setObject = function(v){ this._object = v; return this; };
1454
+
1455
+ ElementTag.prototype.dom = function (){
1456
+ return this._dom;
1457
+ };
1458
+
1459
+ ElementTag.prototype.setDom = function (dom){
1460
+ dom._tag = this;
1461
+ this._dom = dom;
1462
+ return this;
1463
+ };
1464
+
1465
+ ElementTag.prototype.setRef = function (ref){
1466
+ this.flag(this._ref = ref);
1467
+ return this;
1468
+ };
1469
+
1470
+ ElementTag.prototype.setHandler = function (event,handler,ctx){
1471
+ var key = 'on' + event;
1472
+
1473
+ if (handler instanceof Function) {
1474
+ this[key] = handler;
1475
+ } else if (handler instanceof Array) {
1476
+ var fn = handler.shift();
1477
+ this[key] = function(e) { return ctx[fn].apply(ctx,handler.concat(e)); };
1478
+ } else {
1479
+ this[key] = function(e) { return ctx[handler](e); };
1480
+ };
1481
+ return this;
1482
+ };
1483
+
1484
+ ElementTag.prototype.setId = function (id){
1485
+ this.dom().id = id;
1486
+ return this;
1487
+ };
1488
+
1489
+ ElementTag.prototype.id = function (){
1490
+ return this.dom().id;
1491
+ };
1492
+
1493
+ ElementTag.prototype.setAttribute = function (key,new$){
1494
+ var old = this.dom().getAttribute(key);
1495
+
1496
+ if (old == new$) {
1497
+ return new$;
1498
+ } else if (new$ != null && new$ !== false) {
1499
+ return this.dom().setAttribute(key,new$);
1500
+ } else {
1501
+ return this.dom().removeAttribute(key);
1502
+ };
1503
+ };
1504
+
1505
+ ElementTag.prototype.removeAttribute = function (key){
1506
+ return this.dom().removeAttribute(key);
1507
+ };
1508
+
1509
+ ElementTag.prototype.getAttribute = function (key){
1510
+ return this.dom().getAttribute(key);
1511
+ };
1512
+
1513
+ ElementTag.prototype.setContent = function (content){
1514
+ this.setChildren(content); // override?
1515
+ return this;
1516
+ };
1517
+
1518
+ ElementTag.prototype.setChildren = function (nodes){
1519
+ this._empty ? (this.append(nodes)) : (this.empty().append(nodes));
1520
+ this._children = null;
1521
+ return this;
1522
+ };
1523
+
1524
+ ElementTag.prototype.text = function (v){
1525
+ if (arguments.length) { return ((this.setText(v),v),this) };
1526
+ return this._dom.textContent;
1527
+ };
1528
+
1529
+ ElementTag.prototype.setText = function (txt){
1530
+ this._empty = false;
1531
+ this._dom.textContent = txt == null ? (txt = "") : (txt);
1532
+ return this;
1533
+ };
1534
+
1535
+ ElementTag.prototype.empty = function (){
1536
+ while (this._dom.firstChild){
1537
+ this._dom.removeChild(this._dom.firstChild);
1538
+ };
1539
+ this._children = null;
1540
+ this._empty = true;
1541
+ return this;
1542
+ };
1543
+
1544
+ ElementTag.prototype.remove = function (node){
1545
+ var par = this.dom();
1546
+ var el = node && node.dom();
1547
+ if (el && el.parentNode == par) { par.removeChild(el) };
1548
+ return this;
1549
+ };
1550
+
1551
+ ElementTag.prototype.parent = function (){
1552
+ return tag$wrap(this.dom().parentNode);
1553
+ };
1554
+
1555
+
1556
+ ElementTag.prototype.log = function (){
1557
+ var $0 = arguments, i = $0.length;
1558
+ var args = new Array(i>0 ? i : 0);
1559
+ while(i>0) args[i-1] = $0[--i];
1560
+ args.unshift(console);
1561
+ Function.prototype.call.apply(console.log,args);
1562
+ return this;
1563
+ };
1564
+
1565
+ ElementTag.prototype.emit = function (name,pars){
1566
+ if(!pars||pars.constructor !== Object) pars = {};
1567
+ var data = pars.data !== undefined ? pars.data : null;
1568
+ var bubble = pars.bubble !== undefined ? pars.bubble : true;
1569
+ Imba.Events.trigger(name,this,{data: data,bubble: bubble});
1570
+ return this;
1571
+ };
1572
+
1573
+ ElementTag.prototype.css = function (key,val){
1574
+ if (key instanceof Object) {
1575
+ for (var i=0, keys=Object.keys(key), l=keys.length; i < l; i++){
1576
+ this.css(keys[i],key[keys[i]]);
1577
+ };
1578
+ } else if (val == null) {
1579
+ this.dom().style.removeProperty(key);
1580
+ } else if (val == undefined) {
1581
+ return this.dom().style[key];
1582
+ } else {
1583
+ if ((typeof val=='number'||val instanceof Number) && key.match(/width|height|left|right|top|bottom/)) {
1584
+ val = val + "px";
1585
+ };
1586
+ this.dom().style[key] = val;
1587
+ };
1588
+ return this;
1589
+ };
1590
+
1591
+ // selectors / traversal
1592
+ ElementTag.prototype.find = function (sel){
1593
+ return new Imba.Selector(sel,this);
1594
+ };
1595
+
1596
+ ElementTag.prototype.first = function (sel){
1597
+ return sel ? (this.find(sel).first()) : (tag$wrap(this.dom().firstElementChild));
1598
+ };
1599
+
1600
+ ElementTag.prototype.last = function (sel){
1601
+ return sel ? (this.find(sel).last()) : (tag$wrap(this.dom().lastElementChild));
1602
+ };
1603
+
1604
+ ElementTag.prototype.child = function (i){
1605
+ return tag$wrap(this.dom().children[i || 0]);
1606
+ };
1607
+
1608
+ ElementTag.prototype.children = function (sel){
1609
+ var nodes = new Imba.Selector(null,this,this._dom.children);
1610
+ return sel ? (nodes.filter(sel)) : (nodes);
1611
+ };
1612
+
1613
+ ElementTag.prototype.orphanize = function (){
1614
+ var par;
1615
+ if (par = this.dom().parentNode) { par.removeChild(this._dom) };
1616
+ return this;
1617
+ };
1618
+
1619
+ ElementTag.prototype.matches = function (sel){
1620
+ var fn;
1621
+ if (sel instanceof Function) {
1622
+ return sel(this);
1623
+ };
1624
+
1625
+ if (sel.query) { sel = sel.query() };
1626
+ if (fn = (this._dom.webkitMatchesSelector || this._dom.matches)) { return fn.call(this._dom,sel) };
1627
+ // TODO support other browsers etc?
1628
+ };
1629
+
1630
+ ElementTag.prototype.closest = function (sel){
1631
+ if (!sel) { return this.parent() }; // should return self?!
1632
+ var node = this;
1633
+ if (sel.query) { sel = sel.query() };
1634
+
1635
+ while (node){
1636
+ if (node.matches(sel)) { return node };
1637
+ node = node.parent();
1638
+ };
1639
+ return null;
1640
+ };
1641
+
1642
+ ElementTag.prototype.path = function (sel){
1643
+ var node = this;
1644
+ var nodes = [];
1645
+ if (sel && sel.query) { sel = sel.query() };
1646
+
1647
+ while (node){
1648
+ if (!sel || node.matches(sel)) { nodes.push(node) };
1649
+ node = node.parent();
1650
+ };
1651
+ return nodes;
1652
+ };
1653
+
1654
+ ElementTag.prototype.parents = function (sel){
1655
+ var par = this.parent();
1656
+ return par ? (par.path(sel)) : ([]);
1657
+ };
1658
+
1659
+ ElementTag.prototype.up = function (sel){
1660
+ if (!sel) { return this.parent() };
1661
+ return this.parent() && this.parent().closest(sel);
1662
+ };
1663
+
1664
+ ElementTag.prototype.siblings = function (sel){
1665
+ var par, self=this;
1666
+ if (!(par = this.parent())) { return [] }; // FIXME
1667
+ var ary = this.dom().parentNode.children;
1668
+ var nodes = new Imba.Selector(null,this,ary);
1669
+ return nodes.filter(function(n) { return n != self && (!sel || n.matches(sel)); });
1670
+ };
1671
+
1672
+ ElementTag.prototype.next = function (sel){
1673
+ if (sel) {
1674
+ var el = this;
1675
+ while (el = el.next()){
1676
+ if (el.matches(sel)) { return el };
1677
+ };
1678
+ return null;
1679
+ };
1680
+ return tag$wrap(this.dom().nextElementSibling);
1681
+ };
1682
+
1683
+ ElementTag.prototype.prev = function (sel){
1684
+ if (sel) {
1685
+ var el = this;
1686
+ while (el = el.prev()){
1687
+ if (el.matches(sel)) { return el };
1688
+ };
1689
+ return null;
1690
+ };
1691
+ return tag$wrap(this.dom().previousElementSibling);
1692
+ };
1693
+
1694
+ ElementTag.prototype.contains = function (node){
1695
+ return this.dom().contains(node && node._dom || node);
1696
+ };
1697
+
1698
+ ElementTag.prototype.index = function (){
1699
+ var i = 0;
1700
+ var el = this.dom();
1701
+ while (el.previousSibling){
1702
+ el = el.previousSibling;
1703
+ i++;
1704
+ };
1705
+ return i;
1706
+ };
1707
+
1708
+
1709
+ ElementTag.prototype.insert = function (node,pars){
1710
+ if(!pars||pars.constructor !== Object) pars = {};
1711
+ var before = pars.before !== undefined ? pars.before : null;
1712
+ var after = pars.after !== undefined ? pars.after : null;
1713
+ if (after) { before = after.next() };
1714
+ if (node instanceof Array) {
1715
+ node = (t$('fragment').setContent(node).end());
1716
+ };
1717
+ if (before) {
1718
+ this.dom().insertBefore(node.dom(),before.dom());
1719
+ } else {
1720
+ this.append(node);
1721
+ };
1722
+ return this;
1723
+ };
1724
+
1725
+
1726
+ // bind / present
1727
+ // should deprecate / remove
1728
+ ElementTag.prototype.bind = function (obj){
1729
+ this.setObject(obj);
1730
+ return this;
1731
+ };
1732
+
1733
+ ElementTag.prototype.render = function (){
1734
+ return this;
1735
+ };
1736
+
1737
+ ElementTag.prototype.build = function (){
1738
+ this.render();
1739
+ return this;
1740
+ };
1741
+
1742
+ ElementTag.prototype.commit = function (){
1743
+ return this;
1744
+ };
1745
+
1746
+ ElementTag.prototype.end = function (){
1747
+ if (this._built) {
1748
+ this.commit();
1749
+ } else {
1750
+ this._built = true;
1751
+ this.build();
1752
+ };
1753
+ return this;
1754
+ };
1755
+
1756
+ // called whenever a node has rendered itself like in <self> <div> ...
1757
+ ElementTag.prototype.synced = function (){
1758
+ return this;
1759
+ };
1760
+
1761
+ // called when the node is awakened in the dom - either automatically
1762
+ // upon attachment to the dom-tree, or the first time imba needs the
1763
+ // tag for a domnode that has been rendered on the server
1764
+ ElementTag.prototype.awaken = function (){
1765
+ return this;
1766
+ };
1767
+
1768
+ ElementTag.prototype.focus = function (){
1769
+ this.dom().focus();
1770
+ return this;
1771
+ };
1772
+
1773
+ ElementTag.prototype.blur = function (){
1774
+ this.dom().blur();
1775
+ return this;
1776
+ };
1777
+
1778
+ ElementTag.prototype.template = function (){
1779
+ return null;
1780
+ };
1781
+
1782
+ ElementTag.prototype.prepend = function (item){
1783
+ return this.insert(item,{before: this.first()});
1784
+ };
1785
+
1786
+ ElementTag.prototype.append = function (item){
1787
+ // possible to append blank
1788
+ // possible to simplify on server?
1789
+ if (!item) { return this };
1790
+
1791
+ if (item instanceof Array) {
1792
+ for (var i=0, ary=iter$(item), len=ary.length, member; i < len; i++) {
1793
+ member = ary[i];
1794
+ member && this.append(member);
1795
+ };
1796
+ } else if ((typeof item=='string'||item instanceof String) || (typeof item=='number'||item instanceof Number)) {
1797
+ var node = Imba.document().createTextNode(item);
1798
+ this._dom.appendChild(node);
1799
+ if (this._empty) { this._empty = false };
1800
+ } else {
1801
+ this._dom.appendChild(item._dom || item);
1802
+ if (this._empty) { this._empty = false };
1803
+ };
1804
+
1805
+ return this;
1806
+ };
1807
+
1808
+
1809
+ ElementTag.prototype.insertBefore = function (node,rel){
1810
+ if ((typeof node=='string'||node instanceof String)) { node = Imba.document().createTextNode(node) };
1811
+ if (node && rel) { this.dom().insertBefore((node._dom || node),(rel._dom || rel)) };
1812
+ return this;
1813
+ };
1814
+
1815
+ ElementTag.prototype.appendChild = function (node){
1816
+ if ((typeof node=='string'||node instanceof String)) { node = Imba.document().createTextNode(node) };
1817
+ if (node) { this.dom().appendChild(node._dom || node) };
1818
+ return this;
1819
+ };
1820
+
1821
+ ElementTag.prototype.removeChild = function (node){
1822
+ if (node) { this.dom().removeChild(node._dom || node) };
1823
+ return this;
1824
+ };
1825
+
1826
+ ElementTag.prototype.toString = function (){
1827
+ return this._dom.toString(); // really?
1828
+ };
1829
+
1830
+ ElementTag.prototype.classes = function (){
1831
+ return this._dom.classList;
1832
+ };
1833
+
1834
+ ElementTag.prototype.flags = function (){
1835
+ return this._dom.classList;
1836
+ };
1837
+
1838
+ ElementTag.prototype.flag = function (ref,toggle){
1839
+ // it is most natural to treat a second undefined argument as a no-switch
1840
+ // so we need to check the arguments-length
1841
+ if (arguments.length == 2 && !toggle) {
1842
+ this._dom.classList.remove(ref);
1843
+ } else {
1844
+ this._dom.classList.add(ref);
1845
+ };
1846
+ return this;
1847
+ };
1848
+
1849
+ ElementTag.prototype.unflag = function (ref){
1850
+ this._dom.classList.remove(ref);
1851
+ return this;
1852
+ };
1853
+
1854
+ ElementTag.prototype.toggleFlag = function (ref){
1855
+ this._dom.classList.toggle(ref);
1856
+ return this;
1857
+ };
1858
+
1859
+ ElementTag.prototype.hasFlag = function (ref){
1860
+ return this._dom.classList.contains(ref);
1861
+ };
1862
+
1863
+ ElementTag.dom = function (){
1864
+ if (this._dom) { return this._dom };
1865
+
1866
+ var dom;
1867
+ var sup = this.__super__.constructor;
1868
+ var proto = this.prototype;
1869
+
1870
+ // should clone the parent no?
1871
+ if (this._isNative) {
1872
+ this._dom = dom = Imba.document().createElement(this._nodeType);
1873
+ } else if (this._nodeType != sup._nodeType) {
1874
+ this._dom = dom = Imba.document().createElement(this._nodeType);
1875
+ for (var i=0, ary=iter$(sup.dom()), len=ary.length, atr; i < len; i++) {
1876
+ atr = ary[i];
1877
+ dom.setAttribute(atr.name,atr.value);
1878
+ };
1879
+ // dom:className = sup.dom:className
1880
+ // what about default attributes?
1881
+ } else {
1882
+ this._dom = dom = sup.dom().cloneNode(false);
1883
+ };
1884
+
1885
+ // should be a way to use a native domtype without precreating the doc
1886
+ // and still keeping the classes?
1887
+ if (this._domFlags) {
1888
+ for (var i=0, ary=iter$(this._domFlags), len=ary.length; i < len; i++) {
1889
+ proto.flag.call(this,ary[i]);
1890
+ };
1891
+ };
1892
+
1893
+ return this._dom;
1894
+ };
1895
+
1896
+
1897
+ // we really ought to optimize this
1898
+ ElementTag.createNode = function (flags,id){
1899
+ var proto = this._dom || this.dom();
1900
+ var dom = proto.cloneNode(false);
1901
+ return dom;
1902
+ };
1903
+
1904
+ ElementTag.flag = function (flag){
1905
+ // should redirect to the prototype with a dom-node already set?
1906
+ this.dom().classList.add(flag);
1907
+ return this;
1908
+ };
1909
+
1910
+ ElementTag.unflag = function (flag){
1911
+ this.dom().classList.remove(flag);
1912
+ return this;
1913
+ };
1914
+
1915
+ ElementTag.createNode = function (flags,id){
1916
+ var proto = this._dom || this.dom();
1917
+ var dom = proto.cloneNode(false);
1918
+ return dom;
1919
+ };
1920
+
1921
+ ElementTag.prototype.initialize = ElementTag;
1922
+
1923
+ function HTMLElementTag(){ return ElementTag.apply(this,arguments) };
1924
+
1925
+ subclass$(HTMLElementTag,ElementTag);
1926
+
1927
+
1928
+ function SVGElementTag(){ return ElementTag.apply(this,arguments) };
1929
+
1930
+ subclass$(SVGElementTag,ElementTag);
1931
+
1932
+
1933
+
1934
+ HTML_TAGS = "a abbr address area article aside audio b base bdi bdo big blockquote body br button canvas caption cite code col colgroup data datalist dd del details dfn div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hr html i iframe img input ins kbd keygen label legend li link main map mark menu menuitem meta meter nav noscript object ol optgroup option output p param pre progress q rp rt ruby s samp script section select small source span strong style sub summary sup table tbody td textarea tfoot th thead time title tr track u ul var video wbr".split(" ");
1935
+ HTML_TAGS_UNSAFE = "article aside header section".split(" ");
1936
+ SVG_TAGS = "circle defs ellipse g line linearGradient mask path pattern polygon polyline radialGradient rect stop svg text tspan".split(" ");
1937
+
1938
+ Imba.TAGS = {
1939
+ element: ElementTag,
1940
+ htmlelement: HTMLElementTag,
1941
+ svgelement: SVGElementTag
1942
+ };
1943
+
1944
+ Imba.SINGLETONS = {};
1945
+ IMBA_TAGS = Imba.TAGS;
1946
+
1947
+ function extender(obj,sup){
1948
+ for (var i=0, keys=Object.keys(sup), l=keys.length; i < l; i++){
1949
+ obj[keys[i]] = sup[keys[i]];
1950
+ };
1951
+
1952
+ obj.prototype = Object.create(sup.prototype);
1953
+ obj.__super__ = obj.prototype.__super__ = sup.prototype;
1954
+ obj.prototype.initialize = obj.prototype.constructor = obj;
1955
+ return obj;
1956
+ };
1957
+
1958
+ Imba.defineTag = function (name,supr,body){
1959
+ if(body==undefined && typeof supr == 'function') body = supr,supr = '';
1960
+ var m = name.split("$");
1961
+ var name = m[0];
1962
+ var ns = m[1];
1963
+
1964
+ supr || (supr = (idx$(name,HTML_TAGS) >= 0) ? ('htmlelement') : ('div'));
1965
+
1966
+ var suprklass = Imba.TAGS[supr];
1967
+
1968
+ var fname = name == 'var' ? ('vartag') : (name);
1969
+ // should drop this in production / optimized mode, but for debug
1970
+ // we create a constructor with a recognizeable name
1971
+ var Tag = new Function(("return function " + (fname.replace(/[\s\-\:]/g,'_')) + "(dom)\{ this.setDom(dom); \}"))();
1972
+ // var Tag = do |dom| this.setDom(dom)
1973
+ var klass = Tag;
1974
+
1975
+ extender(klass,suprklass);
1976
+
1977
+ klass._nodeType = suprklass._nodeType || name;
1978
+ klass._name = name;
1979
+ klass._ns = ns;
1980
+
1981
+ // add the classes -- if this is not a basic native node?
1982
+ if (klass._nodeType != name) {
1983
+ klass._nodeFlag = "_" + name.replace(/_/g,'-');
1984
+ var nc = suprklass._nodeClass;
1985
+ nc = nc ? (nc.split(/\s+/g)) : ([]);
1986
+ var c = null;
1987
+ if (ns && idx$(c,nc) == -1) { nc.push(c = ("" + ns + "_")) };
1988
+ if (!(idx$(c,nc) >= 0)) { nc.push(c = klass._nodeFlag) };
1989
+ klass._nodeClass = nc.join(" ");
1990
+ klass._domFlags = nc;
1991
+ klass._isNative = false;
1992
+ } else {
1993
+ klass._isNative = true;
1994
+ };
1995
+
1996
+ klass._dom = null;
1997
+ klass.prototype._nodeType = klass._nodeType;
1998
+ klass.prototype._dom = null;
1999
+ klass.prototype._built = false;
2000
+ klass.prototype._empty = true;
2001
+ // add the default flags / classes for ns etc
2002
+ // if namespaced -- this is dangerous
2003
+ if (!ns) { Imba.TAGS[name] = klass };
2004
+ Imba.TAGS[("" + name + "$" + (ns || 'html'))] = klass;
2005
+
2006
+ // create the global shortcut for tag init as well
2007
+ if (body) { body.call(klass,klass,klass.prototype) };
2008
+ return klass;
2009
+ };
2010
+
2011
+ Imba.defineSingletonTag = function (id,supr,body){
2012
+
2013
+ if(body==undefined && typeof supr == 'function') body = supr,supr = '';
2014
+ var superklass = Imba.TAGS[supr || 'div'];
2015
+
2016
+ // should drop this in production / optimized mode, but for debug
2017
+ // we create a constructor with a recognizeable name
2018
+ var fun = new Function(("return function " + (id.replace(/[\s\-\:]/g,'_')) + "(dom)\{ this.setDom(dom); \}"));
2019
+ var singleton = fun();
2020
+
2021
+ var klass = extender(singleton,superklass);
2022
+
2023
+ klass._id = id;
2024
+ klass._ns = superklass._ns;
2025
+ klass._nodeType = superklass._nodeType;
2026
+ klass._nodeClass = superklass._nodeClass;
2027
+ klass._domFlags = superklass._domFlags;
2028
+ klass._isNative = false;
2029
+
2030
+ klass._dom = null;
2031
+ klass._instance = null;
2032
+ klass.prototype._dom = null;
2033
+ klass.prototype._built = false;
2034
+ klass.prototype._empty = true;
2035
+
2036
+ // add the default flags / classes for ns etc
2037
+ // if namespaced -- this is dangerous
2038
+ // console.log('registered singleton')
2039
+ Imba.SINGLETONS[id] = klass;
2040
+ if (body) { body.call(klass,klass,klass.prototype) };
2041
+ return klass;
2042
+ };
2043
+
2044
+ Imba.extendTag = function (name,body){
2045
+ var klass = ((typeof name=='string'||name instanceof String) ? (Imba.TAGS[name]) : (name));
2046
+ if (body) { body && body.call(klass,klass,klass.prototype) };
2047
+ return klass;
2048
+ };
2049
+
2050
+ Imba.tag = function (name){
2051
+ var typ = Imba.TAGS[name];
2052
+ return new typ(typ.createNode());
2053
+ };
2054
+
2055
+ Imba.tagWithId = function (name,id){
2056
+ var typ = Imba.TAGS[name];
2057
+ var dom = typ.createNode();
2058
+ dom.id = id;
2059
+ return new typ(dom);
2060
+ };
2061
+
2062
+ Imba.getTagSingleton = function (id){
2063
+ var type,node,dom;
2064
+
2065
+ if (type = Imba.SINGLETONS[id]) {
2066
+ // return basic awakening if singleton does not exist?
2067
+
2068
+ if (type && type.Instance) { return type.Instance };
2069
+ // no instance - check for element
2070
+ if (dom = Imba.document().getElementById(id)) {
2071
+ // we have a live instance - when finding it through a selector we should awake it, no?
2072
+ // console.log('creating the singleton from existing node in dom?',id,type)
2073
+ node = type.Instance = new type(dom);
2074
+ node.awaken(dom); // should only awaken
2075
+ return node;
2076
+ };
2077
+
2078
+ dom = type.createNode();
2079
+ dom.id = id;
2080
+ // console.log('creating the singleton',id,type)
2081
+ node = type.Instance = new type(dom);
2082
+ node.end().awaken(dom);
2083
+ return node;
2084
+ } else if (dom = Imba.document().getElementById(id)) {
2085
+ // console.log('found plain element with id')
2086
+ return Imba.getTagForDom(dom);
2087
+ };
2088
+ };
2089
+
2090
+
2091
+
2092
+ Imba.getTagForDom = function (dom){
2093
+
2094
+ var m;
2095
+ if (!dom) { return null };
2096
+ if (dom._dom) { return dom }; // could use inheritance instead
2097
+ if (dom._tag) { return dom._tag };
2098
+ if (!dom.nodeName) { return null };
2099
+
2100
+ var ns = null;
2101
+ var id = dom.id;
2102
+ var type = dom.nodeName.toLowerCase();
2103
+ var cls = dom.className;
2104
+
2105
+ if (id && Imba.SINGLETONS[id]) {
2106
+ // FIXME control that it is the same singleton?
2107
+ // might collide -- not good?
2108
+ return Imba.getTagSingleton(id);
2109
+ };
2110
+ // look for id - singleton
2111
+
2112
+ // need better test here
2113
+ if (svgSupport && (dom instanceof SVGElement)) {
2114
+ ns = "svg";
2115
+ cls = dom.className.baseVal;
2116
+ };
2117
+
2118
+ if (cls) {
2119
+ // there can be several matches here - should choose the last
2120
+ // should fall back to less specific later? - otherwise things may fail
2121
+ // TODO rework this
2122
+ if (m = cls.match(/\b_([a-z\-]+)\b(?!\s*_[a-z\-]+)/)) {
2123
+ type = m[1].replace(/-/g,'_');
2124
+ };
2125
+
2126
+ if (m = cls.match(/\b([a-z]+)_\b/)) {
2127
+ ns = m[1];
2128
+ };
2129
+ };
2130
+
2131
+ var spawner = Imba.TAGS[type];
2132
+ return spawner ? (new spawner(dom).awaken(dom)) : (null);
2133
+ };
2134
+
2135
+ t$ = Imba.tag;
2136
+ tc$ = Imba.tagWithFlags;
2137
+ ti$ = Imba.tagWithId;
2138
+ tic$ = Imba.tagWithIdAndFlags;
2139
+ id$ = Imba.getTagSingleton;
2140
+ tag$wrap = Imba.getTagForDom;
2141
+
2142
+
2143
+ // shim for classList
2144
+
2145
+ })()
2146
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
2147
+ },{}],7:[function(require,module,exports){
2148
+ (function(){
2149
+
2150
+ // unless document:documentElement:classList
2151
+ if (!document.documentElement.classList) {
2152
+
2153
+
2154
+
2155
+ ElementTag.prototype.hasFlag = function (ref){
2156
+ return new RegExp('(^|\\s)' + ref + '(\\s|$)').test(this._dom.className);
2157
+ };
2158
+
2159
+ ElementTag.prototype.addFlag = function (ref){
2160
+ if (this.hasFlag(ref)) { return this };
2161
+ this._dom.className += (this._dom.className ? (' ') : ('')) + ref;
2162
+ return this;
2163
+ };
2164
+
2165
+ ElementTag.prototype.unflag = function (ref){
2166
+ if (!this.hasFlag(ref)) { return this };
2167
+ var regex = new RegExp('(^|\\s)*' + ref + '(\\s|$)*','g');
2168
+ this._dom.className = this._dom.className.replace(regex,'');
2169
+ return this;
2170
+ };
2171
+
2172
+ ElementTag.prototype.toggleFlag = function (ref){
2173
+ return this.hasFlag(ref) ? (this.unflag(ref)) : (this.flag(ref));
2174
+ };
2175
+
2176
+ ElementTag.prototype.flag = function (ref,bool){
2177
+ if (arguments.length == 2 && bool == false) {
2178
+ return this.unflag(ref);
2179
+ };
2180
+ return this.addFlag(ref);
2181
+ };
2182
+
2183
+ true;
2184
+ };
2185
+
2186
+ })()
2187
+ },{}],8:[function(require,module,exports){
2188
+ (function(){
2189
+ function iter$(a){ return a ? (a.toArray ? a.toArray() : a) : []; };
2190
+
2191
+
2192
+ function removeNested(root,node,caret){
2193
+ // if node/nodes isa String
2194
+ // we need to use the caret to remove elements
2195
+ // for now we will simply not support this
2196
+ if (node instanceof Array) {
2197
+ for (var i=0, ary=iter$(node), len=ary.length; i < len; i++) {
2198
+ removeNested(root,ary[i],caret);
2199
+ };
2200
+ } else if ((typeof node=='number'||node instanceof Number)) {
2201
+ false; // noop now -- will be used in
2202
+ } else if (node) {
2203
+ root.removeChild(node);
2204
+ };
2205
+
2206
+ return caret;
2207
+ };
2208
+
2209
+ function appendNested(root,node){
2210
+ if (node instanceof Array) {
2211
+ for (var i=0, ary=iter$(node), len=ary.length; i < len; i++) {
2212
+ appendNested(root,ary[i]);
2213
+ };
2214
+ } else if ((typeof node=='number'||node instanceof Number)) {
2215
+ false;
2216
+ } else if ((typeof node=='string'||node instanceof String)) {
2217
+ root.appendChild(Imba.document().createTextNode(node));
2218
+ } else if (node) {
2219
+ root.appendChild(node);
2220
+ };
2221
+
2222
+ return;
2223
+ };
2224
+
2225
+ // insert nodes before a certain node
2226
+ // does not need to return any tail, as before
2227
+ // will still be correct there
2228
+ // before must be an actual domnode
2229
+ function insertNestedBefore(root,node,before){
2230
+
2231
+ if ((typeof node=='string'||node instanceof String)) {
2232
+ node = Imba.document().createTextNode(node);
2233
+ };
2234
+
2235
+ if (node instanceof Array) {
2236
+ for (var i=0, ary=iter$(node), len=ary.length; i < len; i++) {
2237
+ insertNestedBefore(root,ary[i],before);
2238
+ };
2239
+ } else if ((typeof node=='number'||node instanceof Number)) {
2240
+ false; // noop now -- will be used in
2241
+ } else if (node) {
2242
+ root.insertBefore(node,before);
2243
+ };
2244
+
2245
+ return before;
2246
+ };
2247
+
2248
+ // after must be an actual domnode
2249
+ function insertNestedAfter(root,node,after){
2250
+ var before = after ? (after.nextSibling) : (root._dom.firstChild);
2251
+
2252
+ if (before) {
2253
+ insertNestedBefore(root,node,before);
2254
+ return before.previousSibling;
2255
+ } else {
2256
+ appendNested(root,node);
2257
+ return root._dom.lastChild;
2258
+ };
2259
+ };
2260
+
2261
+ function reconcileCollectionChanges(root,new$,old,caret){
2262
+
2263
+ var newLen = new$.length;
2264
+ var oldLen = old.length;
2265
+ var lastNew = new$[newLen - 1];
2266
+
2267
+ // This re-order algorithm is based on the following principle:
2268
+ //
2269
+ // We build a "chain" which shows which items are already sorted.
2270
+ // If we're going from [1, 2, 3] -> [2, 1, 3], the tree looks like:
2271
+ //
2272
+ // 3 -> 0 (idx)
2273
+ // 2 -> -1 (idx)
2274
+ // 1 -> -1 (idx)
2275
+ //
2276
+ // This tells us that we have two chains of ordered items:
2277
+ //
2278
+ // (1, 3) and (2)
2279
+ //
2280
+ // The optimal re-ordering then becomes two keep the longest chain intact,
2281
+ // and move all the other items.
2282
+
2283
+ var newPosition = [];
2284
+
2285
+ // The tree/graph itself
2286
+ var prevChain = [];
2287
+ // The length of the chain
2288
+ var lengthChain = [];
2289
+
2290
+ // Keep track of the longest chain
2291
+ var maxChainLength = 0;
2292
+ var maxChainEnd = 0;
2293
+
2294
+ for (var idx=0, ary=iter$(old), len=ary.length, node; idx < len; idx++) {
2295
+ node = ary[idx];
2296
+ var newPos = new$.indexOf(node);
2297
+ newPosition.push(newPos);
2298
+
2299
+ if (newPos == -1) {
2300
+ root.removeChild(node);
2301
+ prevChain.push(-1);
2302
+ lengthChain.push(-1);
2303
+ continue;
2304
+ };
2305
+
2306
+ var prevIdx = newPosition.length - 2;
2307
+
2308
+ // Build the chain:
2309
+ while (prevIdx >= 0){
2310
+ if (newPosition[prevIdx] == -1) {
2311
+ prevIdx--;
2312
+ } else if (newPos > newPosition[prevIdx]) {
2313
+ // Yay, we're bigger than the previous!
2314
+ break;
2315
+ } else {
2316
+ // Nope, let's walk back the chain
2317
+ prevIdx = prevChain[prevIdx];
2318
+ };
2319
+ };
2320
+
2321
+ prevChain.push(prevIdx);
2322
+
2323
+ var currLength = (prevIdx == -1) ? (0) : (lengthChain[prevIdx] + 1);
2324
+
2325
+ if (currLength > maxChainLength) {
2326
+ maxChainLength = currLength;
2327
+ maxChainEnd = idx;
2328
+ };
2329
+
2330
+ lengthChain.push(currLength);
2331
+ };
2332
+
2333
+ var stickyNodes = [];
2334
+
2335
+ // Now we can walk the longest chain backwards and mark them as "sticky",
2336
+ // which implies that they should not be moved
2337
+ var cursor = newPosition.length - 1;
2338
+ while (cursor >= 0){
2339
+ if (newPosition[cursor] == -1) {
2340
+ // do nothing. it was removed.
2341
+ null
2342
+ } else if (cursor == maxChainEnd) {
2343
+ stickyNodes[newPosition[cursor]] = true;
2344
+ maxChainEnd = prevChain[maxChainEnd];
2345
+ };
2346
+
2347
+ cursor -= 1;
2348
+ };
2349
+
2350
+ // And let's iterate forward, but only move non-sticky nodes
2351
+ for (var idx1=0, ary=iter$(new$), len=ary.length; idx1 < len; idx1++) {
2352
+ if (!stickyNodes[idx1]) {
2353
+ var after = new$[idx1 - 1];
2354
+ insertNestedAfter(root,ary[idx1],(after && after._dom) || caret);
2355
+ };
2356
+ };
2357
+
2358
+ // should trust that the last item in new list is the caret
2359
+ return lastNew && lastNew._dom || caret;
2360
+ };
2361
+
2362
+
2363
+ // expects a flat non-sparse array of nodes in both new and old, always
2364
+ function reconcileCollection(root,new$,old,caret){
2365
+ var k = new$.length;
2366
+ var i = k;
2367
+ var last = new$[k - 1];
2368
+
2369
+
2370
+ if (k == old.length && new$[0] === old[0]) {
2371
+ // running through to compare
2372
+ while (i--){
2373
+ if (new$[i] !== old[i]) { break };
2374
+ };
2375
+ };
2376
+
2377
+ if (i == -1) {
2378
+ return last && last._dom || caret;
2379
+ } else {
2380
+ return reconcileCollectionChanges(root,new$,old,caret);
2381
+ };
2382
+ };
2383
+
2384
+ // the general reconciler that respects conditions etc
2385
+ // caret is the current node we want to insert things after
2386
+ function reconcileNested(root,new$,old,caret,container,ci){
2387
+
2388
+ if (new$ === old) {
2389
+ // remember that the caret must be an actual dom element
2390
+ return (new$ && new$._dom) || new$ || caret;
2391
+ };
2392
+
2393
+ // this could be a dynamic / loop
2394
+ if ((new$ instanceof Array) && (old instanceof Array)) {
2395
+
2396
+ if (new$.static) {
2397
+ // if the static is not nested - we could get a hint from compiler
2398
+ // and just skip it
2399
+ if (new$.static == old.static) {
2400
+ for (var i=0, ary=iter$(new$), len=ary.length; i < len; i++) {
2401
+ caret = reconcileNested(root,ary[i],old[i],caret,new$,i);
2402
+ };
2403
+ return caret;
2404
+ };
2405
+ // if they are not the same we continue through to the default
2406
+ } else {
2407
+ return reconcileCollection(root,new$,old,caret);
2408
+ };
2409
+ } else if ((typeof new$=='string'||new$ instanceof String)) {
2410
+ var textNode;
2411
+
2412
+ if (old instanceof Text) {
2413
+ // make sure not to trigger reflow in certain browsers
2414
+ if (old.textContent != new$) {
2415
+ old.textContent = new$;
2416
+ };
2417
+
2418
+ textNode = old;
2419
+ } else {
2420
+ if (old) { removeNested(root,old,caret) };
2421
+ textNode = Imba.document().createTextNode(new$);
2422
+ insertNestedAfter(root,textNode,caret);
2423
+ };
2424
+
2425
+ // swap the text with textNode in container
2426
+ return container[ci] = caret = textNode;
2427
+ };
2428
+ // simply remove the previous one and add the new one
2429
+ // will these ever be arrays?
2430
+ if (old) { removeNested(root,old,caret) };
2431
+ if (new$) { caret = insertNestedAfter(root,new$,caret) };
2432
+ return caret;
2433
+ };
2434
+
2435
+
2436
+
2437
+ Imba.extendTag('htmlelement', function(tag){
2438
+
2439
+ tag.prototype.setChildren = function (nodes){
2440
+ if (nodes === this._children) {
2441
+ return this;
2442
+ };
2443
+
2444
+ if (nodes && nodes.static) {
2445
+ this.setStaticChildren(nodes);
2446
+ } else if ((nodes instanceof Array) && (this._children instanceof Array)) {
2447
+ reconcileCollection(this,nodes,this._children,null);
2448
+ } else if ((typeof nodes=='string'||nodes instanceof String)) {
2449
+ this.setText(nodes);
2450
+ } else {
2451
+ this.empty().append(nodes);
2452
+ };
2453
+
2454
+ this._children = nodes;
2455
+ return this;
2456
+ };
2457
+
2458
+ tag.prototype.setStaticChildren = function (new$){
2459
+
2460
+ var $1, $2;
2461
+ var old = this._children || [];
2462
+ var caret = null;
2463
+
2464
+ // common case that should bail out from staticChildren
2465
+ if (new$.length == 1 && (typeof new$[($1=0)]=='string'||new$[$1] instanceof String)) {
2466
+ return (this.setText(new$[($2=0)]),new$[$2]);
2467
+ };
2468
+
2469
+ // must be array
2470
+ if (!old.length || !old.static) {
2471
+ old = [];
2472
+ this.empty();
2473
+ };
2474
+
2475
+ for (var i=0, ary=iter$(new$), len=ary.length, node; i < len; i++) {
2476
+ node = ary[i];
2477
+ if (node === old[i]) {
2478
+ if (node && node._dom) { caret = node._dom };
2479
+ } else {
2480
+ caret = reconcileNested(this,node,old[i],caret,new$,i);
2481
+ };
2482
+ };
2483
+
2484
+ this._children = new$;
2485
+ return this;
2486
+ };
2487
+
2488
+ tag.prototype.content = function (){
2489
+ return this._content || this.children().toArray();
2490
+ };
2491
+
2492
+ tag.prototype.setText = function (text){
2493
+ if (text != this._children) {
2494
+ this.dom().textContent = this._children = text;
2495
+ };
2496
+ return this;
2497
+ };
2498
+ });
2499
+
2500
+ })()
2501
+ },{}],9:[function(require,module,exports){
2502
+ (function(){
2503
+ // externs;
2504
+
2505
+ if (typeof window !== 'undefined') {
2506
+ global = window;
2507
+ };
2508
+
2509
+ Imba = {};
2510
+
2511
+ })()
2512
+ },{}],10:[function(require,module,exports){
2513
+ (function(){
2514
+ function iter$(a){ return a ? (a.toArray ? a.toArray() : a) : []; };
2515
+
2516
+ Imba.Selector = function Selector(sel,scope,nodes){
2517
+
2518
+ this._query = sel instanceof Imba.Selector ? (sel.query()) : (sel);
2519
+ this._context = scope;
2520
+
2521
+ if (nodes) {
2522
+ for (var i=0, ary=iter$(nodes), len=ary.length, res=[]; i < len; i++) {
2523
+ res.push(tag$wrap(ary[i]));
2524
+ };
2525
+ this._nodes = res;
2526
+ };
2527
+
2528
+ this._lazy = !nodes;
2529
+ return this;
2530
+ };
2531
+
2532
+
2533
+ Imba.Selector.prototype.__query = {name: 'query'};
2534
+ Imba.Selector.prototype.query = function(v){ return this._query; }
2535
+ Imba.Selector.prototype.setQuery = function(v){ this._query = v; return this; };
2536
+
2537
+ Imba.Selector.prototype.reload = function (){
2538
+ this._nodes = null;
2539
+ return this;
2540
+ };
2541
+
2542
+ Imba.Selector.prototype.scope = function (){
2543
+ var ctx;
2544
+ if (this._scope) { return this._scope };
2545
+ if (!(ctx = this._context)) { return Imba.document() };
2546
+ return this._scope = ctx.toScope ? (ctx.toScope()) : (ctx);
2547
+ };
2548
+
2549
+ Imba.Selector.prototype.first = function (){
2550
+ if (this._lazy) { return tag$wrap(this._first || (this._first = this.scope().querySelector(this.query()))) } else {
2551
+ return this.nodes()[0];
2552
+ };
2553
+ };
2554
+
2555
+ Imba.Selector.prototype.last = function (){
2556
+ return this.nodes()[this._nodes.length - 1];
2557
+ };
2558
+
2559
+ Imba.Selector.prototype.nodes = function (){
2560
+ if (this._nodes) { return this._nodes };
2561
+ var items = this.scope().querySelectorAll(this.query());
2562
+ for (var i=0, ary=iter$(items), len=ary.length, res=[]; i < len; i++) {
2563
+ res.push(tag$wrap(ary[i]));
2564
+ };
2565
+ this._nodes = res;
2566
+ this._lazy = false;
2567
+ return this._nodes;
2568
+ };
2569
+
2570
+ Imba.Selector.prototype.count = function (){
2571
+ return this.nodes().length;
2572
+ };
2573
+ Imba.Selector.prototype.len = function (){
2574
+ return this.nodes().length;
2575
+ };
2576
+ Imba.Selector.prototype.any = function (){
2577
+ return this.count();
2578
+ };
2579
+
2580
+ Imba.Selector.prototype.at = function (idx){
2581
+ return this.nodes()[idx];
2582
+ };
2583
+
2584
+ Imba.Selector.prototype.forEach = function (block){
2585
+ this.nodes().forEach(block);
2586
+ return this;
2587
+ };
2588
+
2589
+ Imba.Selector.prototype.map = function (block){
2590
+ return this.nodes().map(block);
2591
+ };
2592
+
2593
+ Imba.Selector.prototype.toArray = function (){
2594
+ return this.nodes();
2595
+ };
2596
+
2597
+ // Get the first element that matches the selector,
2598
+ // beginning at the current element and progressing up through the DOM tree
2599
+ Imba.Selector.prototype.closest = function (sel){
2600
+ // seems strange that we alter this selector?
2601
+ this._nodes = this.map(function(node) { return node.closest(sel); });
2602
+ return this;
2603
+ };
2604
+
2605
+ // Get the siblings of each element in the set of matched elements,
2606
+ // optionally filtered by a selector.
2607
+ // TODO remove duplicates?
2608
+ Imba.Selector.prototype.siblings = function (sel){
2609
+ this._nodes = this.map(function(node) { return node.siblings(sel); });
2610
+ return this;
2611
+ };
2612
+
2613
+ // Get the descendants of each element in the current set of matched
2614
+ // elements, filtered by a selector.
2615
+ Imba.Selector.prototype.find = function (sel){
2616
+ this._nodes = this.__query__(sel.query(),this.nodes());
2617
+ return this;
2618
+ };
2619
+
2620
+ // TODO IMPLEMENT
2621
+ // Get the children of each element in the set of matched elements,
2622
+ // optionally filtered by a selector.
2623
+ Imba.Selector.prototype.children = function (sel){
2624
+ return true;
2625
+ };
2626
+
2627
+ // TODO IMPLEMENT
2628
+ // Reduce the set of matched elements to those that have a descendant that
2629
+ // matches the selector or DOM element.
2630
+ Imba.Selector.prototype.has = function (){
2631
+ return true;
2632
+ };
2633
+
2634
+ // TODO IMPLEMENT
2635
+ Imba.Selector.prototype.__union = function (){
2636
+ this.p("called Imba.Selector.__union");
2637
+ return this;
2638
+ };
2639
+
2640
+ // TODO IMPLEMENT
2641
+ Imba.Selector.prototype.__intersect = function (){
2642
+ this.p("called Imba.Selector.__union");
2643
+ return this;
2644
+ };
2645
+
2646
+ Imba.Selector.prototype.reject = function (blk){
2647
+ return this.filter(blk,false);
2648
+ };
2649
+
2650
+ Imba.Selector.prototype.filter = function (blk,bool){
2651
+ if(bool === undefined) bool = true;
2652
+ var fn = (blk instanceof Function) && blk || function(n) { return n.matches(blk); };
2653
+ var ary = this.nodes().filter(function(n) { return fn(n) == bool; });
2654
+ // if we want to return a new selector for this, we should do that for
2655
+ // others as well
2656
+ return new Imba.Selector("",this._scope,ary);
2657
+ };
2658
+
2659
+ Imba.Selector.prototype.__query__ = function (query,contexts){
2660
+ var nodes = [];
2661
+ var i = 0;
2662
+ var l = contexts.length;
2663
+
2664
+ while (i < l){
2665
+ nodes.push.apply(nodes,contexts[i++].querySelectorAll(query));
2666
+ };
2667
+ return nodes;
2668
+ };
2669
+
2670
+ Imba.Selector.prototype.__matches__ = function (){
2671
+ return true;
2672
+ };
2673
+
2674
+ // Proxies
2675
+ Imba.Selector.prototype.flag = function (flag){
2676
+ return this.forEach(function(n) { return n.flag(flag); });
2677
+ };
2678
+
2679
+ Imba.Selector.prototype.unflag = function (flag){
2680
+ return this.forEach(function(n) { return n.unflag(flag); });
2681
+ };
2682
+
2683
+ Imba.Selector.prototype.call = function (meth,args){
2684
+ var self=this;
2685
+ if(args === undefined) args = [];
2686
+ return self.forEach(function(n) { var $1;
2687
+ if ((self.setFn(n[($1=meth)]),n[$1])) { return self.fn().apply(n,args) }; });
2688
+ };
2689
+
2690
+ q$ = function(sel,scope) { return new Imba.Selector(sel,scope); };
2691
+
2692
+ q$$ = function(sel,scope) {
2693
+ var el = (scope || Imba.document()).querySelector(sel);
2694
+ return el && tag$wrap(el) || null;
2695
+ };
2696
+
2697
+ // extending tags with query-methods
2698
+ // must be a better way to reopen classes
2699
+ Imba.extendTag('element', function(tag){
2700
+ tag.prototype.querySelectorAll = function (q){
2701
+ return this._dom.querySelectorAll(q);
2702
+ };
2703
+ tag.prototype.querySelector = function (q){
2704
+ return this._dom.querySelector(q);
2705
+ };
2706
+ tag.prototype.find = function (sel){
2707
+ return new Imba.Selector(sel,this);
2708
+ };
2709
+ });
2710
+
2711
+ })()
2712
+ },{}]},{},[1])(1)
2713
+ });