forked from niom/zelect
-
Notifications
You must be signed in to change notification settings - Fork 1
/
loader-demo.html
145 lines (143 loc) · 4.59 KB
/
loader-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
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
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="./zelect.js"></script>
<link rel="stylesheet" href="http://css.cdn.tl/normalize.css" />
<style>
body { font-size: 16px; color: #1e1f19; background-color: #f3f3f3; padding: 10px 20px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }
h2, h3, h4 { color: #464646; }
section { margin-bottom: 40px; }
section:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
#intro .zelect {
display: inline-block;
background-color: white;
min-width: 300px;
cursor: pointer;
line-height: 36px;
border: 1px solid #dbdece;
border-radius: 6px;
position: relative;
}
#intro .zelected {
font-weight: bold;
padding-left: 10px;
}
#intro .zelected.placeholder {
color: #999f82;
}
#intro .zelected:hover {
border-color: #c0c4ab;
box-shadow: inset 0px 5px 8px -6px #dbdece;
}
#intro .zelect.open {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
#intro .dropdown {
background-color: white;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
border: 1px solid #dbdece;
border-top: none;
position: absolute;
left:-1px;
right:-1px;
top: 36px;
z-index: 2;
padding: 3px 5px 3px 3px;
}
#intro .dropdown input {
font-family: sans-serif;
outline: none;
font-size: 14px;
border-radius: 4px;
border: 1px solid #dbdece;
box-sizing: border-box;
width: 100%;
padding: 7px 0 7px 10px;
}
#intro .dropdown table {
padding: 0;
margin: 3px 0 0 0;
max-height: 250px;
display: block;
overflow-y: scroll;
}
#intro .dropdown tr {
padding-left: 10px;
}
#intro .dropdown tr.current {
background-color: #e9ebe1;
}
#intro .dropdown .no-results {
margin-left: 10px;
}
</style>
<script>
$(setup)
function setup() {
var everybody = [
{actor: "Sylvester Stallone", character: 'Barney Ross'},
{actor: "Jason Statham", character: 'Lee Christmas'},
{actor: "Jet Li", character: 'Yin Yang'},
{actor: "Dolph Lundgren", character: 'Gunner Jensen'},
{actor: "Chuck Norris", character: 'Booker'},
{actor: "Jean-Claude Van Damme", character: 'Vilain'},
{actor: "Bruce Willis", character: 'Church'},
{actor: "Arnold Schwarzenegger", character: 'Trench'},
{actor: "Terry Crews", character: 'Hale Caesar'},
{actor: "Randy Couture", character: 'Toll Road'},
{actor: "Liam Hemsworth", character: 'Billy The Kid'},
{actor: "Scott Adkins", character: 'Hector'},
{actor: "Nan Yu", character: 'Maggie'},
{actor: "Amanda Ooms", character: 'Pilar'},
{actor: "Charisma Carpenter", character: 'Lacy'}
];
$('#intro select').zelect({
placeholder:'Plz select...',
loader: function(term, page, callback) {
setTimeout(function () {
var matched = everybody.filter(function (query) {
var actorMatches = term.actor ? ~query.actor.toLowerCase().indexOf(term.actor.toLowerCase()) : true
var characterMatches = term.character ? ~query.character.toLowerCase().indexOf(term.character.toLowerCase()) : true
return actorMatches && characterMatches
})
callback(matched.slice(page * 10, 10 + page * 10))
}, 10)
},
itemPrefix: 'tr',
renderResultContainer: function() {
return $('<table>')
},
renderItem: function (item, term) {
return [$('<td>').text(item.actor), $('<td>').text(item.character)]
},
renderSearch: function () {
return $('<table>')
.append($('<tr>')
.append($('<td>')
.append($('<input>').attr('type', 'text').attr('name', 'actor')))
.append($('<td>')
.append($('<input>').attr('type', 'text').attr('name', 'character')))
)
},
queryExtractor: function($search) {
return function() {
var query = { actor: $search.find('input[name="actor"]').val(), character: $search.find('input[name="character"]').val()};
console.log('searching with', query)
return query
}
}
})
}
</script>
</head>
<body>
<section id="intro">
<h2>$('select').zelect()</h2>
<select>
</select>
</section>
</body>
</html>