Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added collapsible contents block #217

Open
wants to merge 6 commits into
base: 1.x
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions js/localgov-publications.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,54 @@
}
};
})(jQuery, Drupal);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this code should be inside the closure that the existing JS code defines.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I've just realised the existing code is only for admin pages. This new code should probably be in its own file and library definition.

/**
* Collapse able menu for Publication page
*
* @param {object} context
*/
Drupal.behaviors.publicationMenuToggle = {
attach: function(context) {
const menuCollapseBreakpoint = 992;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this value correct for every LGD site? If not, it'll need to be configurable somehow, or done another way.


var headers = [
$('.bfc-publication-navigation__content-header', context),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like some Bracknell forest specific code.

$('.bfc-publication-tableofcontent__content-header', context)
];
var menus = [
$('#block-bfc-publicationnavigation ul.list--no-style', context),
$('#block-bfc-publicationstableofcontentsblock .publication-content-block', context)
];
function toggleMenuVisibilityAndIcon(header, menu) {
header.on('click', function () {
menu.toggleClass('is-hidden');
header.toggleClass('up-icon down-icon');
});
}

let previousWidth = -1;

function initializeStateForMenus() {
const previousCollapseState = previousWidth < menuCollapseBreakpoint;
const newCollapseState = window.innerWidth < menuCollapseBreakpoint;

if (previousCollapseState === newCollapseState && !(previousWidth === -1)) {
return;
}
previousWidth = window.innerWidth;

headers.forEach(function(header, index) {
menus[index].toggleClass('is-hidden', newCollapseState);
header.toggleClass('up-icon', !newCollapseState).toggleClass('down-icon', newCollapseState);
});
}
headers.forEach(function(header, index) {
if (!header.data('menuToggleAttached')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's re-inventing once. Could it use once instead?

toggleMenuVisibilityAndIcon(header, menus[index]);
header.data('menuToggleAttached', true);
}
});
initializeStateForMenus();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need a way to make this feature optional. It can be defaulted to on for new installs, but we can't enable it by default for existing sites.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be achieved by adding a toggle in the block config for setting enabled/disabled?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that seems like a sensible approach.

$(window).resize(initializeStateForMenus);
}
};