User:Dragonjet/scripts/VotingTemplate.js

< User:Dragonjet
Revision as of 14:39, 6 November 2014 by Dragonjet (talk | contribs) (audio player test)

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 / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
$(document).ready(function(){
	// Voting Mechanism
	if($(".sc_vote").length>0){
		var sc_total = $(".sc_vote").length;
		var sc_votes = {};
		$(".sc_vote").each(function(){
			if(typeof sc_votes[$(this).attr("data-value")] == "undefined"){
				sc_votes[$(this).attr("data-value")] = 0;
			}
			sc_votes[$(this).attr("data-value")]+=1;
		});
		$(".sc_tally").each(function(){
			var sc_tally_percent;
			if(typeof sc_votes[$(this).attr("data-value")] == "undefined"){
				sc_tally_percent = 0;
			}else{
				sc_tally_percent = (sc_votes[$(this).attr("data-value")] / sc_total)*100;
			}
			$(".sc_tally_bar", this).css("width", sc_tally_percent+"%");
			$(".sc_tally_count", this).text(sc_votes[$(this).attr("data-value")]);
			$(".sc_tally_val", this).text(Math.round(sc_tally_percent)+"%");
		});
	}
	
	// Small Audio Player
	if($(".ogg_player").length>0){
		$(".ogg_player").css("height", "23px !important");
		$(".ogg_player").css("overflow", "hidden");
		$(".ogg_player button").css("width", "50px !important");
	}
});