mirror of
https://bitbucket.org/bellord13/kit.git
synced 2026-11-13 19:06:11 +03:00
fix
This commit is contained in:
+51
-39
@@ -1,5 +1,6 @@
|
||||
/** @module menu */
|
||||
//todo: instance, options, auto-options-by-node
|
||||
//ok: getChainActiveMenuDataList Скрытие меню открывающихся по клику / 3 depth базовый - след 2
|
||||
__PluginManager__.register('menu',function(module, exports, require, global) {
|
||||
|
||||
|
||||
@@ -67,7 +68,6 @@ __PluginManager__.register('menu',function(module, exports, require, global) {
|
||||
this.itemList = {};
|
||||
this.node = null;
|
||||
this.bInit = false;
|
||||
this.bActive = false;
|
||||
this.options = defaultMenuOptions;
|
||||
this.createNode(); //с пула нужна базовая нода
|
||||
this.setOptions(options);
|
||||
@@ -100,21 +100,28 @@ __PluginManager__.register('menu',function(module, exports, require, global) {
|
||||
};
|
||||
|
||||
|
||||
Menu.prototype.hide = function () {
|
||||
Menu.prototype.isActive = function () {
|
||||
if(this.viewer) {
|
||||
this.viewer.hide();
|
||||
return this.viewer.isShown();
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Menu.prototype.hide = function (options = {}) {
|
||||
if(this.viewer) {
|
||||
this.viewer.hide(options);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
Menu.prototype.show = function () {
|
||||
Menu.prototype.show = function (options = {}) {
|
||||
if(this.viewer) {
|
||||
this.viewer.show();
|
||||
this.viewer.show(options);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Menu.prototype.setPosition = function () {
|
||||
// console.log('setPosition ' + this.id);
|
||||
//console.log('setPosition ' + this.id);
|
||||
if(!(this.getParent() instanceof Element)) {
|
||||
console.warn('Menu.options.parent NOT instanceof Element');
|
||||
return false;
|
||||
@@ -142,6 +149,7 @@ __PluginManager__.register('menu',function(module, exports, require, global) {
|
||||
};
|
||||
|
||||
Menu.prototype.setPositionRecursive = function(){
|
||||
console.log('setPositionRecursive', this.id);
|
||||
var list = getChainActiveMenuDataList(this.id);
|
||||
list.forEach(function (data) {
|
||||
data.menu.setPosition();
|
||||
@@ -228,10 +236,6 @@ __PluginManager__.register('menu',function(module, exports, require, global) {
|
||||
//console.warn('Menu.setParent: Не удалось получить parent. ' + parentNode);
|
||||
return false;
|
||||
}
|
||||
if(this.viewer instanceof Viewer) {
|
||||
this.bActive = this.viewer.isShown();
|
||||
this.viewer.stop();
|
||||
}
|
||||
|
||||
this.options.parent = parentNode;
|
||||
|
||||
@@ -246,14 +250,18 @@ __PluginManager__.register('menu',function(module, exports, require, global) {
|
||||
}
|
||||
};
|
||||
|
||||
Menu.prototype.init = function (setPositionRecursive = false) {
|
||||
var self = this;
|
||||
Menu.prototype.init = function () {
|
||||
var self = this, isActiveBefore = this.isActive();
|
||||
|
||||
if(!(this.options.parent instanceof Element)) {
|
||||
console.warn('Menu.init: Не установлен parent');
|
||||
return false;
|
||||
}
|
||||
|
||||
if(this.viewer instanceof Viewer) {
|
||||
this.viewer.stop();
|
||||
}
|
||||
|
||||
this.render();
|
||||
if(this.node.parentElement !== this.options.parent) {
|
||||
this.node.remove();
|
||||
@@ -265,7 +273,6 @@ __PluginManager__.register('menu',function(module, exports, require, global) {
|
||||
}
|
||||
this.align = new align.Class(this.node, this.options.parent);
|
||||
|
||||
|
||||
if(this.actions instanceof ActionCollection) {
|
||||
this.actions.stop();
|
||||
}
|
||||
@@ -275,6 +282,7 @@ __PluginManager__.register('menu',function(module, exports, require, global) {
|
||||
this.viewer = ua.viewer;
|
||||
ua.viewer.onHideBefore.push(function () {
|
||||
var list = getChainActiveMenuDataList(self.id);
|
||||
//console.log('скрыт', self.id, 'цепочка', (new kit.Collection(list)).pluck('id').toArray().join('-'));
|
||||
list.shift();
|
||||
list.reverse().forEach(function (data) {
|
||||
if(data.menu.viewer) {
|
||||
@@ -283,23 +291,29 @@ __PluginManager__.register('menu',function(module, exports, require, global) {
|
||||
});
|
||||
});
|
||||
ua.viewer.onHide.push(function () {
|
||||
self.bActive = self.viewer.isShown();
|
||||
|
||||
});
|
||||
ua.viewer.onShow.push(function () {
|
||||
ua.viewer.onShow.push(function (options = {}) {
|
||||
//pre('onShow arguments', self.id, arguments[0]);
|
||||
self.setPosition.call(self);
|
||||
self.bActive = self.viewer.isShown();
|
||||
if(options.recursiveMode) {
|
||||
return;
|
||||
}
|
||||
var list = getChainActiveMenuDataList(self.id);
|
||||
//console.log('показан', self.id, 'цепочка', (new kit.Collection(list)).pluck('id').toArray().join('-'));
|
||||
list.shift();
|
||||
list.forEach(function (data) {
|
||||
if(data.menu.viewer) {
|
||||
data.menu.viewer.show({recursiveMode: true, force: true});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
this.actions = new ActionCollection([ua]);
|
||||
this.actions.run();
|
||||
|
||||
if(this.bActive) {
|
||||
if(setPositionRecursive) {
|
||||
this.setPositionRecursive();
|
||||
} else {
|
||||
this.setPosition();
|
||||
}
|
||||
this.show();
|
||||
if(this.isActive() || isActiveBefore) {
|
||||
this.show({force: true});
|
||||
} else {
|
||||
this.hide();
|
||||
}
|
||||
@@ -644,34 +658,31 @@ __PluginManager__.register('menu',function(module, exports, require, global) {
|
||||
return new Menu(options, items);
|
||||
};
|
||||
var getActiveMenuDataList = function(){
|
||||
var idList = [];
|
||||
var dataList = [];
|
||||
var refList = [];
|
||||
function getParentId(id, element) {
|
||||
if(!element) {
|
||||
element = MenuList[id];
|
||||
}
|
||||
var parentId = false, parentMenu;
|
||||
|
||||
var idList = [], dataList = [], refList = [];
|
||||
|
||||
function getParentId(id) {
|
||||
var parentId = false, menu = MenuList[id], parentMenu;
|
||||
if(refList.hasOwnProperty(id) && refList[id].parentMenu) {
|
||||
return refList[id].parentMenu.id;
|
||||
}
|
||||
if(element) {
|
||||
if(menu) {
|
||||
refList[id] = refList[id] || {};
|
||||
parentMenu = refList[id].parentMenu = element.getParentMenu();
|
||||
parentMenu = refList[id].parentMenu = menu.getParentMenu();
|
||||
}
|
||||
parentMenu && (parentId = parentMenu.id);
|
||||
return parentId;
|
||||
}
|
||||
|
||||
MenuList.forEach(function(element){
|
||||
MenuList.forEach(function(menu){
|
||||
var pos, posId, id, parentId;
|
||||
if(!((element instanceof Menu) && element.bInit && element.bActive)) {
|
||||
if(!((menu instanceof Menu) && menu.isActive())) {
|
||||
return;
|
||||
}
|
||||
id = element.id;
|
||||
id = menu.id;
|
||||
refList[id] = refList[id] || {};
|
||||
refList[id].menu = element;
|
||||
parentId = getParentId(id, element);
|
||||
refList[id].menu = menu;
|
||||
parentId = getParentId(id);
|
||||
var depth = function (id){
|
||||
return function() {
|
||||
var pid = refList[id].data.parentId;
|
||||
@@ -725,13 +736,14 @@ __PluginManager__.register('menu',function(module, exports, require, global) {
|
||||
if(data.id === id) {
|
||||
depth = data.depth;
|
||||
}
|
||||
if(depth === data.depth && data.id !== id) {
|
||||
if(depth === data.depth && data.id !== id || depth > data.depth) {
|
||||
depth = 0;
|
||||
}
|
||||
if(depth) {
|
||||
result.push(data);
|
||||
}
|
||||
});
|
||||
//pre(id, (new Collection(result).pluck('id').toArray().join('-')));
|
||||
return result;
|
||||
};
|
||||
var reInitAllMenu = function(){
|
||||
|
||||
Reference in New Issue
Block a user