foundation-sites
Version:
The most advanced responsive front-end framework in the world.
583 lines (545 loc) • 25 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("./foundation.core"), require("jquery"), require("./foundation.util.keyboard"));
else if(typeof define === 'function' && define.amd)
define(["./foundation.core", "jquery", "./foundation.util.keyboard"], factory);
else if(typeof exports === 'object')
exports["__FOUNDATION_EXTERNAL__"] = factory(require("./foundation.core"), require("jquery"), require("./foundation.util.keyboard"));
else
root["__FOUNDATION_EXTERNAL__"] = root["__FOUNDATION_EXTERNAL__"] || {}, root["__FOUNDATION_EXTERNAL__"]["foundation.accordion"] = factory(root["__FOUNDATION_EXTERNAL__"]["foundation.core"], root["jQuery"], root["__FOUNDATION_EXTERNAL__"]["foundation.util.keyboard"]);
})(self, function(__WEBPACK_EXTERNAL_MODULE__foundation_core__, __WEBPACK_EXTERNAL_MODULE_jquery__, __WEBPACK_EXTERNAL_MODULE__foundation_util_keyboard__) {
return /******/ (function() { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./js/foundation.accordion.js":
/*!************************************!*\
!*** ./js/foundation.accordion.js ***!
\************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ Accordion: function() { return /* binding */ Accordion; }
/* harmony export */ });
/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery");
/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./foundation.core.utils */ "./foundation.core");
/* harmony import */ var _foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./foundation.util.keyboard */ "./foundation.util.keyboard");
/* harmony import */ var _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_2__);
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
/**
* Accordion module.
* @module foundation.accordion
* @requires foundation.util.keyboard
*/
var Accordion = /*#__PURE__*/function (_Plugin) {
function Accordion() {
_classCallCheck(this, Accordion);
return _callSuper(this, Accordion, arguments);
}
_inherits(Accordion, _Plugin);
return _createClass(Accordion, [{
key: "_setup",
value:
/**
* Creates a new instance of an accordion.
* @class
* @name Accordion
* @fires Accordion#init
* @param {jQuery} element - jQuery object to make into an accordion.
* @param {Object} options - a plain object with settings to override the default options.
*/
function _setup(element, options) {
this.$element = element;
this.options = jquery__WEBPACK_IMPORTED_MODULE_0___default().extend({}, Accordion.defaults, this.$element.data(), options);
this.className = 'Accordion'; // ie9 back compat
this._init();
_foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_2__.Keyboard.register('Accordion', {
'ENTER': 'toggle',
'SPACE': 'toggle',
'ARROW_DOWN': 'next',
'ARROW_UP': 'previous',
'HOME': 'first',
'END': 'last'
});
}
/**
* Initializes the accordion by animating the preset active pane(s).
* @private
*/
}, {
key: "_init",
value: function _init() {
var _this2 = this;
this._isInitializing = true;
this.$tabs = this.$element.children('[data-accordion-item]');
this.$tabs.each(function (idx, el) {
var $el = jquery__WEBPACK_IMPORTED_MODULE_0___default()(el),
$content = $el.children('[data-tab-content]'),
id = $content[0].id || (0,_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__.GetYoDigits)(6, 'accordion'),
linkId = el.id ? "".concat(el.id, "-label") : "".concat(id, "-label");
$el.find('a:first').attr({
'aria-controls': id,
'id': linkId,
'aria-expanded': false
});
$content.attr({
'role': 'region',
'aria-labelledby': linkId,
'aria-hidden': true,
'id': id
});
});
var $initActive = this.$element.find('.is-active').children('[data-tab-content]');
if ($initActive.length) {
// Save up the initial hash to return to it later when going back in history
this._initialAnchor = $initActive.prev('a').attr('href');
this._openSingleTab($initActive);
}
this._checkDeepLink = function () {
var anchor = window.location.hash;
if (!anchor.length) {
// If we are still initializing and there is no anchor, then there is nothing to do
if (_this2._isInitializing) return;
// Otherwise, move to the initial anchor
if (_this2._initialAnchor) anchor = _this2._initialAnchor;
}
var $anchor = anchor && jquery__WEBPACK_IMPORTED_MODULE_0___default()(anchor);
var $link = anchor && _this2.$element.find("[href$=\"".concat(anchor, "\"]"));
// Whether the anchor element that has been found is part of this element
var isOwnAnchor = !!($anchor.length && $link.length);
if (isOwnAnchor) {
// If there is an anchor for the hash, open it (if not already active)
if ($anchor && $link && $link.length) {
if (!$link.parent('[data-accordion-item]').hasClass('is-active')) {
_this2._openSingleTab($anchor);
}
}
// Otherwise, close everything
else {
_this2._closeAllTabs();
}
// Roll up a little to show the titles
if (_this2.options.deepLinkSmudge) {
(0,_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__.onLoad)(jquery__WEBPACK_IMPORTED_MODULE_0___default()(window), function () {
var offset = _this2.$element.offset();
jquery__WEBPACK_IMPORTED_MODULE_0___default()('html, body').animate({
scrollTop: offset.top - _this2.options.deepLinkSmudgeOffset
}, _this2.options.deepLinkSmudgeDelay);
});
}
/**
* Fires when the plugin has deeplinked at pageload
* @event Accordion#deeplink
*/
_this2.$element.trigger('deeplink.zf.accordion', [$link, $anchor]);
}
};
//use browser to open a tab, if it exists in this tabset
if (this.options.deepLink) {
this._checkDeepLink();
}
this._events();
this._isInitializing = false;
}
/**
* Adds event handlers for items within the accordion.
* @private
*/
}, {
key: "_events",
value: function _events() {
var _this = this;
this.$tabs.each(function () {
var $elem = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this);
var $tabContent = $elem.children('[data-tab-content]');
if ($tabContent.length) {
$elem.children('a').off('click.zf.accordion keydown.zf.accordion').on('click.zf.accordion', function (e) {
e.preventDefault();
_this.toggle($tabContent);
}).on('keydown.zf.accordion', function (e) {
_foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_2__.Keyboard.handleKey(e, 'Accordion', {
toggle: function toggle() {
_this.toggle($tabContent);
},
next: function next() {
var $a = $elem.next().find('a').focus();
if (!_this.options.multiExpand) {
$a.trigger('click.zf.accordion');
}
},
previous: function previous() {
var $a = $elem.prev().find('a').focus();
if (!_this.options.multiExpand) {
$a.trigger('click.zf.accordion');
}
},
first: function first() {
var $a = _this.$tabs.first().find('.accordion-title').focus();
if (!_this.options.multiExpand) {
$a.trigger('click.zf.accordion');
}
},
last: function last() {
var $a = _this.$tabs.last().find('.accordion-title').focus();
if (!_this.options.multiExpand) {
$a.trigger('click.zf.accordion');
}
},
handled: function handled() {
e.preventDefault();
}
});
});
}
});
if (this.options.deepLink) {
jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).on('hashchange', this._checkDeepLink);
}
}
/**
* Toggles the selected content pane's open/close state.
* @param {jQuery} $target - jQuery object of the pane to toggle (`.accordion-content`).
* @function
*/
}, {
key: "toggle",
value: function toggle($target) {
if ($target.closest('[data-accordion]').is('[disabled]')) {
console.info('Cannot toggle an accordion that is disabled.');
return;
}
if ($target.parent().hasClass('is-active')) {
this.up($target);
} else {
this.down($target);
}
//either replace or update browser history
if (this.options.deepLink) {
var anchor = $target.prev('a').attr('href');
if (this.options.updateHistory) {
history.pushState({}, '', anchor);
} else {
history.replaceState({}, '', anchor);
}
}
}
/**
* Opens the accordion tab defined by `$target`.
* @param {jQuery} $target - Accordion pane to open (`.accordion-content`).
* @fires Accordion#down
* @function
*/
}, {
key: "down",
value: function down($target) {
if ($target.closest('[data-accordion]').is('[disabled]')) {
console.info('Cannot call down on an accordion that is disabled.');
return;
}
if (this.options.multiExpand) this._openTab($target);else this._openSingleTab($target);
}
/**
* Closes the tab defined by `$target`.
* It may be ignored if the Accordion options don't allow it.
*
* @param {jQuery} $target - Accordion tab to close (`.accordion-content`).
* @fires Accordion#up
* @function
*/
}, {
key: "up",
value: function up($target) {
if (this.$element.is('[disabled]')) {
console.info('Cannot call up on an accordion that is disabled.');
return;
}
// Don't close the item if it is already closed
var $targetItem = $target.parent();
if (!$targetItem.hasClass('is-active')) return;
// Don't close the item if there is no other active item (unless with `allowAllClosed`)
var $othersItems = $targetItem.siblings();
if (!this.options.allowAllClosed && !$othersItems.hasClass('is-active')) return;
this._closeTab($target);
}
/**
* Make the tab defined by `$target` the only opened tab, closing all others tabs.
* @param {jQuery} $target - Accordion tab to open (`.accordion-content`).
* @function
* @private
*/
}, {
key: "_openSingleTab",
value: function _openSingleTab($target) {
// Close all the others active tabs.
var $activeContents = this.$element.children('.is-active').children('[data-tab-content]');
if ($activeContents.length) {
this._closeTab($activeContents.not($target));
}
// Then open the target.
this._openTab($target);
}
/**
* Opens the tab defined by `$target`.
* @param {jQuery} $target - Accordion tab to open (`.accordion-content`).
* @fires Accordion#down
* @function
* @private
*/
}, {
key: "_openTab",
value: function _openTab($target) {
var _this3 = this;
var $targetItem = $target.parent();
var targetContentId = $target.attr('aria-labelledby');
$target.attr('aria-hidden', false);
$targetItem.addClass('is-active');
jquery__WEBPACK_IMPORTED_MODULE_0___default()("#".concat(targetContentId)).attr({
'aria-expanded': true
});
$target.finish().slideDown(this.options.slideSpeed, function () {
/**
* Fires when the tab is done opening.
* @event Accordion#down
*/
_this3.$element.trigger('down.zf.accordion', [$target]);
});
}
/**
* Closes the tab defined by `$target`.
* @param {jQuery} $target - Accordion tab to close (`.accordion-content`).
* @fires Accordion#up
* @function
* @private
*/
}, {
key: "_closeTab",
value: function _closeTab($target) {
var _this4 = this;
var $targetItem = $target.parent();
var targetContentId = $target.attr('aria-labelledby');
$target.attr('aria-hidden', true);
$targetItem.removeClass('is-active');
jquery__WEBPACK_IMPORTED_MODULE_0___default()("#".concat(targetContentId)).attr({
'aria-expanded': false
});
$target.finish().slideUp(this.options.slideSpeed, function () {
/**
* Fires when the tab is done collapsing up.
* @event Accordion#up
*/
_this4.$element.trigger('up.zf.accordion', [$target]);
});
}
/**
* Closes all active tabs
* @fires Accordion#up
* @function
* @private
*/
}, {
key: "_closeAllTabs",
value: function _closeAllTabs() {
var $activeTabs = this.$element.children('.is-active').children('[data-tab-content]');
if ($activeTabs.length) {
this._closeTab($activeTabs);
}
}
/**
* Destroys an instance of an accordion.
* @fires Accordion#destroyed
* @function
*/
}, {
key: "_destroy",
value: function _destroy() {
this.$element.find('[data-tab-content]').stop(true).slideUp(0).css('display', '');
this.$element.find('a').off('.zf.accordion');
if (this.options.deepLink) {
jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).off('hashchange', this._checkDeepLink);
}
}
}]);
}(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__.Plugin);
Accordion.defaults = {
/**
* Amount of time to animate the opening of an accordion pane.
* @option
* @type {number}
* @default 250
*/
slideSpeed: 250,
/**
* Allow the accordion to have multiple open panes.
* @option
* @type {boolean}
* @default false
*/
multiExpand: false,
/**
* Allow the accordion to close all panes.
* @option
* @type {boolean}
* @default false
*/
allowAllClosed: false,
/**
* Link the location hash to the open pane.
* Set the location hash when the opened pane changes, and open and scroll to the corresponding pane when the location changes.
* @option
* @type {boolean}
* @default false
*/
deepLink: false,
/**
* If `deepLink` is enabled, adjust the deep link scroll to make sure the top of the accordion panel is visible
* @option
* @type {boolean}
* @default false
*/
deepLinkSmudge: false,
/**
* If `deepLinkSmudge` is enabled, animation time (ms) for the deep link adjustment
* @option
* @type {number}
* @default 300
*/
deepLinkSmudgeDelay: 300,
/**
* If `deepLinkSmudge` is enabled, the offset for scrollToTtop to prevent overlap by a sticky element at the top of the page
* @option
* @type {number}
* @default 0
*/
deepLinkSmudgeOffset: 0,
/**
* If `deepLink` is enabled, update the browser history with the open accordion
* @option
* @type {boolean}
* @default false
*/
updateHistory: false
};
/***/ }),
/***/ "./foundation.core":
/*!****************************************************************************************************************************************************************!*\
!*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.core"],"amd":"./foundation.core","commonjs":"./foundation.core","commonjs2":"./foundation.core"} ***!
\****************************************************************************************************************************************************************/
/***/ (function(module) {
module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_core__;
/***/ }),
/***/ "./foundation.util.keyboard":
/*!****************************************************************************************************************************************************************************************************!*\
!*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.util.keyboard"],"amd":"./foundation.util.keyboard","commonjs":"./foundation.util.keyboard","commonjs2":"./foundation.util.keyboard"} ***!
\****************************************************************************************************************************************************************************************************/
/***/ (function(module) {
module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_util_keyboard__;
/***/ }),
/***/ "jquery":
/*!********************************************************************************************!*\
!*** external {"root":["jQuery"],"amd":"jquery","commonjs":"jquery","commonjs2":"jquery"} ***!
\********************************************************************************************/
/***/ (function(module) {
module.exports = __WEBPACK_EXTERNAL_MODULE_jquery__;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ !function() {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function() { return module['default']; } :
/******/ function() { return module; };
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ !function() {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = function(exports, definition) {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ !function() {
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
/******/ }();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ !function() {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ }();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
!function() {
/*!****************************************************!*\
!*** ./js/entries/plugins/foundation.accordion.js ***!
\****************************************************/
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ Accordion: function() { return /* reexport safe */ _foundation_accordion__WEBPACK_IMPORTED_MODULE_1__.Accordion; },
/* harmony export */ Foundation: function() { return /* reexport safe */ _foundation_core__WEBPACK_IMPORTED_MODULE_0__.Foundation; }
/* harmony export */ });
/* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./foundation.core */ "./foundation.core");
/* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_foundation_core__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _foundation_accordion__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../foundation.accordion */ "./js/foundation.accordion.js");
_foundation_core__WEBPACK_IMPORTED_MODULE_0__.Foundation.plugin(_foundation_accordion__WEBPACK_IMPORTED_MODULE_1__.Accordion, 'Accordion');
}();
/******/ return __webpack_exports__;
/******/ })()
;
});
//# sourceMappingURL=foundation.accordion.js.map