vendor/assets/js/foundation.drilldown.js.es6 in foundation-rails-6.3.1.0 vs vendor/assets/js/foundation.drilldown.js.es6 in foundation-rails-6.4.1.0
- old
+ new
@@ -1,34 +1,40 @@
'use strict';
-!function($) {
+import $ from 'jquery';
+import { Keyboard } from './foundation.util.keyboard';
+import { Nest } from './foundation.util.nest';
+import { GetYoDigits, transitionend } from './foundation.util.core';
+import { Box } from './foundation.util.box';
+import { Plugin } from './foundation.plugin';
/**
* Drilldown module.
* @module foundation.drilldown
* @requires foundation.util.keyboard
- * @requires foundation.util.motion
* @requires foundation.util.nest
+ * @requires foundation.util.box
*/
-class Drilldown {
+class Drilldown extends Plugin {
/**
* Creates a new instance of a drilldown menu.
* @class
+ * @name Drilldown
* @param {jQuery} element - jQuery object to make into an accordion menu.
* @param {Object} options - Overrides to the default plugin settings.
*/
- constructor(element, options) {
+ _setup(element, options) {
this.$element = element;
this.options = $.extend({}, Drilldown.defaults, this.$element.data(), options);
+ this.className = 'Drilldown'; // ie9 back compat
- Foundation.Nest.Feather(this.$element, 'drilldown');
+ Nest.Feather(this.$element, 'drilldown');
this._init();
- Foundation.registerPlugin(this, 'Drilldown');
- Foundation.Keyboard.register('Drilldown', {
+ Keyboard.register('Drilldown', {
'ENTER': 'open',
'SPACE': 'open',
'ARROW_RIGHT': 'next',
'ARROW_UP': 'up',
'ARROW_DOWN': 'down',
@@ -42,14 +48,22 @@
/**
* Initializes the drilldown by creating jQuery collections of elements
* @private
*/
_init() {
+ if(this.options.autoApplyClass) {
+ this.$element.addClass('drilldown');
+ }
+
+ this.$element.attr({
+ 'role': 'tree',
+ 'aria-multiselectable': false
+ });
this.$submenuAnchors = this.$element.find('li.is-drilldown-submenu-parent').children('a');
- this.$submenus = this.$submenuAnchors.parent('li').children('[data-submenu]');
- this.$menuItems = this.$element.find('li').not('.js-drilldown-back').attr('role', 'menuitem').find('a');
- this.$element.attr('data-mutate', (this.$element.attr('data-drilldown') || Foundation.GetYoDigits(6, 'drilldown')));
+ this.$submenus = this.$submenuAnchors.parent('li').children('[data-submenu]').attr('role', 'group');
+ this.$menuItems = this.$element.find('li').not('.js-drilldown-back').attr('role', 'treeitem').find('a');
+ this.$element.attr('data-mutate', (this.$element.attr('data-drilldown') || GetYoDigits(6, 'drilldown')));
this._prepareMenu();
this._registerEvents();
this._keyboardEvents();
@@ -76,11 +90,11 @@
$link.data('savedHref', $link.attr('href')).removeAttr('href').attr('tabindex', 0);
$link.children('[data-submenu]')
.attr({
'aria-hidden': true,
'tabindex': 0,
- 'role': 'menu'
+ 'role': 'group'
});
_this._events($link);
});
this.$submenus.each(function(){
var $menu = $(this),
@@ -151,11 +165,10 @@
_this._hideAll();
$body.off('.zf.drilldown');
});
}
});
- this.$element.on('mutateme.zf.trigger', this._resize.bind(this));
}
/**
* Adds event handlers to the menu element.
* @function
@@ -164,21 +177,22 @@
_registerEvents() {
if(this.options.scrollTop){
this._bindHandler = this._scrollTop.bind(this);
this.$element.on('open.zf.drilldown hide.zf.drilldown closed.zf.drilldown',this._bindHandler);
}
+ this.$element.on('mutateme.zf.trigger', this._resize.bind(this));
}
/**
* Scroll to Top of Element or data-scroll-top-element
* @function
* @fires Drilldown#scrollme
*/
_scrollTop() {
var _this = this;
var $scrollTopElement = _this.options.scrollTopElement!=''?$(_this.options.scrollTopElement):_this.$element,
- scrollPos = parseInt($scrollTopElement.offset().top+_this.options.scrollTopOffset);
+ scrollPos = parseInt($scrollTopElement.offset().top+_this.options.scrollTopOffset, 10);
$('html, body').stop(true).animate({ scrollTop: scrollPos }, _this.options.animationDuration, _this.options.animationEasing,function(){
/**
* Fires after the menu has scrolled
* @event Drilldown#scrollme
*/
@@ -205,23 +219,23 @@
$nextElement = $elements.eq(Math.min(i+1, $elements.length-1));
return;
}
});
- Foundation.Keyboard.handleKey(e, 'Drilldown', {
+ Keyboard.handleKey(e, 'Drilldown', {
next: function() {
if ($element.is(_this.$submenuAnchors)) {
_this._show($element.parent('li'));
- $element.parent('li').one(Foundation.transitionend($element), function(){
+ $element.parent('li').one(transitionend($element), function(){
$element.parent('li').find('ul li a').filter(_this.$menuItems).first().focus();
});
return true;
}
},
previous: function() {
_this._hide($element.parent('li').parent('ul'));
- $element.parent('li').parent('ul').one(Foundation.transitionend($element), function(){
+ $element.parent('li').parent('ul').one(transitionend($element), function(){
setTimeout(function() {
$element.parent('li').parent('ul').parent('li').children('a').first().focus();
}, 1);
});
return true;
@@ -244,19 +258,19 @@
}
},
open: function() {
if (!$element.is(_this.$menuItems)) { // not menu item means back button
_this._hide($element.parent('li').parent('ul'));
- $element.parent('li').parent('ul').one(Foundation.transitionend($element), function(){
+ $element.parent('li').parent('ul').one(transitionend($element), function(){
setTimeout(function() {
$element.parent('li').parent('ul').parent('li').children('a').first().focus();
}, 1);
});
return true;
} else if ($element.is(_this.$submenuAnchors)) {
_this._show($element.parent('li'));
- $element.parent('li').one(Foundation.transitionend($element), function(){
+ $element.parent('li').one(transitionend($element), function(){
$element.parent('li').find('ul li a').filter(_this.$menuItems).first().focus();
});
return true;
}
},
@@ -276,11 +290,11 @@
* @fires Drilldown#closed
*/
_hideAll() {
var $elem = this.$element.find('.is-drilldown-submenu.is-active').addClass('is-closing');
if(this.options.autoHeight) this.$wrapper.css({height:$elem.parent().closest('ul').data('calcHeight')});
- $elem.one(Foundation.transitionend($elem), function(e){
+ $elem.one(transitionend($elem), function(e){
$elem.removeClass('is-active is-closing');
});
/**
* Fires when the menu is fully closed.
* @event Drilldown#closed
@@ -355,11 +369,11 @@
if(this.options.autoHeight) this.$wrapper.css({height:$elem.parent().closest('ul').data('calcHeight')});
var _this = this;
$elem.parent('li').attr('aria-expanded', false);
$elem.attr('aria-hidden', true).addClass('is-closing')
$elem.addClass('is-closing')
- .one(Foundation.transitionend($elem), function(){
+ .one(transitionend($elem), function(){
$elem.removeClass('is-active is-closing');
$elem.blur().addClass('invisible');
});
/**
* Fires when the submenu has closed.
@@ -376,11 +390,11 @@
*/
_getMaxDims() {
var maxHeight = 0, result = {}, _this = this;
this.$submenus.add(this.$element).each(function(){
var numOfElems = $(this).children('li').length;
- var height = Foundation.Box.GetDimensions(this).height;
+ var height = Box.GetDimensions(this).height;
maxHeight = height > maxHeight ? height : maxHeight;
if(_this.options.autoHeight) {
$(this).data('calcHeight',height);
if (!$(this).hasClass('is-drilldown-submenu')) result['height'] = height;
}
@@ -395,38 +409,45 @@
/**
* Destroys the Drilldown Menu
* @function
*/
- destroy() {
+ _destroy() {
if(this.options.scrollTop) this.$element.off('.zf.drilldown',this._bindHandler);
this._hideAll();
this.$element.off('mutateme.zf.trigger');
- Foundation.Nest.Burn(this.$element, 'drilldown');
+ Nest.Burn(this.$element, 'drilldown');
this.$element.unwrap()
.find('.js-drilldown-back, .is-submenu-parent-item').remove()
.end().find('.is-active, .is-closing, .is-drilldown-submenu').removeClass('is-active is-closing is-drilldown-submenu')
.end().find('[data-submenu]').removeAttr('aria-hidden tabindex role');
this.$submenuAnchors.each(function() {
$(this).off('.zf.drilldown');
});
- this.$submenus.removeClass('drilldown-submenu-cover-previous');
+ this.$submenus.removeClass('drilldown-submenu-cover-previous invisible');
this.$element.find('a').each(function(){
var $link = $(this);
$link.removeAttr('tabindex');
if($link.data('savedHref')){
$link.attr('href', $link.data('savedHref')).removeData('savedHref');
}else{ return; }
});
- Foundation.unregisterPlugin(this);
};
}
Drilldown.defaults = {
/**
+ * Drilldowns depend on styles in order to function properly; in the default build of Foundation these are
+ * on the `drilldown` class. This option auto-applies this class to the drilldown upon initialization.
+ * @option
+ * @type {boolian}
+ * @default true
+ */
+ autoApplyClass: true,
+ /**
* Markup used for JS generated back button. Prepended or appended (see backButtonPosition) to submenu lists and deleted on `destroy` method, 'js-drilldown-back' class required. Remove the backslash (`\`) if copy and pasting.
* @option
* @type {string}
* @default '<li class="js-drilldown-back"><a tabindex="0">Back</a></li>'
*/
@@ -510,9 +531,6 @@
*/
animationEasing: 'swing'
// holdOpen: false
};
-// Window exports
-Foundation.plugin(Drilldown, 'Drilldown');
-
-}(jQuery);
+export {Drilldown};