MediaWiki:Vector.js

From World Zero Wiki
Jump to navigation Jump to search

Note: After publishing, 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: Press Ctrl-F5.
/* All JavaScript here will be loaded for users of the Vector skin */

$(function(){
	$('.slider').each(function(){
		var $box = $(this);
		var view_more_text = $box.data('view-more-text') || 'View more';
		var duration = ((0 + $box.data('duration')) || 5)*1000;
		var $index = $('<div></div>').appendTo($box);
		var $timerbar = $('<span></span>').appendTo($box);
		var timer;
		var switchTo = function($item){
			clearTimeout(timer);
			$timerbar.stop(true);
			$box.find('.current').removeClass('current');
			$item.addClass('current').data('ref').addClass('current');
			$timerbar.css('width', '100%').animate({'width': '0%'}, duration);
			timer = setTimeout(function(){
				var $next = $item.next();
				if($next.length){
					switchTo($next);
				}
				else{
					switchTo($index.find('img').first());
				}
			}, duration);
		}		
		$box.find('ul li').each(function(){
			var $li = $(this);
			var $img = $li.find('img').first();
			$img.clone().data('ref', $li).appendTo($index).on('click', function(){
				switchTo($(this));
			});
			if($img.parent().prop('tagName') == 'A'){
				var $anchor = $img.parent();
				$img.insertBefore($anchor);
				$anchor.text(view_more_text).appendTo($li);
			}
		});
		$box.find('ul li').first().addClass('current');
		$index.find('img').first().addClass('current');
		switchTo($index.find('.current'));
	});
	
});