foundation-sites
Version:
The most advanced responsive front-end framework in the world.
530 lines (495 loc) • 24.9 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"), require("./foundation.util.nest"));
else if(typeof define === 'function' && define.amd)
define(["./foundation.core", "jquery", "./foundation.util.keyboard", "./foundation.util.nest"], factory);
else if(typeof exports === 'object')
exports["__FOUNDATION_EXTERNAL__"] = factory(require("./foundation.core"), require("jquery"), require("./foundation.util.keyboard"), require("./foundation.util.nest"));
else
root["__FOUNDATION_EXTERNAL__"] = root["__FOUNDATION_EXTERNAL__"] || {}, root["__FOUNDATION_EXTERNAL__"]["foundation.accordionMenu"] = factory(root["__FOUNDATION_EXTERNAL__"]["foundation.core"], root["jQuery"], root["__FOUNDATION_EXTERNAL__"]["foundation.util.keyboard"], root["__FOUNDATION_EXTERNAL__"]["foundation.util.nest"]);
})(self, function(__WEBPACK_EXTERNAL_MODULE__foundation_core__, __WEBPACK_EXTERNAL_MODULE_jquery__, __WEBPACK_EXTERNAL_MODULE__foundation_util_keyboard__, __WEBPACK_EXTERNAL_MODULE__foundation_util_nest__) {
return /******/ (function() { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./js/foundation.accordionMenu.js":
/*!****************************************!*\
!*** ./js/foundation.accordionMenu.js ***!
\****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ AccordionMenu: function() { return /* binding */ AccordionMenu; }
/* 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_util_keyboard__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./foundation.util.keyboard */ "./foundation.util.keyboard");
/* harmony import */ var _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _foundation_util_nest__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./foundation.util.nest */ "./foundation.util.nest");
/* harmony import */ var _foundation_util_nest__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_nest__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./foundation.core.plugin */ "./foundation.core");
/* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_3__);
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); }
/**
* AccordionMenu module.
* @module foundation.accordionMenu
* @requires foundation.util.keyboard
* @requires foundation.util.nest
*/
var AccordionMenu = /*#__PURE__*/function (_Plugin) {
function AccordionMenu() {
_classCallCheck(this, AccordionMenu);
return _callSuper(this, AccordionMenu, arguments);
}
_inherits(AccordionMenu, _Plugin);
return _createClass(AccordionMenu, [{
key: "_setup",
value:
/**
* Creates a new instance of an accordion menu.
* @class
* @name AccordionMenu
* @fires AccordionMenu#init
* @param {jQuery} element - jQuery object to make into an accordion menu.
* @param {Object} options - Overrides to the default plugin settings.
*/
function _setup(element, options) {
this.$element = element;
this.options = jquery__WEBPACK_IMPORTED_MODULE_0___default().extend({}, AccordionMenu.defaults, this.$element.data(), options);
this.className = 'AccordionMenu'; // ie9 back compat
this._init();
_foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_1__.Keyboard.register('AccordionMenu', {
'ENTER': 'toggle',
'SPACE': 'toggle',
'ARROW_RIGHT': 'open',
'ARROW_UP': 'up',
'ARROW_DOWN': 'down',
'ARROW_LEFT': 'close',
'ESCAPE': 'closeAll'
});
}
/**
* Initializes the accordion menu by hiding all nested menus.
* @private
*/
}, {
key: "_init",
value: function _init() {
_foundation_util_nest__WEBPACK_IMPORTED_MODULE_2__.Nest.Feather(this.$element, 'accordion');
var _this = this;
this.$element.find('[data-submenu]').not('.is-active').slideUp(0); //.find('a').css('padding-left', '1rem');
this.$element.attr({
'aria-multiselectable': this.options.multiOpen
});
this.$menuLinks = this.$element.find('.is-accordion-submenu-parent');
this.$menuLinks.each(function () {
var linkId = this.id || (0,_foundation_core_utils__WEBPACK_IMPORTED_MODULE_3__.GetYoDigits)(6, 'acc-menu-link'),
$elem = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this),
$sub = $elem.children('[data-submenu]'),
subId = $sub[0].id || (0,_foundation_core_utils__WEBPACK_IMPORTED_MODULE_3__.GetYoDigits)(6, 'acc-menu'),
isActive = $sub.hasClass('is-active');
if (_this.options.parentLink) {
var $anchor = $elem.children('a');
$anchor.clone().prependTo($sub).wrap('<li data-is-parent-link class="is-submenu-parent-item is-submenu-item is-accordion-submenu-item"></li>');
}
if (_this.options.submenuToggle) {
$elem.addClass('has-submenu-toggle');
$elem.children('a').after('<button id="' + linkId + '" class="submenu-toggle" aria-controls="' + subId + '" aria-expanded="' + isActive + '" title="' + _this.options.submenuToggleText + '"><span class="submenu-toggle-text">' + _this.options.submenuToggleText + '</span></button>');
} else {
$elem.attr({
'aria-controls': subId,
'aria-expanded': isActive,
'id': linkId
});
}
$sub.attr({
'aria-labelledby': linkId,
'aria-hidden': !isActive,
'role': 'group',
'id': subId
});
});
var initPanes = this.$element.find('.is-active');
if (initPanes.length) {
initPanes.each(function () {
_this.down(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this));
});
}
this._events();
}
/**
* Adds event handlers for items within the menu.
* @private
*/
}, {
key: "_events",
value: function _events() {
var _this = this;
this.$element.find('li').each(function () {
var $submenu = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).children('[data-submenu]');
if ($submenu.length) {
if (_this.options.submenuToggle) {
jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).children('.submenu-toggle').off('click.zf.accordionMenu').on('click.zf.accordionMenu', function () {
_this.toggle($submenu);
});
} else {
jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).children('a').off('click.zf.accordionMenu').on('click.zf.accordionMenu', function (e) {
e.preventDefault();
_this.toggle($submenu);
});
}
}
}).on('keydown.zf.accordionMenu', function (e) {
var $element = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this),
$elements = $element.parent('ul').children('li'),
$prevElement,
$nextElement,
$target = $element.children('[data-submenu]');
$elements.each(function (i) {
if (jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).is($element)) {
$prevElement = $elements.eq(Math.max(0, i - 1)).find('a').first();
$nextElement = $elements.eq(Math.min(i + 1, $elements.length - 1)).find('a').first();
if (jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).children('[data-submenu]:visible').length) {
// has open sub menu
$nextElement = $element.find('li:first-child').find('a').first();
}
if (jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).is(':first-child')) {
// is first element of sub menu
$prevElement = $element.parents('li').first().find('a').first();
} else if ($prevElement.parents('li').first().children('[data-submenu]:visible').length) {
// if previous element has open sub menu
$prevElement = $prevElement.parents('li').find('li:last-child').find('a').first();
}
if (jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).is(':last-child')) {
// is last element of sub menu
$nextElement = $element.parents('li').first().next('li').find('a').first();
}
return;
}
});
_foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_1__.Keyboard.handleKey(e, 'AccordionMenu', {
open: function open() {
if ($target.is(':hidden')) {
_this.down($target);
$target.find('li').first().find('a').first().focus();
}
},
close: function close() {
if ($target.length && !$target.is(':hidden')) {
// close active sub of this item
_this.up($target);
} else if ($element.parent('[data-submenu]').length) {
// close currently open sub
_this.up($element.parent('[data-submenu]'));
$element.parents('li').first().find('a').first().focus();
}
},
up: function up() {
$prevElement.focus();
return true;
},
down: function down() {
$nextElement.focus();
return true;
},
toggle: function toggle() {
if (_this.options.submenuToggle) {
return false;
}
if ($element.children('[data-submenu]').length) {
_this.toggle($element.children('[data-submenu]'));
return true;
}
},
closeAll: function closeAll() {
_this.hideAll();
},
handled: function handled(preventDefault) {
if (preventDefault) {
e.preventDefault();
}
}
});
}); //.attr('tabindex', 0);
}
/**
* Closes all panes of the menu.
* @function
*/
}, {
key: "hideAll",
value: function hideAll() {
this.up(this.$element.find('[data-submenu]'));
}
/**
* Opens all panes of the menu.
* @function
*/
}, {
key: "showAll",
value: function showAll() {
this.down(this.$element.find('[data-submenu]'));
}
/**
* Toggles the open/close state of a submenu.
* @function
* @param {jQuery} $target - the submenu to toggle
*/
}, {
key: "toggle",
value: function toggle($target) {
if (!$target.is(':animated')) {
if (!$target.is(':hidden')) {
this.up($target);
} else {
this.down($target);
}
}
}
/**
* Opens the sub-menu defined by `$target`.
* @param {jQuery} $target - Sub-menu to open.
* @fires AccordionMenu#down
*/
}, {
key: "down",
value: function down($target) {
var _this2 = this;
// If having multiple submenus active is disabled, close all the submenus
// that are not parents or children of the targeted submenu.
if (!this.options.multiOpen) {
// The "branch" of the targetted submenu, from the component root to
// the active submenus nested in it.
var $targetBranch = $target.parentsUntil(this.$element).add($target).add($target.find('.is-active'));
// All the active submenus that are not in the branch.
var $othersActiveSubmenus = this.$element.find('.is-active').not($targetBranch);
this.up($othersActiveSubmenus);
}
$target.addClass('is-active').attr({
'aria-hidden': false
});
if (this.options.submenuToggle) {
$target.prev('.submenu-toggle').attr({
'aria-expanded': true
});
} else {
$target.parent('.is-accordion-submenu-parent').attr({
'aria-expanded': true
});
}
$target.slideDown(this.options.slideSpeed, function () {
/**
* Fires when the menu is done opening.
* @event AccordionMenu#down
*/
_this2.$element.trigger('down.zf.accordionMenu', [$target]);
});
}
/**
* Closes the sub-menu defined by `$target`. All sub-menus inside the target will be closed as well.
* @param {jQuery} $target - Sub-menu to close.
* @fires AccordionMenu#up
*/
}, {
key: "up",
value: function up($target) {
var _this3 = this;
var $submenus = $target.find('[data-submenu]');
var $allmenus = $target.add($submenus);
$submenus.slideUp(0);
$allmenus.removeClass('is-active').attr('aria-hidden', true);
if (this.options.submenuToggle) {
$allmenus.prev('.submenu-toggle').attr('aria-expanded', false);
} else {
$allmenus.parent('.is-accordion-submenu-parent').attr('aria-expanded', false);
}
$target.slideUp(this.options.slideSpeed, function () {
/**
* Fires when the menu is done collapsing up.
* @event AccordionMenu#up
*/
_this3.$element.trigger('up.zf.accordionMenu', [$target]);
});
}
/**
* Destroys an instance of accordion menu.
* @fires AccordionMenu#destroyed
*/
}, {
key: "_destroy",
value: function _destroy() {
this.$element.find('[data-submenu]').slideDown(0).css('display', '');
this.$element.find('a').off('click.zf.accordionMenu');
this.$element.find('[data-is-parent-link]').detach();
if (this.options.submenuToggle) {
this.$element.find('.has-submenu-toggle').removeClass('has-submenu-toggle');
this.$element.find('.submenu-toggle').remove();
}
_foundation_util_nest__WEBPACK_IMPORTED_MODULE_2__.Nest.Burn(this.$element, 'accordion');
}
}]);
}(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_3__.Plugin);
AccordionMenu.defaults = {
/**
* Adds the parent link to the submenu.
* @option
* @type {boolean}
* @default false
*/
parentLink: false,
/**
* Amount of time to animate the opening of a submenu in ms.
* @option
* @type {number}
* @default 250
*/
slideSpeed: 250,
/**
* Adds a separate submenu toggle button. This allows the parent item to have a link.
* @option
* @example true
*/
submenuToggle: false,
/**
* The text used for the submenu toggle if enabled. This is used for screen readers only.
* @option
* @example true
*/
submenuToggleText: 'Toggle menu',
/**
* Allow the menu to have multiple open panes.
* @option
* @type {boolean}
* @default true
*/
multiOpen: true
};
/***/ }),
/***/ "./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__;
/***/ }),
/***/ "./foundation.util.nest":
/*!************************************************************************************************************************************************************************************!*\
!*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.util.nest"],"amd":"./foundation.util.nest","commonjs":"./foundation.util.nest","commonjs2":"./foundation.util.nest"} ***!
\************************************************************************************************************************************************************************************/
/***/ (function(module) {
module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_util_nest__;
/***/ }),
/***/ "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.accordionMenu.js ***!
\********************************************************/
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ AccordionMenu: function() { return /* reexport safe */ _foundation_accordionMenu__WEBPACK_IMPORTED_MODULE_1__.AccordionMenu; },
/* 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_accordionMenu__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../foundation.accordionMenu */ "./js/foundation.accordionMenu.js");
_foundation_core__WEBPACK_IMPORTED_MODULE_0__.Foundation.plugin(_foundation_accordionMenu__WEBPACK_IMPORTED_MODULE_1__.AccordionMenu, 'AccordionMenu');
}();
/******/ return __webpack_exports__;
/******/ })()
;
});
//# sourceMappingURL=foundation.accordionMenu.js.map