MediaWiki:Common.js

From Uncompromising Mode 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.
mw.loader.getScript( 'https://commons.wiki.gg/index.php?title=MediaWiki:Common-base.js&action=raw&ctype=text/javascript' ).then(function(){
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
/*end of mw.loader.getScript().then callback*/ });

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * main page slider
*/
$(function(){
	$('#mainpage-wrap .slider').each(function(){
		var $box = $(this);
		$prev = $('<div class="prev"/>').appendTo($box);
		$next = $('<div class="next"/>').appendTo($box);
		$box = $box.find('ul').first();
		var $current = $box.find('li').first();
		$box.find('li').each(function(){
			var $this = $(this);
			$this.data('left', $this.position().left);
			$this.css('background-image', 'url('+$this.find('img').first().attr('src')+')');
		});
		
		var timeout;
		
		var switchTo = function($item){
			$box.css('transform', 'translateX(-'+$item.data('left')+'px)');
		}
		var goNext = function(){
				clearTimeout(timeout);
				$current = $current.next('li');
				if($current.length === 0){
					$current = $box.find('li').first();
				}
				switchTo($current);
				timeout = setTimeout(goNext, 5000);
		};
		var goPrev = function(){
				clearTimeout(timeout);
				$current = $current.prev('li');
				if($current.length === 0){
					$current = $box.find('li').last();
				}
				switchTo($current);
				timeout = setTimeout(goNext, 5000);
		};

		timeout = setTimeout(goNext, 5000);
		
		$prev.on('click', goPrev);
		$next.on('click', goNext);
		
		
		
	});
});