This commit is contained in:
2021-10-03 20:06:12 +03:00
parent dee5c19f48
commit a0a6a9b710
11 changed files with 459 additions and 168 deletions
@@ -0,0 +1,39 @@
/** @module UserActionManager */
/**
* в разработке
*/
kit.PluginManager.register('UserActionManager',function(module, exports, require, global) {
var actionList = ['click', 'hover'];
var UserAction = function () {
};
var proto = UserAction.prototype;
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;
});
+106 -10
View File
@@ -1,9 +1,9 @@
/** @module collection */ /** @module collection */
kit.PluginManager.register('collection',function(module, exports, require, global) { kit.PluginManager.register('collection',function(module, exports, require, global) {
function valueEx(value) { function valueEx(value, item, key) {
if(typeof value === 'function') { if(typeof value === 'function') {
return value(); return value(item, key);
} }
return value; return value;
} }
@@ -18,7 +18,8 @@ kit.PluginManager.register('collection',function(module, exports, require, globa
idStr += (Math.floor((Math.random() * 35))).toString(36); idStr += (Math.floor((Math.random() * 35))).toString(36);
} while (idStr.length < length); } while (idStr.length < length);
return (idStr); return (idStr);
}; }
var ArrayCollection = function (data){ var ArrayCollection = function (data){
this.data = data; this.data = data;
@@ -28,7 +29,9 @@ kit.PluginManager.register('collection',function(module, exports, require, globa
}; };
ArrayCollection.prototype.put = function (key, value) { ArrayCollection.prototype.put = function (key, value) {
this.data[key] = value; this.data[key] = value;
return this;
}; };
ArrayCollection.prototype.set = ArrayCollection.prototype.put;
ArrayCollection.prototype.push = function (value) { ArrayCollection.prototype.push = function (value) {
this.data.push(value); this.data.push(value);
}; };
@@ -36,11 +39,36 @@ kit.PluginManager.register('collection',function(module, exports, require, globa
if(this.data.hasOwnProperty(key)) { if(this.data.hasOwnProperty(key)) {
return this.data[key]; return this.data[key];
} }
return valueEx(defValue); return valueEx(defValue, this.data[key], key);
}; };
ArrayCollection.prototype.has = function (key) { ArrayCollection.prototype.has = function (key) {
return this.data.hasOwnProperty(key); return this.data.hasOwnProperty(key);
}; };
ArrayCollection.prototype.count = function () {
return Object.keys(this.data).length;
};
ArrayCollection.prototype.isEmpty = function () {
return this.count() === 0;
};
ArrayCollection.prototype.map = function (callback) {
for (var key of Object.keys(this.data)) {
this.data[key] = callback(this.data[key], key, this.data);
}
return this;
};
ArrayCollection.prototype.each = function (callback) {
var BreakException = {};
try {
for (var key of Object.keys(this.data)) {
if(callback(this.data[key], key, this.data) === false) {
throw BreakException;
}
}
} catch (e) {
if (e !== BreakException) throw e;
}
return this;
};
var ObjectCollection = function (data){ var ObjectCollection = function (data){
@@ -48,26 +76,94 @@ kit.PluginManager.register('collection',function(module, exports, require, globa
}; };
ObjectCollection.prototype.all = ArrayCollection.prototype.all; ObjectCollection.prototype.all = ArrayCollection.prototype.all;
ObjectCollection.prototype.put = ArrayCollection.prototype.put; ObjectCollection.prototype.put = ArrayCollection.prototype.put;
ObjectCollection.prototype.set = ArrayCollection.prototype.put;
ObjectCollection.prototype.push = function (value) { ObjectCollection.prototype.push = function (value) {
this.data[uniqueId(8)] = value; this.data[uniqueId(8)] = value;
return this;
}; };
ObjectCollection.prototype.get = ArrayCollection.prototype.get; ObjectCollection.prototype.get = ArrayCollection.prototype.get;
ObjectCollection.prototype.has = ArrayCollection.prototype.has; ObjectCollection.prototype.has = ArrayCollection.prototype.has;
ObjectCollection.prototype.count = ArrayCollection.prototype.count;
ObjectCollection.prototype.isEmpty = ArrayCollection.prototype.isEmpty;
ObjectCollection.prototype.map = ArrayCollection.prototype.map;
ObjectCollection.prototype.each = ArrayCollection.prototype.each;
var NodeCollection = function (data){
this.data = data;
};
NodeCollection.prototype.all = ArrayCollection.prototype.all;
NodeCollection.prototype.put = ArrayCollection.prototype.put;
NodeCollection.prototype.set = ArrayCollection.prototype.put;
NodeCollection.prototype.push = ArrayCollection.prototype.push;
NodeCollection.prototype.get = ArrayCollection.prototype.get;
NodeCollection.prototype.has = ArrayCollection.prototype.has;
NodeCollection.prototype.count = ArrayCollection.prototype.count;
NodeCollection.prototype.isEmpty = ArrayCollection.prototype.isEmpty;
NodeCollection.prototype.map = ArrayCollection.prototype.map;
NodeCollection.prototype.each = ArrayCollection.prototype.each;
function collectionCall(method, args) {
if(this.__driver.__proto__.hasOwnProperty(method)) {
var r = this.__driver[method].apply(this.__driver, args);
return r === this.__driver ? this : r;
}
return this;
}
/** /**
* @extends ArrayCollection
* @memberof kitCore * @memberof kitCore
* @instance * @instance
*/ */
var Collection = function (data) { var Collection = function (data) {
if(typeof data === 'object') { if(data instanceof NodeList) {
return new ObjectCollection(data); this.__driver = new NodeCollection(data);
} }
if(Array.isArray(data)) { else if(Array.isArray(data)) {
return new ArrayCollection(data); this.__driver = new ArrayCollection(data);
} }
return new ArrayCollection([data]); else if(typeof data === 'object') {
} this.__driver = new ObjectCollection(data);
}
else {
console.warn('collection: not support data', data);
}
};
Collection.prototype.all = function () {
return collectionCall.call(this, 'all', arguments);
};
Collection.prototype.put = function (key, value) {
return collectionCall.call(this, 'put', arguments);
};
Collection.prototype.set = function (key, value) {
return collectionCall.call(this, 'set', arguments);
};
Collection.prototype.push = function (value) {
return collectionCall.call(this, 'push', arguments);
};
Collection.prototype.get = function (key, defValue = undefined) {
return collectionCall.call(this, 'get', arguments);
};
Collection.prototype.has = function (key) {
return collectionCall.call(this, 'has', arguments);
};
Collection.prototype.count = function () {
return collectionCall.call(this, 'count', arguments);
};
Collection.prototype.isEmpty = function () {
return collectionCall.call(this, 'isEmpty', arguments);
};
Collection.prototype.map = function (callback) {
return collectionCall.call(this, 'map', arguments);
};
Collection.prototype.each = function (callback) {
return collectionCall.call(this, 'each', arguments);
};
return module.exports = Collection; return module.exports = Collection;
}); });
+18 -7
View File
@@ -436,12 +436,13 @@ window.kit = window.kit || {};
* @return {boolean} * @return {boolean}
*/ */
__proto.require = function (pluginId, callback) { __proto.require = function (pluginId, callback) {
//console.warn('PluginManager.require: plugin ' + pluginId + ' ('+(this.plugins[pluginId]?this.plugins[pluginId].state:'0')+')');
var plugin = this.__getPlugin(pluginId); var plugin = this.__getPlugin(pluginId);
if(plugin) { if(!plugin) {
pluginId = plugin.id; console.warn('PluginManager.require: plugin ' + pluginId + ' not found ('+(this.plugins[pluginId]?this.plugins[pluginId].state:'0')+')');
return undefined;
} }
pluginId = plugin.id;
var module = plugin.module; var module = plugin.module;
if(!this.__checkState(pluginId, stateList.registered)) { if(!this.__checkState(pluginId, stateList.registered)) {
@@ -578,15 +579,25 @@ window.kit = window.kit || {};
if(this.plugins.hasOwnProperty(pluginId)) { if(this.plugins.hasOwnProperty(pluginId)) {
return this.plugins[pluginId]; return this.plugins[pluginId];
} }
var _pluginId; var _pluginId, alias;
for (_pluginId in this.plugins) { for (_pluginId in this.plugins) {
if(this.plugins.hasOwnProperty(_pluginId) && this.plugins[_pluginId].config.alias.indexOf(pluginId) !== -1) { if(this.plugins.hasOwnProperty(_pluginId) && this.plugins[_pluginId].config.alias.indexOf(pluginId) !== -1) {
return this.plugins[_pluginId]; return this.plugins[_pluginId];
} }
} }
_pluginId = pluginId[0].toUpperCase() + pluginId.slice(1); var pluginIdLowerCase = pluginId.toLowerCase();
if(_pluginId !== pluginId) { for (_pluginId in this.plugins) {
return this.__getPlugin(_pluginId); if(!this.plugins.hasOwnProperty(_pluginId)) {
continue;
}
if(pluginIdLowerCase === _pluginId.toLowerCase()) {
return this.plugins[_pluginId];
}
for(alias of this.plugins[_pluginId].config.alias) {
if(pluginIdLowerCase === alias.toLowerCase()) {
return this.plugins[_pluginId];
}
}
} }
return undefined; return undefined;
}; };
+19 -4
View File
@@ -6,7 +6,7 @@ __PluginManager__.registerPlugins({
'/menu.css' '/menu.css'
], ],
type: 'loader', type: 'loader',
deps: ['lib', 'align', 'utils', 'animations'] deps: ['lib', 'align', 'dataStructures', 'animations']
}, },
lib: { lib: {
path: __pmConfig__.assetsPath + '/lib', path: __pmConfig__.assetsPath + '/lib',
@@ -18,9 +18,9 @@ __PluginManager__.registerPlugins({
module: '/align.js', module: '/align.js',
type: 'loader', type: 'loader',
}, },
utils: { support: {
path: __pmConfig__.assetsPath + '/utils', path: __pmConfig__.assetsPath + '/support',
module: '/utils.js', module: '/support.js',
type: 'loader', type: 'loader',
}, },
jquery: { jquery: {
@@ -147,6 +147,21 @@ __PluginManager__.registerPlugins({
module: '/animations.js', module: '/animations.js',
type: 'loader', type: 'loader',
}, },
Collection: {
path: __pmConfig__.assetsPath + '/collection',
module: '/collection.js',
type: 'loader',
},
dataStructures: {
path: __pmConfig__.assetsPath + '/dataStructures',
module: '/dataStructures.js',
type: 'loader',
},
UserActionManager: {
path: __pmConfig__.assetsPath + '/UserActionManager',
module: '/UserActionManager.js',
type: 'loader',
},
}); });
+55
View File
@@ -0,0 +1,55 @@
/** @module dataStructures */
__PluginManager__.register('dataStructures', function(module, exports, require, global){
/**
* @memberof kitCore
* @instance
*/
var dataStructures = {
StackExecutionLimiter: (function () {
var stack = function (context, callback, timeout = 1000) {
this.counter = 0;
this.timerId = 0;
this.timeout = 0;
this.arguments = null;
this.context = null;
this.setContext(context);
this.setCallback(callback);
this.setTimeout(timeout);
};
stack.prototype.setCallback = function(callback){
this.callback = callback;
};
stack.prototype.setContext = function(context){
this.context = context || window;
};
stack.prototype.setTimeout = function(timeout){
this.timeout = timeout;
};
stack.prototype.exec = function() {
this.arguments = arguments;
this.counter++;
if(this.timerId === 0) {
this.__exec(this.counter);
}
};
stack.prototype.__exec = function (counter) {
this.timerId = setTimeout((function(){
if(this.counter > counter) {
this.__exec(this.counter);
return null;
}
this.timerId = 0;
}).bind(this), this.timeout);
this.callback.apply(this.context, this.arguments);
};
stack.prototype.reset = function () {
clearTimeout(this.timerId);
this.timerId = 0;
};
return stack;
})()
};
return module.exports = dataStructures;
});
+122 -77
View File
@@ -1,11 +1,11 @@
/** @module menu */ /** @module menu */
//todo: instance, options, auto-options-by-node, fast reCalc, fast reInit, userEventManager, collection //todo: instance, options, auto-options-by-node, userEventManager
__PluginManager__.register('menu',function(module, exports, require) { __PluginManager__.register('menu',function(module, exports, require) {
var align = require('align'); var align = require('align');
var libModule = require('lib'); var libModule = require('lib');
var utils = require('utils'); var dataStructures = require('dataStructures');
/** /**
* @class kitMenuClassDefaultOptions * @class kitMenuClassDefaultOptions
@@ -120,19 +120,20 @@ __PluginManager__.register('menu',function(module, exports, require) {
} }
this.addAnimation(); this.addAnimation();
}; };
Menu.prototype.hide = function () {
getChainActiveMenuDataList(this.id).reverse().forEach(function (data) {
data.menu.hideNodeNow();
});
return this;
};
Menu.prototype.hideNode = function () { Menu.prototype.hideNode = function () {
// console.log('Menu: hideNode'); this.hideNodeNow();
this.hideNodeDeferred();
}; };
Menu.prototype.hideNodeDeferred = function () { Menu.prototype.hideNodeDeferred = function () {
this.deferredHideCancel(); this.deferredHideCancel();
this.deferredHideID = setTimeout(this.hideNodeNow.bind(this), this.options.hideDelay); this.deferredHideID = setTimeout(this.hideNodeNow.bind(this), this.options.hideDelay);
// console.log('hideNodeDeferred ' + this.deferredHideID);
}; };
/**
* @returns {Menu}
*/
Menu.prototype.deferredHideCancel = function () { Menu.prototype.deferredHideCancel = function () {
if(this.deferredHideID) { if(this.deferredHideID) {
clearTimeout(this.deferredHideID); clearTimeout(this.deferredHideID);
@@ -140,10 +141,6 @@ __PluginManager__.register('menu',function(module, exports, require) {
} }
return this; return this;
}; };
/**
* @returns {Menu}
*/
Menu.prototype.hideNodeNow = function () { Menu.prototype.hideNodeNow = function () {
// console.log('Menu: hideNodeNow'); // console.log('Menu: hideNodeNow');
this.deferredHideCancel(); this.deferredHideCancel();
@@ -167,18 +164,7 @@ __PluginManager__.register('menu',function(module, exports, require) {
} }
}; };
/** Menu.prototype.calcStyle = function () {
* @returns {Menu}
*/
Menu.prototype.hide = function () {
this.hideNodeNow();
var tmp = this;
while(tmp instanceof MenuClass) {
tmp = tmp.hideNodeNow().getParentMenu();
}
return this;
};
Menu.prototype.calcStyle = function (recursive = false) {
// console.log('calcStyle ' + this.id); // console.log('calcStyle ' + this.id);
if(!(this.options.parent instanceof Element)) { if(!(this.options.parent instanceof Element)) {
console.warn('Menu.options.parent NOT instanceof Element'); console.warn('Menu.options.parent NOT instanceof Element');
@@ -208,33 +194,12 @@ __PluginManager__.register('menu',function(module, exports, require) {
.setHorizontal(hDirection, hAlign) .setHorizontal(hDirection, hAlign)
.setVertical('bottom', 'top'); .setVertical('bottom', 'top');
if(recursive) {
this.calcStyleChildMenu(true, MenuList);
}
}; };
Menu.prototype.calcStyleChildMenu = function(recursive = false, MenuList = null){ Menu.prototype.calcStyleChain = function(){
var i, MenuListActive = []; getChainActiveMenuDataList(this.id).forEach(function (data) {
for(i in MenuList){ data.menu.calcStyle();
if(!MenuList.hasOwnProperty(i) || !(MenuList[i] instanceof Menu)) { })
continue;
}
if(MenuList[i].bActive && this !== MenuList[i]) {
MenuListActive.push(MenuList[i]);
}
}
for(i in MenuListActive){
if(MenuListActive[i].getParentMenu() === this) {
MenuListActive[i].calcStyle();
if(recursive) {
MenuListActive[i].calcStyleChildMenu(true, MenuListActive);
}
}
}
}; };
/** /**
@@ -389,10 +354,6 @@ __PluginManager__.register('menu',function(module, exports, require) {
this.node.removeEventListener('mouseenter', this.nodeActionHandler, false); this.node.removeEventListener('mouseenter', this.nodeActionHandler, false);
this.node.removeEventListener('mouseleave', this.nodeActionHandler, false); this.node.removeEventListener('mouseleave', this.nodeActionHandler, false);
}; };
Menu.prototype.toggleParent = function() {
this.node.classList.toggle('active');
return this.node.classList.contains('active');
};
Menu.prototype.insertToNode = function (parent) { Menu.prototype.insertToNode = function (parent) {
if(!(parent instanceof Element)) { if(!(parent instanceof Element)) {
console.warn('Menu.insertToNode - node NOT instanceof Element'); console.warn('Menu.insertToNode - node NOT instanceof Element');
@@ -435,14 +396,19 @@ __PluginManager__.register('menu',function(module, exports, require) {
//this.removeAnimation(); //this.removeAnimation();
if(this.node.parentElement !== this.options.parent) { if(this.node.parentElement !== this.options.parent) {
this.removeAnimation();
this.node.remove(); this.node.remove();
this.options.parent.prepend(this.getNode()); this.options.parent.prepend(this.node);
} }
this.render(); this.render();
if(this.bActive) { if(this.bActive) {
this.calcStyle(recursiveCalcStyle); if(recursiveCalcStyle) {
this.calcStyleChain();
} else {
this.calcStyle();
}
this.showNode(); this.showNode();
} else { } else {
this.hideNode(); this.hideNode();
@@ -455,10 +421,10 @@ __PluginManager__.register('menu',function(module, exports, require) {
Menu.prototype.toggle = function() { Menu.prototype.toggle = function() {
if(this.toggleParent()) { if(this.node.classList.toggle('active')) {
this.showNode(); this.showNode();
} else { } else {
this.hideNode(); this.hide();
} }
}; };
Menu.prototype.parentAction = function (event) { Menu.prototype.parentAction = function (event) {
@@ -467,7 +433,7 @@ __PluginManager__.register('menu',function(module, exports, require) {
switch (event.type) { switch (event.type) {
case 'mouseout': case 'mouseout':
if (this.needHideByParent(event.relatedTarget)) { if (this.needHideByParent(event.relatedTarget)) {
this.hideNode(); this.hideNodeDeferred();
} }
break; break;
case 'mouseover': case 'mouseover':
@@ -488,7 +454,7 @@ __PluginManager__.register('menu',function(module, exports, require) {
break; break;
case 'mouseleave': case 'mouseleave':
if(this.options.eventType === 'hover') { if(this.options.eventType === 'hover') {
this.hideNode(); this.hideNodeDeferred();
} }
break; break;
case 'mouseenter': case 'mouseenter':
@@ -842,32 +808,109 @@ __PluginManager__.register('menu',function(module, exports, require) {
} }
return new MenuClass(options, items); return new MenuClass(options, items);
}; };
var getActiveMenuIdList = function(){ var getActiveMenuDataList = function(){
function valueEx(value) {
if(typeof value === 'function') {
return value();
}
return value;
}
var idList = []; var idList = [];
MenuList.forEach(function(element, index, array){ var dataList = [];
var refList = [];
function getParentId(id, element) {
if(!element) {
element = MenuList[id];
}
var parentId = false, parentMenu;
if(!(refList.hasOwnProperty(id) && refList[id].parentMenu)) {
if(element) {
refList[id] = refList[id] || {};
parentMenu = refList[id].parentMenu = element.getParentMenu();
}
parentMenu && (parentId = parentMenu.id);
return parentId;
}
return refList[id].parentMenu.id;
}
MenuList.forEach(function(element){
var pos, posId, id, parentId; var pos, posId, id, parentId;
if((element instanceof MenuClass) && element.bInit && element.bActive) { if(!((element instanceof MenuClass) && element.bInit && element.bActive)) {
id = element.id; return;
parentId = false; }
element.getParentMenu() && (parentId = element.getParentMenu().id); id = element.id;
!(parentId!==false&&(((pos=idList.indexOf(parentId))!==-1)?((idList.indexOf(id)===-1)&&idList.splice(pos refList[id] = refList[id] || {};
+1,0,id)):(((posId=idList.indexOf(id))!==-1)?idList.splice(posId,0,parentId):(idList.push(parentId), refList[id].menu = element;
idList.push(id))),0))&&(idList.indexOf(id)===-1)&&(idList.push(id)); parentId = getParentId(id, element);
var depth = function (id){
return function() {
return 1 + valueEx(refList[refList[id].data.parentId].data.depth)
};
};
!(
parentId!==false
&&
(
((pos=idList.indexOf(parentId))!==-1)
?
(
(idList.indexOf(id)===-1)&&(idList.splice(pos+1,0,id), dataList.splice(pos+1,0, refList[id].data = {id:id, depth: depth(id), parentId: parentId, type: 1}))
)
:
(
(
refList[parentId] = refList[parentId] || {},
(posId=idList.indexOf(id))!==-1
)?
(
idList.splice(posId,0,parentId),
dataList.splice(posId,0,refList[parentId].data = {id:parentId, depth: depth(parentId), parentId: getParentId(parentId), type: 5})
):
(
idList.push(parentId),
dataList.push(refList[parentId].data = {id:parentId, depth: depth(parentId), parentId: getParentId(parentId), type: 2}),
idList.push(id),
dataList.push(refList[id].data = {id:id, depth: depth(id), parentId: parentId, type: 3})
)
),
0
)
)
&&(idList.indexOf(id)===-1)&&(idList.push(id), dataList.push(refList[id].data = {id:id, depth: 1, parentId: 0, type: 4}));
});
dataList.forEach(function (data) {
data.depth = valueEx(data.depth);
data.menu = refList[data.id].menu;
});
return dataList;
};
var getChainActiveMenuDataList = function (id) {
var dataList = getActiveMenuDataList(), result = [], depth = 0;
dataList.forEach(function(data) {
if(data.id === id) {
depth = data.depth;
}
if(depth === data.depth && data.id !== id) {
depth = 0;
}
if(depth) {
result.push(data);
} }
}); });
return idList return result;
}; };
var reInitAllMenu = function(){ var reInitAllMenu = function(){
var idList = getActiveMenuIdList(); var dataList = getActiveMenuDataList();
idList.forEach(function(id, i, arr) { dataList.forEach(function(data) {
MenuList[id].reInit(); data.menu.reInit();
}); });
}; };
var reCalcAllMenu = function(){ var reCalcAllMenu = function(){
console.log('reCalcAllMenu'); console.log('reCalcAllMenu');
var idList = getActiveMenuIdList(); var dataList = getActiveMenuDataList();
idList.forEach(function(id, i, arr) { dataList.forEach(function(data) {
MenuList[id].calcStyle(); data.menu.calcStyle();
}); });
}; };
var autoload = function(doc = document, selector = '.kit-menu'){ var autoload = function(doc = document, selector = '.kit-menu'){
@@ -884,7 +927,7 @@ __PluginManager__.register('menu',function(module, exports, require) {
); );
}; };
var reCalcAllMenuLimiter = new utils.StackExecutionLimiter(this, reCalcAllMenu, 200); var reCalcAllMenuLimiter = new dataStructures.StackExecutionLimiter(this, reCalcAllMenu, 250);
var globalHandlers = { var globalHandlers = {
resize: function(){ resize: function(){
reCalcAllMenuLimiter.exec(); reCalcAllMenuLimiter.exec();
@@ -903,6 +946,8 @@ __PluginManager__.register('menu',function(module, exports, require) {
reInitAllMenu: reInitAllMenu, reInitAllMenu: reInitAllMenu,
reCalcAllMenu: reCalcAllMenu, reCalcAllMenu: reCalcAllMenu,
autoload: autoload, autoload: autoload,
getActiveMenuDataList: getActiveMenuDataList,
getChainActiveMenuDataList: getChainActiveMenuDataList,
MenuList: MenuList, MenuList: MenuList,
}; };
+20
View File
@@ -0,0 +1,20 @@
/** @module support */
__PluginManager__.register('support', function(module, exports, require, global){
var str = {
ucFirst: function (str) {
if (!str) return str;
return str[0].toUpperCase() + str.slice(1);
}
};
/**
* @memberof kitCore
* @instance
*/
var support = {
str: str,
};
return module.exports = support;
});
-65
View File
@@ -1,65 +0,0 @@
/** @module utils */
__PluginManager__.register('utils', function(module, exports, require){
var StackExecutionLimiter = (function () {
var stack = function (context, callback, timeout = 1000) {
this.counter = 0;
this.timerId = 0;
this.timeout = 0;
this.arguments = null;
this.context = null;
this.setContext(context);
this.setCallback(callback);
this.setTimeout(timeout);
};
stack.prototype.setCallback = function(callback){
this.callback = callback;
};
stack.prototype.setContext = function(context){
this.context = context || window;
};
stack.prototype.setTimeout = function(timeout){
this.timeout = timeout;
};
stack.prototype.exec = function() {
this.arguments = arguments;
this.counter++;
if(this.timerId === 0) {
this.__exec(this.counter);
}
};
stack.prototype.__exec = function (counter) {
this.timerId = setTimeout((function(){
if(this.counter > counter) {
this.__exec(this.counter);
return null;
}
this.timerId = 0;
}).bind(this), this.timeout);
this.callback.apply(this.context, this.arguments);
};
stack.prototype.reset = function () {
clearTimeout(this.timerId);
this.timerId = 0;
};
return stack;
})();
var str = {
ucFirst: function (str) {
if (!str) return str;
return str[0].toUpperCase() + str.slice(1);
}
};
/**
* @memberof kitCore
* @instance
*/
var utils = {
StackExecutionLimiter: StackExecutionLimiter,
str: str,
};
return module.exports = utils;
});
+1
View File
@@ -5,5 +5,6 @@
<a href="flex-kit.php">flex-kit</a> <a href="flex-kit.php">flex-kit</a>
<a href="cheatsheet.php">cheatsheet</a> <a href="cheatsheet.php">cheatsheet</a>
<a href="card/block.php">card/block</a> <a href="card/block.php">card/block</a>
<a href="kit.Collection.php">kit.Collection</a>
</div> </div>
+77
View File
@@ -0,0 +1,77 @@
<script src="../assets/config/config.js"></script>
<script src="../assets/core/core.js"></script>
<script src="../assets/core/core.register.js"></script>
<script>
kit.PluginManager.install('Collection');
function assertSame(value, need, msg) {
if(value === need) {
console.log(true, msg);
return;
}
console.error(msg, value, need);
}
</script>
<h1>в консоле</h1>
<script>
kit.ready(['collection'], function () {
console.warn('ARRAY');
var arr = [];
arr[10] = 100;
var collection = new kit.Collection(arr);
assertSame(collection.count(), 1, 'Количество');
assertSame(collection.has(10), true, 'has');
assertSame(collection.has('10'), true, 'has');
assertSame(collection.has('5'), false, 'has');
assertSame(collection.get(3, 2), 2, 'get');
assertSame(collection.get(10, 2), 100, 'get');
assertSame(collection.get(11), undefined, 'get');
console.warn('Object');
var ob = {
a: 1,
b: 2,
10: 3,
};
collection = new kit.Collection(ob);
assertSame(collection.count(), 3, 'Количество');
assertSame(collection.has(10), true, 'has');
assertSame(collection.has('10'), true, 'has');
assertSame(collection.has('5'), false, 'has');
assertSame(collection.get('a'), 1, 'get');
assertSame(collection.get(3, 2), 2, 'get');
assertSame(collection.get(10, 2), 3, 'get');
assertSame(collection.get(11), undefined, 'get');
assertSame(JSON.stringify(collection.set(5, 19).all()), JSON.stringify({
a: 1,
b: 2,
10: 3,
5: 19,
}), 'get');
var testFunction = function (q, w, e, r, t, y) {
var c = new kit.Collection(arguments);
assertSame(c.count(), 8, 'arguments count');
assertSame(c.get(0), 1, 'arguments get');
assertSame(c.get(7), 8, 'arguments get');
assertSame(c.get(8, 80), 80, 'arguments get');
}
testFunction(1, 2, 3, 4, 5, 6, 7, 8);
});
</script>
+2 -5
View File
@@ -264,14 +264,12 @@ kit.ready(['menu', 'animations'], function () {
label: 'меняем предка на R', label: 'меняем предка на R',
click: function(e, menuItem, menu) { click: function(e, menuItem, menu) {
console.log('клик by ' + menuItem.options.label); console.log('клик by ' + menuItem.options.label);
menu.setParent(document.querySelector('#change-context-menu-r'));
menuItem.setVisible(false); menuItem.setVisible(false);
var tMenu = menu.getItemById(item2.getId()); var tMenu = menu.getItemById(item2.getId());
if(tMenu) { if(tMenu) {
tMenu.setVisible(true); tMenu.setVisible(true);
} }
// kit.menu.reInitAllMenu(); menu.setParent(document.querySelector('#change-context-menu-r'));
// todo перерасчет только внутренних меню
}, },
}, true); }, true);
var item2 = menuBase.addItem({ var item2 = menuBase.addItem({
@@ -279,13 +277,12 @@ kit.ready(['menu', 'animations'], function () {
visible: false, visible: false,
click: function(e, menuItem, menu) { click: function(e, menuItem, menu) {
console.log('клик by ' + menuItem.options.label); console.log('клик by ' + menuItem.options.label);
menu.setParent(document.querySelector('#change-context-menu-x'));
menuItem.setVisible(false); menuItem.setVisible(false);
var tMenu = menu.getItemById(item1.getId()); var tMenu = menu.getItemById(item1.getId());
if(tMenu) { if(tMenu) {
tMenu.setVisible(true); tMenu.setVisible(true);
} }
// kit.menu.reInitAllMenu(); menu.setParent(document.querySelector('#change-context-menu-x'));
}, },
}, true); }, true);