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
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.11.1/typeahead.jquery.min.js"></script>
<script src="../dist-browser/fuzzaldrin-plus.js"></script>
<!--script src="../dist-browser/fuzzaldrin-plus.min.js"></script-->
<link href="demo.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<h2>Source</h2>
<textarea id="sourcetxt"></textarea>
<div class="center">
<label>Enter one item per line then press update</label>
<button onclick="set_txt_source()"> Update source</button>
</div>
<h2>Make a search</h2>
<div class="typeahead">
<input id="demo-query" class="twitter-typeahead" name="demo-query" autocomplete="off" type="text">
</div>
<!-- allow to scroll so autocomplete is at top of page -->
<div style="height: 500px;"></div>
<script>
var global_query = "";
var global_candidates = [];
//- - - - - - - - - - -
// Typeahead Setup
// - - - - - - - - - - -
$('#demo-query').typeahead({
minLength: 2,
highlight: false //let FuzzySearch handle highlight
},
{
name: 'filtered',
limit: 10,
source: function (query, callback) {
global_query = query;
callback(fuzzaldrin.filter(global_candidates, query))
},
templates: {
suggestion: function (result) {
return "<div>" + fuzzaldrin.wrap(result, global_query) + "</div>"
}
}
});
// - - - - - - - - - - - -
// Setup dataset
//- - - - - - - - - - - - -
$.ajaxSetup({cache: true});
function set_json_source(url) {
$.getJSON(url).then(function (response) {
global_candidates = response;
$("#sourcetxt").val(response.join("\n"))
});
}
// Load movie dataset, default options are good for list of string.
set_json_source("movies.json");
function set_txt_source() {
global_candidates = $("#sourcetxt").val().split("\n")
}
</script>
</body>
</html>
|