diff --git a/assets/animations/animations.css b/assets/animations/animations.css index c502539..365603d 100644 --- a/assets/animations/animations.css +++ b/assets/animations/animations.css @@ -1,6 +1,6 @@ .anim-scale-in { animation-name: scale-in; - animation-duration: .15s; + animation-duration: var(--animation-duration, 0.15s); animation-timing-function: cubic-bezier(0.2, 0, 0.13, 1.5); } @@ -16,8 +16,8 @@ } .anim-scale-out { - -webkit-animation: scale-out-center 0.15s cubic-bezier(0.2, 0, 0.13, 1.5); - animation: scale-out-center 0.15s cubic-bezier(0.2, 0, 0.13, 1.5); + -webkit-animation: scale-out-center var(--animation-duration, 0.15s) cubic-bezier(0.2, 0, 0.13, 1.5); + animation: scale-out-center var(--animation-duration, 0.15s) cubic-bezier(0.2, 0, 0.13, 1.5); } @-webkit-keyframes scale-out-center { 0% { diff --git a/assets/core/core.register.js b/assets/core/core.register.js index f57343b..3b06245 100644 --- a/assets/core/core.register.js +++ b/assets/core/core.register.js @@ -278,6 +278,11 @@ __PluginManager__.registerPlugins({ } }, + makeCSSAnimations: { + path: __pmConfig__.assetsPath + '/makeCSSAnimations', + js: '/makeCSSAnimations.js', + deps: ['jQuery', 'support'], + }, }); diff --git a/assets/makeCSSAnimations/makeCSSAnimations.js b/assets/makeCSSAnimations/makeCSSAnimations.js new file mode 100644 index 0000000..95db7f4 --- /dev/null +++ b/assets/makeCSSAnimations/makeCSSAnimations.js @@ -0,0 +1,62 @@ +/** @module makeCSSAnimations */ +kit.PluginManager.register('makeCSSAnimations', function(module, exports, require, global) { + + var support = require('support'); + var $ = require('jQuery'); + + var whichAnimationEvent = support.whichAnimationEvent(); + + /** + * @memberOf kit + * @param options {{container: jQuery, animationClass: string, stateClass: string, direction: 'fwd'|'back', before: null|function, after: null|function}} + */ + var makeCSSAnimations = function (options) { + + var defaults = { + container: null, + animationClass: null, + stateClass: null, + before: null, + after: null, + direction: 'fwd' // 'back' + }; + + var settings = $.extend(defaults, options); + + if (settings.before !== null && typeof settings.before === 'function') { + settings.before(); + } + + if (whichAnimationEvent) { + + if (settings.direction === 'fwd') { + settings.container.addClass(settings.stateClass); + } + + settings.container.addClass(settings.animationClass); + + settings.container.one(whichAnimationEvent, function () { + settings.container.removeClass(settings.animationClass); + if (settings.direction === 'back') { + settings.container.removeClass(settings.stateClass); + } + if (settings.after !== null && typeof settings.after === 'function') { + settings.after(); + } + }); + } else { + + if (settings.direction === 'fwd') { + settings.container.addClass(settings.stateClass); + } else if (settings.direction === 'back') { + settings.container.removeClass(settings.stateClass); + } + + if (settings.after !== null && typeof settings.after === 'function') { + settings.after(); + } + } + }; + + return module.exports = makeCSSAnimations; +}); \ No newline at end of file diff --git a/assets/support/support.js b/assets/support/support.js index 184a8e1..164d483 100644 --- a/assets/support/support.js +++ b/assets/support/support.js @@ -441,6 +441,42 @@ __PluginManager__.register('support', function(module, exports, require, global) node.getAttribute('') } + /** + * @description Событие окончания CSS transition + */ + function whichTransitionEvent() { + var el = document.createElement("fakeelement"); + var transitions = { + "transition": "transitionend", + "OTransition": "oTransitionEnd", + "MozTransition": "transitionend", + "WebkitTransition": "webkitTransitionEnd" + }; + for (var t in transitions) { + if (el.style[t] !== undefined) { + return transitions[t]; + } + } + }; + + /** + * @description Событие окончания CSS animation + */ + function whichAnimationEvent() { + var el = document.createElement("fakeelement2"); + var animations = { + "animation": "animationend", + "OAnimation": "oAnimationEnd", + "MozAnimation": "animationend", + "WebkitAnimation": "webkitAnimationEnd" + }; + for (var t in animations) { + if (el.style[t] !== undefined) { + return animations[t]; + } + } + }; + /** * @memberOf kit */ @@ -478,7 +514,9 @@ __PluginManager__.register('support', function(module, exports, require, global) tagName: setTagName, data, setObjProp, - getObjProp + getObjProp, + whichAnimationEvent, + whichTransitionEvent }; return module.exports = support; diff --git a/tests/makeCSSAnimationsTest.php b/tests/makeCSSAnimationsTest.php new file mode 100644 index 0000000..2083935 --- /dev/null +++ b/tests/makeCSSAnimationsTest.php @@ -0,0 +1,92 @@ + +service()->assets()->setPlugins([ + 'kit:config', + 'kit:flex-kit', + 'kit:core', + 'kit:bsCore', + 'kit:collapse', + 'kit:site', + 'kit:toolkit', + 'kit:theme', + ])->render(); +} +$APPLICATION->ShowHead(); + +?> + + +
+
+
+
+
+ +
+ \ No newline at end of file