Skip to content

Commit

Permalink
Updating the SEE MORE button on IRC page (#1625)
Browse files Browse the repository at this point in the history
  • Loading branch information
RamithaHeshan33 authored May 12, 2024
1 parent 156708c commit 14e400c
Showing 1 changed file with 40 additions and 26 deletions.
66 changes: 40 additions & 26 deletions irc.html
Original file line number Diff line number Diff line change
Expand Up @@ -427,37 +427,51 @@ <h5 class="title">
dataType: 'json',
success: function (data) {

//slice array to two parts
if (data.length >= 8) {
let partOne = data.slice(0, 8);
let partTwo = data.slice(8);
// Define global variable to keep track of displayed profiles
let displayedProfiles = 8;

//mustache render - part one
let contentPartOne = Mustache.render($("#templateTeam").html(), {"data": partOne});
// Function to display profiles based on the number to show
function displayProfiles(numToShow) {
// Slice the data array based on the number to show
let profilesToShow = data.slice(0, numToShow);
// Render the profiles using Mustache
let content = Mustache.render($("#templateTeam").html(), {"data": profilesToShow});
// Display the rendered profiles
$("#teamContent").html(content);
}

//display first 8 profiles
$("#teamContent").html(contentPartOne);
$("#btnShowLess").hide();
//hide button
$("#btnShowMore").click(function () {
let contentPartTwo = Mustache.render($("#templateTeam").html(), {"data": partTwo});
$("#teamContent").append(contentPartTwo);
// Displaying first 8 profiles
displayProfiles(displayedProfiles);
$("#btnShowLess").hide();


// Show More button click event
$("#btnShowMore").click(function () {
// Increment the number of displayed profiles
displayedProfiles += 8;
// Display profiles based on the updated count
displayProfiles(displayedProfiles);
// Hide or show appropriate buttons
if (displayedProfiles >= data.length) {
$("#btnShowMore").hide();
$("#btnShowLess").show();
});
$("#btnShowLess").click(function () {
$("#teamContent").html(contentPartOne);
$("#btnShowMore").show();
$("#btnShowLess").hide();
});
} else {
//mustache render
let content = Mustache.render($("#templateTeam").html(), {"data": data});
}
$("#btnShowLess").show();
});

//display first 8 profiles
$("#teamContent").html(content);
// Show Less button click event
$("#btnShowLess").click(function () {
// Reset the displayed profiles count to 8
displayedProfiles = 8;
// Display the initial 8 profiles
displayProfiles(displayedProfiles);
// Hide the Show Less button
$("#btnShowLess").hide();
// Show the Show More button
$("#btnShowMore").show();
});

//hide button
// Hide buttons if there are no more than 8 profiles
if (data.length <= 8) {
$("#btnShowMore").hide();
$("#btnShowLess").hide();
}
Expand Down

0 comments on commit 14e400c

Please sign in to comment.