-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
304 lines (257 loc) · 9.82 KB
/
index.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="description" content="BBSearch is JS plugin to transform an input field in an auto-search element based on Backbone." />
<meta name="keywords" content="Backbone, jQuery, plugin, auto-search, auto-complete" />
<meta name="author" content="http://fernandoguillen.info" />
<title>BBSearch</title>
<!-- demo page styles -->
<link rel="stylesheet" href="./reset.css" ></style>
<link rel="stylesheet" href="./style.css" ></style>
<!-- dependencies -->
<script src="./vendor/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="./vendor/underscore.js" type="text/javascript" charset="utf-8"></script>
<script src="./vendor/backbone.js" type="text/javascript" charset="utf-8"></script>
<script src="./lib/bbsearch.js" type="text/javascript" charset="utf-8"></script>
<!-- syntax highlighting -->
<link href="./assets/rainbow/themes/github.css" rel="stylesheet" type="text/css">
<script src="./assets/rainbow/js/rainbow.min.js"></script>
<script src="./assets/rainbow/js/language/generic.js"></script>
<script src="./assets/rainbow/js/language/javascript.js"></script>
<script src="./assets/rainbow/js/language/html.js"></script>
<style>
/* Example 1 */
#results-1 {
width: 600px;
}
#results-1 p{
font-size: 14px;
line-height: 14px;
}
/* Example 2 */
#results-wrapper-2 {
display: none;
position: relative;
margin-top: -5px;
z-index: 100;
}
#results-wrapper-2 .arrow-up {
margin-left: 10px;
width: 0;
height: 0;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
border-bottom: 15px solid #ccc;
}
#results-wrapper-2 .results {
width: 600px;
border: 1px solid #ccc;
}
#results-wrapper-2 .result{
padding: 5px;
border-bottom: 1px dotted #ccc;
overflow: hidden;
background-color: white;
box-sizing: border-box;
}
#results-wrapper-2 .result:hover {
background-color: #ccc;
cursor: pointer;
}
#results-wrapper-2 .result:hover .content h1 {
color: white;
}
#results-wrapper-2 .result .avatar {
float: left;
width: 60px;
}
#results-wrapper-2 .result .avatar img{
width: 60px;
height: 60px;
}
#results-wrapper-2 .result .content {
float: left;
width: 520px;
margin-left: 10px;
}
#results-wrapper-2 .result .content h1 {
font-size: 12px;
color: #ccc;
margin-bottom: 5px;
}
#results-wrapper-2 .result .content p {
color: black;
font-size: 16px;
font-style: italic;
line-height: 16px
}
#loading {
width: 20px;
margin-left: -20px;
margin-top: 8px;
float: left;
}
#loading img {
display: none;
}
</style>
</head>
<body>
<div id="container">
<h1>BBSearch</h1>
<h2>BBSearch is a JS plugin to transform an <em>input field</em> in an auto-search element based on Backbone.</h2>
<p>
<ul>
<li><a href="https://github.com/fguillen/BBSearch">BBSearch's code</a></li>
<li><a href="http://fguillen.github.com/BBSearch">BBSearch's demo page</a></li>
<li><a href="https://github.com/fguillen/BBSearch/blob/master/README.md">BBSearch's README</a></li>
</ul>
</p>
<p><strong>Demo page</strong>: play with the examples</p>
<h3>Use</h3>
<pre><code data-language="javascript">
new BBSearch({
// (Required) the query will be added at the end of the url
// you can also use the "#bbsearch-query#" placeholder to insert the query
// in any part of the url
url: "http://myapi.server.com/search.json?q=",
// (Required) reference to the user input field
inputElement: $("#my-input"),
// (Required) reference to the DOM element when the search results will be shown
resultsElement: $("#my-results"),
// (Required) UnderscoreJS style template
itemTemplate: "title: <%= title %>",
// handler for a _click_ in one of the elements
// a reference to the actual Backbone.Model will be sent
onClick: function( model ){ $("#my-input").val( model.get( "text" ) ) },
// handler to be called when the search request start
onStart: function(){ $("#loading").show();},
// handler to be called when the search request ends
// and all the elements have been rendered
onEnd: function( collection ){ $("#loading").hide(); },
// in case your search response has especial _parse_ needs
parse: function( response ){ return response.results; },
});
</code></pre>
<section>
<h1>Example 1 (simple): Github Search API</h1>
<p>This remote-auto-search element is connected to <a href="http://developer.github.com/v3/">Github search API</a>.
Click any text on it and wait for results.</p>
<h2>Code <a href="#show-code" onclick="$('#code-example-1').toggle('fast'); return false;">toggle</a></h2>
<div id="code-example-1" class="code">
<pre><code data-language="javascript">
new BBSearch({
url: "https://api.github.com/legacy/repos/search/#bbsearch-query#?callback=?&",
inputElement: $("#search-input-1"),
resultsElement: $("#results-1"),
itemTemplate: '<p>[@<%= owner %>] <a href="<%= url %>"><%= name %></a></p>',
parse: function( response ){ return response.data.repositories; }
});
</code></pre>
</div>
<input id="search-input-1" class="big" />
<div id="results-1"></div>
<script>
$(function(){
new BBSearch({
url: "https://api.github.com/legacy/repos/search/#bbsearch-query#?callback=?&",
inputElement: $("#search-input-1"),
resultsElement: $("#results-1"),
itemTemplate: "<p>[@<%= owner %>] <a href=\"https://github.com/<%= owner %>/<%= name %>\"><%= name %></a></p>",
parse: function( response ){ return response.data.repositories; }
});
});
</script>
</section>
<section>
<h1>Example 2 (styled/events): Twitter Search API</h1>
<p>This remote-auto-search element is connected to <a href="https://dev.twitter.com/docs/api/1/get/search">Twitter search API</a>.
Write any text on it and wait for results. The results are clickable and the twitt will be setted at the input field.</p>
<h2>Code <a href="#show-code" onclick="$('#code-example-2').toggle('fast'); return false;">toggle</a></h2>
<div id="code-example-2" class="code">
<pre><code data-language="javascript">new BBSearch({
url: "http://search.twitter.com/search.json?callback=?&q=",
inputElement: $("#search-input-2"),
resultsElement: $("#results-wrapper-2 > .results"),
itemTemplate: $("#template-result").html(),
onClick: function( model ){
$("#search-input-2").val( model.get( "text" ) )
},
onStart: function(){
$("#results-wrapper-2").slideUp( "fast" );
$("#loading img").show();
},
onEnd: function( collection ){
if( collection.length > 0 ) $("#results-wrapper-2").slideDown( "slow" );
$("#loading img").fadeOut( "fast" );
},
parse: function( response ){
return response.results;
},
});</code></pre>
</div>
<div id="loading"><img src="./assets/loading.gif" /></div>
<input id="search-input-2" class="big" />
<div id="results-wrapper-2">
<div class="arrow-up"></div>
<div class="results"></div>
</div>
<script>
$(function(){
new BBSearch({
url: "http://search.twitter.com/search.json?callback=?&q=",
inputElement: $("#search-input-2"),
resultsElement: $("#results-wrapper-2 > .results"),
itemTemplate: $("#template-result").html(),
onClick: function( model ){
$("#search-input-2").val( model.get( "text" ) )
},
onStart: function(){
$("#results-wrapper-2").slideUp( "fast" );
$("#loading img").show();
},
onEnd: function( collection ){
if( collection.length > 0 ) $("#results-wrapper-2").slideDown( "slow" );
$("#loading img").fadeOut( "fast" );
},
parse: function( response ){
return response.results;
},
});
});
</script>
<script type="text/template" id="template-result">
<div class="result" id="result-<%= id %>">
<div class="avatar">
<img src="<%= profile_image_url %>" />
</div>
<div class="content">
<h1>@<%= from_user %></h1>
<p><%= text %></p>
</div>
</div>
</script>
</section>
<footer>
<p>
<a rel="license" href="http://creativecommons.org/licenses/by/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by/3.0/80x15.png" /></a>
<br />
<span xmlns:dct="http://purl.org/dc/terms/" href="http://purl.org/dc/dcmitype/InteractiveResource" property="dct:title" rel="dct:type">BBSearch Backbone/JS plugin</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://fernandoguillen.info" property="cc:attributionName" rel="cc:attributionURL">Fernando Guillen</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</a>.
</p>
</footer>
</div>
<!-- google analytics -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-34268044-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<!-- google analytics -->
</body>
</html>