Revision 646166313238 () - Diff

Link to this snippet: https://friendpaste.com/WgMzFX0bHyrfD4iGmK1D9
Embed:
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script src="lib/jquery-1.2.6.pack.js" type="text/javascript"></script>
<script src="lib/chain.js" type="text/javascript"></script>
<script type="text/javascript">
$.Chain.extend('chain', {
defaultBuilder: function(builder, root)
{
var res = builder ? (builder.apply(this, [root]) !== false) : true;
var func = function(data, path)
{
for(var i in data)
{
if(typeof data[i] == 'object')
{
func.call(this, data[i], path ? (path+'.'+i) : i);
}
else if(typeof data[i] != 'function')
{
var name = (path ? (path+'.'+i) : i).replace(/(\W)/g, '\\$1');
this.find('> .'+name+', *:not(.chain-element) .'+name)
.each(function(){
var match = $(this);
if(match.filter(':input').length)
{match.val(data[i]);}
else if(match.filter('img').length)
{match.attr('src', data[i]);}
else
{match.html(data[i]);}
});
}
}
}
if(res)
{
this.bind('update', function(event, data){
var self = $(this);
func.call(self, data);
});
}
}
});
$(function(){
$('#info')
.items([
{ "@attributes":{name: 'Braeburn', value: 'Eating'} },
{ "@attributes":{name: 'Bramley', value: 'Cooking'} },
])
.chain();
})
</script>
</head>

<body>
<table border="1" cellspacing="5" cellpadding="5">
<tbody id="info">
<tr>
<td class="@attributes.name">Test</td>
<td><input type="text" class="@attributes.value"/></td>
</tr>
</tbody>
</table>
</body>
</html>