What's new?
|
Help
|
Directory
|
Sign in
domplate
Advanced JavaScript Template System
Project Home
Downloads
Wiki
Issues
Source
Checkout
|
Browse
|
Changes
|
Source Path:
svn
/
trunk
/
apache
/
MultipleFunctionArguments
/
index.php
‹ r14
r22
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
<html>
<head>
<title>Domplate Test</title>
<script type="text/javascript">
// This is just so domplate works
function FBL() {};
function FBTrace() {};
if (!top.console || !top.console.firebug)
{
top.console = {
log: function() {},
time: function() {},
timeEnd: function() {}
}
}
function ddd()
{
console.log.apply(console, arguments);
}
function dir()
{
console.dir.apply(console, arguments);
}
function $(id)
{
return document.getElementById(id);
}
</script>
<!-- include domplate -->
<script src="/libraries/domplate/domplate-debug.js" type="text/javascript"></script>
<script type="text/javascript">
with (FBL) {
function Formatter() {};
Formatter.prototype = domplate({
table:
TABLE({border:1},
TBODY(
TR(
TH('Col 1'),
TH('Col 2')
),
FOR('row','$value,$styles|getRowData',
TR(
FOR('row','$row.value,$row.style|getRowData',
TD({'style':'background-color: $row.style.color'},'$row.value|wrap|wrap')
)
)
)
)
),
getRowData: function(value,styles){
var parts = [];
for (var i=0; i < value.length; i++) {
part = {name: i+1, value: value[i], style: styles[i] };
parts.push(part);
}
return parts;
},
wrap: function(value) {
return '[' + value + ']';
},
table2:
TABLE(
TBODY(
TR(
TH({'style':'background-color: gray;'},
'Names')
),
FOR('row','$people|getRows',
TR(
TD({'style':'background-color: $row.color'},
'Hello $row.name|formatName')
)
)
)
),
getRows: function(data){
var rows = [];
for (var i=0; i < data.length; i++) {
rows.push({
name: data[i],
color: (i%2==1)?'lightgray':'white'
});
}
return rows;
},
formatName: function(value) {
return value.substr(0, 1).toUpperCase() + value.substr(1);
}
});
formatter = new Formatter();
};
function runTest(){
with (FBL){
DomplateDebug.enabled = true;
var rows = [
["row data 1","r1c2"],
["row data 2","r2c2"],
["row data 3","r3c2"]
];
var styles = [
[{color:"red"},{color:"cyan"}],
[{color:"blue"},{color:"gray"}],
[{color:"yellow"},{color:"green"}]
];
formatter.table.append({value:rows, styles:styles}, $("test"));
var names = [
'John Doe',
'Brad Smith',
'Susan Kent',
'Tamara Clayton'
];
formatter.table2.append({people:names}, $("test2"));
}
};
window.addEventListener("load", runTest, false);
</script>
</head>
<body>
<div id="test"></div>
<br>
<div id="test2"></div>
</body>
</html>
Show details
Hide details
Change log
r15
by christoph.dorn on Sep 10, 2008
Diff
[No log message]
Go to:
...tipleFunctionArguments/index.php
Project members,
sign in
to write a code review
Older revisions
r14
by christoph.dorn on Sep 10, 2008
Diff
Added support for multiple function arguments
r13
by christoph.dorn on Sep 10, 2008
Diff
[No log message]
All revisions of this file
File info
Size: 3356 bytes, 160 lines
View raw file