-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
125 lines (106 loc) · 4.29 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<style>
.logo { width: 200px }
.whitebg { background-color: white; color: black }
.blackbg { background-color: black; color: white }
.otherbg { background-color: green; color: white }
.clickable { cursor:pointer; color:blue; text-decoration:underline; }
</style>
</head>
<body>
<h1 id="foo">Rollerder.by Logo Finder</h1>
<p><a href="#" id="click">Click this</a> to start again</p>
<div id="maintext"></div>
<script>
$(function() {
window.logoURL = "http://rollerder.by/logos";
window.apiURL = window.logoURL+"/api.php";
window.onhashchange = loadData;
loadData();
});
function loadData() {
// Figure out where we should be.
var dirName = decodeURIComponent(window.location.hash.replace(/^#/, ''));
console.log("Given "+dirName);
$.get(apiURL, { cmd: "list", dir: dirName })
.done(function(data) { displaystuff(data); });
}
/* This is not what you want to do, but is here as an example. Use this to DOWNLOAD an image to do 'stuff' with it later. */
function loadLogoData(row) {
var filename = row.data("filename");
$.get(apiURL, { cmd: "getimg", file: filename }, function(data) {
row.html("<img class='logo' src='data:image/png;base64,"+data['data']+"' />");
});
}
function loadLogo(row) {
var filename = row.data("filename");
row.html("<img class='logo' src='"+window.logoURL+"/"+filename+"' />");
}
function displaystuff(data) {
console.log(data);
window.mydata = data;
window.mystatus = data['status'];
// I have data. I need to display stuff
var newHTML = "";
// Just bail out if there's no status returned.
if (!("status" in data)) { return false; }
var mystatus = data['status'];
// If this is a parent, these will be here.
if (mystatus['title'] != null) {
newHTML += "<h1>"+mystatus['title']+"</h1>";
}
if (mystatus['description'] != null) {
newHTML += "<p>"+mystatus['description']+"</p>";
}
newHTML += "<table>";
$.each( data['data']['directories'], function(i, v) {
newHTML += "<tr><td><span class='clickable' data-id='"+v+"'>"+v+"</span></td></tr>";
});
newHTML += "</table>";
// If this is a league, these will be here.
if (mystatus['League'] != null) {
newHTML += "<h1>"+mystatus['League']+"</h1>";
}
if (mystatus['copyright_waiver'] != null) {
newHTML += "<p>Copyright waiver agreed by: "+mystatus['copyright_waiver']+"</p>";
}
if (mystatus['facebook_page'] != null) {
newHTML += "<p>Leagues Website/Facebook Page: <a href='"+mystatus['facebook_page']+"'>"+mystatus['facebook_page']+"</a></p>";
}
if ("teams" in mystatus) {
newHTML += "<table>";
$.each( mystatus['teams'], function(i, v) {
if ("logos" in v) {
newHTML += "<tr><td data-id='"+i+"' colspan=5><span class='leaguename'>"+v['description']+"</span></td></tr>";
console.log(v);
$.each( v['logos'], function (i, logo) {
newHTML += "<tr><td>"+logo['filename']+"</td>";
if (logo['black'] == true) {
newHTML += "<td class='logo blackbg used' data-filename='"+logo['filename']+"' data-loaded='false'>Loading...</td>";
} else {
newHTML += "<td></td>";
}
if (logo['white'] == true) {
newHTML += "<td class='logo whitebg used' data-filename='"+logo['filename']+"' data-loaded='false'>Loading...</td>";
} else {
newHTML += "<td></td>";
}
if (logo['white'] == true) {
newHTML += "<td class='logo otherbg used' data-filename='"+logo['filename']+"' data-loaded='false'>Loading...</td>";
} else {
newHTML += "<td></td>";
}
newHTML += "</tr>";
});
}
});
newHTML += "</table>";
}
$("#maintext").html(newHTML);
$.each($(".used"), function() { loadLogo($(this)); });
$(".clickable").on("click", function(x) { location.hash = encodeURIComponent($(this).data('id')); });
}
</script>