git ssb

0+

k4ml / belajar-js



Commit 084c01b393044ead2958af330fb5de1515de5682

renamed app.js to ta.js

Kamal Mustafa committed on 3/19/2015, 10:51:00 PM
Parent: ce4b7beb55a8ce0ae7e807490fa7dcb9fc37190d

Files changed

javascripts/app.jsdeleted
javascripts/ta.jsadded
typeahead-bare.htmlchanged
typeahead.htmlchanged
javascripts/app.jsView
@@ -1,69 +1,0 @@
1-var substringMatcher = function(strs) {
2- return function findMatches(q, cb) {
3- var matches, substrRegex;
4-
5- // an array that will be populated with substring matches
6- matches = [];
7-
8- // regex used to determine if a string contains the substring `q`
9- substrRegex = new RegExp(q, 'i');
10-
11- // iterate through the pool of strings and for any string that
12- // contains the substring `q`, add it to the `matches` array
13- $.each(strs, function(i, str) {
14- if (substrRegex.test(str)) {
15- // the typeahead jQuery plugin expects suggestions to a
16- // JavaScript object, refer to typeahead docs for more info
17- matches.push({ value: str });
18- }
19- });
20-
21- cb(matches);
22- };
23-};
24-
25-var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
26- 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
27- 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
28- 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
29- 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
30- 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
31- 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
32- 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
33- 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
34-];
35-
36-$('#the-basics .typeahead').typeahead({
37- hint: true,
38- highlight: true,
39- minLength: 1
40-},
41-{
42- name: 'states',
43- displayKey: 'value',
44- source: substringMatcher(states)
45-});
46-
47-// constructs the suggestion engine
48-var states = new Bloodhound({
49- datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
50- queryTokenizer: Bloodhound.tokenizers.whitespace,
51- // `states` is an array of state names defined in "The Basics"
52- local: $.map(states, function(state) { return { value: state }; })
53-});
54-
55-// kicks off the loading/processing of `local` and `prefetch`
56-states.initialize();
57-
58-$('#bloodhound .typeahead').typeahead({
59- hint: true,
60- highlight: true,
61- minLength: 1
62-},
63-{
64- name: 'states',
65- displayKey: 'value',
66- // `ttAdapter` wraps the suggestion engine in an adapter that
67- // is compatible with the typeahead jQuery plugin
68- source: states.ttAdapter()
69-});
javascripts/ta.jsView
@@ -1,0 +1,69 @@
1+var substringMatcher = function(strs) {
2+ return function findMatches(q, cb) {
3+ var matches, substrRegex;
4+
5+ // an array that will be populated with substring matches
6+ matches = [];
7+
8+ // regex used to determine if a string contains the substring `q`
9+ substrRegex = new RegExp(q, 'i');
10+
11+ // iterate through the pool of strings and for any string that
12+ // contains the substring `q`, add it to the `matches` array
13+ $.each(strs, function(i, str) {
14+ if (substrRegex.test(str)) {
15+ // the typeahead jQuery plugin expects suggestions to a
16+ // JavaScript object, refer to typeahead docs for more info
17+ matches.push({ value: str });
18+ }
19+ });
20+
21+ cb(matches);
22+ };
23+};
24+
25+var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
26+ 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
27+ 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
28+ 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
29+ 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
30+ 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
31+ 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
32+ 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
33+ 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
34+];
35+
36+$('#the-basics .typeahead').typeahead({
37+ hint: true,
38+ highlight: true,
39+ minLength: 1
40+},
41+{
42+ name: 'states',
43+ displayKey: 'value',
44+ source: substringMatcher(states)
45+});
46+
47+// constructs the suggestion engine
48+var states = new Bloodhound({
49+ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
50+ queryTokenizer: Bloodhound.tokenizers.whitespace,
51+ // `states` is an array of state names defined in "The Basics"
52+ local: $.map(states, function(state) { return { value: state }; })
53+});
54+
55+// kicks off the loading/processing of `local` and `prefetch`
56+states.initialize();
57+
58+$('#bloodhound .typeahead').typeahead({
59+ hint: true,
60+ highlight: true,
61+ minLength: 1
62+},
63+{
64+ name: 'states',
65+ displayKey: 'value',
66+ // `ttAdapter` wraps the suggestion engine in an adapter that
67+ // is compatible with the typeahead jQuery plugin
68+ source: states.ttAdapter()
69+});
typeahead-bare.htmlView
@@ -24,5 +24,5 @@
2424 <h2>Using Bloodhound</h2>
2525 <div id="bloodhound">
2626 <input class="typeahead" type="text" placeholder="States of USA">
2727 </div>
28-<script src="javascripts/app.js"></script>
28+<script src="javascripts/ta.js"></script>
typeahead.htmlView
@@ -7,5 +7,5 @@
77 <h2>Using Bloodhound</h2>
88 <div id="bloodhound">
99 <input class="typeahead" type="text" placeholder="States of USA">
1010 </div>
11-<script src="javascripts/app.js"></script>
11+<script src="javascripts/ta.js"></script>

Built with git-ssb-web