-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.html
59 lines (54 loc) · 2.84 KB
/
demo.html
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
<html>
<head>
<title>PmTokenizer Demo</title>
<link rel="stylesheet" href="https://raw.github.com/necolas/normalize.css/master/normalize.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="src/css/pmtokenizer.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="lib/underscore.js"></script>
<script type="text/javascript" src="src/jquery.pmtokenizer.js"></script>
<style type="text/css">
body { font-family: Arial, Helvetica; margin: 20px; }
</style>
<script type="text/javascript" charset="utf-8">
$(function() {
var data = [
{ id : 1 , label : 'Superman' , email : '[email protected]' , image : 'http://lorempixel.com/100/100' } ,
{ id : 2 , label : 'Ironman' , email : '[email protected]' , image : 'http://lorempixel.com/100/100' } ,
{ id : 3 , label : 'Batman' , email : '[email protected]' , image : 'http://lorempixel.com/100/100' } ,
{ id : 4 , label : 'Thor' , email : '[email protected]' , image : 'http://lorempixel.com/100/100' } ,
{ id : 5 , label : 'Hulk' , email : '[email protected]' , image : 'http://lorempixel.com/100/100' } ,
{ id : 6 , label : 'Wolverine' , email : '[email protected]' , image : 'http://lorempixel.com/100/100' } ,
{ id : 7 , label : 'Captain America' , email : '[email protected]' , image : 'http://lorempixel.com/100/100' } ,
{ id : 8 , label : 'Spiderman' , email : '[email protected]' , image : 'http://lorempixel.com/100/100' } ,
{ id : 9 , label : 'Robin' , email : '[email protected]' , image : 'http://lorempixel.com/100/100' } ,
] ;
function log(token, level, data) {
$('#logs').text($('#logs').text() + '\n' + level + ' --- ' + token + '---' + data);
};
var tokenizer = new $.pmTokenizer($('#demo1'), {source : data,
// labelHandler handles html to show in autocomplete
labelHandler : function(data) {
var template = _.template('\
<img src="<%= image %>" />\
<span class="name"><%= label %></span>\
<span class="email"><%= email %></span>\
');
return template(data);
},
tokenHandler : function(data) {
var template = _.template('\
<%= _.isString(data) ? data : data.label %>\
');
return template({data : data});
},
});
});
</script>
</head>
<body>
<h1 id="demo">Demo</h1>
<input type="text" id="demo1" />
<h2>Events</h2>
<textarea cols="100" rows="40" id="logs" readonly="readonly"></textarea>
</body>
</html>