MediaWiki:Common.js

De Wiki Gla
Revisão de 05h08min de 3 de junho de 2022 por Rag (discussão | contribs)
Ir para navegação Ir para pesquisar

Nota: Após salvar, você pode ter que limpar o "cache" do seu navegador para ver as alterações.

  • Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
  • Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
  • Internet Explorer/Edge: PressioneCtrl enquanto clica Recarregar, ou Pressione Ctrl-F5
  • Opera: Pressione Ctrl-F5.
  $(document).ready(function() {
	
  	  	//------- TOOLTIP IMAGE---------
	  	  	const offset = { x: 20, y: 10 };
	  	  	
	  		$('.tooltip-image').hover(function(e) {
	  			var src = $(this).attr('src');
	  			var size = $(this).width() * 1.35;
	  			
	  			$('<img src="'+ src +'" id="bigImage" />').css('left', e.pageX + offset.x).css('top', e.pageY + offset.y).css('width', size + "px").appendTo('body').hide().fadeIn(500);
	  			}, function(){
	  				$('#bigImage').remove();
	  		});
	  		
	  		$('.tooltip-image').mousemove(function(e) {
	  			$('#bigImage').css('left', e.pageX + offset.x).css('top', e.pageY + offset.y);
	  		});
  		//------- TOOLTIP IMAGE---------
  		
  		const timer = $('#event-time');
  		const eventImage = $('.event-image');
  		
  		const eventsInfo = {
  			sunday: [
  				{name: 'Foxy race (ship)', time: '09:30:00', src: '/images/9/93/Event_raceship.png'},
  				{name: 'Foxy count', time: '15:00:00', src: '/images/e/e4/Event_count.png'},
  				{name: 'Foxy quiz', time: '19:00:00', src: '/images/6/6f/Event_quiz.png'},
  				{name: 'Deathmatch', time: '22:00:00', src: '/images/8/84/Event_dm.png'},
  			],
  			monday: [
  				{name: 'Foxy count', time: '09:30:00', src: '/images/e/e4/Event_count.png'},
  				{name: 'Foxy quiz', time: '15:00:00', src: '/images/6/6f/Event_quiz.png'},
  				{name: 'Deathmatch', time: '19:00:00', src: '/images/8/84/Event_dm.png'},
  				{name: 'Foxy race (ship)', time: '22:00:00', src: '/images/9/93/Event_raceship.png'},
  			],
  			tuesday: [
  				{name: 'Foxy quiz', time: '09:30:00', src: '/images/6/6f/Event_quiz.png'},
  				{name: 'Deathmatch', time: '15:00:00', src: '/images/8/84/Event_dm.png'},
  				{name: 'Foxy race', time: '19:00:00', src: '/images/0/03/Event_race.png'},
  				{name: 'Foxy count', time: '22:00:00', src: '/images/e/e4/Event_count.png'},
  			],
  			wednesday: [
  				{name: 'Deathmatch', time: '09:30:00', src: '/images/8/84/Event_dm.png'},
  				{name: 'Foxy race (ship)', time: '15:00:00', src: '/images/9/93/Event_raceship.png'},
  				{name: 'Foxy count', time: '19:00:00', src: '/images/e/e4/Event_count.png'},
  				{name: 'Foxy quiz', time: '22:00:00', src: '/images/6/6f/Event_quiz.png'},
  			],
  			thursday: [
  				{name: 'Foxy race', time: '09:30:00', src: '/images/0/03/Event_race.png'},
  				{name: 'Foxy count', time: '15:00:00', src: '/images/e/e4/Event_count.png'},
  				{name: 'Foxy quiz', time: '19:00:00', src: '/images/6/6f/Event_quiz.png'},
  				{name: 'Deathmatch', time: '22:00:00', src: '/images/8/84/Event_dm.png'},
  			],
  			friday: [
  				{name: 'Foxy count', time: '09:30:00', src: '/images/e/e4/Event_count.png'},
  				{name: 'Foxy quiz', time: '15:00:00', src: '/images/6/6f/Event_quiz.png'},
  				{name: 'Deathmatch', time: '19:00:00', src: '/images/8/84/Event_dm.png'},
  				{name: 'Foxy race (ship)', time: '22:00:00', src: '/images/9/93/Event_raceship.png'},
  			],
  			saturday: [
  				{name: 'Foxy quiz', time: '09:30:00', src: '/images/6/6f/Event_quiz.png'},
  				{name: 'Deathmatch', time: '15:00:00', src: '/images/8/84/Event_dm.png'},
  				{name: 'Foxy race', time: '19:00:00', src: '/images/0/03/Event_race.png'},
  				{name: 'Foxy count', time: '22:00:00', src: '/images/e/e4/Event_count.png'},
  			]
  		};
  		
  		var dayEvents;
  		var distance;
  		var eventTime = new Date();
	  	var eventStarting = new Date();
  		
  		function pad(d) {
		    return (d < 10) ? '0' + String(d) : String(d);
  		}
  		
  		function startTimer(eventTime, name){
			setInterval(function() {
	  			distance = eventTime - new Date();
	  			
	  			if(distance > 0){
	  				hour = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
	  				minute = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
	  				seconds = Math.floor((distance % (1000 * 60)) / 1000);
	  				
	  				timer.html(pad(hour) + ":" + pad(minute) + ":" + pad(seconds));
	  			}else {
	  				setDayEvents(dayEvents);
	  				return false;
	  			}
	  		}, 1000);
		}
  		
  		function setDayEvents (array) {
  			dayEvents = array;
  			var split;
	  		var currentTime = new Date();
	  		
  			$.each(array, function (key, item) {
  				split = item.time.split(":");
  				eventTime.setHours(split[0], split[1], split[2]);
	  			eventStarting.setHours(split[0], (Number(split[1]) + 5), split[2]);
	  			
	  			if(currentTime <= eventTime){
	  				var distance = eventTime - currentTime;
	  				hour = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
	  				minute = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
	  				seconds = Math.floor((distance % (1000 * 60)) / 1000);
	  				
	  				timer.html(pad(hour) + ":" + pad(minute) + ":" + pad(seconds));
	  				eventImage.attr('src', item.src);
	  				startTimer(eventTime, item.name);
	  				return false;
	  			}else if(eventTime < currentTime  && currentTime < eventStarting){
	  				eventImage.attr('src', item.src);
	  				timer.html('Evento está começando!');
	  				return false;
	  			}else if(eventTime < currentTime){
	  				timer.html('Não há mais eventos hoje ;-;');
	  			}
	  		});
  		}
  		
  		switch(new Date().getDay()) {
  			case 0:
  				setDayEvents(eventsInfo.sunday);
  			break;
  			case 1:
  				setDayEvents(eventsInfo.monday);
  			break;
  			case 2:
  				setDayEvents(eventsInfo.tuesday);
  			break;
  			case 3:
  				setDayEvents(eventsInfo.wednesday);
  			break;
  			case 4:
  				setDayEvents(eventsInfo.thursday);
  			break;
  			case 5:
  				setDayEvents(eventsInfo.friday);
  			break;
  			case 6:
  				setDayEvents(eventsInfo.saturday);
  			break;
  			default:
  				setDayEvents(eventsInfo.sunday);
  		}
  });