-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: 1.x
Are you sure you want to change the base?
Changes from 1 commit
40a4d5c
96ccb5b
25697b7
4e72940
9881a49
0696b6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,54 @@ | |
} | ||
}; | ||
})(jQuery, Drupal); | ||
|
||
/** | ||
* Collapse able menu for Publication page | ||
* | ||
* @param {object} context | ||
*/ | ||
Drupal.behaviors.publicationMenuToggle = { | ||
attach: function(context) { | ||
const menuCollapseBreakpoint = 992; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that seems like a sensible approach. |
||
$(window).resize(initializeStateForMenus); | ||
} | ||
}; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.