mirror of
https://bitbucket.org/bellord13/kit.git
synced 2026-11-13 19:06:11 +03:00
169 lines
5.6 KiB
JavaScript
169 lines
5.6 KiB
JavaScript
/** @module UserActionManager */
|
|
/**
|
|
* в разработке
|
|
*/
|
|
kit.PluginManager.register('UserActionManager',function(module, exports, require, global) {
|
|
|
|
var Collection = require('collection');
|
|
|
|
var actionList = ['click', 'hover'];
|
|
|
|
var UserAction = function () {
|
|
|
|
this.parentActionHandler = this.parentAction.bind(this);
|
|
this.documentListenerHandler = this.documentListener.bind(this);
|
|
this.nodeActionHandler = this.nodeAction.bind(this);
|
|
|
|
this.clickHandlerCollection = new Collection([]);
|
|
this.dblclickHandlerCollection = new Collection([]);
|
|
this.mouseoverHandlerCollection = new Collection([]);
|
|
this.mouseoutHandlerCollection = new Collection([]);
|
|
|
|
this.handleEvent = function(event) {
|
|
switch(event.type) {
|
|
case 'mouseover':
|
|
this.mouseoverHandlerCollection.each(function (event, ) {
|
|
item
|
|
});
|
|
break;
|
|
case 'mouseout':
|
|
this.options.hover(event, _thisMenuItem, MenuList[_thisMenuItem.parentId]);
|
|
break;
|
|
case 'click':
|
|
this.options.click(event, _thisMenuItem, MenuList[_thisMenuItem.parentId]);
|
|
break;
|
|
case 'dblclick':
|
|
this.options.dblclick(event, _thisMenuItem, MenuList[_thisMenuItem.parentId]);
|
|
break;
|
|
}
|
|
};
|
|
};
|
|
var proto = UserAction.prototype;
|
|
proto.documentListener = function(event) {
|
|
|
|
if(this.options.eventType === 'click') {
|
|
if (this.needHideByParent(event.target)) {
|
|
this.toggle();
|
|
}
|
|
}
|
|
};
|
|
proto.parentAction = function (event) {
|
|
event.stopPropagation();
|
|
// event.stopImmediatePropagation();
|
|
switch (event.type) {
|
|
case 'mouseout':
|
|
if (this.needHideByParent(event.relatedTarget)) {
|
|
this.hideNodeDeferred();
|
|
}
|
|
break;
|
|
case 'mouseover':
|
|
this.showNode();
|
|
break;
|
|
case 'click':
|
|
this.toggle();
|
|
break;
|
|
}
|
|
};
|
|
proto.nodeAction = function (event) {
|
|
event.stopPropagation();
|
|
// event.stopImmediatePropagation();
|
|
switch (event.type) {
|
|
case 'mouseout':
|
|
break;
|
|
case 'mouseover':
|
|
break;
|
|
case 'mouseleave':
|
|
if(this.options.eventType === 'hover') {
|
|
this.hideNodeDeferred();
|
|
}
|
|
break;
|
|
case 'mouseenter':
|
|
this.deferredHideCancel();
|
|
break;
|
|
}
|
|
};
|
|
|
|
proto.addDocumentEventListener = function() {
|
|
document.addEventListener('click', this.documentListenerHandler, false);
|
|
};
|
|
proto.removeDocumentEventListener = function() {
|
|
document.removeEventListener('click', this.documentListenerHandler, false);
|
|
};
|
|
proto.removeParentEventListener = function() {
|
|
// console.log('Menu: removeParentEventListener');
|
|
if(this.node instanceof Element) {
|
|
this.node.classList.remove('active');
|
|
this.node.removeEventListener('click', this.parentActionHandler, false);
|
|
this.node.removeEventListener('mouseover', this.parentActionHandler, false);
|
|
this.node.removeEventListener('mouseout', this.parentActionHandler, false);
|
|
}
|
|
};
|
|
proto.addParentEventListener = function() {
|
|
if(this.node instanceof Element) {
|
|
if(this.options.eventType === 'hover') {
|
|
this.node.addEventListener('mouseover', this.parentActionHandler, false);
|
|
this.node.addEventListener('mouseout', this.parentActionHandler, false);
|
|
}
|
|
if(this.options.eventType === 'click') {
|
|
this.node.addEventListener(this.options.eventType, this.parentActionHandler, false);
|
|
}
|
|
}
|
|
};
|
|
proto.addNodeEventListener = function() {
|
|
if(!this.node) {
|
|
return;
|
|
}
|
|
|
|
this.node.addEventListener('mouseenter', this.nodeActionHandler, false);
|
|
this.node.addEventListener('mouseleave', this.nodeActionHandler, false);
|
|
};
|
|
proto.removeNodeEventListener = function() {
|
|
if(!this.node) {
|
|
return;
|
|
}
|
|
|
|
this.node.removeEventListener('mouseenter', this.nodeActionHandler, false);
|
|
this.node.removeEventListener('mouseleave', this.nodeActionHandler, false);
|
|
};
|
|
proto.active = function(){
|
|
this.node.addEventListener('mouseover', this, false);
|
|
this.node.addEventListener('click', this, false);
|
|
this.node.addEventListener('dblclick', this, false);
|
|
};
|
|
proto.clear = function(){
|
|
this.node.removeEventListener('mouseover', this, false);
|
|
this.node.removeEventListener('click', this, false);
|
|
this.node.removeEventListener('dblclick', this, false);
|
|
};
|
|
proto.destroy = function(){
|
|
|
|
};
|
|
|
|
proto.setAction = function (action) {
|
|
if(actionList.indexOf(action) === -1) {
|
|
action = 'click';
|
|
}
|
|
this.action = action;
|
|
return this;
|
|
};
|
|
proto.setNode = function (node) {
|
|
this.node = node;
|
|
return this;
|
|
};
|
|
proto.setTakeNode = function (takeNode) {
|
|
this.takeNode = takeNode;
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* @memberof kitCore
|
|
* @instance
|
|
*/
|
|
var UserActionManager = function () {
|
|
|
|
};
|
|
|
|
return module.exports = UserActionManager;
|
|
});
|