-
Notifications
You must be signed in to change notification settings - Fork 0
/
banner.js
68 lines (58 loc) · 2.61 KB
/
banner.js
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
document.addEventListener('DOMContentLoaded', function () {
/* バナーロード */
const goldBanner = document.getElementById('goldBanner');
const silverBanner = document.getElementById('silverBanner');
const URLBannerData = 'https://rikoten.github.io/2020-bannerData/banner.json';
const requestBannerData = new XMLHttpRequest();
requestBannerData.open('GET', URLBannerData);
requestBannerData.responseType = 'json';
requestBannerData.send();
requestBannerData.onload = function() {
const BannerData = requestBannerData.response;
const GoldBannerData = BannerData[0];
const SilverBannerData = BannerData[1];
let iG = 0;
let columnG = 0;
let rowG = 0;
GoldBannerData.forEach(function(elem) {
if (typeof elem["disabled"] == "undefined") {
let bannerElem = document.createElement('a');
columnG = 1;
if (iG % 2 != 0) columnG = 3;
let bgcolor = "#fff";
if (typeof elem["bgcolor"] !== 'undefined' && elem["bgcolor"] != "") bgcolor = elem["bgcolor"];
bannerElem.setAttribute('href', elem["url"]);
bannerElem.setAttribute('target', '_blank');
bannerElem.setAttribute('rel', 'noopener');
style = '-ms-grid-column: ' + String(columnG) + '; -ms-grid-row: ' + String(rowG) + '; background-color: ' + bgcolor + ';'
bannerElem.setAttribute('style', style);
bannerElem.innerHTML = '<img src = "https://rikoten.github.io/2020-bannerData/img/' + elem["img"] + '" alt = "' + elem["alt"] + '">';
goldBanner.appendChild(bannerElem);
if (iG % 2 != 0) rowG++;
iG++;
}
});
let iS = 0;
let columnS = 0;
let rowS = 0;
SilverBannerData.forEach(function(elem) {
if (typeof elem["disabled"] == "undefined") {
let bannerElem = document.createElement('a');
columnS = 1;
if (iG % 3 == 1) columnS = 3;
else if (iG % 3 == 2) columnS = 5;
let bgcolor = "#fff";
if (typeof elem["bgcolor"] !== 'undefined' && elem["bgcolor"] != "") bgcolor = elem["bgcolor"];
bannerElem.setAttribute('href', elem["url"]);
bannerElem.setAttribute('target', '_blank');
bannerElem.setAttribute('rel', 'noopener');
style = '-ms-grid-column: ' + String(columnS) + '; -ms-grid-row: ' + String(rowS) + '; background-color: ' + bgcolor + ';'
bannerElem.setAttribute('style', style);
bannerElem.innerHTML = '<img src = "https://rikoten.github.io/2020-bannerData/img/' + elem["img"] + '" alt = "' + elem["alt"] + '">';
silverBanner.appendChild(bannerElem);
if (iS % 3 == 2) rowS++;
iS++;
}
});
}
});