- allow users to open a particular accordion panel at page load with a hash-appended URL
```html_example
-<ul class="accordion" data-accordion data-deep-link="true" id="deeplinked-accordion">
+<ul class="accordion" data-accordion data-deep-link="true" data-update-history="true" data-deep-link-smudge="true" data-deep-link-smudge="500" id="deeplinked-accordion">
<li class="accordion-item is-active" data-accordion-item>
<a href="#deeplink1" class="accordion-title">Accordion 1</a>
<div class="accordion-content" data-tab-content id="deeplink1">
$content.attr({'role': 'tabpanel', 'aria-labelledby': linkId, 'aria-hidden': true, 'id': id});
});
- var $initActive = this.$element.find('.is-active').children('[data-tab-content]'),
- firstTimeInit = true;
+ var $initActive = this.$element.find('.is-active').children('[data-tab-content]');
+ this.firstTimeInit = true;
if($initActive.length){
- this.down($initActive, firstTimeInit);
- firstTimeInit = false;
+ this.down($initActive, this.firstTimeInit);
+ this.firstTimeInit = false;
}
- //use browser to open a tab, if it exists in this tabset
- if (this.options.deepLink) {
+ this._checkDeepLink = () => {
var anchor = window.location.hash;
//need a hash and a relevant anchor in this tabset
if(anchor.length) {
if ($link.length && $anchor) {
if (!$link.parent('[data-accordion-item]').hasClass('is-active')) {
- this.down($anchor, firstTimeInit);
- firstTimeInit = false;
+ this.down($anchor, this.firstTimeInit);
+ this.firstTimeInit = false;
};
//roll up a little to show the titles
}
}
+ //use browser to open a tab, if it exists in this tabset
+ if (this.options.deepLink) {
+ this._checkDeepLink();
+ }
+
this._events();
}
});
}
});
+ if(this.options.deepLink) {
+ $(window).on('popstate', this._checkDeepLink);
+ }
}
/**
destroy() {
this.$element.find('[data-tab-content]').stop(true).slideUp(0).css('display', '');
this.$element.find('a').off('.zf.accordion');
+ if(this.options.deepLink) {
+ $(window).off('popstate', this._checkDeepLink);
+ }
Foundation.unregisterPlugin(this);
}