+'use strict';
+
/**
* Tabs module.
* @module foundation.tabs
* @requires foundation.util.keyboard
* @requires foundation.util.timerAndImageLoader if tabs contain images
*/
-!function($, Foundation) {
- 'use strict';
+export default class Tabs {
/**
* Creates a new instance of tabs.
* @class
* @param {jQuery} element - jQuery object to make into tabs.
* @param {Object} options - Overrides to the default plugin settings.
*/
- function Tabs(element, options){
+ constructor(element, options) {
this.$element = element;
this.options = $.extend({}, Tabs.defaults, this.$element.data(), options);
});
}
- Tabs.defaults = {
- // /**
- // * Allows the JS to alter the url of the window. Not yet implemented.
- // */
- // deepLinking: false,
- // /**
- // * If deepLinking is enabled, allows the window to scroll to content if window is loaded with a hash including a tab-pane id
- // */
- // scrollToContent: false,
- /**
- * Allows the window to scroll to content of active pane on load if set to true.
- * @option
- * @example false
- */
- autoFocus: false,
- /**
- * Allows keyboard input to 'wrap' around the tab links.
- * @option
- * @example true
- */
- wrapOnKeys: true,
- /**
- * Allows the tab content panes to match heights if set to true.
- * @option
- * @example false
- */
- matchHeight: false,
- /**
- * Class applied to `li`'s in tab link list.
- * @option
- * @example 'tabs-title'
- */
- linkClass: 'tabs-title',
- // contentClass: 'tabs-content',
- /**
- * Class applied to the content containers.
- * @option
- * @example 'tabs-panel'
- */
- panelClass: 'tabs-panel'
- };
-
/**
* Initializes the tabs by showing and focusing (if autoFocus=true) the preset active tab.
* @private
*/
- Tabs.prototype._init = function(){
+ _init() {
var _this = this;
this.$tabTitles = this.$element.find(`.${this.options.linkClass}`);
}
}
this._events();
- };
+ }
+
/**
* Adds event handlers for items within the tabs.
* @private
*/
- Tabs.prototype._events = function(){
+ _events() {
this._addKeyHandler();
this._addClickHandler();
if(this.options.matchHeight){
$(window).on('changed.zf.mediaquery', this._setHeight.bind(this));
}
- };
+ }
/**
* Adds click handlers for items within the tabs.
* @private
*/
- Tabs.prototype._addClickHandler = function(){
+ _addClickHandler() {
var _this = this;
this.$element.off('click.zf.tabs')
.on('click.zf.tabs', `.${this.options.linkClass}`, function(e){
}
_this._handleTabChange($(this));
});
- };
+ }
/**
* Adds keyboard event handlers for items within the tabs.
* @private
*/
- Tabs.prototype._addKeyHandler = function(){
+ _addKeyHandler() {
var _this = this;
var $firstTab = _this.$element.find('li:first-of-type');
var $lastTab = _this.$element.find('li:last-of-type');
}
});
});
- };
-
+ }
/**
* Opens the tab `$targetContent` defined by `$target`.
* @fires Tabs#change
* @function
*/
- Tabs.prototype._handleTabChange = function($target){
+ _handleTabChange($target) {
var $tabLink = $target.find('[role="tab"]'),
hash = $tabLink[0].hash,
$targetContent = $(hash),
*/
this.$element.trigger('change.zf.tabs', [$target]);
// Foundation.reflow(this.$element, 'tabs');
- };
+ }
/**
* Public method for selecting a content pane to display.
* @param {jQuery | String} elem - jQuery object or string of the id of the pane to display.
* @function
*/
- Tabs.prototype.selectTab = function(elem){
+ selectTab(elem) {
var idStr;
if(typeof elem === 'object'){
idStr = elem[0].id;
* @function
* @private
*/
- Tabs.prototype._setHeight = function(){
+ _setHeight() {
var max = 0;
this.$tabContent.find(`.${this.options.panelClass}`)
.css('height', '')
max = temp > max ? temp : max;
})
.css('height', `${max}px`);
- };
+ }
/**
* Destroys an instance of an tabs.
* @fires Tabs#destroyed
*/
- Tabs.prototype.destroy = function() {
+ destroy() {
this.$element.find(`.${this.options.linkClass}`)
.off('.zf.tabs').hide().end()
.find(`.${this.options.panelClass}`)
}
Foundation.unregisterPlugin(this);
};
+}
+
+Tabs.defaults = {
+ // /**
+ // * Allows the JS to alter the url of the window. Not yet implemented.
+ // */
+ // deepLinking: false,
+ // /**
+ // * If deepLinking is enabled, allows the window to scroll to content if window is loaded with a hash including a tab-pane id
+ // */
+ // scrollToContent: false,
+ /**
+ * Allows the window to scroll to content of active pane on load if set to true.
+ * @option
+ * @example false
+ */
+ autoFocus: false,
+ /**
+ * Allows keyboard input to 'wrap' around the tab links.
+ * @option
+ * @example true
+ */
+ wrapOnKeys: true,
+ /**
+ * Allows the tab content panes to match heights if set to true.
+ * @option
+ * @example false
+ */
+ matchHeight: false,
+ /**
+ * Class applied to `li`'s in tab link list.
+ * @option
+ * @example 'tabs-title'
+ */
+ linkClass: 'tabs-title',
+ // contentClass: 'tabs-content',
+ /**
+ * Class applied to the content containers.
+ * @option
+ * @example 'tabs-panel'
+ */
+ panelClass: 'tabs-panel'
+};
+
+function checkClass($elem){
+ return $elem.hasClass('is-active');
+}
+
+// Window exports
+if (window.Foundation) {
+ window.Foundation.plugin(Tabs, 'Tabs');
+}
+
- Foundation.plugin(Tabs, 'Tabs');
- function checkClass($elem){
- return $elem.hasClass('is-active');
- }
-}(jQuery, window.Foundation);