site-accueil-insa/assets/scripts/planningScript.js
2018-05-20 23:35:17 +02:00

50 lines
1.5 KiB
JavaScript

var current = null;
var classes = null;
$(document).ready(function () {
/*
* Display clicked event as selected, change info box content and scroll to it
*/
$(".event").click(function () {
/* Reset last selected items */
if (current != null) {
setEventShadow(current, "none");
}
/* Set style for currently selected items */
current = this.className.split(" ")[1];
setEventShadow(current, "0px 0px 10px #ee293d");
/* Load info box text and smoothly scroll to it */
$("#infoBox").load("includes/planning_events/" + current + ".html");
$('html, body').animate({
scrollTop: $("#infoBox").offset().top
}, 300);
});
/*
* Display shadow on hovered events
*/
$(".event").hover(function () {
var element = this.className.split(" ")[1];
if (element != current) {
setEventShadow(element, "0px 0px 10px #1a5dad");
}
}, function () {
var element = this.className.split(" ")[1];
if (element != current) {
setEventShadow(element, "none");
}
});
/*
* Display shadow under all elements with the save eventName
*/
function setEventShadow(eventName, shadow) {
classes = document.getElementsByClassName(eventName);
for (var i = 0; i < classes.length; i++) {
classes[i].style.boxShadow = shadow;
classes[i].style.textShadow = shadow;
}
}
});