Каталог файловtilda-vote-1.1.js
101function tvote__makeFullVoteID(vote) {102 // TODO: jquery element103 if (!(vote instanceof Element)) vote = vote[0];104 105 var voteID = vote.getAttribute('data-vote-id');106 107 if (!voteID) return;108 109 var fullVoteID = document.querySelector('#allrecords').getAttribute('data-tilda-project-id') + voteID;110 111 fullVoteID = fullVoteID.replace('"', '').replace(''', '').replace(/[&/\\#,+()$~%.'":;*?!<>{}\-_\s]/g, '');112
История файла и сравнение версий
vote.setAttribute('data-vote-id', fullVoteID);
118 * Check vote condition 120 * @param {object} opts - data params vote 122 function t_vote__checkVoteCondition(opts) { 123 // get results if we need to show it 124 var curVoteCookie = t_vote__getCookie('vote' + opts.voteID); 125 var curVoteResult = t_vote__getCookie('voteresult' + opts.voteID); 127 // show results, if settings let to do it 128 if (opts.voteVisibility === 'yes' || (opts.voteVisibility === 'onclick' && curVoteCookie)) { 129 var btnsResult = opts.voteEl.querySelectorAll('.t-vote__btn-res'); 131 Array.prototype.forEach.call(btnsResult, function(result) { 132 result.style.display = 'block'; 135 // add style, if you've already voted 137 opts.voteEl.classList.add('js-vote-sended'); 138 opts.voteEl.classList.add('t-vote_sended'); 141 if (opts.type === 'single' && curVoteCookie && curVoteResult) { 142 opts.voteEl.querySelector('[data-answer-id="' + curVoteResult + '"] .t-vote__btn-el').classList.add('t-vote__btn-el_active'); 145 // get results from server 146 tvote__getResult(opts.voteID); 152 * @param {string} name - name cookie key 153 * @returns {string | undefined} - return cookie 155function t_vote__getCookie(name) { 156 var matches = document.cookie.match(new RegExp( 157 '(?:^|; )' + name.replace(/([.$?*|{}()[\]\\/+^])/g, '\\$1') + '=([^;]*)' 159 return matches ? decodeURIComponent(matches[1]) : undefined; 163 * Get result in vote block 165 * @param {string} voteID - block vote id 168function tvote__getResult(voteID) { 169 var vote = document.querySelector('[data-vote-id="' + voteID + '"]'); 170 var type = vote.getAttribute('data-vote-type'); 172 if (type === 'single') { 173 var url = 'https://vote.tildaapi.' + t_vote__getRootZone() + '/vote/1/getresult/'; 175 if (type === 'multi') { 176 var url = 'https://vote.tildaapi.' + t_vote__getRootZone() + '/vote/2/getresult/'; 181 var xhr = new XMLHttpRequest(); 183 url += '?' + 'voteid=' + voteID + '&' + 'host=' + location.protocol + '//' + location.host; 185 // TODO: async flag is set to false but the browser notifies about the bad tone https://xhr.spec.whatwg.org/ 186 xhr.open('GET', url, true); 187 xhr.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8'); 188 xhr.onload = function() { 189 if (xhr.status >= 200 && xhr.status < 400) { 190 var data = xhr.responseText; 192 var objData = JSON.parse(data); 193 if (typeof objData === 'object') { 194 if (!objData['error']) { 195 if (type === 'single') { 196 Array.prototype.forEach.call(Object.keys(objData[0]), function(key) { 197 var counters = vote.querySelectorAll('[data-answer-id="' + key + '"] .js-vote-count'); 198 if (counters.length) { 199 Array.prototype.forEach.call(counters, function(counter) { 200 counter.innerHTML = objData[0][key];