Skip to content

Commit

Permalink
test 2
Browse files Browse the repository at this point in the history
completely remove quick search for debug test
  • Loading branch information
SethClydesdale committed Dec 25, 2024
1 parent 7c92a75 commit 18178e5
Showing 1 changed file with 0 additions and 128 deletions.
128 changes: 0 additions & 128 deletions resources/javascript/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,134 +9,6 @@
}*/


// # QUICK SEARCH #
if (false) {
window.QuickSearcher = {
grammarIndex : /grammar-index/.test(window.location.href),
search : document.getElementById('quick-search'),
results : document.getElementById('quick-search-results'),
hitsCounter : document.getElementById('quick-search-hits'),

// set after definition
li : null,
exLen : null,

// search for the specified value
query : function (value) {
// clear existing timeout
if (window.GenkiSearchTimeout) {
window.clearTimeout(GenkiSearchTimeout);
}

// wait 300ms before submitting search, just in case the user is still typing
window.GenkiSearchTimeout = window.setTimeout(function() {
var frag = document.createDocumentFragment(),
hits = 0,
i = 0,
clone;

// clear prior searches
QuickSearcher.results.innerHTML = '';

// loop over the exercises if a value is present
if (value) {
for (; i < QuickSearcher.exLen; i++) {
if ((QuickSearcher.li[i].innerHTML.replace(/||<.*?>/g, '').toLowerCase().indexOf(value.toLowerCase()) != -1 || (QuickSearcher.li[i].dataset && QuickSearcher.li[i].dataset.keywords && QuickSearcher.li[i].dataset.keywords.toLowerCase().indexOf(value.toLowerCase()) != -1)) && QuickSearcher.li[i].getElementsByTagName('A')[0] && !/note/.test(QuickSearcher.li[i].id)) {
// clone the link (if on homepage) or create a new link (if on the grammar index)
if (QuickSearcher.grammarIndex) {
clone = document.createElement('LI');
clone.innerHTML = '<a href="#' + QuickSearcher.li[i].id + '">' + QuickSearcher.li[i].innerHTML.replace(/||<a.*?>.*?<\/a>/g, '') + '</a>';
} else {
clone = QuickSearcher.li[i].cloneNode(true); // clone the match for displaying in the results node
}

// add lesson number to exercise or grammar point
clone.dataset.lesson = QuickSearcher.grammarIndex ? 'L' + QuickSearcher.li[i].id.replace(/l(\d+)-p\d+/, '$1') : clone.getElementsByTagName('A')[0].href.replace(/.*?\/(lesson-\d+).*|.*?\/(study-tools).*|.*?\/(appendix).*/, function (Match, $1, $2, $3) {
if ($1) {
return $1.charAt(0).toUpperCase() + $1.split('-').pop();

} else if ($2) {
return 'tool'

} else if ($3) {
return 'appendix'
}
});

// add tooltip in case the text gets cut off
clone.title = clone.innerText;

// add the clone to the fragment if it's valid
if (!/^file|^http/.test(clone.dataset.lesson)) {
frag.appendChild(clone);
hits++; // increment hits
}
}
}
}

// append the matched exercises or display an error message/hide the search results
if (frag.childNodes.length) {
QuickSearcher.results.appendChild(frag);

} else {
QuickSearcher.results.innerHTML = value ? '<li>No results found for "' + value + '".</li>' : '';
}

// update the hits counter and add a button to copy the search link
QuickSearcher.hitsCounter.innerHTML = hits ? '(' + hits + ') '+
'<a '+
'class="fa" '+
'style="color:#17A;" '+
'href="#copy-search-link" '+
'title="Copy the search link" '+
'onclick="GenkiModal.open({'+
'title : \'Copy Search Link\','+
'content : \'<div class=&quot;center&quot;><p>You can copy the direct search link from the box below.</p>'+
'<textarea id=&quot;copied-search-link&quot; onfocus=&quot;this.select();&quot; style=&quot;width:80%;height:100px;&quot;>' + (window.location.protocol + '//' + window.location.host + window.location.pathname) + '?search=' + encodeURIComponent(value) + '#quick-search-exercises</textarea></div>\','+
'focus : \'#copied-search-link\''+
'}); return false;"'+
'>&#xf0ea;</a>' : '';

delete window.GenkiSearchTimeout;
}, 300);
}
};

// set remaining data for search functionality
QuickSearcher.li = document.querySelectorAll(QuickSearcher.grammarIndex ? '.workbook-title' : '.lesson-exercises li');
QuickSearcher.exLen = QuickSearcher.li.length;


// set the value of the search field via the url (e.g. ?search=kanji)
if (window.location.search) {
var query = window.location.search.slice(1).split('&'),
i = 0,
j = query.length,
keyVal;

for (; i < j; i++) {
keyVal = query[i].split('=');

if (/^search$/i.test(keyVal[0])) {
QuickSearcher.search.value = decodeURIComponent(keyVal[1]);
break;
}
}
}

// search for exercises when the user inputs text
QuickSearcher.search.oninput = function () {
QuickSearcher.query(this.value);
};

// resume previous searches (in the event the user goes back in history) or those initiated by ?search=query
if (QuickSearcher.search.value) {
QuickSearcher.query(QuickSearcher.search.value);
}
}


// # QUICK NAV SUB-SECTIONS #
// Adds buttons for showing sub-sections in each lesson.
for (var a = document.querySelectorAll('#quick-nav-list a'), i = 0, j = a.length, l; i < j; i++) {
Expand Down

0 comments on commit 18178e5

Please sign in to comment.