-
Notifications
You must be signed in to change notification settings - Fork 36
/
shell.js
111 lines (100 loc) · 2.51 KB
/
shell.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
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
(function (window, document) {
if (!window.XMPlayer) {
window.XMPlayer = {};
}
var XMPlayer = window.XMPlayer;
if (!window.XMView) {
window.XMView = {};
}
var XMView = window.XMView;
function loadXMAndInit(xmdata) {
if (!XMPlayer.load(xmdata)) {
return;
}
XMView.init();
var playbutton = document.getElementById("playpause");
playbutton.innerHTML='Play';
playbutton.onclick = function() {
if (XMPlayer.playing) {
XMPlayer.pause();
playbutton.innerHTML='Play';
} else {
XMPlayer.play();
playbutton.innerHTML='Pause';
}
};
playbutton.disabled = false;
return XMPlayer.xm;
}
function downloadXM(uri) {
var xmReq = new XMLHttpRequest();
xmReq.open("GET", uri, true);
xmReq.responseType = "arraybuffer";
xmReq.onload = function (xmEvent) {
var arrayBuffer = xmReq.response;
if (arrayBuffer) {
loadXMAndInit(arrayBuffer);
} else {
console.log("unable to load", uri);
}
};
xmReq.send(null);
}
XMPlayer.allowDrop = function(ev) {
ev.stopPropagation();
ev.preventDefault();
var elem = document.getElementById("playercontainer");
elem.className = (ev.type == "dragover" ? "draghover" : "playercontainer");
return false;
};
XMPlayer.handleDrop = function(e) {
console.log(e);
e.preventDefault();
var elem = document.getElementById("playercontainer");
elem.className = "playercontainer";
var files = e.target.files || e.dataTransfer.files;
if (files.length < 1) return false;
var reader = new FileReader();
reader.onload = function(e) {
XMPlayer.stop();
loadXMAndInit(e.target.result);
};
reader.readAsArrayBuffer(files[0]);
return false;
};
function initFilelist() {
var el = document.getElementById('filelist');
xmuris.forEach(function(entry) {
var a = document.createElement('a');
a.text = entry[0];
a.href = '#'+entry[1];
a.onclick = function() {
el.style.display = "none";
XMPlayer.stop();
downloadXM(baseuri + entry[1]);
};
el.appendChild(a);
el.appendChild(document.createElement('br'));
});
var loadbutton = document.getElementById('loadbutton');
loadbutton.onclick = function() {
if (el.style.display == "none") {
el.style.display = "block";
} else {
el.style.display = "none";
}
};
}
window.onload = function() {
XMPlayer.init();
initFilelist();
var uri = location.hash.substr(1);
if (uri === "") {
uri = "kamel.xm";
}
if (!uri.startsWith("http")) {
uri = baseuri + uri;
}
downloadXM(uri);
};
})(window, document);