diff --git a/assets/Viewer/Viewer.js b/assets/Viewer/Viewer.js index 63e5a3f..3eb7f53 100644 --- a/assets/Viewer/Viewer.js +++ b/assets/Viewer/Viewer.js @@ -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(); diff --git a/assets/collection/collection.js b/assets/collection/collection.js index 9810b41..d56ccbd 100644 --- a/assets/collection/collection.js +++ b/assets/collection/collection.js @@ -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; }); \ No newline at end of file diff --git a/assets/flex-kit/flex-kit.css b/assets/flex-kit/flex-kit.css index 6f74aaa..6be16ea 100644 --- a/assets/flex-kit/flex-kit.css +++ b/assets/flex-kit/flex-kit.css @@ -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; diff --git a/assets/menu/menu.js b/assets/menu/menu.js index 2973e24..f23cc98 100644 --- a/assets/menu/menu.js +++ b/assets/menu/menu.js @@ -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(){ diff --git a/assets/support/support.js b/assets/support/support.js index dd0af10..50ba7c4 100644 --- a/assets/support/support.js +++ b/assets/support/support.js @@ -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); diff --git a/templates/svg/comment.php b/templates/svg/comment.php new file mode 100644 index 0000000..f8662dd --- /dev/null +++ b/templates/svg/comment.php @@ -0,0 +1,3 @@ + + + diff --git a/templates/svg/comments.php b/templates/svg/comments.php new file mode 100644 index 0000000..5d9fe8c --- /dev/null +++ b/templates/svg/comments.php @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/templates/svg/eye.php b/templates/svg/eye.php new file mode 100644 index 0000000..240e974 --- /dev/null +++ b/templates/svg/eye.php @@ -0,0 +1,3 @@ + + + diff --git a/templates/svg/thumb-up.php b/templates/svg/thumb-up.php index 0a66e16..17fce48 100644 --- a/templates/svg/thumb-up.php +++ b/templates/svg/thumb-up.php @@ -1,3 +1,3 @@ - - + + diff --git a/tests/kit.Collection.php b/tests/kit.Collection.php index 65f46d1..0cf366d 100644 --- a/tests/kit.Collection.php +++ b/tests/kit.Collection.php @@ -221,7 +221,25 @@ kit.ready(['collection'], function () { assertSame(x.indexKey('11'), 3, 'indexKey (string)'); assertSame(x.indexKey('111'), -1, 'indexKey (-1)'); - + xOb = [ + { + name: 'Igor', + age: 20, + }, + { + name: 'Max', + age: 19, + }, + { + name: 'Nikita', + age: 18, + }, + ]; + x = new kit.Collection(xOb); + y = x.pluck('name'); + assertSame(y.toArray().join('-'), 'Igor-Max-Nikita', 'pluck'); + y = x.pluck('age'); + assertSame(y.toArray().join('-'), '20-19-18', 'pluck с проверкой сохранения порядка'); });