This commit is contained in:
2021-11-01 21:52:13 +03:00
parent 353e0715ca
commit 82452a959e
12 changed files with 798 additions and 844 deletions
+12 -8
View File
@@ -2,26 +2,30 @@
kit.PluginManager.register('ActionCollection', function(module, exports, require, global) {
var Collection = require('Collection');
var support = require('support');
/**
* @class ActionCollection
* @extends {kit.Collection}
* @memberOf kit
*/
var ActionCollection = function (list = []) {
this.collection = new Collection(list);
Collection.prototype.constructor.apply(this, arguments);
};
ActionCollection.prototype.push = function (action) {
this.collection.push(action);
};
ActionCollection.prototype.run = function (count = -1) {
this.collection.map(function (action) {
var proto = ActionCollection.prototype;
proto.run = function (count = -1) {
this.map(function (action) {
action.run(count);
})
};
ActionCollection.prototype.stop = function () {
this.collection.map(function (action) {
proto.stop = function () {
this.map(function (action) {
action.stop();
})
};
support.extend(ActionCollection.prototype, Collection.prototype);
return module.exports = ActionCollection;
});
+72 -26
View File
@@ -10,12 +10,13 @@ kit.PluginManager.register('Viewer', function(module, exports, require, global)
var AnimationTrap = function (node, callbackBefore = function(){}, callbackAfter = function(){}) {
this.node = support.getNode(node);
this.active = 0;
this.active = false;
this.__timeoutId = 0;
this.__callbackOptions = {};
this.callbackBefore = callbackBefore;
this.callbackAfter = callbackAfter;
this.__callbackAfterHandler = function () {
this.callbackAfter();
this.callbackAfter(this.__callbackOptions);
this.stop();
}.bind(this);
this.__animationstart = false;
@@ -28,30 +29,43 @@ kit.PluginManager.register('Viewer', function(module, exports, require, global)
new Action(this.node, 'animationcancel', this.__callbackAfterHandler)
]);
};
AnimationTrap.prototype.run = function () {
AnimationTrap.prototype.run = function (options = {}) {
if(this.active === 1){
if(this.active){
return;
}
this.active = 1;
this.__callbackOptions = Object.assign({
useAnim: true
}, options);
if(!this.__callbackOptions.useAnim){
this.callbackBefore(this.__callbackOptions);
this.callbackAfter(this.__callbackOptions);
this.stop();
return;
}
this.active = true;
this.__animationStartAction.run(1);
this.callbackBefore();
this.callbackBefore(this.__callbackOptions);
this.__animationEndAction.run(1);
this.__timeoutId = setTimeout(function () {
if(!this.__animationstart) {
this.__callbackAfterHandler();
this.__callbackAfterHandler(this.__callbackOptions);
}
}.bind(this), 100);
};
AnimationTrap.prototype.stop = function () {
clearTimeout(this.__timeoutId);
this.__timeoutId = 0;
this.__callbackOptions = {};
this.__animationstart = false;
this.__animationStartAction.stop();
this.__animationEndAction.stop();
this.active = 0;
this.active = false;
};
@@ -76,26 +90,36 @@ kit.PluginManager.register('Viewer', function(module, exports, require, global)
this.node = support.getNode(node);
this.masterNode = support.getNode(masterNode);
this.onShow = new Collection();
this.onShowBefore = new Collection();
this.onHide = new Collection();
this.onHideBefore = new Collection();
this.animShowClass = '';
this.animHideClass = '';
this.delayHide = 0;
this.activeMasterClass = 'active';
this.__aminationTrapHide = new AnimationTrap(this.node, function () {
this.__aminationTrapHide = new AnimationTrap(this.node, function (options) {
if(options.onHideBefore !== false) {
this.onHideBefore.eachCall();
}
removeAnimation.call(this, this.animShowClass);
addAnimation.call(this, this.animHideClass);
}.bind(this), function () {
}.bind(this), function (options) {
if(this.masterNode && this.activeMasterClass) {
this.masterNode.classList.remove(this.activeMasterClass);
}
this.node.classList.add('hide');
this.node.classList.remove('show');
this.onHide.eachCall();
if(options.onHide !== false) {
this.onHide.eachCall();
}
this.node.style.display = 'none';
}.bind(this));
this.__aminationTrapShow = new AnimationTrap(this.node, function () {
this.__aminationTrapShow = new AnimationTrap(this.node, function (options = {}) {
if(options.onShowBefore !== false) {
this.onShowBefore.eachCall();
}
this.node.classList.remove('hide');
this.node.classList.add('show');
if(this.node.style.display === 'none') {
@@ -104,10 +128,13 @@ kit.PluginManager.register('Viewer', function(module, exports, require, global)
if(this.masterNode && this.activeMasterClass) {
this.masterNode.classList.add(this.activeMasterClass);
}
removeAnimation.call(this, this.animHideClass);
addAnimation.call(this, this.animShowClass);
this.onShow.eachCall();
}.bind(this), function () {
if(options.onShow !== false) {
this.onShow.eachCall();
}
}.bind(this), function (options = {}) {
}.bind(this));
@@ -121,30 +148,42 @@ kit.PluginManager.register('Viewer', function(module, exports, require, global)
};
var proto = Viewer.prototype;
proto.show = function(){
proto.show = function(options = {}){
if(this.isShown()) {
return;
}
deferredHideCancel.call(this);
this.__aminationTrapHide.stop();
this.__aminationTrapShow.run();
options.useAnim = !!this.animHideClass;
this.stop();
this.__aminationTrapShow.run(options);
};
proto.hide = function(){
proto.hide = function(options = {}){
if(this.isHidden()) {
return;
}
options.useAnim = !!this.animHideClass;
this.__aminationTrapShow.stop();
var hideDeferred = function () {
deferredHideCancel.call(this);
this.__deferredHideID = setTimeout(hide.bind(this), this.delayHide);
if(this.delayHide) {
this.__deferredHideID = setTimeout(hide.bind(this), this.delayHide);
return;
}
hide();
}.bind(this);
var hide = function() {
deferredHideCancel.call(this);
this.__aminationTrapShow.stop();
this.__aminationTrapHide.run();
this.__aminationTrapHide.run(options);
}.bind(this);
hideDeferred();
};
proto.toggle = function(){
@@ -156,15 +195,22 @@ kit.PluginManager.register('Viewer', function(module, exports, require, global)
return false;
};
proto.isShown = function(){
return !this.isHidden() && !this.__aminationTrapHide.active;
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;
return result || this.__aminationTrapHide.active || this.__deferredHideID;
};
proto.stop = function () {
this.__aminationTrapHide.stop();
this.__aminationTrapShow.stop();
deferredHideCancel.call(this);
// removeAnimation.call(this, this.animHideClass);
// removeAnimation.call(this, this.animShowClass);
};
return module.exports = Viewer;
});
+28 -9
View File
@@ -457,6 +457,11 @@ kit.PluginManager.register('align',function(module, exports, require) {
};
/**
*
* @param node
* @return {AlignClass}
*/
AlignClass.prototype.setNode = function(node){
this.unset();
this.node = support.getNode(node);
@@ -471,6 +476,10 @@ kit.PluginManager.register('align',function(module, exports, require) {
return this;
};
/**
* @param node
* @return {AlignClass}
*/
AlignClass.prototype.setParentNode = function(node){
this.parentNode = support.getNode(node);
if(this.__calc) {
@@ -478,6 +487,7 @@ kit.PluginManager.register('align',function(module, exports, require) {
}
return this;
};
AlignClass.prototype.setLimiterNode = function(node){
this.limiterNode = support.getNode(node) || window;
if(this.__calc) {
@@ -520,18 +530,27 @@ kit.PluginManager.register('align',function(module, exports, require) {
return this;
};
/**
*
* @param hAlign
* @param vAlign
* @param hDirection
* @param vDirection
* @return {AlignClass}
*/
AlignClass.prototype.set = function(hAlign, vAlign, hDirection, vDirection){
this.setEx('vertical', vDirection, vAlign);
this.setEx('horizontal', hDirection, hAlign);
return this;
};
AlignClass.prototype.setVertical = function(direction, align){
this.setEx('vertical', direction, align);
this.setEx('vertical', vAlign, vDirection);
this.setEx('horizontal', hAlign, hDirection);
return this;
};
AlignClass.prototype.setHorizontal = function(direction, align){
this.setEx('horizontal', direction, align);
AlignClass.prototype.setVertical = function(align, direction){
this.setEx('vertical', align, direction);
return this;
};
AlignClass.prototype.setHorizontal = function(align, direction){
this.setEx('horizontal', align, direction);
return this;
};
@@ -544,7 +563,7 @@ kit.PluginManager.register('align',function(module, exports, require) {
}
};
AlignClass.prototype.setEx = function(axis, direction, align){
AlignClass.prototype.setEx = function(axis, align, direction){
this.reset(axis === 'horizontal', axis === 'vertical');
+28 -37
View File
@@ -91,13 +91,16 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
return ob;
};
Collection.prototype.serialize = function () {
return JSON.stringify(this.all());
return JSON.stringify(this.toObject());
};
Collection.prototype.serializeArray = function () {
return JSON.stringify(this.toArray());
};
Collection.prototype.has = function (key) {
return this.data.hasOwnProperty(key) && this.__keys.includes(safeArrayKey(key));
return this.__keys.includes(safeArrayKey(key));
};
Collection.prototype.indexKey = function (key) {
return this.__keys.indexOf(key);
return this.__keys.indexOf(safeArrayKey(key));
};
/**
* @param key
@@ -157,17 +160,13 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
* @return {kit.Collection}
*/
Collection.prototype.each = function (callback = true) {
var BreakException = {}, i;
try {
if(this.__keys.length)
for (i = 0; i < this.__keys.length; i++) {
if(valueEx(callback, this.__values[i], this.__keys[i], this.data) === false) {
throw BreakException;
}
var i;
if(this.__keys.length)
for (i = 0; i < this.__keys.length; i++) {
if(valueEx(callback, this.__values[i], this.__keys[i], this.data) === false) {
break;
}
} catch (e) {
if (e !== BreakException) throw e;
}
}
return this;
};
/**
@@ -175,17 +174,13 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
* @return {kit.Collection}
*/
Collection.prototype.eachReverse = function (callback = true) {
var BreakException = {}, i;
try {
if(this.__keys.length)
for (i = this.__keys.length - 1; i >= 0; i--) {
if(valueEx(callback, this.__values[i], this.__keys[i], this.data) === false) {
throw BreakException;
}
var i;
if(this.__keys.length)
for (i = this.__keys.length - 1; i >= 0; i--) {
if(valueEx(callback, this.__values[i], this.__keys[i], this.data) === false) {
break;
}
} catch (e) {
if (e !== BreakException) throw e;
}
}
return this;
};
/**
@@ -328,7 +323,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
* Method removes and returns the last item from the collection
*/
Collection.prototype.pop = function(){
var index = this.length - 1;
var index = this.__keys.length - 1;
if(index < 0) {
return undefined;
}
@@ -381,23 +376,19 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
* @return {kit.Collection}
*/
Collection.prototype.eachCall = function (context, args1, args2) {
var args = [];
var args = [], i;
if(arguments.length > 1)
for(var i = 1; arguments.length - 1 >= i;i++) {
for(i = 1; arguments.length - 1 >= i;i++) {
args.push(arguments[i]);
}
var BreakException = {}, i;
try {
if(this.__keys.length)
for (i = 0; i < this.__keys.length; i++) {
if(typeof this.__values[i] === 'function' &&
this.__values[i].apply(context, [].concat(args, this.__keys[i])) === false) {
throw BreakException;
}
if(this.__keys.length)
for (i = 0; i < this.__keys.length; i++) {
if(typeof this.__values[i] === 'function' &&
this.__values[i].apply(context, [].concat(args, this.__keys[i])) === false) {
throw BreakException;
}
} catch (e) {
if (e !== BreakException) throw e;
}
}
return this;
};
+5 -1
View File
@@ -8,8 +8,12 @@ window.kit = window.kit || {};
*/
kit.config = kit.config || {};
// [PluginManager]
kit.config.assetsPath = '/local/templater.dev/kit/assets';
kit.config.requiredDependencies = ['bsCore', 'toolkit', 'support'];
kit.config.autoloadPluginList = ['tooltip', 'support'];
kit.config.debug = true;
kit.config.defaultPhoneMask = '+7 (999) 999-99-99';
kit.config.defaultPhoneMask = '+7 (999) 999-99-99';
// [OtherPlugins]
+10 -2
View File
@@ -29,12 +29,20 @@
border-right: var(--kit-menu-border-width) solid var(--kit-color-primary, #3c9cdd);
box-shadow: 0 0 10px 0 #00000033, inset -5px 0 5px -5px var(--kit-color-primary-b2, #2283c3);
}
.kit-menu.active {
.kit-menu.active, .kit-menu.show {
display: block;
z-index: 1000;
}
.kit-text-debug {
position: absolute;
background-color: #363636;
pointer-events: none;
color: #dddddd;
font-size: 12px;
font-family: monospace;
line-height: 1.1em;
}
+571 -737
View File
File diff suppressed because it is too large Load Diff
+17 -10
View File
@@ -86,18 +86,23 @@ __PluginManager__.register('support', function(module, exports, require, global)
if(isNode(selector) || isElement(selector)) {
return selector;
}
return undefined;
return null;
}
var nameFromToStringRegex = /^function\s?([^\s(]*)/;
function className(object, defaultName) {
var result = "";
if (typeof object === 'function') {
result = object.name || object.toString().match(nameFromToStringRegex)[1];
} else if (typeof object.constructor === 'function') {
result = className(object.constructor, defaultName);
var extend = function(target) {
if(!arguments[1]) {
return;
}
return result || defaultName;
}
for(i=1; i < arguments.length; i++) {
var source = arguments[i];
for(var prop in source) {
if(!target[prop] && source.hasOwnProperty(prop)) {
target[prop] = source[prop];
}
}
}
};
/**
@@ -117,7 +122,9 @@ __PluginManager__.register('support', function(module, exports, require, global)
isFloat,
isString,
isNode,
isElement,
getNode,
extend,
};
return module.exports = support;
+16 -3
View File
@@ -7,7 +7,13 @@ kit.PluginManager.register('userAction', function(module, exports, require, glob
var Viewer = require('Viewer');
/**
*
* @param masterNode
* @param slaveNode
* @return {Popover}
* @constructor
*/
var Popover = function (masterNode, slaveNode) {
this.__setMasterNode(masterNode);
this.__setSlaveNode(slaveNode);
@@ -54,8 +60,15 @@ kit.PluginManager.register('userAction', function(module, exports, require, glob
this.__masterAction.stop();
};
})();
/**
*
* @param masterNode
* @param slaveNode
* @return {Hint}
* @constructor
*/
var Hint = function (masterNode, slaveNode) {
this.__setMasterNode(masterNode);
this.__setSlaveNode(slaveNode);