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

check to run only one hash check #396

Merged
merged 2 commits into from
Dec 9, 2021
Merged
Changes from all commits
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
19 changes: 11 additions & 8 deletions src/assets/_project/_blocks/components/accordion/qg-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class QgAccordion {
}

/**
* hashTrigger function open matching accordion if it finds #title-Of-Accordion in the url
* hashTrigger function open matching accordion if it finds #title-Of-Accordion or #id-panel-section in the url
* function trims down the hash value, and then it matches with the titles of the accordion, and if there is a matching title, then it open that panel
* @return {undefined}
**/
Expand All @@ -41,19 +41,22 @@ export class QgAccordion {
let hashValTrimmed = this.filterSpecialChar(window.location.hash);
let hashValueIdMatch = window.location.hash.replace('#', '');
if (hashValTrimmed.length > 0) {
// supports title match
self.$accordion.find('.title').each(function (index, titleEl){
if (self.filterSpecialChar($(titleEl).text()) === hashValTrimmed){
$(this).parents(self.$accHeading).trigger('click');
}
});
// supports ID match
self.$accordion.find('.collapsing-section').each(function (index, titleEl){
if ($(this).attr('id') === hashValueIdMatch){
console.log(hashValueIdMatch === $(this).attr('id'));
$(this).parent('article').find(self.$accHeading).trigger('click');
}
});

// supports title match
// check if any panel already open that worked with ID matching
if ($('.qg-accordion--open').length <= 0){
self.$accordion.find('.title').each(function (index, titleEl){
if (self.filterSpecialChar($(titleEl).text()) === hashValTrimmed){
$(this).parents(self.$accHeading).trigger('click');
}
});
}
}
}

Expand Down