import tmpl from 'blueimp-tmpl'; import { nodeId } from './settings'; import fetcher from './fetcher'; let node = null; let afterInit = null; if (document.readyState !== 'complete') { window.addEventListener('DOMContentLoaded', initNode); } else { initNode(); } function initNode () { if (node) return; node = document.getElementById(nodeId); if (!node) return; if (afterInit) { afterInit(); } } function handleClick(rootNode, e) { if (!e.target) return; if (e.target && e.target.classList.contains('remark42__vote')) { handleVote(rootNode, e); } } function handleVote(rootNode, e) { const { target: node } = e; if (node.classList.contains('remark42__vote_selected')) return; const commentId = node.closest('.remark42__comment').dataset.id; if (node.classList.contains('remark42__vote_type_up')) { console.log('+1'); changeScore(rootNode, 1); fetcher.put(`/vote/${commentId}?url=https://radio-t.com/p/2017/12/16/podcast-576/&vote=1`); } else { console.log('-1'); changeScore(rootNode, -1); fetcher.put(`/vote/${commentId}?url=https://radio-t.com/p/2017/12/16/podcast-576/&vote=-1`); } node.classList.add('remark42__vote_selected'); } function changeScore(rootNode, delta) { const valueNode = rootNode.querySelector('.remark42__score-value'); const currentValue = parseInt(valueNode.dataset.value); const newValue = currentValue + delta; valueNode.dataset.value = newValue; valueNode.textContent = Math.abs(newValue); } export default data => { // TODO: link to profile? // TODO: link to comment? // TODO: add photo? const templateComment = `