mirror of
https://bitbucket.org/bellord13/kit.git
synced 2026-11-13 19:06:11 +03:00
fix
This commit is contained in:
+18
-13
@@ -100,7 +100,7 @@ kit.PluginManager.register('Viewer', function(module, exports, require, global)
|
||||
|
||||
this.__aminationTrapHide = new AnimationTrap(this.node, function (options) {
|
||||
if(options.onHideBefore !== false) {
|
||||
this.onHideBefore.eachCall();
|
||||
this.onHideBefore.eachCall(window, options);
|
||||
}
|
||||
removeAnimation.call(this, this.animShowClass);
|
||||
addAnimation.call(this, this.animHideClass);
|
||||
@@ -111,14 +111,14 @@ kit.PluginManager.register('Viewer', function(module, exports, require, global)
|
||||
this.node.classList.add('hide');
|
||||
this.node.classList.remove('show');
|
||||
if(options.onHide !== false) {
|
||||
this.onHide.eachCall();
|
||||
this.onHide.eachCall(window, options);
|
||||
}
|
||||
this.node.style.display = 'none';
|
||||
}.bind(this));
|
||||
|
||||
this.__aminationTrapShow = new AnimationTrap(this.node, function (options = {}) {
|
||||
if(options.onShowBefore !== false) {
|
||||
this.onShowBefore.eachCall();
|
||||
this.onShowBefore.eachCall(window, options);
|
||||
}
|
||||
this.node.classList.remove('hide');
|
||||
this.node.classList.add('show');
|
||||
@@ -132,7 +132,7 @@ kit.PluginManager.register('Viewer', function(module, exports, require, global)
|
||||
removeAnimation.call(this, this.animHideClass);
|
||||
addAnimation.call(this, this.animShowClass);
|
||||
if(options.onShow !== false) {
|
||||
this.onShow.eachCall();
|
||||
this.onShow.eachCall(window, options);
|
||||
}
|
||||
}.bind(this), function (options = {}) {
|
||||
|
||||
@@ -149,8 +149,8 @@ kit.PluginManager.register('Viewer', function(module, exports, require, global)
|
||||
|
||||
var proto = Viewer.prototype;
|
||||
proto.show = function(options = {}){
|
||||
|
||||
if(this.isShown()) {
|
||||
//console.log('viewer show', this.node.kit.menu.id, options);
|
||||
if(this.isShown() && !options.force) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -162,7 +162,8 @@ kit.PluginManager.register('Viewer', function(module, exports, require, global)
|
||||
};
|
||||
|
||||
proto.hide = function(options = {}){
|
||||
if(this.isHidden()) {
|
||||
//console.log('viewer hide', this.node.kit.menu.id);
|
||||
if(this.isHidden() && !options.force) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -198,12 +199,16 @@ kit.PluginManager.register('Viewer', function(module, exports, require, global)
|
||||
return !this.isHidden();
|
||||
};
|
||||
proto.isHidden = function(){
|
||||
var result = this.node.classList.contains('hide');
|
||||
result = result || getComputedStyle(this.node).display === 'none';
|
||||
if(this.masterNode && this.activeMasterClass) {
|
||||
result = result || !this.masterNode.classList.contains(this.activeMasterClass);
|
||||
}
|
||||
return result || this.__aminationTrapHide.active || this.__deferredHideID;
|
||||
return this.__aminationTrapHide.active || this.__deferredHideID || this.node.classList.contains('hide') ||
|
||||
(getComputedStyle(this.node).display === 'none') ||
|
||||
(this.masterNode && this.activeMasterClass && !this.masterNode.classList.contains(this.activeMasterClass));
|
||||
|
||||
// var result = this.node.classList.contains('hide');
|
||||
// result = result || getComputedStyle(this.node).display === 'none';
|
||||
// if(this.masterNode && this.activeMasterClass) {
|
||||
// result = result || !this.masterNode.classList.contains(this.activeMasterClass);
|
||||
// }
|
||||
// return result || this.__aminationTrapHide.active || this.__deferredHideID;
|
||||
};
|
||||
proto.stop = function () {
|
||||
this.__aminationTrapHide.stop();
|
||||
|
||||
@@ -436,5 +436,21 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Метод извлекает все значения для данного ключа
|
||||
* ключи оставляет исходные
|
||||
* Значения в коллекци должны быть массиво подобные
|
||||
*
|
||||
* @param key
|
||||
* @return {kit.Collection}
|
||||
*/
|
||||
Collection.prototype.pluck = function (key) {
|
||||
return this.map(function (value) {
|
||||
if(value instanceof Object && value.hasOwnProperty(key)){
|
||||
return value[key];
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
};
|
||||
return module.exports = Collection;
|
||||
});
|
||||
@@ -14,7 +14,7 @@
|
||||
--col-span: 1;
|
||||
--line-clamp: 3;
|
||||
--line-clamp-height: 1.3em;
|
||||
--width-wrapper: 800px;
|
||||
--width-wrapper: 1200px;
|
||||
--flex-aspect-ratio: 1;
|
||||
--flex-line-count: 1;
|
||||
--flex-col-count: 2;
|
||||
|
||||
+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(){
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/** @module support */
|
||||
__PluginManager__.register('support', function(module, exports, require, global){
|
||||
|
||||
window.pre = console.log;
|
||||
|
||||
var node = {
|
||||
isRelate: function (node, container = document) {
|
||||
return node === container || container.contains(node);
|
||||
|
||||
Reference in New Issue
Block a user