import { Box } from './foundation.util.box';
import { rtl as Rtl } from './foundation.util.core';
import { Plugin } from './foundation.plugin';
-
+import { Touch } from './foundation.util.touch'
/**
* DropdownMenu module.
* @requires foundation.util.keyboard
* @requires foundation.util.box
* @requires foundation.util.nest
+ * @requires foundation.util.touch
*/
class DropdownMenu extends Plugin {
this.options = $.extend({}, DropdownMenu.defaults, this.$element.data(), options);
this.className = 'DropdownMenu'; // ie9 back compat
+ Touch.init($); // Touch init is idempotent, we just need to make sure it's initialied.
+
this._init();
Keyboard.register('DropdownMenu', {
}
}
this.changed = false;
- this.isTouchMove = false;
this._events();
};
* @private
*/
_addBodyHandler() {
- var $body = $(document.body),
- _this = this;
- $body.off('mouseup.zf.dropdownMenu touchend.zf.dropdownMenu')
- .on('mouseup.zf.dropdownMenu touchend.zf.dropdownMenu', function(e) {
- var $link = _this.$element.find(e.target);
- if ($link.length || _this.isTouchMove){
- _this.isTouchMove = false;
- return;
- }
-
- _this._hide();
- $body.off('mouseup.zf.dropdownMenu touchend.zf.dropdownMenu');
- });
+ const $body = $(document.body);
+ $body
+ .off('click.zf.dropdownMenu tap.zf.dropdownMenu')
+ .on('click.zf.dropdownMenu tap.zf.dropdownMenu', (e) => {
+ var $link = this.$element.find(e.target);
+ if ($link.length) return;
+
+ this._hide();
+ $body.off('click.zf.dropdownMenu tap.zf.dropdownMenu');
+ });
}
/**
function onTouchMove(e) {
if ($.spotSwipe.preventDefault) { e.preventDefault(); }
+
+ // Moved: swipe
if(isMoving) {
var x = e.touches[0].pageX;
var y = e.touches[0].pageY;
$(this).trigger('swipe', dir).trigger(`swipe${dir}`);
}
}
+ // Otherwise: tap
+ else {
+ $(this).trigger('tap');
+ }
+
}
function onTouchStart(e) {