2018-04-09 20:12:02 +02:00

197 lines
3.7 KiB
JavaScript

var $json = 0;
var $playing = false;
var $musicon = true;
var light = new Array("black", "#CAD3FF", "#FFFFA6");
var dark = new Array("white", "black", "black");
var currentstyle = light;
function Client() {
}
Client.prototype.mobileClients = [
"midp",
"240x320",
"blackberry",
"netfront",
"nokia",
"panasonic",
"portalmmm",
"sharp",
"sie-",
"sonyericsson",
"symbian",
"windows ce",
"benq",
"mda",
"mot-",
"opera mini",
"philips",
"pocket pc",
"sagem",
"samsung",
"sda",
"sgh-",
"vodafone",
"xda",
"iphone",
"android"
];
Client.prototype.isMobileClient = function(userAgent)
{
userAgent=userAgent.toLowerCase();
for (var i in this.mobileClients) {
if (userAgent.indexOf(this.mobileClients[i]) != -1) {
return true;
}
}
return false;
}
var $client = new Client();
function StringBuilder(value) {
this.strings = new Array("");
this.append(value);
};
StringBuilder.prototype.append = function(value) {
if (value) {
this.strings.push(value);
}
};
StringBuilder.prototype.clear = function() {
this.strings.length = 1;
};
StringBuilder.prototype.toString = function() {
return this.strings.join("");
};
function buildLinks(columns, JSON) {
$("#fsdienst").children().remove();
var counter = 0;
for ( var props in JSON) {
counter++;
}
var rows = Math.round(counter / columns);
if ((counter % columns) != 0) {
rows++;
}
var ul = new Array(rows);
for ( var i = 0; i < rows; i++) {
var id = "kwicks" + i;
ul[i] = id;
var kwicks = "<ul class='kwicks' id='" + id + "'></ul>";
$("#fsdienst").append(kwicks);
}
var row = 0;
var i = 1;
var number = 1;
$.each(JSON, function() {
var sb = new StringBuilder();
var id = "kwick" + number;
var li = new StringBuilder();
li.append("<li id='");
li.append(id);
if($client.isMobileClient(navigator.userAgent)){
li.append("' ondblclick");
}else{
li.append("' onclick");
}
li.append("=\"redirect('");
li.append(this.href);
li.append("');\" onmouseover=\"noise();\"></li>");
$("#" + ul[row]).append(li.toString());
sb.append("<div class='kwicks_inner'><div class='bigLetter'>");
sb.append(this.title.charAt(0));
sb.append("</div><div class='smallLetters'>");
sb.append(this.title.slice(1, this.title.length));
sb.append("</div></div>");
$("#" + id).append(sb.toString());
sb.clear();
changeStyle(id);
number++;
if (i == columns) {
i = 1;
row++;
} else {
i++;
}
});
$().ready(function() {
$('.kwicks').kwicks({
max : 205,
spacing : 5,
sticky : true
});
});
};
var audio = new Audio("GN.ogg");
function noise() {
if ($musicon) {
if (audio.currentTime == 0 || audio.currentTime == audio.duration) {
audio.play();
}
}
};
function changeStyle(id) {
var sheet = document.styleSheets[0];
var normal = "#" + id + "{ background-color: " + currentstyle[1] + ";}"
sheet.insertRule(normal, 0);
var active = "#" + id + ".active { background-color: " + currentstyle[2]
+ ";}";
sheet.insertRule(active, 0);
};
function change() {
if ($json == 0) {
buildLinks(4, unilinks);
document.getElementById("header").innerHTML = "Links zur Universität";
$json = 1;
} else if ($json == 1){
buildLinks(3, adminstrationslinks);
document.getElementById("header").innerHTML = "Administrative Links";
$json = 2;
} else{
buildLinks(4, fachschaftslinks);
document.getElementById("header").innerHTML = "Für den Fachschaftsdienst";
$json = 0;
}
};
function redirect(toUrl) {
window.open(toUrl);
};
function music() {
$musicon = !$musicon;
if ($musicon) {
document.getElementById('music').setAttribute("style",
"background-image: url(soundon.png)");
} else {
document.getElementById('music').setAttribute("style",
"background-image: url(soundoff.png)");
}
};
function view() {
currentstyle = dark;
buildLinks(4, fachschaftslinks);
};