mirror of
https://github.com/quatalog/site.git
synced 2025-01-16 01:27:11 +00:00
Continue working on search
This commit is contained in:
parent
997883b7ff
commit
de7c73e5d0
|
@ -1,16 +1,35 @@
|
||||||
const search_helper = function() {
|
"use strict";
|
||||||
const input = document.getElementById("search").value;
|
const search_helper = function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
// "a b cde 12" => "a b cde 12"
|
||||||
|
const input = document.getElementById("search").value.split(" ").join(" ");
|
||||||
console.log(input);
|
console.log(input);
|
||||||
/*
|
|
||||||
const courseCodeInput = elem.value.replace(" ", "").replace("-", "");
|
var course_code = false;
|
||||||
const subCode = courseCodeInput.substring(0,4).toUpperCase();
|
if(input.length == 8) {
|
||||||
const courseNum = courseCodeInput.substring(courseCodeInput.length-4,courseCodeInput.length);
|
// "abcd1345" => ["abcd","1345"]
|
||||||
if(`${subCode}-${courseNum}` in catalog){
|
course_code = input.match(/.{1,3}/g)
|
||||||
// course exists
|
} else if(input.length == 9) {
|
||||||
window.location.href = "./coursedisplay.html?course="+subCode+"-"+courseNum;
|
// "abcd - 1345" => ["abcd","1345"]
|
||||||
} else {
|
course_code = input.split(/(?:,| )+/);
|
||||||
// course doesn't exist
|
}
|
||||||
window.location.href = "./search.html?search="+encodeURIComponent(elem.value);
|
// only do this logic if the string might be a course code
|
||||||
showSearchResults();
|
if(course_code) {
|
||||||
}*/
|
// ["abcd","1345"] => "ABCD-1345"
|
||||||
|
course_code[0] = course_code[0].toUpperCase();
|
||||||
|
const code_str = course_code.join("-");
|
||||||
|
|
||||||
|
// check if "ABCD-1345" is a real course code
|
||||||
|
const course_exists = fetch("../courses_list.json")
|
||||||
|
.then(list => list.json())
|
||||||
|
.then(list => code_str in list);
|
||||||
|
|
||||||
|
// if it is, redirect to it
|
||||||
|
if(course_exists) {
|
||||||
|
location.href = code_str;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
location.href = "../search?search=" + encodeURIComponent(input);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue