4,554
edits
No edit summary |
No edit summary Tag: Reverted |
||
Line 1: | Line 1: | ||
$(document).ready(function () { | $(document).ready(function () { | ||
var areFiltersActive = false; | var areFiltersActive = false; | ||
var communityFeatured = $('#community-featured'); | |||
var communityFeaturedBlock1 = $('#community-featured-block-1'); | |||
var communityFeaturedBlock2 = $('#community-featured-block-2'); | |||
var communityFeaturedBlock3 = $('#community-featured-block-3'); | |||
var communityFeaturedList1 = $('#community-featured-list-1'); | |||
var communityFeaturedList2 = $('#community-featured-list-2'); | |||
var communityFeaturedList3 = $('#community-featured-list-3'); | |||
var filteredCards = $('.filtered-list-item'); | var filteredCards = $('.filtered-list-item'); | ||
var showArticleWrapper = $('#show-article-wrapper'); | var showArticleWrapper = $('#show-article-wrapper'); | ||
Line 11: | Line 18: | ||
}); | }); | ||
updateCommunityFeaturedPosition('block', '1'); | |||
// Insert the community featured element after the second card | |||
if (communityFeatured.length && filteredCards.length >= 2) { | |||
console.log("Community Featured element and at least two filtered cards found."); | |||
communityFeatured.detach(); | |||
filteredCards.eq(1).after(communityFeatured); | |||
communityFeatured.show(); | |||
console.log("Community Featured element has been moved after the second filtered card."); | |||
} else { | |||
if (!communityFeatured.length) { | |||
console.log("No Community Featured element found."); | |||
} | |||
if (filteredCards.length < 2) { | |||
console.log("Less than two filtered cards found. Found: ", filteredCards.length); | |||
} | |||
} | |||
function updateCommunityFeaturedPosition(view, section) { | |||
// Only proceed if filters are not active | |||
if (!areFiltersActive) { | |||
// Hide all communityFeatured elements initially | |||
$('[id^="community-featured-"]').hide(); | |||
// Determine the appropriate communityFeatured element based on the current view and section | |||
var communityFeatured; | |||
if (view === 'block') { | |||
communityFeatured = $('#community-featured-block-' + section); | |||
} else if (view === 'list') { | |||
communityFeatured = $('#community-featured-list-' + section); | |||
} | |||
// Position the appropriate communityFeatured element after the second card if it exists | |||
if (communityFeatured.length) { | |||
var filteredCards = communityFeatured.closest('.list-container').find('.filtered-list-item'); | |||
if (filteredCards.length >= 2) { | |||
communityFeatured.detach(); | |||
filteredCards.eq(1).after(communityFeatured); | |||
communityFeatured.show(); | |||
} | |||
} | |||
} | |||
} | |||
// Check if the specific element exists on the page | // Check if the specific element exists on the page | ||
Line 35: | Line 85: | ||
} | } | ||
// Using delegated event handling for both #list, #list-list and their variations | |||
$('#list, #list-list, #list-block-1, #list-block-2, #list-block-3, #list-list-1, #list-list-2, #list-list-3').on('mousedown', '.filtered-value-option', function(event) { | |||
console.log("Filter clicked within context:", this); | |||
// Check context and hide the corresponding communityFeatured element | |||
var context = $(this).closest('[id]').attr('id'); // Get the closest parent with an ID | |||
switch (context) { | |||
case 'list': | |||
communityFeatured.hide(); | |||
break; | |||
case 'list-block-1': | |||
communityFeaturedBlock1.hide(); | |||
break; | |||
case 'list-block-2': | |||
communityFeaturedBlock2.hide(); | |||
break; | |||
case 'list-block-3': | |||
communityFeaturedBlock3.hide(); | |||
break; | |||
case 'list-list-1': | |||
communityFeaturedList1.hide(); | |||
break; | |||
case 'list-list-2': | |||
communityFeaturedList2.hide(); | |||
break; | |||
case 'list-list-3': | |||
communityFeaturedList3.hide(); | |||
break; | |||
default: | |||
// If the context does not match any case, you can log it or handle it as needed | |||
console.log("Unknown context:", context); | |||
} | |||
// Additional debugging: Check the event target and its parents | |||
console.log("Event target:", event.target); | |||
console.log("Parents of event target:", $(event.target).parents()); | |||
}); | |||
// Format paragraphs | // Format paragraphs | ||
Line 82: | Line 169: | ||
toggleButton.text('[Close]'); | toggleButton.text('[Close]'); | ||
console.log("Filters shown."); | console.log("Filters shown."); | ||
} else { | } else { | ||
filtersDiv.attr('style', 'display: none !important'); | filtersDiv.attr('style', 'display: none !important'); | ||
toggleButton.text('[Open]'); | toggleButton.text('[Open]'); | ||
console.log("Filters hidden."); | console.log("Filters hidden."); | ||
} | } | ||
}); | }); | ||
} | } | ||
// Function to check if filters are cleared for given selectors and update visibility of corresponding community elements | |||
function updateCommunityElementsVisibility(selectors, communityElements) { | |||
for (var i = 0; i < selectors.length; i++) { | |||
var selector = selectors[i]; | |||
var communityElement = communityElements[i]; // Access the corresponding community element | |||
var checkedFilters = $(selector + ' .filtered-value-option input[type="checkbox"]:checked'); | |||
console.log("Checked filters count in " + selector + ":", checkedFilters.length); | |||
// If no filters are checked, show the community element associated with this selector | |||
if (checkedFilters.length === 0) { | |||
console.log("All filters are cleared in " + selector); | |||
communityElement.show(); | |||
} else { | |||
console.log("Some filters are still active in " + selector); | |||
communityElement.hide(); // Hide the community element if any filters are active | |||
} | |||
} | |||
} | |||
// Initial checks | |||
var selectors = [ | |||
'#list', | |||
'#list-block-1', | |||
'#list-block-2', | |||
'#list-block-3', | |||
'#list-list-1', | |||
'#list-list-2', | |||
'#list-list-3' | |||
]; | |||
var communityElements = [ | |||
$('#community-featured'), | |||
$('#community-featured-block-1'), | |||
$('#community-featured-block-2'), | |||
$('#community-featured-block-3'), | |||
$('#community-featured-list-1'), | |||
$('#community-featured-list-2'), | |||
$('#community-featured-list-3') | |||
]; | |||
// Call the function to initially set the visibility based on filters | |||
updateCommunityElementsVisibility(selectors, communityElements); | |||
// You can also call this function in response to filter changes or page events where filters might be modified | |||
$('#list, #list-block-1, #list-block-2, #list-block-3, #list-list-1, #list-list-2, #list-list-3').on('change', '.filtered-value-option input[type="checkbox"]', function() { | |||
areFiltersActive = $('.filtered-value-option input[type="checkbox"]:checked').length > 0; | |||
updateCommunityElementsVisibility(selectors, communityElements); | |||
}); | |||
// Function to open the modal and adjust the list | // Function to open the modal and adjust the list | ||
Line 108: | Line 243: | ||
// Adjust width of filtered-list-items in #list | // Adjust width of filtered-list-items in #list | ||
filteredListItems.css('width', 'calc(33.333% - 0px)'); | filteredListItems.css('width', 'calc(33.333% - 0px)'); | ||
// Hide communityFeatured | |||
$('[id^="community-featured"]').hide(); | |||
// Clear existing content in modal | // Clear existing content in modal | ||
Line 290: | Line 428: | ||
// End of openModal | // End of openModal | ||
} | } | ||
// Function to check if all filters are cleared in block view and its variations | |||
function checkBlockFiltersCleared() { | |||
var selectors = ['#list', '#list-block-1', '#list-block-2', '#list-block-3']; | |||
for (var i = 0; i < selectors.length; i++) { | |||
var selector = selectors[i]; | |||
var checkedFilters = $(selector + ' .filtered-value-option input[type="checkbox"]:checked'); | |||
console.log('Checked filters count in ' + selector + ':', checkedFilters.length); | |||
if (checkedFilters.length === 0) { | |||
console.log('All filters are cleared in ' + selector); | |||
// Show all community elements related to block views | |||
$('#community-featured, #community-featured-block-1, #community-featured-block-2, #community-featured-block-3').show(); | |||
} else { | |||
console.log('Some filters are still active in ' + selector); | |||
// Hide all community elements related to block views | |||
$('#community-featured, #community-featured-block-1, #community-featured-block-2, #community-featured-block-3').hide(); | |||
} | |||
} | |||
} | |||
// Function to check if all filters are cleared in list view and its variations | |||
function checkListFiltersCleared() { | |||
var selectors = ['#list-list', '#list-list-1', '#list-list-2', '#list-list-3']; | |||
for (var i = 0; i < selectors.length; i++) { | |||
var selector = selectors[i]; | |||
var checkedFilters = $(selector + ' .filtered-value-option input[type="checkbox"]:checked'); | |||
console.log('Checked filters count in ' + selector + ':', checkedFilters.length); | |||
if (checkedFilters.length === 0) { | |||
console.log('All filters are cleared in ' + selector); | |||
// Show all community elements related to list views | |||
$('#community-featured, #community-featured-list-1, #community-featured-list-2, #community-featured-list-3').show(); | |||
} else { | |||
console.log('Some filters are still active in ' + selector); | |||
// Hide all community elements related to list views | |||
$('#community-featured, #community-featured-list-1, #community-featured-list-2, #community-featured-list-3').hide(); | |||
} | |||
} | |||
} | |||
// closeModal function | // closeModal function | ||
Line 476: | Line 654: | ||
$(".home-block-view > div").hide(); | $(".home-block-view > div").hide(); | ||
$(".home-chronicle-block").show(); | $(".home-chronicle-block").show(); | ||
// Update the position of the communityFeatured elements for the chronicle block view | |||
updateCommunityFeaturedPosition('block', '1'); // '1' corresponds to chronicle | |||
}); | }); | ||
Line 486: | Line 667: | ||
$(".home-list-view > div").hide(); | $(".home-list-view > div").hide(); | ||
$(".home-chronicle-list").show(); | $(".home-chronicle-list").show(); | ||
// Update the position of the communityFeatured elements for the chronicle list view | |||
updateCommunityFeaturedPosition('list', '1'); // '1' corresponds to chronicle | |||
}); | }); | ||
Line 493: | Line 677: | ||
$(".home-list-view > div").hide(); | $(".home-list-view > div").hide(); | ||
$(".home-chronicle-list").show(); | $(".home-chronicle-list").show(); | ||
// Update the position of the communityFeatured element for the chronicle list view | |||
updateCommunityFeaturedPosition('list', '1'); // '1' corresponds to chronicle | |||
}); | }); | ||
Line 500: | Line 687: | ||
$(".home-list-view > div").hide(); | $(".home-list-view > div").hide(); | ||
$(".home-random-list").show(); | $(".home-random-list").show(); | ||
// Update the position of the communityFeatured element for the random list view | |||
updateCommunityFeaturedPosition('list', '2'); // '2' corresponds to random | |||
// Refresh the page | |||
location.reload(); | |||
}); | }); | ||
Line 506: | Line 698: | ||
$(".home-list-view > div").hide(); | $(".home-list-view > div").hide(); | ||
$(".home-alphabetical-list").show(); | $(".home-alphabetical-list").show(); | ||
// Update the position of the communityFeatured element for the alphabetical list view | |||
updateCommunityFeaturedPosition('list', '3'); // '3' corresponds to alphabetical | |||
}); | }); | ||
Line 514: | Line 709: | ||
$(".home-block-view > div").hide(); | $(".home-block-view > div").hide(); | ||
$(".home-chronicle-block").show(); | $(".home-chronicle-block").show(); | ||
// Update the position of the communityFeatured element for the alphabetical list view | |||
updateCommunityFeaturedPosition('block', '1'); // '1' corresponds to chronicle | |||
}); | }); | ||
Line 520: | Line 718: | ||
$(".home-block-view > div").hide(); | $(".home-block-view > div").hide(); | ||
$(".home-random-block").show(); | $(".home-random-block").show(); | ||
// Update the position of the communityFeatured element for the random list view | |||
updateCommunityFeaturedPosition('block', '2'); // '2' corresponds to random | |||
}); | }); | ||
Line 526: | Line 727: | ||
$(".home-block-view > div").hide(); | $(".home-block-view > div").hide(); | ||
$(".home-alphabetical-block").show(); | $(".home-alphabetical-block").show(); | ||
// Update the position of the communityFeatured element for the alphabetical list view | |||
updateCommunityFeaturedPosition('block', '3'); // '3' corresponds to alphabetical | |||
}); | }); | ||
}); | }); |