Skip to content

Commit

Permalink
Update courses.html
Browse files Browse the repository at this point in the history
  • Loading branch information
qwqtw committed Nov 22, 2023
1 parent d16697d commit 04c5005
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions lms/templates/courseware/courses.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<div id="discovery-message" class="search-status-label" style="display: none;"></div>

<div class="search-results-count" style="display: none;">
<span id="results-count"></span> results find for "<span id="search-term"></span>"
<span id="results-count"></span> find for "<span id="search-term"></span>"
</div>

</div>
Expand Down Expand Up @@ -327,38 +327,40 @@ <h2 class="header-search-facets">${_('Refine Your Search')}</h2>
% endif

<script>
document.addEventListener('DOMContentLoaded', function() {
var searchForm = document.getElementById('discovery-form');
var resultsCountContainer = document.querySelector('.search-results-count');
var resultsCount = document.getElementById('results-count');
var searchTermDisplay = document.getElementById('search-term');
var discoveryMessage = document.getElementById('discovery-message');

searchForm.addEventListener('submit', function(event) {
event.preventDefault(); // Prevents the form from submitting traditionally

var searchTerm = document.getElementById('discovery-input').value.trim();

// Delay the execution to wait for discovery-message to update
setTimeout(function() {
var messageText = discoveryMessage.textContent || '';
var numberOfResults;

if (messageText.includes("any results")) {
numberOfResults = 0;
} else {
numberOfResults = parseInt(messageText.match(/\d+/)[0]) || 0;
}

// Update the display inside the setTimeout function
resultsCountContainer.style.display = 'block';
resultsCount.textContent = numberOfResults;
searchTermDisplay.textContent = searchTerm;
}, 200); // Adjust the delay time as needed
});
});

</script>
document.addEventListener('DOMContentLoaded', function() {
var searchForm = document.getElementById('discovery-form');
var resultsCountContainer = document.querySelector('.search-results-count');
var resultsCount = document.getElementById('results-count');
var searchTermDisplay = document.getElementById('search-term');
var discoveryMessage = document.getElementById('discovery-message');

searchForm.addEventListener('submit', function(event) {
event.preventDefault(); // Prevents the form from submitting traditionally

var searchTerm = document.getElementById('discovery-input').value.trim();

setTimeout(function() {
var messageText = discoveryMessage.textContent || '';
var numberOfResults;
var resultTerm;

if (messageText.includes("any results")) {
numberOfResults = 0;
resultTerm = 'results'; // Plural, as "0 results" is the conventional expression
} else {
numberOfResults = parseInt(messageText.match(/\d+/)[0]) || 0;
resultTerm = (numberOfResults === 1) ? 'result' : 'results'; // Singular for 1, plural otherwise
}

// Update the display inside the setTimeout function
resultsCountContainer.style.display = 'block';
resultsCount.textContent = numberOfResults + ' ' + resultTerm;
searchTermDisplay.textContent = searchTerm;
}, 500); // Adjust the delay time as needed
});
});
</script>


</section>
</section>
Expand Down

0 comments on commit 04c5005

Please sign in to comment.