174 lines
4.9 KiB
JavaScript
174 lines
4.9 KiB
JavaScript
|
|
function clear_text(id,defaultValue) {
|
|
var element = document.getElementById(id);
|
|
if ( element.value == defaultValue ) {
|
|
element.value = '';
|
|
}
|
|
}
|
|
|
|
|
|
function index_form_enter(event) {
|
|
if (event.which || event.keyCode) {
|
|
if ((event.which == 13) || (event.keyCode == 13)) {
|
|
index_form_submit();
|
|
}
|
|
};
|
|
}
|
|
|
|
|
|
function index_form_submit() {
|
|
window.location = window.location + "/list/" +
|
|
document.getElementById("index_form_name").value;
|
|
}
|
|
|
|
|
|
function infoToggle() {
|
|
var info = document.getElementById("list_info");
|
|
info.style.display = info.style.display === 'block' ? 'none' : 'block';
|
|
}
|
|
|
|
|
|
function scriptToggle() {
|
|
var el = document.getElementById("list_script");
|
|
if (el) {
|
|
el.style.display = el.style.display === 'block' ? 'none' : 'block';
|
|
}
|
|
}
|
|
|
|
|
|
function UploadFile(file,file_no,files_total) {
|
|
if (uploadTurn != file_no) {
|
|
// Wait for our turn to upload. check every 0.5s
|
|
setTimeout(
|
|
function() {
|
|
UploadFile(file,file_no,files_total);
|
|
},
|
|
500
|
|
);
|
|
return
|
|
}
|
|
var file_counter = "(" + (file_no + 1) + "/" + files_total + ") ";
|
|
var xhr = new XMLHttpRequest();
|
|
if (xhr.upload) {
|
|
var o = document.getElementById("progress");
|
|
xhr.upload.addEventListener(
|
|
"progress",
|
|
function(e) {
|
|
var pc = parseInt((e.loaded / e.total * 100));
|
|
o.className = "";
|
|
o.innerHTML = "Uploading: " + file_counter + pc + "%";
|
|
if (pc == 100) {
|
|
o.innerHTML = "Finishing up " + file_counter + "wait ...";
|
|
}
|
|
// upload works, hide button
|
|
document.getElementById("list_upload_button").hidden = true;
|
|
},
|
|
false
|
|
);
|
|
|
|
// file received/failed
|
|
xhr.onreadystatechange = function(e) {
|
|
if (xhr.readyState == 4) {
|
|
o.className = (xhr.status == 200 ? "success" : "failure");
|
|
if (xhr.status == 200) {
|
|
if (file_no + 1 == files_total) {
|
|
location = location;
|
|
}
|
|
} else {
|
|
o.innerHTML = xhr.response;
|
|
}
|
|
uploadTurn += 1;
|
|
}
|
|
};
|
|
|
|
// start upload
|
|
xhr.open("POST", document.getElementById("upload_form").action, true);
|
|
xhr.setRequestHeader("X-FILENAME", file.name);
|
|
var formData = new FormData();
|
|
formData.append('name', document.getElementById("list_upload_name").value);
|
|
formData.append('from_gui', 'true');
|
|
formData.append('file', file);
|
|
xhr.send(formData);
|
|
|
|
}
|
|
}
|
|
|
|
// file selection
|
|
function FileSelectHandler(e) {
|
|
|
|
// fetch FileList object
|
|
var files = e.target.files || e.dataTransfer.files;
|
|
uploadTurn = 0;
|
|
// process all File objects
|
|
for (var i = 0, f; f = files[i]; i++) {
|
|
UploadFile(f,i,files.length);
|
|
}
|
|
}
|
|
// Variable to stop parallel uploads
|
|
var uploadTurn = -1;
|
|
|
|
|
|
function UploadURL() {
|
|
var URL = document.getElementById("list_url_upload_text").value;
|
|
var xhr = new XMLHttpRequest();
|
|
if (xhr.upload) {
|
|
var o = document.getElementById("progress");
|
|
xhr.upload.addEventListener(
|
|
"progress",
|
|
function(e) {
|
|
o.className = "";
|
|
o.innerHTML = "Uploading...";
|
|
console.log(e);
|
|
// upload works, hide button
|
|
document.getElementById("list_url_upload_button").setAttribute("disabled", "disabled");
|
|
},
|
|
false
|
|
);
|
|
|
|
// file received/failed
|
|
xhr.onreadystatechange = function(e) {
|
|
if (xhr.readyState == 4) {
|
|
o.className = (xhr.status == 200 ? "success" : "failure");
|
|
if (xhr.status == 200) {
|
|
// refresh page at upload finish
|
|
location = location;
|
|
} else {
|
|
o.innerHTML = xhr.response;
|
|
document.getElementById("list_url_upload_button").removeAttribute("disabled");
|
|
}
|
|
}
|
|
};
|
|
|
|
// start upload
|
|
xhr.open("POST", document.getElementById("url_upload_form").action, true);
|
|
var formData = new FormData();
|
|
formData.append('name', document.getElementById("list_upload_name").value);
|
|
formData.append('from_gui', 'true');
|
|
formData.append('url', URL);
|
|
xhr.send(formData);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
function changeTitle(newTitle) {
|
|
document.title = "Flees - " + newTitle;
|
|
}
|
|
|
|
function back() {
|
|
window.history.back();
|
|
}
|
|
|
|
function keyboardEntry(ev){
|
|
var kC=ev.keyCode;
|
|
var k=String.fromCharCode(ev.keyCode);
|
|
if ( document.activeElement === document.getElementById("list_url_upload_text")) {
|
|
return
|
|
}
|
|
if (/T/.test(k)) {
|
|
infoToggle();
|
|
}
|
|
}
|
|
|
|
document.onkeyup = keyboardEntry;
|