/
movies.html
234 lines (187 loc) · 6.95 KB
/
movies.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
<!Doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQueryUI MultiSearch - My Favorite Movies Demo</title>
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.1.0/lodash.underscore.min.js"></script>
<script src="../src/jqueryui-multisearch.js"></script>
<script src="backbone.js"></script>
<script src="moment.js"></script>
<script src="movies.js"></script>
</head>
<body>
<style>
.panel[data-role="picker"] {
position: absolute;
border-top: medium none;
margin-left: 15px;
width: 300px;
overflow: hidden;
}
a.list-group-item.hover {
background-color: #F5F5F5;
text-decoration: none;
}
div.list-group-item.hover, div.list-group-item:hover, div.list-group-item:focus {
background-color: #F5F5F5;
text-decoration: none;
}
div.list-group-item.active, div.list-group-item:active {
color: #000 !important;
background-color: #DEF2F8 !important;
text-decoration: none;
}
.osb-waiting {
padding: 5px;
}
.close {
position: relative;
right: 5px;
}
</style>
<div class="container">
<div class="row">
<div class="col-lg-3">
</div>
<div class="col-lg-6">
<br/><br/>
<div>
<a href="../index.html">< Back to home</a> |
<a href="https://github.com/bseth99/jquery-ui-multisearch/blob/master/examples/movies.html">View Source</a>
</div>
<br/>
<p>
This example uses a custom source function to fetch data from a Backbone Collection. The remote source is the
RottenTomatoes Movie API. The search API is a bit slow so there's hooks on the search events to toggle a
throbber when you start searching. Additionally, once a movie is selected, there is a custom handler to
load more details about the movie. The initial selection adds the item data as it exists in the picker which
is from the query API. The model.fetch() is called to grab more details and add that result back into the item
list using multisearch.add() which will replace the existing item based on its key.
</p>
<br/>
<div id="movie-finder">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body">
<input class="form-control" data-role="input" type="text" placeholder="Search for movie..."/>
</div>
<div class="list-group" data-role="selected-list"></div>
</div>
</div>
</div>
<div data-role="picker" class="panel panel-default">
<div class="panel-header">
<center class="osb-waiting">
Searching <img src="http://i1345.photobucket.com/albums/p665/benknowscode/waitbutton-loading_zps1e22f026.gif" border="0"/>
</center>
</div>
<div class="list-group osb-ready" data-role="picker-list">
</div>
</div>
</div>
</div>
<div class="col-lg-3">
</div>
</div>
</div>
<script id="picker-item" type="text/template">
<a class="list-group-item">
<div class="row">
<div class="col-lg-2"><img src="<%= image %>" width="30px"/></div>
<div class="col-lg-10">
<div class="row">
<div class="col-lg-12"><%= title %></div>
</div>
<div class="row">
<div class="col-lg-6"><small><strong>Year: </strong><%= year %></small></div>
<div class="col-lg-6"><small><strong>Rating: </strong><%= mpaa_rating %></small></div>
</div>
</div>
</div>
</a>
</script>
<script id="selected-item" type="text/template">
<div class="list-group-item">
<div class="row">
<a class="close glyphicon glyphicon-remove" data-action="remove" aria-hidden="true"></a>
<div class="col-lg-3 text-center">
<img src="<%= image %>" border="0" height="90" />
</div>
<div class="col-lg-8">
<div><span style="color: orange; font-weight: bold;"><%= title %> (<%= year %>)</span></div>
<% if ( loading ) { %>
<center class="osb-waiting">
Loading details <img src="http://i1345.photobucket.com/albums/p665/benknowscode/waitbutton-loading_zps1e22f026.gif" border="0"/>
</center>
<% } else { %>
<div><strong>Genre: </strong><%= genre %></div>
<div><strong>Studio: </strong><%= studio %></div>
<div><strong>Cast: </strong><%= cast %></div>
<% } %>
</div>
</div>
<% if ( !loading ) { %>
<div class="row">
<div class="col-lg-12">
<%= synopsis %>
<a href="<%= link %>" target="rotten">... More</a>
<br/><br/>
</div>
</div>
<% } %>
</div>
</script>
<script>
$(function() {
movies = new MovieCollection();
$("#movie-finder").multisearch({
searchThrottle: 1000,
minLocalCache: 50,
preventNotFound: true,
useAutoWidth: false,
inputPosition: 'start',
source: function( term, callback ) {
movies.search( term ).done( function() { callback( movies.toJSON() ); } );
},
searchAttrs: [ 'title' ],
formatPickerItem: _.template( $('#picker-item').html() ),
formatSelectedItem: _.template( $('#selected-item').html() ),
searching: function( event, ui ) {
ui.picker.find( '.osb-ready' ).hide();
ui.picker.find( '.osb-waiting' ).show();
},
searched: function( event, ui ) {
ui.picker.find( '.osb-ready' ).show();
ui.picker.find( '.osb-waiting' ).hide();
},
adding: function( event, ui ) {
ui.data.loading = true;
},
added: function( event, ui ) {
var movie = movies.get( ui.data.id );
movie.fetch().done(function() {
var data = movie.toJSON();
data.loading = false;
$("#movie-finder").multisearch( 'add', data );
});
},
});
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-34780028-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>
</body>
</html>