4501/**4502* Подписывает элемент на окончание анимации4503*4504* @param {AnimatedHTML} el - текущий элемент4505*/4506function t_animationSBS__animationEnd(el) {4507el.removeEventListener('animationend', t_animationSBS__animationEndingEvent);4508el.addEventListener('animationend', t_animationSBS__animationEndingEvent);4509}45104511/**4512* Окончание анимации hover/click: снимает флаг проигрывания и запускает запланированное направление,
* если пользователь успел навести или убрать курсор во время анимации * * @param {AnimationEvent} e */function t_animationSBS__animationEndingEvent(e) { // анимации цвета заканчиваются вместе с основной, повторная обработка сбросила бы флаг уже запущенного реверса if (t_animationSBS__isColorAnimationEvent(e)) return; this.classList.remove('t-sbs-anim_playing'); var plannedDirection = this.getAttribute('data-planned-dir'); if (plannedDirection === 'play' && this.classList.contains('t-sbs-anim_reversed')) { t_animationSBS__playAnimation(this, false); } else if (plannedDirection === 'reverse' && !this.classList.contains('t-sbs-anim_reversed')) { t_animationSBS__playAnimation(this, true); } this.setAttribute('data-planned-dir', '');}/** * return the time it takes to complete the full animation cycle * * @param {AnimatedHTML} el - current element * @param {Boolean} needDelay - calculate delay * @returns {number} - time */function t_animationSBS__getAnimationFullTime(el, needDelay) { var dataAnimateSbsOpts = el.getAttribute('data-animate-sbs-opts'); if (!dataAnimateSbsOpts) return 0; var animateSbsOpts = JSON.parse(el.getAttribute('data-animate-sbs-opts').split("'").join('"')); return animateSbsOpts.reduce(function (prev, next) { if (needDelay) prev += parseInt(next.dt, 10) || 0; return prev + (parseInt(next.ti, 10) || 0); }, 0);}/** * Play animation on action. * Only for click and hover triggers. * * @param {AnimatedHTML} el - current element * @param {Boolean} isReversed */function t_animationSBS__playAnimation(el, isReversed) { el.classList.remove('t-sbs-anim_started'); if (!isReversed) el.classList.remove('t-sbs-anim_reversed'); t_animationSBS__forceRepaint(el); var animTime = t_animationSBS__getAnimationFullTime(el, false); var classListValues = ['t-sbs-anim_started']; if (isReversed) classListValues.push('t-sbs-anim_reversed'); if (animTime > 0) classListValues.push('t-sbs-anim_playing'); classListValues.forEach(function (className) { el.classList.add(className); }); t_animationSBS__animationEnd(el);}/** * by default animation wouldn't be played twice * if we want to restart it — we need to force an element to be repainted * * @param {HTMLElement} el - current Element */function t_animationSBS__forceRepaint(el) { el.offsetWidth;}//============================ end of action animation: hover and click ============================////============================ on accordion item open ============================///** * Анимации с событием 'on accordion item open' играют вперёд при раскрытии ближайшего Item аккордеона над элементом * и назад при сворачивании. Скрипт аккордеона отправляет на Item событие zero:accordion-item-toggle. * Скрипты грузятся в любом порядке, поэтому Item, раскрытые до инициализации SBS, проверяются по классу * * @param {animatedObject} animatedObject - options */function t_animationSBS__initAccordionItemOpenTriggers(animatedObject) { var accordionElements = animatedObject.elements.filter(function (el) { return el.animType === 'accordionitemopen'; }); t_animationSBS__updateAnimatedObjectState(animatedObject, 'accordionItemOpenEls', accordionElements); if (!accordionElements.length) return; if (!animatedObject.onAccordionItemToggle) { t_animationSBS__setKeyForAnimatedObject(animatedObject, 'onAccordionItemToggle', function (e) { animatedObject.accordionItemOpenEls.forEach(function (el) { if (t_animationSBS__getAccordionItem(el) === e.target) { t_animationSBS__playAccordionItemAnimation(el, e.detail.open);