מדיה ויקי:סקריפטים/16.js

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
// סקריפט ספירת הצבעות. נכתב על ידי [[משתמש:Yonidebest]], שוכתב על ידי קיפודנחש.
(function () {
var link;
if (mw.config.get('wgNamespaceNumber') == 4)
    link = mw.util.addPortletLink('p-tb', '#', 'ספירת הצבעות');

if ( !link ) {
    return;
}

link.onclick = function(event) {
	
	event.preventDefault();
	
	function recalculate() {
		var total = 0;
		$('div.voteCounterSpan span.voteResults').text(''); // clear all.
		$('div.voteCounterSpan').each(function() { // count totlas
			var $this = $(this);
			if ($this.find('input').prop('checked'))
				total += $this.next('ol').find('li').length;
		});
		
		if (total > 0)
			$('div.voteCounterSpan').each(function() {
				var $this = $(this);
				if ($this.find('input').prop('checked')) {
					var votes = $this.next('ol').find('li').length;
					$this.find('span.voteResults').text(votes + '/' + total + ' (' + (100 * votes/total).toFixed(1) + '%)');
				}
			});
	}
	
	mw.util.$content.find('ol:has(li)').before(
		$('<div>', {'class': 'voteCounterSpan'})
			.css({'font-size': '140%', border: '2px solid red', 'margin-bottom': '20px', padding: '8px', width: 'auto'})
			.text('חישוב אפשרות זו')
			.append(
				$('<input>', {'type': 'checkbox'})
				.change(recalculate)
				)
			.append($('<span>', {'class': 'voteResults'}))
	);
};
}() );