Mudanças entre as edições de "MediaWiki:Common.js"

De Wiki Gla
Ir para navegação Ir para pesquisar
Linha 67: Linha 67:
   function pad(d) {
   function pad(d) {
    return (d < 10) ? '0' + String(d) : String(d);
    return (d < 10) ? '0' + String(d) : String(d);
  }
 
  function startTimer(eventTime){
var distance;
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 countdown (name, event, current){
  setInterval(function() {
  var distance = event - current;
 
  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('<h3 style="display: inline;">'+ name + ' - </h3> ' + pad(hour) + ":" + pad(minute) + ":" + pad(seconds));
  }else {
  setDayEvents(dayEvents);
  }
  }, 1000);
  }
  
  
   function setDayEvents (array) {
   function setDayEvents (array) {
   dayEvents = array;
   dayEvents = array;
 
   $.each(array, function (key, item) {
   $.each(array, function (key, item) {
  var split = item.time.split(":");
  var split = item.time.split(":");
Linha 92: Linha 95:
  var eventTime = new Date();
  var eventTime = new Date();
  var eventStarting = new Date();
  var eventStarting = new Date();
  var runTimer = false;
  eventTime.setHours(split[0], split[1], split[2]);
  eventTime.setHours(split[0], split[1], split[2]);
  eventStarting.setHours(split[0], (Number(split[1]) + 5), split[2]);
  eventStarting.setHours(split[0], (Number(split[1]) + 5), split[2]);
Linha 100: Linha 104:
  minute = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  minute = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  seconds = Math.floor((distance % (1000 * 60)) / 1000);
  seconds = Math.floor((distance % (1000 * 60)) / 1000);
 
  timer.html( '<h3 style="display: inline;">'+ item.name + ' - </h3> ' + pad(hour) + ":" + pad(minute) + ":" + pad(seconds));
  timer.html( '<h3 style="display: inline;">'+ item.name + ' - </h3> ' + pad(hour) + ":" + pad(minute) + ":" + pad(seconds));
  countdown(item.name, eventTime, currentTime);
  startTimer(eventTime, currentTime);
  return false;
  return false;
  }else if(eventStarting > currentTime > eventTime){
  }else if(eventStarting > currentTime > eventTime){

Edição das 17h51min de 29 de maio de 2022

  $(document).ready(function() {
  	  	//------- TOOLTIP IMAGE---------
	  	  	const offset = { x: 20, y: 10 };
	  	  	
	  		$('.tooltip-image').hover(function(e) {
	  			var src = $(this).attr('src');
	  			
	  			$('<img src="'+ src +'" id="bigImage" />').css('left', e.pageX + offset.x).css('top', e.pageY + offset.y).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 eventsInfo = {
  			sunday: [
  				{name: 'Foxy race (ship)', time: '09:30:00'},
  				{name: 'Foxy count', time: '15:00:00'},
  				{name: 'Foxy quiz', time: '19:00:00'},
  				{name: 'Deathmatch', time: '22:00:00'},
  			],
  			monday: [
  				{name: 'Foxy count', time: '09:30:00'},
  				{name: 'Foxy quiz', time: '15:00:00'},
  				{name: 'Deathmatch', time: '19:00:00'},
  				{name: 'Foxy race (ship)', time: '22:00:00'},
  			],
  			tuesday: [
  				{name: 'Foxy quiz', time: '09:30:00'},
  				{name: 'Deathmatch', time: '15:00:00'},
  				{name: 'Foxy race', time: '19:00:00'},
  				{name: 'Foxy count', time: '22:00:00'},
  			],
  			wednesday: [
  				{name: 'Deathmatch', time: '09:30:00'},
  				{name: 'Foxy race (ship)', time: '15:00:00'},
  				{name: 'Foxy count', time: '19:00:00'},
  				{name: 'Foxy quiz', time: '22:00:00'},
  			],
  			thursday: [
  				{name: 'Foxy race', time: '09:30:00'},
  				{name: 'Foxy count', time: '15:00:00'},
  				{name: 'Foxy quiz', time: '19:00:00'},
  				{name: 'Deathmatch', time: '22:00:00'},
  			],
  			friday: [
  				{name: 'Foxy count', time: '09:30:00'},
  				{name: 'Foxy quiz', time: '15:00:00'},
  				{name: 'Deathmatch', time: '19:00:00'},
  				{name: 'Foxy race (ship)', time: '22:00:00'},
  			],
  			saturday: [
  				{name: 'Foxy quiz', time: '09:30:00'},
  				{name: 'Deathmatch', time: '15:00:00'},
  				{name: 'Foxy race', time: '19:00:00'},
  				{name: 'Foxy count', time: '22:00:00'},
  			]
  		};
  		
  		var dayEvents;
  		
  		function pad(d) {
		    return (d < 10) ? '0' + String(d) : String(d);
  		}
  		
  		function startTimer(eventTime){
			var distance;
			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;
  			
  			$.each(array, function (key, item) {
	  			var split = item.time.split(":");
	  			var currentTime = new Date();
	  			var eventTime = new Date();
	  			var eventStarting = new Date();
	  			var runTimer = false;
	  			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( '<h3 style="display: inline;">'+ item.name + ' - </h3> ' + pad(hour) + ":" + pad(minute) + ":" + pad(seconds));
	  				startTimer(eventTime, currentTime);
	  				return false;
	  			}else if(eventStarting > currentTime > eventTime){
	  				timer.html( '<h3 style="display: inline;">'+ item.name + ' - </h3> ' + 'Evento está começando!');
	  				return false;
	  			}
	  		});
  		}
  		
  		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);
  		}
  });