aboutsummaryrefslogtreecommitdiff
path: root/assets/js/home_page.js
diff options
context:
space:
mode:
authorkdam0 <kumar.damani@mail.utoronto.ca>2017-01-30 05:02:09 +0000
committerkdam0 <kumar.damani@mail.utoronto.ca>2017-01-30 05:02:09 +0000
commit98c9cbc6258f699fc944f025230c35faf8575bc2 (patch)
treef2c1e809bb2b2573d88ef9bd77eafa65808dca94 /assets/js/home_page.js
parent541341598d5ed0e5c8ef9b2325dc6bbec958463a (diff)
feat. added auto fill for search bar.
Diffstat (limited to 'assets/js/home_page.js')
-rw-r--r--assets/js/home_page.js44
1 files changed, 43 insertions, 1 deletions
diff --git a/assets/js/home_page.js b/assets/js/home_page.js
index 449461d..b04832c 100644
--- a/assets/js/home_page.js
+++ b/assets/js/home_page.js
@@ -22,5 +22,47 @@ function main(){
console.log("Error: Click not registered");
}
});
+
+
+ // for auto-complete
+ var substringMatcher = function(strs) {
+ return function findMatches(q, cb) {
+ var matches, substringRegex;
+ // an array that will be populated with substring matches
+ matches = [];
+
+ // regex used to determine if a string contains the substring `q`
+ substrRegex = new RegExp(q, 'i');
+
+ // iterate through the pool of strings and for any string that
+ // contains the substring `q`, add it to the `matches` array
+ $.each(strs, function(i, str) {
+ if (substrRegex.test(str)) {
+ matches.push(str);
+ }
+ });
+
+ cb(matches);
+ };
+ };
+ // get array of all courses from controllers
+ $.ajax({
+ url: '/auto-complete-courses',
+ type: 'GET',
+ success: function(data){
+ // console.log(JSON.parse(data));
+ var states = JSON.parse(data);
+
+ $('.typeahead').typeahead({
+ hint: true,
+ highlight: true,
+ minLength: 1
+ },
+ {
+ name: 'courseNames',
+ source: substringMatcher(states)
+ });
+ }
+ });
}
-$(document).ready(main); \ No newline at end of file
+$(document).ready(main);