Debian Codegraph @

demo/demo.html

raw
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title></title>
6
7
8 <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
9 <script src="https://cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.11.1/typeahead.jquery.min.js"></script>
10
11 <script src="../dist-browser/fuzzaldrin-plus.js"></script>
12 <!--script src="../dist-browser/fuzzaldrin-plus.min.js"></script-->
13
14
15 <link href="demo.css" rel="stylesheet" type="text/css"/>
16
17
18 </head>
19 <body>
20
21 <h2>Source</h2>
22 <textarea id="sourcetxt"></textarea>
23
24 <div class="center">
25 <label>Enter one item per line then press update</label>
26 <button onclick="set_txt_source()"> Update source</button>
27 </div>
28
29 <h2>Make a search</h2>
30
31 <div class="typeahead">
32 <input id="demo-query" class="twitter-typeahead" name="demo-query" autocomplete="off" type="text">
33 </div>
34
35 <!-- allow to scroll so autocomplete is at top of page -->
36 <div style="height: 500px;"></div>
37
38
39 <script>
40
41 var global_query = "";
42 var global_candidates = [];
43
44
45 //- - - - - - - - - - -
46 // Typeahead Setup
47 // - - - - - - - - - - -
48 $('#demo-query').typeahead({
49 minLength: 2,
50 highlight: false //let FuzzySearch handle highlight
51 },
52 {
53 name: 'filtered',
54 limit: 10,
55
56 source: function (query, callback) {
57 global_query = query;
58 callback(fuzzaldrin.filter(global_candidates, query))
59 },
60
61 templates: {
62 suggestion: function (result) {
63 return "<div>" + fuzzaldrin.wrap(result, global_query) + "</div>"
64 }
65 }
66
67 });
68
69
70 // - - - - - - - - - - - -
71 // Setup dataset
72 //- - - - - - - - - - - - -
73
74 $.ajaxSetup({cache: true});
75 function set_json_source(url) {
76 $.getJSON(url).then(function (response) {
77 global_candidates = response;
78 $("#sourcetxt").val(response.join("\n"))
79 });
80 }
81 // Load movie dataset, default options are good for list of string.
82 set_json_source("movies.json");
83
84 function set_txt_source() {
85 global_candidates = $("#sourcetxt").val().split("\n")
86 }
87
88
89 </script>
90
91
92 </body>
93 </html>