scratch – Blame information for rev 125
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
125 | office | 1 | var citynames = new Bloodhound({ |
2 | datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'), |
||
3 | queryTokenizer: Bloodhound.tokenizers.whitespace, |
||
4 | prefetch: { |
||
5 | url: 'assets/citynames.json', |
||
6 | filter: function(list) { |
||
7 | return $.map(list, function(cityname) { |
||
8 | return { name: cityname }; }); |
||
9 | } |
||
10 | } |
||
11 | }); |
||
12 | citynames.initialize(); |
||
13 | |||
14 | var cities = new Bloodhound({ |
||
15 | datumTokenizer: Bloodhound.tokenizers.obj.whitespace('text'), |
||
16 | queryTokenizer: Bloodhound.tokenizers.whitespace, |
||
17 | prefetch: 'assets/cities.json' |
||
18 | }); |
||
19 | cities.initialize(); |
||
20 | |||
21 | /** |
||
22 | * Typeahead |
||
23 | */ |
||
24 | var elt = $('.example_typeahead > > input'); |
||
25 | elt.tagsinput({ |
||
26 | typeaheadjs: { |
||
27 | name: 'citynames', |
||
28 | displayKey: 'name', |
||
29 | valueKey: 'name', |
||
30 | source: citynames.ttAdapter() |
||
31 | } |
||
32 | }); |
||
33 | |||
34 | /** |
||
35 | * Objects as tags |
||
36 | */ |
||
37 | elt = $('.example_objects_as_tags > > input'); |
||
38 | elt.tagsinput({ |
||
39 | itemValue: 'value', |
||
40 | itemText: 'text', |
||
41 | typeaheadjs: { |
||
42 | name: 'cities', |
||
43 | displayKey: 'text', |
||
44 | source: cities.ttAdapter() |
||
45 | } |
||
46 | }); |
||
47 | |||
48 | elt.tagsinput('add', { "value": 1 , "text": "Amsterdam" , "continent": "Europe" }); |
||
49 | elt.tagsinput('add', { "value": 4 , "text": "Washington" , "continent": "America" }); |
||
50 | elt.tagsinput('add', { "value": 7 , "text": "Sydney" , "continent": "Australia" }); |
||
51 | elt.tagsinput('add', { "value": 10, "text": "Beijing" , "continent": "Asia" }); |
||
52 | elt.tagsinput('add', { "value": 13, "text": "Cairo" , "continent": "Africa" }); |
||
53 | |||
54 | /** |
||
55 | * Categorizing tags |
||
56 | */ |
||
57 | elt = $('.example_tagclass > > input'); |
||
58 | elt.tagsinput({ |
||
59 | tagClass: function(item) { |
||
60 | switch (item.continent) { |
||
61 | case 'Europe' : return 'label label-primary'; |
||
62 | case 'America' : return 'label label-danger label-important'; |
||
63 | case 'Australia': return 'label label-success'; |
||
64 | case 'Africa' : return 'label label-default'; |
||
65 | case 'Asia' : return 'label label-warning'; |
||
66 | } |
||
67 | }, |
||
68 | itemValue: 'value', |
||
69 | itemText: 'text', |
||
70 | // typeaheadjs: { |
||
71 | // name: 'cities', |
||
72 | // displayKey: 'text', |
||
73 | // source: cities.ttAdapter() |
||
74 | // } |
||
75 | typeaheadjs: [ |
||
76 | { |
||
77 | hint: true, |
||
78 | highlight: true, |
||
79 | minLength: 2 |
||
80 | }, |
||
81 | { |
||
82 | name: 'cities', |
||
83 | displayKey: 'text', |
||
84 | source: cities.ttAdapter() |
||
85 | } |
||
86 | ] |
||
87 | }); |
||
88 | elt.tagsinput('add', { "value": 1 , "text": "Amsterdam" , "continent": "Europe" }); |
||
89 | elt.tagsinput('add', { "value": 4 , "text": "Washington" , "continent": "America" }); |
||
90 | elt.tagsinput('add', { "value": 7 , "text": "Sydney" , "continent": "Australia" }); |
||
91 | elt.tagsinput('add', { "value": 10, "text": "Beijing" , "continent": "Asia" }); |
||
92 | elt.tagsinput('add', { "value": 13, "text": "Cairo" , "continent": "Africa" }); |
||
93 | |||
94 | // HACK: overrule hardcoded display inline-block of typeahead.js |
||
95 | $(".twitter-typeahead").css('display', 'inline'); |