Skip to content

Commit

Permalink
Merge pull request #1304 from Ubersmake/AnchorTabs
Browse files Browse the repository at this point in the history
Open product tabs on load.
  • Loading branch information
Ubersmake authored Jul 11, 2018
2 parents 30ce4f7 + b312912 commit d2eee0a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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');
}
}
}
}

0 comments on commit d2eee0a

Please sign in to comment.