Revision 326666313464 () - Diff

Link to this snippet: https://friendpaste.com/1a9VFdl9cnWkTwCfivlJnp
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
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:pure="http://beebole.com/pure">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/purePacked.js"></script>
<script type="text/javascript">
var jsonContext = null;
var directive = null;
var renderPureJs = function() {
jsonContext = {
"noofRows":"10",
"userprefList":[{
"userId":"1233",
"defaultLanguage" :"09",
"defaultLocale" :"01",
"preferredName" :"Jon",
}],
"resultList":[{
"languages":[
{"name":"English","class":"EN", "value":01},
{"name":" French", "class":"FR", "value":02},
{"name":"Italian", "class":"IT", "value":03},
{"name":"Japanese", "class":"JPN", "value":04},
{"name":"Chinese", "class":"CH", "value":05},
{"name":"German", "class":"DE", "value":06}
],
"locales":[
{"name":"India","class":"IN", "value":"01"},
{"name":"USA","class":"US", "value":"02"},
{"name":"England","class":"UK", "value":"03"},
{"name":"Germany","class":"DE", "value":"04"},
{"name":"Japan","class":"JP", "value":"05"}
],
"preferredName" :[{"value":" John Chambers"}]
}]
};
window.console.log("1 ");
/* directive = {
'tbody' : 'data<-resultList',
'tbody tr' : 'language<-data.languages',
'tbody tr td[class]' : function(obj){
var oddEven = (obj.pos % 2 == 0) ? 'left' : 'right';
console.log(" obj.pos : " + obj.pos + ", oddEven : " + oddEven);
return oddEven;
},
'tbody tr td' : 'language.name',
};
*/
directive = {
'div.abc' : 'data<-resultList',
'div ul' : 'language<-data.languages',
'li input.lang[value]' : 'language.value',
'li span.langName' : 'language.name'
};
renderPage();
}
function renderPage(){
if(!$p.compiledFunctions['f6']){
console.log(" Compiled version not available");
$.ajax({
async: false,
dataType: 'html',
type: 'GET',
url: 'extFile.html', //load external html file
success: function(data, textStatus) {
var menu = $(data).mapDirective(directive);
$p.compile(menu, 'f6');

},
error: function(xhr, textStatus, err) {
console.log(' err = '+err);
}
});
}else{
console.log(" Compiled version available");
}
console.log (' $p.compiledFunctions f6 : ' + $p.compiledFunctions['f6'] )
$('div#userPrefForm').html( $p.render('f6', jsonContext) )
console.log (' jsonContext : ' + $('div#userPrefForm').html());
}
</script>
</head>
<body>

<input type="button" onclick="renderPureJs();" value="render" />
<hr />
<div class="userPrefForm" id="userPrefForm" >

</div>
<hr />

</body>
</html>

------------------external file(extFile.html) --------------------

<!--
<table class="listTable" width=100% style='table-layout:fixed'>
<tbody>
<tr>
<td class='left'>
<nobr>
<input class='email' type="checkbox" name="name[1]">language1
</nobr>
</td>
<td class='right'>
<nobr>
<input class='email' type="checkbox" name="name[2]">language2
</nobr>
</td>
</tr>
</table>
-->


<div class='abc'>
<ul>
<li>
<input class='lang' type='checkbox' />
<span class='langName'> <span>
</li>
<ul>
</div>