-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjtmpl.js
1743 lines (1436 loc) · 45.5 KB
/
jtmpl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
863
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.jtmpl=e()}}(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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.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(_dereq_,module,exports){
'use strict';
function freak(obj, root, parent, prop) {
var listeners = {
'change': {},
'update': {},
'insert': {},
'delete': {}
};
var _dependentProps = {};
var _dependentContexts = {};
var cache = {};
var children = {};
// Assert condition
function assert(cond, msg) {
if (!cond) {
throw msg || 'assertion failed';
}
}
// Mix properties into target
function mixin(target, properties) {
for (var i = 0, props = Object.getOwnPropertyNames(properties), len = props.length;
i < len; i++) {
target[props[i]] = properties[props[i]];
}
}
function deepEqual(x, y) {
if (typeof x === "object" && x !== null &&
typeof y === "object" && y !== null) {
if (Object.keys(x).length !== Object.keys(y).length) {
return false;
}
for (var prop in x) {
if (x.hasOwnProperty(prop)) {
if (y.hasOwnProperty(prop)) {
if (!deepEqual(x[prop], y[prop])) {
return false;
}
}
else {
return false;
}
}
}
return true;
}
else if (x !== y) {
return false;
}
return true;
}
// Event functions
function on() {
var event = arguments[0];
var prop = ['string', 'number'].indexOf(typeof arguments[1]) > -1 ?
arguments[1] : null;
var callback =
typeof arguments[1] === 'function' ?
arguments[1] :
typeof arguments[2] === 'function' ?
arguments[2] : null;
// Args check
assert(['change', 'update', 'insert', 'delete'].indexOf(event) > -1);
assert(
(['change'].indexOf(event) > -1 && prop !== null) ||
(['insert', 'delete', 'update'].indexOf(event) > -1 && prop === null)
);
// Init listeners for prop
if (!listeners[event][prop]) {
listeners[event][prop] = [];
}
// Already registered?
if (listeners[event][prop].indexOf(callback) === -1) {
listeners[event][prop].push(callback);
}
}
// Remove all or specified listeners given event and property
function off() {
var event = arguments[0];
var prop = typeof arguments[1] === 'string' ? arguments[1] : null;
var callback =
typeof arguments[1] === 'function' ?
arguments[1] :
typeof arguments[2] === 'function' ?
arguments[2] : null;
var i;
if (!listeners[event][prop]) return;
// Remove all property watchers?
if (!callback) {
listeners[event][prop] = [];
}
else {
// Remove specific callback
i = listeners[event][prop].indexOf(callback);
if (i > -1) {
listeners[event][prop].splice(i, 1);
}
}
}
// trigger('change', prop)
// trigger('update', prop)
// trigger('insert' or 'delete', index, count)
function trigger(event, a, b) {
var handlers = (listeners[event][['change'].indexOf(event) > -1 ? a : null] || []);
var i, len = handlers.length;
for (i = 0; i < len; i++) {
handlers[i].call(instance, a, b);
};
}
// Export model to JSON string
// NOT exported:
// - properties starting with _ (Python private properties convention)
// - computed properties (derived from normal properties)
function toJSON() {
function filter(obj) {
var key, filtered = Array.isArray(obj) ? [] : {};
for (key in obj) {
if (typeof obj[key] === 'object') {
filtered[key] = filter(obj[key]);
}
else if (typeof obj[key] !== 'function' && key[0] !== '_') {
filtered[key] = obj[key];
}
}
return filtered;
}
return JSON.stringify(filter(obj));
}
// Load model from JSON string or object
function fromJSON(data) {
var key;
if (typeof data === 'string') {
data = JSON.parse(data);
}
for (key in data) {
instance(key, data[key]);
trigger('update', key);
}
instance.len = obj.length;
}
// Update handler: recalculate dependent properties,
// trigger change if necessary
function update(prop) {
if (!deepEqual(cache[prop], get(prop, function() {}, true))) {
trigger('change', prop);
}
// Notify dependents
for (var i = 0, dep = _dependentProps[prop] || [], len = dep.length;
i < len; i++) {
delete children[dep[i]];
_dependentContexts[prop][i].trigger('update', dep[i]);
}
if (instance.parent) {
// Notify computed properties, depending on parent object
instance.parent.trigger('update', instance.prop);
}
}
// Proxy the accessor function to record
// all accessed properties
function getDependencyTracker(prop) {
function tracker(context) {
return function(_prop, _arg) {
if (!context._dependentProps[_prop]) {
context._dependentProps[_prop] = [];
context._dependentContexts[_prop] = [];
}
if (context._dependentProps[_prop].indexOf(prop) === -1) {
context._dependentProps[_prop].push(prop);
context._dependentContexts[_prop].push(instance);
}
return context(_prop, _arg, true);
}
}
var result = tracker(instance);
construct(result);
if (parent) {
result.parent = tracker(parent);
}
result.root = tracker(root || instance);
return result;
}
// Shallow clone an object
function shallowClone(obj) {
var key, clone;
if (obj && typeof obj === 'object') {
clone = {};
for (key in obj) {
clone[key] = obj[key];
}
}
else {
clone = obj;
}
return clone;
}
// Getter for prop, if callback is given
// can return async value
function get(prop, callback, skipCaching) {
var val = obj[prop];
if (typeof val === 'function') {
val = val.call(getDependencyTracker(prop), callback);
if (!skipCaching) {
cache[prop] = (val === undefined) ? val : shallowClone(val);
}
}
else if (!skipCaching) {
cache[prop] = val;
}
return val;
}
function getter(prop, callback, skipCaching) {
var result = get(prop, callback, skipCaching);
return result && typeof result === 'object' ?
// Wrap object
children[prop] ?
children[prop] :
children[prop] = freak(result, root || instance, instance, prop) :
// Simple value
result;
}
// Set prop to val
function setter(prop, val) {
var oldVal = get(prop);
if (typeof obj[prop] === 'function') {
// Computed property setter
obj[prop].call(getDependencyTracker(prop), val);
}
else {
// Simple property
obj[prop] = val;
if (val && typeof val === 'object') {
delete cache[prop];
delete children[prop];
}
}
if (oldVal !== val) {
trigger('update', prop);
}
}
// Functional accessor, unify getter and setter
function accessor(prop, arg, skipCaching) {
return (
(arg === undefined || typeof arg === 'function') ?
getter : setter
)(prop, arg, skipCaching);
}
// Attach instance members
function construct(target) {
mixin(target, {
values: obj,
parent: parent || null,
root: root || target,
prop: prop === undefined ? null : prop,
// .on(event[, prop], callback)
on: on,
// .off(event[, prop][, callback])
off: off,
// .trigger(event[, prop])
trigger: trigger,
toJSON: toJSON,
// Deprecated. It has always been broken, anyway
// Will think how to implement properly
fromJSON: fromJSON,
// Internal: dependency tracking
_dependentProps: _dependentProps,
_dependentContexts: _dependentContexts
});
// Wrap mutating array method to update
// state and notify listeners
function wrapArrayMethod(method, func) {
return function() {
var result = [][method].apply(obj, arguments);
this.len = this.values.length;
cache = {};
children = {};
func.apply(this, arguments);
target.parent.trigger('update', target.prop);
return result;
};
}
if (Array.isArray(obj)) {
mixin(target, {
// Function prototype already contains length
// `len` specifies array length
len: obj.length,
pop: wrapArrayMethod('pop', function() {
trigger('delete', this.len, 1);
}),
push: wrapArrayMethod('push', function() {
trigger('insert', this.len - 1, 1);
}),
reverse: wrapArrayMethod('reverse', function() {
trigger('delete', 0, this.len);
trigger('insert', 0, this.len);
}),
shift: wrapArrayMethod('shift', function() {
trigger('delete', 0, 1);
}),
unshift: wrapArrayMethod('unshift', function() {
trigger('insert', 0, 1);
}),
sort: wrapArrayMethod('sort', function() {
trigger('delete', 0, this.len);
trigger('insert', 0, this.len);
}),
splice: wrapArrayMethod('splice', function() {
if (arguments[1]) {
trigger('delete', arguments[0], arguments[1]);
}
if (arguments.length > 2) {
trigger('insert', arguments[0], arguments.length - 2);
}
})
});
}
}
on('update', update);
// Create freak instance
var instance = function() {
return accessor.apply(null, arguments);
};
// Attach instance members
construct(instance);
return instance;
}
// CommonJS export
if (typeof module === 'object') module.exports = freak;
},{}],2:[function(_dereq_,module,exports){
var RE_DELIMITED_VAR = /^\{\{([\w\.\-]+)\}\}$/;
/*
* Attribute rules
*
*/
module.exports = [
/**
* value="{{var}}"
*/
function(node, attr) {
var match = node.getAttribute(attr).match(RE_DELIMITED_VAR);
if (attr === 'value' && match) {
return {
prop: match[1],
rule: function(node, attr, model, prop) {
function change() {
var val = jtmpl._get(model, prop);
if (node[attr] !== val) {
node[attr] = val || '';
}
}
// text input?
var eventType = ['text', 'password'].indexOf(node.type) > -1 ?
'keyup' : 'change'; // IE9 incorectly reports it supports input event
node.addEventListener(eventType, function() {
model(prop, node[attr]);
});
model.on('change', prop, change);
change();
}
};
}
},
/**
* selected="{{var}}"
*/
function(node, attr) {
var match = node.getAttribute(attr).match(RE_DELIMITED_VAR);
if (attr === 'jtmpl-selected' && match) {
return {
prop: match[1],
rule: function(node, attr, model, prop) {
function change() {
if (node.nodeName === 'OPTION') {
var i = selects.indexOf(node.parentNode);
if (selectsUpdating[i]) {
return;
}
for (var j = 0, len = selectOptions[i].length; j < len; j++) {
selectOptions[i][j].selected = selectOptionsContexts[i][j](prop);
}
}
else {
node.selected = model(prop);
}
}
if (node.nodeName === 'OPTION') {
// Process async, as parentNode is still documentFragment
setTimeout(function() {
var i = selects.indexOf(node.parentNode);
if (i === -1) {
// Add <select> to list
i = selects.push(node.parentNode) - 1;
// Init options
selectOptions.push([]);
// Init options contexts
selectOptionsContexts.push([]);
// Attach change listener
node.parentNode.addEventListener('change', function() {
selectsUpdating[i] = true;
for (var oi = 0, olen = selectOptions[i].length; oi < olen; oi++) {
selectOptionsContexts[i][oi](prop, selectOptions[i][oi].selected);
}
selectsUpdating[i] = false;
});
}
// Remember option and context
selectOptions[i].push(node);
selectOptionsContexts[i].push(model);
}, 0);
}
else {
node.addEventListener('change', function() {
model(prop, this.selected);
});
}
model.on('change', prop, change);
setTimeout(change);
}
};
}
},
/**
* checked="{{var}}"
*/
function(node, attr) {
var match = node.getAttribute(attr).match(RE_DELIMITED_VAR);
if (attr === 'jtmpl-checked' && match) {
return {
prop: match[1],
rule: function(node, attr, model, prop) {
function change() {
if (node.name) {
if (radioGroupsUpdating[node.name]) {
return;
}
for (var i = 0, len = radioGroups[node.name][0].length; i < len; i++) {
radioGroups[node.name][0][i].checked = radioGroups[node.name][1][i](prop);
}
}
else {
node.checked = model(prop);
}
}
function init() {
// radio group?
if (node.type === 'radio' && node.name) {
if (!radioGroups[node.name]) {
// Init radio group ([0]: node, [1]: model)
radioGroups[node.name] = [[], []];
}
// Add input to radio group
radioGroups[node.name][0].push(node);
// Add context to radio group
radioGroups[node.name][1].push(model);
}
node.addEventListener('click', function() {
if (node.type === 'radio' && node.name) {
radioGroupsUpdating[node.name] = true;
// Update all inputs from the group
for (var i = 0, len = radioGroups[node.name][0].length; i < len; i++) {
radioGroups[node.name][1][i](prop, radioGroups[node.name][0][i].checked);
}
radioGroupsUpdating[node.name] = false;
}
else {
// Update current input only
model(prop, node.checked);
}
});
model.on('change', prop, change);
setTimeout(change);
}
setTimeout(init);
}
};
}
},
/**
* attribute="{{var}}"
*/
function(node, attr) {
var match = node.getAttribute(attr).match(RE_DELIMITED_VAR);
if (match) {
return {
prop: match[1],
rule: function(node, attr, model, prop) {
function change() {
var val = jtmpl._get(model, prop);
return val ?
node.setAttribute(attr, val) :
node.removeAttribute(attr);
}
model.on('change', prop, change);
change();
}
};
}
},
/**
* Fallback rule, process via @see utemplate
* Strip jtmpl- prefix
*/
function(node, attr) {
return {
prop: node.getAttribute(attr),
rule: function(node, attr, model, prop) {
var attrName = attr.replace('jtmpl-', '');
function change() {
node.setAttribute(
attrName,
jtmpl.utemplate(prop, model, change)
);
}
change();
}
};
}
];
},{}],3:[function(_dereq_,module,exports){
/*
* Node rules
*
*/
module.exports = [
/* jshint evil: true */
/**
* {{var}}
*/
function(node) {
if (node.innerHTML.match(/^[\w\.\-]+$/)) {
return {
prop: node.innerHTML,
rule: function(fragment, model, prop) {
var textNode = document.createTextNode(jtmpl._get(model, prop) || '');
fragment.appendChild(textNode);
model.on('change', prop, function() {
textNode.data = jtmpl._get(model, prop) || '';
});
}
};
}
},
/**
* {{&var}}
*/
function(node) {
var match = node.innerHTML.match(/^&([\w\.\-]+)$/);
if (match) {
return {
prop: match[1],
rule: function(fragment, model, prop) {
// Anchor node for keeping section location
var anchor = document.createComment('');
// Number of rendered nodes
var length = 0;
function change() {
var frag = document.createDocumentFragment();
var el = document.createElement('body');
var i;
// Delete old rendering
while (length) {
anchor.parentNode.removeChild(anchor.previousSibling);
length--;
}
el.innerHTML = model(prop) || '';
length = el.childNodes.length;
for (i = 0; i < length; i++) {
frag.appendChild(el.childNodes[0]);
}
anchor.parentNode.insertBefore(frag, anchor);
}
fragment.appendChild(anchor);
model.on('change', prop, change);
change();
}
};
}
},
/**
* {{>partial}}
*/
function(node) {
// match: [1]=var_name, [2]='single-quoted' [3]="double-quoted"
var match = node.innerHTML.match(/>([\w\.\-]+)|'([^\']*)\'|"([^"]*)"/);
if (match) {
return {
prop: match,
rule: function(fragment, model, match) {
var anchor = document.createComment('');
var target;
function loader() {
if (!target) {
target = anchor.parentNode;
}
jtmpl.loader(
target,
match[1] ?
// Variable
model(match[1]) :
// Literal
match[2] || match[3],
model
);
}
if (match[1]) {
// Variable
model.on('change', match[1], loader);
}
fragment.appendChild(anchor);
// Load async
setTimeout(loader);
}
};
}
},
/**
* {{#section}}
*/
function(node) {
var match = node.innerHTML.match(/^#([\w\.\-]+)$/);
if (match) {
return {
block: match[1],
rule: function(fragment, model, prop, template) {
// Anchor node for keeping section location
var anchor = document.createComment('');
// Number of rendered nodes
var length = 0;
// How many childNodes in one section item
var chunkSize;
function update(i) {
return function() {
var parent = anchor.parentNode;
var anchorIndex = [].indexOf.call(parent.childNodes, anchor);
var pos = anchorIndex - length + i * chunkSize;
var size = chunkSize;
var arr = prop === '.' ? model : model(prop);
while (size--) {
parent.removeChild(parent.childNodes[pos]);
}
parent.insertBefore(
eval(template + '(arr(i))'),
parent.childNodes[pos]
);
};
}
function insert(index, count) {
var parent = anchor.parentNode;
var anchorIndex = [].indexOf.call(parent.childNodes, anchor);
var pos = anchorIndex - length + index * chunkSize;
var size = count * chunkSize;
var i, fragment;
var arr = prop === '.' ? model : model(prop);
for (i = 0, fragment = document.createDocumentFragment();
i < count; i++) {
fragment.appendChild(eval(template + '(arr(index + i))'));
}
parent.insertBefore(fragment, parent.childNodes[pos]);
length = length + size;
}
function del(index, count) {
var parent = anchor.parentNode;
var anchorIndex = [].indexOf.call(parent.childNodes, anchor);
var pos = anchorIndex - length + index * chunkSize;
var size = count * chunkSize;
length = length - size;
while (size--) {
parent.removeChild(parent.childNodes[pos]);
}
}
function change() {
var val = prop === '.' ? model : model(prop);
var i, len, render;
// Delete old rendering
while (length) {
anchor.parentNode.removeChild(anchor.previousSibling);
length--;
}
// Array?
if (typeof val === 'function' && val.len !== undefined) {
val.on('insert', insert);
val.on('delete', del);
render = document.createDocumentFragment();
//console.log('rendering ' + val.len + ' values');
var func = eval(template);
var child, childModel;
for (i = 0, len = val.values.length; i < len; i++) {
// TODO: implement event delegation for array indexes
// Also, using val.values[i] instead of val[i]
// saves A LOT of heap memory. Figure out how to do
// on demand model creation.
val.on('change', i, update(i));
//render.appendChild(eval(template + '(val(i))'));
//render.appendChild(func(val.values[i]));
childModel = val(i);
child = func(childModel);
child.__jtmpl__ = childModel;
render.appendChild(child);
}
length = render.childNodes.length;
chunkSize = ~~(length / len);
anchor.parentNode.insertBefore(render, anchor);
}
// Object?
else if (typeof val === 'function' && val.len === undefined) {
render = eval(template + '(val)');
length = render.childNodes.length;
chunkSize = length;
anchor.parentNode.insertBefore(render, anchor);
anchor.parentNode.__jtmpl__ = model;
}
// Cast to boolean
else {
if (!!val) {
render = eval(template + '(model)');
length = render.childNodes.length;
chunkSize = length;
anchor.parentNode.insertBefore(render, anchor);
}
}
}
fragment.appendChild(anchor);
change();
model.on('change', prop, change);
}
};
}
},
/**
* {{^inverted_section}}
*/
function(node) {
var match = node.innerHTML.match(/^\^([\w\.\-]+)$/);
if (match) {
return {
block: match[1],
rule: function(fragment, model, prop, template) {
// Anchor node for keeping section location
var anchor = document.createComment('');
// Number of rendered nodes
var length = 0;
function change() {
var val = prop === '.' ? model : model(prop);
var i, len, render;
// Delete old rendering
while (length) {
anchor.parentNode.removeChild(anchor.previousSibling);
length--;
}
// Array?
if (typeof val === 'function' && val.len !== undefined) {
val.on('insert', change);
val.on('delete', change);
render = document.createDocumentFragment();
if (val.len === 0) {
render.appendChild(eval(template + '(val(i))'));
}
length = render.childNodes.length;
anchor.parentNode.insertBefore(render, anchor);
}
// Cast to boolean
else {
if (!val) {
render = eval(template + '(model)');
length = render.childNodes.length;
anchor.parentNode.insertBefore(render, anchor);
}
}
}
fragment.appendChild(anchor);
change();
model.on('change', prop, change);
}
};
}
},
/*
* Fallback rule, not recognized jtmpl tag
*/
function(node) {
return {
rule: function(fragment) {
fragment.appendChild(document.createTextNode('REMOVEMELATER'));
}
};
}
];
},{}],4:[function(_dereq_,module,exports){
/**
* Compile a template, parsed by @see parse
*
* @param {documentFragment} template
* @param {string|undefined} sourceURL - include sourceURL to aid debugging
*
* @returns {string} - Function body, accepting Freak instance parameter, suitable for eval()
*/
function compile(template, sourceURL, depth) {
var ri, rules, rlen;
var match, block;
// Generate dynamic function body
var func = '(function(model) {\n' +
'var frag = document.createDocumentFragment(), node;\n\n';
if (!depth) {
// Global bookkeeping
func +=
'var radioGroups = {};\n' +
'var radioGroupsUpdating = {};\n' +
'var selects = [];\n' +
'var selectsUpdating = [];\n' +
'var selectOptions = [];\n' +
'var selectOptionsContexts = [];\n\n';
}
// Wrap model in a Freak instance, if necessary
func += 'model = typeof model === "function" ?' +
'model : ' +
'typeof model === "object" ?' +
'jtmpl(model) :' +
'jtmpl({".": model});\n\n';
// Iterate childNodes
for (var i = 0, childNodes = template.childNodes, len = childNodes.length, node;
i < len; i++) {