91 lines
4.0 KiB
JavaScript
91 lines
4.0 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
|
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
var TributeMenuEvents = function () {
|
|
function TributeMenuEvents(tribute) {
|
|
_classCallCheck(this, TributeMenuEvents);
|
|
|
|
this.tribute = tribute;
|
|
this.tribute.menuEvents = this;
|
|
this.menu = this.tribute.menu;
|
|
}
|
|
|
|
_createClass(TributeMenuEvents, [{
|
|
key: 'bind',
|
|
value: function bind(menu) {
|
|
var _this = this;
|
|
|
|
menu.menuKeydownEvent = this.tribute.events.keydown.bind(this.menu, this);
|
|
this.menuClickEvent = this.tribute.events.click.bind(null, this);
|
|
this.menuContainerScrollEvent = this.debounce(function () {
|
|
if (_this.tribute.isActive) {
|
|
_this.tribute.showMenuFor(_this.tribute.current.element, false);
|
|
}
|
|
}, 300, false);
|
|
this.windowResizeEvent = this.debounce(function () {
|
|
if (_this.tribute.isActive) {
|
|
_this.tribute.range.positionMenuAtCaret(true);
|
|
}
|
|
}, 300, false);
|
|
|
|
// fixes IE11 issues with mousedown
|
|
this.tribute.range.getDocument().addEventListener('MSPointerDown', this.menuKeydownEvent, false);
|
|
menu.addEventListener('keydown', this.menuKeydownEvent, false);
|
|
this.tribute.range.getDocument().addEventListener('mousedown', this.menuClickEvent, false);
|
|
window.addEventListener('resize', this.windowResizeEvent);
|
|
|
|
if (this.menuContainer) {
|
|
this.menuContainer.addEventListener('scroll', this.menuContainerScrollEvent, false);
|
|
} else {
|
|
window.addEventListener('scroll', this.menuContainerScrollEvent);
|
|
}
|
|
}
|
|
}, {
|
|
key: 'unbind',
|
|
value: function unbind(menu) {
|
|
menu.removeEventListener('keydown', menu.menuKeydownEvent, false);
|
|
delete menu.menuKeydownEvent;
|
|
this.tribute.range.getDocument().removeEventListener('mousedown', this.menuClickEvent, false);
|
|
this.tribute.range.getDocument().removeEventListener('MSPointerDown', this.menuClickEvent, false);
|
|
window.removeEventListener('resize', this.windowResizeEvent);
|
|
|
|
if (this.menuContainer) {
|
|
this.menuContainer.removeEventListener('scroll', this.menuContainerScrollEvent, false);
|
|
} else {
|
|
window.removeEventListener('scroll', this.menuContainerScrollEvent);
|
|
}
|
|
}
|
|
}, {
|
|
key: 'debounce',
|
|
value: function debounce(func, wait, immediate) {
|
|
var _this2 = this,
|
|
_arguments = arguments;
|
|
|
|
var timeout;
|
|
return function () {
|
|
var context = _this2,
|
|
args = _arguments;
|
|
var later = function later() {
|
|
timeout = null;
|
|
if (!immediate) func.apply(context, args);
|
|
};
|
|
var callNow = immediate && !timeout;
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(later, wait);
|
|
if (callNow) func.apply(context, args);
|
|
};
|
|
}
|
|
}]);
|
|
|
|
return TributeMenuEvents;
|
|
}();
|
|
|
|
exports.default = TributeMenuEvents;
|
|
module.exports = exports['default']; |