} if (opts.type === 'single' && action === 'add') { t_vote__incrementAnswerNum(opts.voteID, opts.answerID); var actionElement = opts.voteEl.querySelector('[data-answer-id="' + opts.answerID + '"] .t-vote__btn-el'); actionElement.classList.add('t-vote__btn-el_active'); } if (opts.type === 'single' && action === 'remove') { t_vote__decrementAnswerNum(opts.voteID, opts.answerID); var actionElement = opts.voteEl.querySelector('.t-vote__btn-el_active'); actionElement.classList.remove('t-vote__btn-el_active'); }}/** * Changing stat in multiple voting * * @param {object} opts - data params vote * @param {string} action - completed action */function t_vote__changeStat(opts, action) { var questions = opts.voteEl.querySelectorAll('.js-vote-question'); Array.prototype.forEach.call(questions, function(question) { var answers = question.querySelectorAll('.js-vote-item'); var sum = 0; Array.prototype.forEach.call(answers, function(answer) { var counter = answer.querySelector('.js-vote-count'); if (!counter) return; var amount = counter.textContent * 1; var checkedEl = answer.querySelectorAll('.js-vote-btn:checked').length; sum += amount; if (checkedEl !== 0 && action === 'add') { sum++; amount++; counter.innerHTML = amount; } if (checkedEl !== 0 && action === 'remove') { sum--; amount--; counter.innerHTML = amount; } }); // recalculate percantage Array.prototype.forEach.call(answers, function(answer) { var counter = answer.querySelector('.js-vote-count'); var percent = answer.querySelector('.js-vote-percent'); var amount = 0; if (counter) { amount = counter.textContent * 1; } var percentAge = Math.round((amount * 100) / sum); if (sum !== 0) { if (counter) { counter.innerHTML = amount; } if (percent) { percent.innerHTML = percentAge + '%'; } } else { if (counter) { counter.innerHTML = 0; } if (percent) { percent.innerHTML = '0%'; } } }); }); if (opts.voteEl) t_triggerEvent(opts.voteEl, 'tildavote:numberschanged');}/** * Increment answer number in a single vote * * @param {string} voteID - id group vote * @param {string} answerId - id btn vote */