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

Open product tabs on load. #1304

Merged
merged 2 commits into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Draft
- Open correct product page tabs when URL contains a fragment identifier referring to that content [#1304](https://github.com/bigcommerce/cornerstone/pull/1304)

## 2.2.1 (2018-07-10)
- Fix wishlist dropdown background color bleeding out of container [#1283](https://github.com/bigcommerce/cornerstone/pull/1283)
Expand Down
23 changes: 22 additions & 1 deletion assets/js/theme/common/product-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export default class ProductDetails {
this.imageGallery.init();
this.listenQuantityChange();
this.initRadioAttributes();

Wishlist.load(this.context);
this.getTabRequests();

const $form = $('form[data-cart-item-add]', $scope);
const $productOptionsElement = $('[data-product-option-change]', $form);
Expand Down Expand Up @@ -607,4 +607,25 @@ export default class ProductDetails {
$radio.attr('data-state', $radio.prop('checked'));
});
}

/**
* Check for fragment identifier in URL requesting a specific tab
*/
getTabRequests() {
if (window.location.hash && window.location.hash.indexOf('#tab-') === 0) {
const $activeTab = $('.tabs').has(`[href='${window.location.hash}']`);
const $tabContent = $(`${window.location.hash}`);

if ($activeTab.length > 0) {
$activeTab.find('.tab')
.removeClass('is-active')
.has(`[href='${window.location.hash}']`)
.addClass('is-active');

$tabContent.addClass('is-active')
.siblings()
.removeClass('is-active');
}
}
}
}