Upgrade typeahead to 0.10.2

This commit is contained in:
Sébastien Lucas 2014-04-06 21:20:49 +02:00
parent d2e39e5eed
commit a2a6652487
5 changed files with 38 additions and 1159 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

View file

@ -22,7 +22,7 @@
<link rel="stylesheet" type="text/css" href="resources/Magnific-Popup/magnific-popup.css?v={{=it.version}}" media="screen" />
<script type="text/javascript" src="resources/doT/doT.min.js?v={{=it.version}}"></script>
<script type="text/javascript" src="resources/lru/lru.js?v={{=it.version}}"></script>
<script type="text/javascript" src="resources/typeahead/typeahead.js?v={{=it.version}}"></script>
<script type="text/javascript" src="resources/typeahead/typeahead.bundle.min.js?v={{=it.version}}"></script>
{{?}}
<script type="text/javascript" src="util.js"></script>
<link rel="related" href="{{=it.opds_url}}" type="application/atom+xml;profile=opds-catalog" title="{{=it.title}}" />

View file

@ -337,6 +337,7 @@ width:100%;
{
vertical-align: middle;
width: 100%;
color: black;
}
.tt-hint, .tt-query {
@ -386,7 +387,7 @@ width: 100%;
line-height: 14px;
}
.tt-suggestion.tt-is-under-cursor {
.tt-suggestion.tt-cursor {
color: #1c1c1c;
background-color: #778899;
}

45
util.js
View file

@ -15,6 +15,23 @@ $.ajaxSetup({
cache: false
});
var copsTypeahead = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('title'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 30,
remote: {
url: 'getJSON.php?page=9&search=1&db=%DB&query=%QUERY',
replace: function (url, query) {
if (currentData.multipleDatabase === 1 && currentData.databaseId === "") {
return url.replace('%QUERY', query).replace('&db=%DB', "");
}
return url.replace('%QUERY', query).replace('%DB', currentData.databaseId);
}
}
});
copsTypeahead.initialize();
var DEBUG = false;
var isPushStateEnabled = window.history && window.history.pushState && window.history.replaceState &&
// pushState isn't reliable on iOS until 5.
@ -288,25 +305,19 @@ updatePage = function (data) {
$("#sortForm").hide ();
}
$('input[name=query]').typeahead([
$('input[name=query]').typeahead(
{
hint: true,
minLength : 3
},
{
name: 'search',
allowDuplicates: true,
minLength : 3,
valueKey: 'title',
limit: 24,
template: templateSuggestion,
remote: {
url: 'getJSON.php?page=9&search=1&db=%DB&query=%QUERY',
replace: function (url, query) {
if (currentData.multipleDatabase === 1 && currentData.databaseId === "") {
return url.replace('%QUERY', query).replace('&db=%DB', "");
}
return url.replace('%QUERY', query).replace('%DB', currentData.databaseId);
}
}
}
]);
displayKey: 'title',
templates: {
suggestion: templateSuggestion
},
source: copsTypeahead.ttAdapter()
});
$('input[name=query]').bind('typeahead:selected', function(obj, datum) {
if (isPushStateEnabled) {