Skip to content

Instantly share code, notes, and snippets.

@nakamuraagatha
Created May 15, 2017 07:47
Show Gist options
  • Save nakamuraagatha/d4b1642f88afd9fe60f193d46734831f to your computer and use it in GitHub Desktop.
Save nakamuraagatha/d4b1642f88afd9fe60f193d46734831f to your computer and use it in GitHub Desktop.
wp expand collapse
function bgExpandCollapsedContent() {
var bgCollapseExpandItems = document.querySelectorAll('input[bg_collapse_expand]');
for ( i=0; i<bgCollapseExpandItems.length; i++) {
var showHideButton = document.getElementById('bg-showmore-action-'+bgCollapseExpandItems[i].value);
var hiddenContent = document.getElementById('bg-showmore-hidden-'+bgCollapseExpandItems[i].value);
if (showHideButton && hiddenContent) {
showHideButton.addEventListener('click', function(event) {bgExpandCollapsedContentAction(event, this);} );
}
}
}
function bgExpandCollapsedContentAction(event, thisObj) {
event.preventDefault();
var bgUniqId = thisObj.id.replace('bg-showmore-action-', '');
var showHideButton = document.getElementById('bg-showmore-action-'+bgUniqId);
var hiddenContent = document.getElementById('bg-showmore-hidden-'+bgUniqId);
var showLessText = document.getElementById('bg-show-less-text-'+bgUniqId).value;
var showMoreText = document.getElementById('bg-show-more-text-'+bgUniqId).value;
var text = jQuery(showHideButton).text();
jQuery( hiddenContent ).toggle();
if (showLessText === '') {
jQuery( showHideButton ).toggle();
if (jQuery( showHideButton ).parent().prop("tagName") === 'LI') {
jQuery( showHideButton ).parent().toggle();
}
}
else {
jQuery(showHideButton).text(
text == showMoreText ? showLessText : showMoreText
);
jQuery(showHideButton).toggleClass("close");
}
if ('undefined' !== typeof gmspAllMaps) {
gmspResizeMaps();
}
}
jQuery(document).ready(function() {
bgExpandCollapsedContent();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment