User:Nx/Extensions/wigo3/js/multi.js
From RationalWiki
< User:Nx | Extensions
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Clear the cache in Tools → Preferences
/*<![CDATA[*/ function multiupdate(req,voteid,val,count) { if (req.readyState == 4 && req.status == 200) { results = req.responseText.split(':'); for (i=0, sum=0; i<results.length; sum+=parseInt(results[i++],10)); for (i=0; i<count; ++i) { span = document.getElementById(voteid + "-" + i + "-result"); titlespan = document.getElementById(voteid + "-" + i); if (span) { //get number of votes currentvotes = parseInt(span.innerHTML,10); //update and invalidate if number of votes changed newvotes = parseInt(results[i],10); if (newvotes != currentvotes) { wigoinvalidate(); span.innerHTML = newvotes; //calculate column width and update columndiv = document.getElementById(voteid + "-" + i + "-column"); if (columndiv) { if (sum == 0) { percent = 0; } else { percent = newvotes/sum * 100; } columndiv.style.width = percent + "%"; } } //add class and bolding if my vote if (i == val) { //add class if (!span.className || span.className == "") { span.className = "myvote"; } else { span.className += " myvote"; } span.style.fontWeight = "bold"; if (!titlespan.className || titlespan.className == "") { titlespan.className = "myvote"; } else { titlespan.className += " myvote"; } titlespan.style.fontWeight = "bold"; } else { //remove class and bolding span.style.fontWeight = "normal"; if (span.className.match(/(\s*|^)myvote(\s*|$)/)) { span.className = span.className.replace(/(\s*|^)myvote(\s*|$)/g,' ') } titlespan.style.fontWeight = "normal"; if (titlespan.className.match(/(\s*|^)myvote(\s*|$)/)) { titlespan.className = titlespan.className.replace(/(\s*|^)myvote(\s*|$)/g,' ') } } } } } else { alert('An error occured: ' + req.responseText); } } function multivotesend(voteid,val,count) { if (voteid.substr(0,5) != 'multi') { alert('Invalid vote id'); } else { sajax_do_call('multivote',[voteid,val,count],function(req) { multiupdate(req,voteid,val,count); }); } } /*]]>*/