4,130
edits
No edit summary Tag: Reverted |
No edit summary Tags: Manual revert Reverted |
||
Line 1: | Line 1: | ||
$(document).ready(function () { | $(document).ready(function () { | ||
var communityFeatured = $('#community-featured'); | var communityFeatured = $('#community-featured'); | ||
var | var filteredCards = $('.filtered-list-item'); | ||
var showArticleWrapper = $('#show-article-wrapper'); | var showArticleWrapper = $('#show-article-wrapper'); | ||
var listLists = [$('#list'), $('#list-list'), $('#list-list-1'), $('#list-list-2'), $('#list-list-3')]; | var list = $('#list'); | ||
var listList = $('#list-list'); | |||
var filteredListItems = $('#list .filtered-list-item'); // Selecting filtered-list-items in #list | |||
var listLists = [$('#list'), $('#list-list'), $('#list-list-1'), $('#list-list-2'), $('#list-list-3')]; // Store jQuery objects in an array | |||
var originalWidths = listLists.map(function(list) { | |||
return list.width(); | |||
}); | |||
// Insert the community featured element after the second card | |||
if (communityFeatured.length && filteredCards.length >= 2) { | |||
communityFeatured.detach(); | |||
filteredCards.eq(1).after(communityFeatured); | |||
communityFeatured.show(); | |||
} | |||
// Setup images in original Entry pages | |||
if ($('#show-article-wrapper-entry').length > 0 || $('#show-article-wrapper').length > 0) { | |||
var images = []; // Initialize an empty array to store the images | |||
$('.article-images .image-container').each(function() { | |||
var img = $(this).find('img'); | |||
var captionDiv = $(this).find('div[class^="caption-image"]'); | |||
var image = { | |||
src: img.attr('src'), | |||
alt: img.attr('alt'), | |||
caption: captionDiv.text(), | |||
captionClass: captionDiv.attr('class') | |||
}; | |||
images.push(image); // Add the image object to the images array | |||
}); | |||
if (images.length > 0) { | |||
setupImageToggle(images); // Call the setupImageToggle function with the images array | |||
if ( | updateImageLabel(1, images.length); // Set the label for the first image immediately | ||
} | } | ||
} | } | ||
// FILTERS | |||
$('#list, #list-list').on('mousedown', '.filtered-value-option', function(event) { | |||
console.log("Filter clicked within context:", this); | |||
if ($(this).closest('#list').length) { | |||
console.log("Context: #list"); | |||
console.log("Before hiding, Community Featured display:", communityFeatured.css('display')); | |||
console.log("After hiding, Community Featured display:", communityFeatured.css('display')); | |||
} else if ($(this).closest('#list-list').length) { | |||
console.log("Context: #list-list"); | |||
console.log("Before hiding, Community List Featured display:", communityFeatured.css('display')); | |||
console.log("After hiding, Community List Featured display:", communityFeatured.css('display')); | |||
} | |||
// Additional debugging: Check the event target and its parents | |||
console.log("Event target:", event.target); | |||
console.log("Parents of event target:", $(event.target).parents()); | |||
}); | |||
// | //cleaned uppppppppppppppppppp | ||
$('#list, #list-list').on('mousedown', '.filtered-value-option', function(event) { | |||
// Determine the context based on whether the clicked element is within #list or #list-list | |||
var context = $(this).closest('#list').length ? '#list' : '#list-list'; | |||
// Call a function to update the visibility of communityFeatured based on the active filters within the context | |||
updateCommunityFeaturedVisibility(context); | |||
}); | |||
function updateCommunityFeaturedVisibility(context) { | |||
// Check if there are any checked filters within the given context | |||
var checkedFilters = $(context + ' .filtered-value-option input[type="checkbox"]:checked').length; | |||
// Show or hide communityFeatured based on whether there are checked filters | |||
if (checkedFilters === 0) { | |||
communityFeatured.show(); | |||
} else { | |||
communityFeatured.hide(); | |||
} | |||
}// end of cleaned uppppppppppppppppppp | |||
// Format paragraphs | |||
function formatParagraphs(text) { | |||
var paragraphs = text.split('\n').filter(function (p) { return p.trim() !== '' }); | |||
return paragraphs.map(function (p) { return '<p>' + p.trim() + '</p>'; }).join(''); | |||
} | |||
// Format community card, when in the Community Entries page | |||
if ($('.community-card').length) { | |||
formatCommunityCardDescriptions(); | |||
} | |||
function formatCommunityCardDescriptions() { | |||
console.log("Formatting community card descriptions"); | |||
$('.community-card').each(function() { | |||
console.log("Processing a community card"); | |||
// Format paragraphs in community-description | |||
var descriptionContainer = $(this).find('.community-description'); | |||
var rawDescription = descriptionContainer.text(); | |||
var formattedDescription = formatParagraphs(rawDescription); | |||
descriptionContainer.html(formattedDescription); | |||
// Remove empty elements in the entire card | |||
$(this).find('*').each(function() { | |||
if ($(this).is(':empty') || $(this).html().trim() === '<br>') { | |||
$(this).remove(); | |||
} | |||
}); | |||
console.log("Formatted Community Card HTML:", $(this).html()); | |||
}); | |||
} | |||
var toggleButton = $('.toggle-filters'); | |||
var filtersDiv = $('.filtered-filters'); | |||
// Open and Close button for filters | |||
if (toggleButton.length && filtersDiv.length) { | |||
toggleButton.on('click', function(event) { | |||
event.preventDefault(); | |||
console.log("Button clicked. Current display style:", filtersDiv.css('display')); | |||
if (filtersDiv.css('display') === 'none' || filtersDiv.css('display') === '') { | |||
filtersDiv.attr('style', 'display: flex !important'); | |||
toggleButton.text('[Close]'); | |||
console.log("Filters shown."); | |||
} else { | |||
filtersDiv.attr('style', 'display: none !important'); | |||
toggleButton.text('[Open]'); | |||
console.log("Filters hidden."); | |||
} | } | ||
} | }); | ||
} | } | ||
/* // Function to check if filters are cleared and update visibility of community elements | |||
function checkFiltersCleared(selector, communityElement) { | |||
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); | |||
communityElement.show(); | |||
} else { | |||
console.log("Some filters are still active in " + selector); | |||
communityElement.hide(); // Hide the element if any filters are active | |||
} | |||
} */ | |||
/* // Event delegation for filter changes in both block and list views | |||
$('#list, #list-list').on('change', '.filtered-value-option input[type="checkbox"]', function() { | |||
// Determine the closest list or list-list element to identify the context | |||
var closestContext = $(this).closest('#list, #list-list'); | |||
var contextId = closestContext.attr('id'); // Get the id ('list' or 'list-list') | |||
// Call the checkFiltersCleared function with the appropriate context and communityFeatured element | |||
checkFiltersCleared('#' + contextId, communityFeatured); | |||
}); | |||
// Initial checks | |||
var selectors = ['#list', '#list-list']; | |||
// Iterate over the selectors and perform initial checks | |||
selectors.forEach(function(selector) { | |||
checkFiltersCleared(selector, communityFeatured); | |||
}); */ | |||
// | // simplify | ||
$('#list, #list-list').on(' | // Event delegation for filter changes in both block and list views | ||
updateCommunityFeaturedVisibility( | $('#list, #list-list').on('change', '.filtered-value-option input[type="checkbox"]', function() { | ||
// Call the new function to update the visibility of communityFeatured based on current filters | |||
updateCommunityFeaturedVisibility(); | |||
}); | }); | ||
// Perform initial check on page load or when the script is initially run | |||
updateCommunityFeaturedVisibility(); | |||
// Function to check if all filters are cleared and return boolean | |||
function areFiltersCleared(selector) { | |||
var checkedFilters = $(selector + ' .filtered-value-option input[type="checkbox"]:checked'); | |||
return checkedFilters.length === 0; | |||
} | |||
// Function to open the modal and adjust the list | |||
function openModal(cardElement, event) { | |||
event.stopPropagation(); // Prevent the event from bubbling up | |||
console.log('openModal called with:', cardElement); | |||
var isRelatedArticle = $(cardElement).hasClass('related-article'); | |||
console.log('Is this a related article?:', isRelatedArticle); | |||
showArticleWrapper.css('display', 'block'); | |||
// Set new width using .each() to iterate over the jQuery objects | |||
$.each(listLists, function(index, list) { | |||
if (isRelatedArticle) { | list.css('cssText', 'width: 60% !important;'); | ||
}); | |||
// Adjust width of filtered-list-items in #list | |||
filteredListItems.css('width', 'calc(33.333% - 0px)'); | |||
// Hide communityFeatured | |||
communityFeatured.hide(); | |||
// Clear existing content in modal | |||
$('#article-title').empty(); | |||
$('#article-content').empty(); | |||
if (isRelatedArticle) { | |||
// Handle card elements (existing logic) | // Handle card elements (existing logic) | ||
var cardImages = []; | var cardImages = []; | ||
Line 232: | Line 381: | ||
$('#list, #list-list, #list-list-1, #list-list-2, #list-list-3, #list-block-1, #list-block-2, #list-block-3').addClass('fade-out'); | $('#list, #list-list, #list-list-1, #list-list-2, #list-list-3, #list-block-1, #list-block-2, #list-block-3').addClass('fade-out'); | ||
// End of openModal | // End of openModal | ||
} | |||
// Function to check if all filters are cleared in block view | |||
function checkBlockFiltersCleared() { | |||
var checkedFilters = $('#list .filtered-value-option input[type="checkbox"]:checked'); | |||
console.log("Checked filters count:", checkedFilters.length); | |||
if (checkedFilters.length === 0) { | |||
console.log("All filters are cleared in block view"); | |||
communityFeatured.show(); | |||
} else { | |||
console.log("Some filters are still active in block view"); | |||
} | |||
} | |||
// Function to check if all filters are cleared in list view | |||
function checkListFiltersCleared() { | |||
var checkedFilters = $('#list-list .filtered-value-option input[type="checkbox"]:checked'); | |||
console.log("Checked filters count:", checkedFilters.length); | |||
if (checkedFilters.length === 0) { | |||
console.log("All filters are cleared in list view"); | |||
communityFeatured.show(); | |||
} else { | |||
console.log("Some filters are still active in list view"); | |||
} | |||
} | |||
// closeModal function | |||
function closeModal() { | |||
showArticleWrapper.hide(); | |||
// Revert width of filtered-list-items in listLists | |||
$.each(listLists, function(index, list) { | |||
list.width(originalWidths[index]); | |||
}); | |||
// Revert width of filtered-list-items in #list | |||
filteredListItems.css('width', 'calc(20% - 0px)'); | |||
// Check if filters are cleared before showing the featured content | |||
checkBlockFiltersCleared(); | |||
checkListFiltersCleared(); | |||
} | |||
// Button to open [Nr.s] | // Button to open [Nr.s] |