vendor/assets/js/plugins/foundation.dropdown.js in foundation-rails-6.5.3.0 vs vendor/assets/js/plugins/foundation.dropdown.js in foundation-rails-6.6.1.0

- old
+ new

@@ -227,10 +227,11 @@ /** * Dropdown module. * @module foundation.dropdown * @requires foundation.util.keyboard * @requires foundation.util.box + * @requires foundation.util.touch * @requires foundation.util.triggers */ var Dropdown = /*#__PURE__*/ @@ -256,12 +257,13 @@ */ value: function _setup(element, options) { this.$element = element; this.options = jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend({}, Dropdown.defaults, this.$element.data(), options); this.className = 'Dropdown'; // ie9 back compat - // Triggers init is idempotent, just need to make sure it is initialized + // Touch and Triggers init are idempotent, just need to make sure they are initialized + _foundation_util_touch__WEBPACK_IMPORTED_MODULE_5__["Touch"].init(jquery__WEBPACK_IMPORTED_MODULE_0___default.a); _foundation_util_triggers__WEBPACK_IMPORTED_MODULE_4__["Triggers"].init(jquery__WEBPACK_IMPORTED_MODULE_0___default.a); this._init(); _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_1__["Keyboard"].register('Dropdown', { @@ -378,20 +380,30 @@ */ }, { key: "_events", value: function _events() { - var _this = this; + var _this = this, + hasTouch = 'ontouchstart' in window || typeof window.ontouchstart !== 'undefined'; this.$element.on({ 'open.zf.trigger': this.open.bind(this), '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.$anchors.off('click.zf.trigger').on('click.zf.trigger', function (e) { _this._setCurrentAnchor(this); + + if (_this.options.forceFollow === false) { + // if forceFollow false, always prevent default action + e.preventDefault(); + } else if (hasTouch && _this.options.hover && _this.$element.hasClass('is-open') === false) { + // if forceFollow true and hover option true, only prevent default action on 1st click + // on 2nd click (dropown opened) the default action (e.g. follow a href) gets executed + e.preventDefault(); + } }); if (this.options.hover) { this.$anchors.off('mouseenter.zf.dropdown mouseleave.zf.dropdown').on('mouseenter.zf.dropdown', function () { _this._setCurrentAnchor(this); @@ -460,22 +472,22 @@ key: "_addBodyHandler", value: function _addBodyHandler() { var $body = jquery__WEBPACK_IMPORTED_MODULE_0___default()(document.body).not(this.$element), _this = this; - $body.off('click.zf.dropdown').on('click.zf.dropdown', function (e) { + $body.off('click.zf.dropdown tap.zf.dropdown').on('click.zf.dropdown tap.zf.dropdown', function (e) { if (_this.$anchors.is(e.target) || _this.$anchors.find(e.target).length) { return; } if (_this.$element.is(e.target) || _this.$element.find(e.target).length) { return; } _this.close(); - $body.off('click.zf.dropdown'); + $body.off('click.zf.dropdown tap.zf.dropdown'); }); } /** * Opens the dropdown pane, and fires a bubbling event to close other dropdowns. * @function @@ -579,11 +591,11 @@ }, { key: "_destroy", value: function _destroy() { this.$element.off('.zf.trigger').hide(); this.$anchors.off('.zf.dropdown'); - jquery__WEBPACK_IMPORTED_MODULE_0___default()(document.body).off('click.zf.dropdown'); + jquery__WEBPACK_IMPORTED_MODULE_0___default()(document.body).off('click.zf.dropdown tap.zf.dropdown'); } }]); return Dropdown; }(_foundation_positionable__WEBPACK_IMPORTED_MODULE_3__["Positionable"]); @@ -691,11 +703,19 @@ * Allows a click on the body to close the dropdown. * @option * @type {boolean} * @default false */ - closeOnClick: false + closeOnClick: false, + + /** + * If true the default action of the toggle (e.g. follow a link with href) gets executed on click. If hover option is also true the default action gets prevented on first click for mobile / touch devices and executed on second click. + * @option + * @type {boolean} + * @default true + */ + forceFollow: true }; /***/ }), @@ -878,23 +898,19 @@ value: function _setPosition($anchor, $element, $parent) { if ($anchor.attr('aria-expanded') === 'false') { return false; } - var $eleDims = _foundation_util_box__WEBPACK_IMPORTED_MODULE_0__["Box"].GetDimensions($element), - $anchorDims = _foundation_util_box__WEBPACK_IMPORTED_MODULE_0__["Box"].GetDimensions($anchor); - if (!this.options.allowOverlap) { // restore original position & alignment before checking overlap this.position = this.originalPosition; this.alignment = this.originalAlignment; } $element.offset(_foundation_util_box__WEBPACK_IMPORTED_MODULE_0__["Box"].GetExplicitOffsets($element, $anchor, this.position, this.alignment, this._getVOffset(), this._getHOffset())); if (!this.options.allowOverlap) { - var overlaps = {}; var minOverlap = 100000000; // default coordinates to how we start, in case we can't figure out better var minCoordinates = { position: this.position, alignment: this.alignment @@ -1059,12 +1075,13 @@ } else { jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger('toggle.zf.trigger'); } }, closeableListener: function closeableListener(e) { + var animation = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('closable'); // Only close the first closable element. See https://git.io/zf-7833 + e.stopPropagation(); - var animation = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('closable'); if (animation !== '') { _foundation_util_motion__WEBPACK_IMPORTED_MODULE_2__["Motion"].animateOut(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), animation, function () { jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger('closed.zf'); }); @@ -1291,10 +1308,10 @@ !*** multi ./js/entries/plugins/foundation.dropdown.js ***! \*********************************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { -module.exports = __webpack_require__(/*! /Users/ncoden/Documents/Documents/Projects/Programmation/Web/2016/Foundation/foundation-sites/js/entries/plugins/foundation.dropdown.js */"./js/entries/plugins/foundation.dropdown.js"); +module.exports = __webpack_require__(/*! /Volumes/Data/Development/Foundation/foundation-sites/js/entries/plugins/foundation.dropdown.js */"./js/entries/plugins/foundation.dropdown.js"); /***/ }), /***/ "jquery": \ No newline at end of file