mirror of
https://bitbucket.org/bellord13/kit.git
synced 2026-11-13 19:06:11 +03:00
fix
This commit is contained in:
+72
-26
@@ -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;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user