1
0
mirror of synced 2025-02-04 06:09:23 +03:00

catch up to master

This commit is contained in:
Igor Vaynberg 2013-02-12 00:13:56 -08:00
parent 46732aec28
commit 7338d8eaed
3 changed files with 68 additions and 2 deletions

View File

@ -1021,6 +1021,7 @@ $(document).ready(function () {
is useful for cases where local data is used with just a few results, in which case the search box
is not very useful and wastes screen space.
</p>
<p>The option can be set to a <code>negative value</code> to permanently hide the search field</p>
<p class="alert alert-info">Only applies to single-value select boxes</p>
</td>
</tr>

@ -1 +1 @@
Subproject commit b3a0c3269a9c3eae2d7a7a9a71c452b0d60fb2d3
Subproject commit cd3d7421c4e8af04f65fc6b7f0a2e7c0c1be6c0d

View File

@ -23,7 +23,10 @@
</select><br/>
<input type="text" size="30"/>
</div>
<script>
<input type="hidden" class="bigdrop" id="e6" style="width:600px" value="16340"/>
<script>
$(document).ready(function() {
function format(state) {
if (!state.id) return state.text; // optgroup
@ -53,6 +56,68 @@
update();
});
</script>
<script id="script_e6">
function movieFormatResult(movie) {
var markup = "<table class='movie-result'><tr>";
if (movie.posters !== undefined && movie.posters.thumbnail !== undefined) {
markup += "<td class='movie-image'><img src='" + movie.posters.thumbnail + "'/></td>";
}
markup += "<td class='movie-info'><div class='movie-title'>" + movie.title + "</div>";
if (movie.critics_consensus !== undefined) {
markup += "<div class='movie-synopsis'>" + movie.critics_consensus + "</div>";
}
else if (movie.synopsis !== undefined) {
markup += "<div class='movie-synopsis'>" + movie.synopsis + "</div>";
}
markup += "</td></tr></table>"
return markup;
}
function movieFormatSelection(movie) {
return movie.title;
}
$(document).ready(function() {
$("#e6").select2({
placeholder: "Search for a movie",
minimumInputLength: 1,
multiple:true,
ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
url: "http://api.rottentomatoes.com/api/public/v1.0/movies.json",
dataType: 'jsonp',
data: function (term, page) {
return {
q: term, // search term
page_limit: 10,
apikey: "ju6z9mjyajq2djue3gbvv26t" // please do not use so this example keeps working
};
},
results: function (data, page) { // parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to alter remote JSON data
return {results: data.movies};
}
},
initSelection: function(element, callback) {
// the input tag has a value attribute preloaded that points to a preselected movie's id
// this function resolves that id attribute to an object that select2 can render
// using its formatResult renderer - that way the movie name is shown preselected
var id=$(element).val();
if (id!=="") {
$.ajax("http://api.rottentomatoes.com/api/public/v1.0/movies/"+id+".json", {
data: {
apikey: "ju6z9mjyajq2djue3gbvv26t"
},
dataType: "jsonp"
}).done(function(data) { callback(data); });
}
},
formatResult: movieFormatResult, // omitted for brevity, see the source of this page
formatSelection: movieFormatSelection, // omitted for brevity, see the source of this page
dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
});
});
</script>
</body>
</html>