Compare commits
	
		
			2 Commits
		
	
	
		
			980ab5b84c
			...
			f88202b792
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| f88202b792 | |||
| baa691fa03 | 
							
								
								
									
										52
									
								
								main.js
									
									
									
									
									
								
							
							
						
						
									
										52
									
								
								main.js
									
									
									
									
									
								
							| @ -59,7 +59,7 @@ document.addEventListener("keydown", (e) => { | |||||||
|         //if search box not focused, and if we're not on the home page, go back to home page
 |         //if search box not focused, and if we're not on the home page, go back to home page
 | ||||||
|         if (!header.querySelector("input").matches(":focus") && !header.classList.contains("fullscreen")) { |         if (!header.querySelector("input").matches(":focus") && !header.classList.contains("fullscreen")) { | ||||||
|             e.preventDefault(); |             e.preventDefault(); | ||||||
|             animateHeader(true); |             goHome(); | ||||||
|         } else if (header.querySelector("input").matches(":focus") && ime != null) { |         } else if (header.querySelector("input").matches(":focus") && ime != null) { | ||||||
|             toggleIME(); |             toggleIME(); | ||||||
|         } else if (header.querySelector("input").matches(":focus")) { |         } else if (header.querySelector("input").matches(":focus")) { | ||||||
| @ -226,15 +226,33 @@ function search(word) { | |||||||
|     for (let key in searchDictionary) { |     for (let key in searchDictionary) { | ||||||
|         for (let value in searchDictionary[key]) { |         for (let value in searchDictionary[key]) { | ||||||
|             if (searchDictionary[key][value].includes(word)) { |             if (searchDictionary[key][value].includes(word)) { | ||||||
|                 result.push(key); |                 if (value == 0) { | ||||||
|                 break; //????
 |                     result.push(key); | ||||||
|  |                     break; | ||||||
|  |                 } else { | ||||||
|  |                     //if its a description (i.e: includes a space)
 | ||||||
|  |                     //do startsWith or something instead to prevent
 | ||||||
|  |                     //false positive search results
 | ||||||
|  |                     let t = false; | ||||||
|  |                     let d = searchDictionary[key][value].split(" ") | ||||||
|  |                     for (let w in d) { | ||||||
|  |                         if (d[w].startsWith(word)) { | ||||||
|  |                             t = true; | ||||||
|  |                             console.log(searchDictionary[key][value] + " " + d[w]); | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                     if (t) { | ||||||
|  |                         result.push(key); | ||||||
|  |                         break; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     return result; |     return result; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function doSearch() { | function doSearch(state = true) { | ||||||
|     let val = header.querySelector("input").value; |     let val = header.querySelector("input").value; | ||||||
|     let results = search(val); |     let results = search(val); | ||||||
|     if (results.length == 0) { |     if (results.length == 0) { | ||||||
| @ -323,6 +341,16 @@ function doSearch() { | |||||||
|         } |         } | ||||||
|         main.prepend(header); |         main.prepend(header); | ||||||
|     } |     } | ||||||
|  |     const url = new URL(window.location); | ||||||
|  |     url.searchParams.set('s', val); | ||||||
|  |     if (state == true) history.pushState(val, "", url); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function goHome(state = true) { | ||||||
|  |     animateHeader(true); | ||||||
|  |     const url = new URL(window.location); | ||||||
|  |     url.searchParams.delete('s'); | ||||||
|  |     if (state == true) history.pushState(null, "", url); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| window.onload = () => { | window.onload = () => { | ||||||
| @ -331,10 +359,24 @@ window.onload = () => { | |||||||
|     header.querySelector("#search button").onclick = () => {toggleIME();}; |     header.querySelector("#search button").onclick = () => {toggleIME();}; | ||||||
|     header.querySelector("span.heonian").onclick = () => { |     header.querySelector("span.heonian").onclick = () => { | ||||||
|         if (!header.classList.contains("fullscreen")) { |         if (!header.classList.contains("fullscreen")) { | ||||||
|             animateHeader(true); |             goHome(); | ||||||
|         } |         } | ||||||
|     }; |     }; | ||||||
|     loadDictionary(); |     loadDictionary(); | ||||||
|  |     window.addEventListener('popstate', (e) => { | ||||||
|  |         if (e.state == null) { | ||||||
|  |             if (!header.classList.contains("fullscreen")) { | ||||||
|  |                 goHome(false); | ||||||
|  |             } | ||||||
|  |         } else { | ||||||
|  |             if (header.classList.contains("fullscreen")) { | ||||||
|  |                 animateHeader(false); | ||||||
|  |             } | ||||||
|  |             header.querySelector("input").value = e.state; | ||||||
|  |             doSearch(false); | ||||||
|  |         } | ||||||
|  |         console.log("location: " + document.location + ", state: " + JSON.stringify(e.state)); | ||||||
|  |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const sortObject = obj => Object.keys(obj).sort().reduce((res, key) => (res[key] = obj[key], res), {}) | const sortObject = obj => Object.keys(obj).sort().reduce((res, key) => (res[key] = obj[key], res), {}) | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user