Каталог файловtilda-vote-1.1.js
301 * Handler click for single vote302 *303 * @param {object} opts - data params vote304 * @returns {boolean} - return true/false validation305 */306function t_vote__handleClick_single(opts) {307 // prevent from click on unactive items, when already voted308 if (!opts.clickedEl.classList.contains('t-vote__btn-el_active') && opts.voteEl.classList.contains('js-vote-sended')) {309 return false;310 }311 312
История файла и сравнение версий
if (opts.clickedEl.classList.contains('t-vote__btn-el_active') && opts.voteEl.classList.contains('js-vote-sended')) {
313 if (t_vote__getCookie('vote_candelete' + opts.voteID)) { 314 t_vote__itemDelete_single(opts); 323 * Handler click for multu vote 325 * @param {object} opts - data params vote 326 * @returns {boolean} - return true/false validation 328function t_vote__handleClick_multi(opts) { 330 var answeredVotes = opts.voteEl.querySelectorAll('.js-vote-question'); 331 var votesNum = opts.voteEl.querySelectorAll('.js-vote-question').length; 333 answeredVotes = Array.prototype.filter.call(answeredVotes, function(answeredVote) { 334 if (answeredVote.querySelector('.js-vote-btn:checked')) return answeredVote; 337 // don't send data, if already voted 338 if (opts.voteEl.classList.contains('js-vote-sended')) { 342 // don't send if not all the questions are answered 343 if (answeredVotes.length != votesNum) { 344 if (window.t_vote__browserLang === 'RU') { 345 t_vote__showError(opts.voteID, 'Пожалуйста, ответьте на все вопросы.'); 347 t_vote__showError(opts.voteID, 'Please, answer all questions.'); 352 // get all answers and save in array 353 Array.prototype.forEach.call(answeredVotes, function(vote) { 354 var questionID = vote.getAttribute('data-question-id'); 355 var questionAnswers = vote.querySelectorAll('.js-vote-btn:checked'); 356 var questionResult = []; 358 Array.prototype.forEach.call(questionAnswers, function(answer) { 359 var answerId = answer.closest('.js-vote-item').getAttribute('data-answer-id'); 360 questionResult.push(answerId + '-' + questionID + '-' + opts.voteID); 364 answer: questionResult, 365 question: questionID, 369 opts.answerArr = result; 374 * Get key and session cookie 376 * @param {object} opts - data params vote 378function t_vote__itemSend(opts) { 379 opts.seconds_fromStart = (new Date().getTime() - opts.startDate.getTime()) / 1000; 381 t_vote__changeVoteCondition(opts, 'add'); 382 opts.voteEl.classList.add('js-vote-sending'); 383 opts.voteEl.classList.add('t-multivote_sended'); 384 t_vote__addLoadingStyle(opts.voteEl); 386 if (opts.voteVisibility === 'onclick') { 387 var btnsResult = opts.voteEl.querySelectorAll('.t-vote__btn-res'); 389 Array.prototype.forEach.call(btnsResult, function(result) { 390 result.style.display = 'block'; 394 var formData = new FormData(); 395 var xhr = new XMLHttpRequest(); 397 formData.append('host', location.protocol + '//' + location.host); 399 // TODO: async flag is set to false but the browser notifies about the bad tone https://xhr.spec.whatwg.org/ 400 xhr.open('POST', opts.url + 'init/', true);