vendor/assets/js/foundation.dropdown.js in foundation-rails-6.4.1.3 vs vendor/assets/js/foundation.dropdown.js in foundation-rails-6.4.3.0
- old
+ new
@@ -459,31 +459,32 @@
}, {
key: '_init',
value: function _init() {
var $id = this.$element.attr('id');
- this.$anchor = __WEBPACK_IMPORTED_MODULE_0_jquery___default()('[data-toggle="' + $id + '"]').length ? __WEBPACK_IMPORTED_MODULE_0_jquery___default()('[data-toggle="' + $id + '"]') : __WEBPACK_IMPORTED_MODULE_0_jquery___default()('[data-open="' + $id + '"]');
- this.$anchor.attr({
+ this.$anchors = __WEBPACK_IMPORTED_MODULE_0_jquery___default()('[data-toggle="' + $id + '"]').length ? __WEBPACK_IMPORTED_MODULE_0_jquery___default()('[data-toggle="' + $id + '"]') : __WEBPACK_IMPORTED_MODULE_0_jquery___default()('[data-open="' + $id + '"]');
+ this.$anchors.attr({
'aria-controls': $id,
'data-is-focus': false,
'data-yeti-box': $id,
'aria-haspopup': true,
'aria-expanded': false
-
});
+ this._setCurrentAnchor(this.$anchors.first());
+
if (this.options.parentClass) {
this.$parent = this.$element.parents('.' + this.options.parentClass);
} else {
this.$parent = null;
}
this.$element.attr({
'aria-hidden': 'true',
'data-yeti-box': $id,
'data-resize': $id,
- 'aria-labelledby': this.$anchor[0].id || __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2__foundation_util_core__["GetYoDigits"])(6, 'dd-anchor')
+ 'aria-labelledby': this.$currentAnchor.id || __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2__foundation_util_core__["GetYoDigits"])(6, 'dd-anchor')
});
_get(Dropdown.prototype.__proto__ || Object.getPrototypeOf(Dropdown.prototype), '_init', this).call(this);
this._events();
}
}, {
@@ -499,11 +500,11 @@
}
}, {
key: '_getDefaultAlignment',
value: function _getDefaultAlignment() {
// handle legacy float approach
- var horizontalPosition = /float-(\S+)/.exec(this.$anchor[0].className);
+ var horizontalPosition = /float-(\S+)/.exec(this.$currentAnchor.className);
if (horizontalPosition) {
return horizontalPosition[1];
}
return _get(Dropdown.prototype.__proto__ || Object.getPrototypeOf(Dropdown.prototype), '_getDefaultAlignment', this).call(this);
@@ -517,14 +518,28 @@
*/
}, {
key: '_setPosition',
value: function _setPosition() {
- _get(Dropdown.prototype.__proto__ || Object.getPrototypeOf(Dropdown.prototype), '_setPosition', this).call(this, this.$anchor, this.$element, this.$parent);
+ _get(Dropdown.prototype.__proto__ || Object.getPrototypeOf(Dropdown.prototype), '_setPosition', this).call(this, this.$currentAnchor, this.$element, this.$parent);
}
/**
+ * Make it a current anchor.
+ * Current anchor as the reference for the position of Dropdown panes.
+ * @param {HTML} el - DOM element of the anchor.
+ * @function
+ * @private
+ */
+
+ }, {
+ key: '_setCurrentAnchor',
+ value: function _setCurrentAnchor(el) {
+ this.$currentAnchor = __WEBPACK_IMPORTED_MODULE_0_jquery___default()(el);
+ }
+
+ /**
* Adds event listeners to the element utilizing the triggers utility library.
* @function
* @private
*/
@@ -537,55 +552,61 @@
'close.zf.trigger': this.close.bind(this),
'toggle.zf.trigger': this.toggle.bind(this),
'resizeme.zf.trigger': this._setPosition.bind(this)
});
+ this.$anchors.off('click.zf.trigger').on('click.zf.trigger', function () {
+ _this._setCurrentAnchor(this);
+ });
+
if (this.options.hover) {
- this.$anchor.off('mouseenter.zf.dropdown mouseleave.zf.dropdown').on('mouseenter.zf.dropdown', function () {
+ this.$anchors.off('mouseenter.zf.dropdown mouseleave.zf.dropdown').on('mouseenter.zf.dropdown', function () {
+ _this._setCurrentAnchor(this);
+
var bodyData = __WEBPACK_IMPORTED_MODULE_0_jquery___default()('body').data();
if (typeof bodyData.whatinput === 'undefined' || bodyData.whatinput === 'mouse') {
clearTimeout(_this.timeout);
_this.timeout = setTimeout(function () {
_this.open();
- _this.$anchor.data('hover', true);
+ _this.$anchors.data('hover', true);
}, _this.options.hoverDelay);
}
}).on('mouseleave.zf.dropdown', function () {
clearTimeout(_this.timeout);
_this.timeout = setTimeout(function () {
_this.close();
- _this.$anchor.data('hover', false);
+ _this.$anchors.data('hover', false);
}, _this.options.hoverDelay);
});
if (this.options.hoverPane) {
this.$element.off('mouseenter.zf.dropdown mouseleave.zf.dropdown').on('mouseenter.zf.dropdown', function () {
clearTimeout(_this.timeout);
}).on('mouseleave.zf.dropdown', function () {
clearTimeout(_this.timeout);
_this.timeout = setTimeout(function () {
_this.close();
- _this.$anchor.data('hover', false);
+ _this.$anchors.data('hover', false);
}, _this.options.hoverDelay);
});
}
}
- this.$anchor.add(this.$element).on('keydown.zf.dropdown', function (e) {
+ this.$anchors.add(this.$element).on('keydown.zf.dropdown', function (e) {
var $target = __WEBPACK_IMPORTED_MODULE_0_jquery___default()(this),
visibleFocusableElements = __WEBPACK_IMPORTED_MODULE_1__foundation_util_keyboard__["Keyboard"].findFocusable(_this.$element);
__WEBPACK_IMPORTED_MODULE_1__foundation_util_keyboard__["Keyboard"].handleKey(e, 'Dropdown', {
open: function () {
- if ($target.is(_this.$anchor)) {
+ if ($target.is(_this.$anchors)) {
_this.open();
_this.$element.attr('tabindex', -1).focus();
e.preventDefault();
}
},
close: function () {
_this.close();
- _this.$anchor.focus();
+ _this.$anchors.focus();
}
});
});
}
@@ -599,11 +620,11 @@
key: '_addBodyHandler',
value: function _addBodyHandler() {
var $body = __WEBPACK_IMPORTED_MODULE_0_jquery___default()(document.body).not(this.$element),
_this = this;
$body.off('click.zf.dropdown').on('click.zf.dropdown', function (e) {
- if (_this.$anchor.is(e.target) || _this.$anchor.find(e.target).length) {
+ if (_this.$anchors.is(e.target) || _this.$anchors.find(e.target).length) {
return;
}
if (_this.$element.find(e.target).length) {
return;
}
@@ -626,11 +647,11 @@
/**
* Fires to close other open dropdowns, typically when dropdown is opening
* @event Dropdown#closeme
*/
this.$element.trigger('closeme.zf.dropdown', this.$element.attr('id'));
- this.$anchor.addClass('hover').attr({ 'aria-expanded': true });
+ this.$anchors.addClass('hover').attr({ 'aria-expanded': true });
// this.$element/*.show()*/;
this.$element.addClass('is-opening');
this._setPosition();
this.$element.removeClass('is-opening').addClass('is-open').attr({ 'aria-hidden': false });
@@ -669,11 +690,11 @@
if (!this.$element.hasClass('is-open')) {
return false;
}
this.$element.removeClass('is-open').attr({ 'aria-hidden': true });
- this.$anchor.removeClass('hover').attr('aria-expanded', false);
+ this.$anchors.removeClass('hover').attr('aria-expanded', false);
/**
* Fires once the dropdown is no longer visible.
* @event Dropdown#hide
*/
@@ -691,11 +712,11 @@
}, {
key: 'toggle',
value: function toggle() {
if (this.$element.hasClass('is-open')) {
- if (this.$anchor.data('hover')) return;
+ if (this.$anchors.data('hover')) return;
this.close();
} else {
this.open();
}
}
@@ -707,11 +728,11 @@
}, {
key: '_destroy',
value: function _destroy() {
this.$element.off('.zf.trigger').hide();
- this.$anchor.off('.zf.dropdown');
+ this.$anchors.off('.zf.dropdown');
__WEBPACK_IMPORTED_MODULE_0_jquery___default()(document.body).off('click.zf.dropdown');
}
}]);
return Dropdown;
@@ -968,13 +989,12 @@
plugins.each(function () {
var _this = __WEBPACK_IMPORTED_MODULE_0_jquery___default()(this);
_this.triggerHandler('close.zf.trigger', [_this]);
});
}
-};
-// Global, parses whole document.
-Triggers.Initializers.addClosemeListener = function (pluginName) {
+ // Global, parses whole document.
+};Triggers.Initializers.addClosemeListener = function (pluginName) {
var yetiBoxes = __WEBPACK_IMPORTED_MODULE_0_jquery___default()('[data-yeti-box]'),
plugNames = ['dropdown', 'tooltip', 'reveal'];
if (pluginName) {
if (typeof pluginName === 'string') {
\ No newline at end of file