mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-02-12 15:48:40 +00:00
Added mouse type events
Longpress, click, context
This commit is contained in:
parent
3072b20d2a
commit
9696363f5e
19
UI/Input/Mouse/EventType.enum.js
Normal file
19
UI/Input/Mouse/EventType.enum.js
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/**
|
||||||
|
* Click type.
|
||||||
|
*
|
||||||
|
* @author OMS Development Team <dev@oms.com>
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
* @copyright 2013 Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0 * @since 1.0.0
|
||||||
|
*/
|
||||||
|
(function (jsOMS, undefined)
|
||||||
|
{
|
||||||
|
jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Mouse');
|
||||||
|
|
||||||
|
jsOMS.UI.Input.Mouse.EventType = Object.freeze({
|
||||||
|
CONTEXT: 0,
|
||||||
|
LONGPRESS: 1,
|
||||||
|
CLICK: 2
|
||||||
|
});
|
||||||
|
}(window.jsOMS = window.jsOMS || {}));
|
||||||
|
|
@ -5,28 +5,55 @@
|
||||||
jsOMS.UI.Input.Mouse.MouseManager = function ()
|
jsOMS.UI.Input.Mouse.MouseManager = function ()
|
||||||
{
|
{
|
||||||
this.elements = {};
|
this.elements = {};
|
||||||
this.down = [];
|
this.click = {time: 0};
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.UI.Input.Mouse.MouseManager.prototype.add = function (element, callback, exact)
|
jsOMS.UI.Input.Mouse.MouseManager.prototype.add = function (element, type, button, callback, exact)
|
||||||
{
|
{
|
||||||
if (typeof this.elements[element] === 'undefined') {
|
if (typeof this.elements[element] === 'undefined') {
|
||||||
this.elements[element] = [];
|
this.elements[element] = [];
|
||||||
|
|
||||||
this.bind(element);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.elements[element].push({callback: callback, exact: exact});
|
this.bind(element, type);
|
||||||
|
this.elements[element].push({callback: callback, type: type, button: button, exact: exact});
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.UI.Input.Mouse.MouseManager.prototype.bind = function (element)
|
jsOMS.UI.Input.Mouse.MouseManager.prototype.bind = function (element, type)
|
||||||
{
|
{
|
||||||
let self = this;
|
let self = this,
|
||||||
|
e = document.getElementById(element);
|
||||||
|
|
||||||
document.getElementById(element).addEventListener('contextmenu', function (event)
|
if(e === null) {
|
||||||
{
|
return;
|
||||||
self.run(element, event);
|
}
|
||||||
}, false);
|
|
||||||
|
if (type === jsOMS.UI.Input.Mouse.EventType.CONTEXT) {
|
||||||
|
e.addEventListener('contextmenu', function (event)
|
||||||
|
{
|
||||||
|
self.run(element, event);
|
||||||
|
}, false);
|
||||||
|
} else if (type === jsOMS.UI.Input.Mouse.EventType.LONGPRESS) {
|
||||||
|
e.addEventListener('mousedown', function (event)
|
||||||
|
{
|
||||||
|
self.click.time = new Date().getTime();
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
e.addEventListener('mouseup', function (event)
|
||||||
|
{
|
||||||
|
let duration = new Date().getTime() - self.click.time;
|
||||||
|
|
||||||
|
if (duration > 650) {
|
||||||
|
self.run(element, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.click.time = 0;
|
||||||
|
}, false);
|
||||||
|
} else if (type === jsOMS.UI.Input.Mouse.EventType.CLICK) {
|
||||||
|
e.addEventListener('click', function (event)
|
||||||
|
{
|
||||||
|
self.run(element, event);
|
||||||
|
}, false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.UI.Input.Mouse.MouseManager.prototype.run = function (element, event)
|
jsOMS.UI.Input.Mouse.MouseManager.prototype.run = function (element, event)
|
||||||
|
|
@ -38,10 +65,8 @@
|
||||||
let actions = this.elements[element],
|
let actions = this.elements[element],
|
||||||
length = actions.length;
|
length = actions.length;
|
||||||
|
|
||||||
console.log();
|
|
||||||
|
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
if(!actions[i].exact || event.target.getAttribute('id') === element) {
|
if ((!actions[i].exact || event.target.getAttribute('id') === element) && actions[i].button === event.button) {
|
||||||
jsOMS.preventAll(event);
|
jsOMS.preventAll(event);
|
||||||
actions[i].callback();
|
actions[i].callback();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user