2017-11-10 12:39:55 +01:00
|
|
|
/* global ListNavigator, Toolbar, DetailsWindow */
|
|
|
|
|
|
|
|
var Viewer = {
|
|
|
|
currentFile: "",
|
2019-06-04 20:14:25 +02:00
|
|
|
title: "", // Contains either the file name or list title
|
2017-11-10 12:39:55 +01:00
|
|
|
listId: "",
|
|
|
|
isList: false,
|
|
|
|
isFile: false,
|
|
|
|
initialized: false,
|
2018-10-04 23:36:34 +02:00
|
|
|
|
2017-11-10 12:39:55 +01:00
|
|
|
init: function(type, data){
|
|
|
|
if(this.initialized){
|
|
|
|
return;
|
|
|
|
}
|
2018-10-04 23:36:34 +02:00
|
|
|
|
2017-11-10 12:39:55 +01:00
|
|
|
// On small screens the toolbar takes too much space, so it collapses automatically
|
2019-07-17 23:29:44 +02:00
|
|
|
if($("#filepreview").width() > 500 && !Toolbar.visible){
|
2019-06-04 20:14:25 +02:00
|
|
|
Toolbar.toggle();
|
2017-11-10 12:39:55 +01:00
|
|
|
}
|
2018-10-04 23:36:34 +02:00
|
|
|
|
2019-07-18 19:53:09 +02:00
|
|
|
// The close button only works if the window has an opener. So we hide
|
|
|
|
// the button if it does not
|
2019-07-18 20:36:55 +02:00
|
|
|
if (window.opener === null && window.history.length !== 1) {
|
2019-07-18 19:53:09 +02:00
|
|
|
$("#button_close_file_viewer").remove();
|
|
|
|
}
|
|
|
|
|
2017-11-10 12:39:55 +01:00
|
|
|
if(type === "file"){
|
|
|
|
this.isFile = true;
|
|
|
|
this.currentFile = data.id;
|
2019-06-04 20:14:25 +02:00
|
|
|
this.title = data.name;
|
2017-11-10 12:39:55 +01:00
|
|
|
this.setFile(data);
|
|
|
|
} else if (type === "list") {
|
|
|
|
this.isList = true;
|
|
|
|
this.listId = data.id;
|
2019-06-04 20:14:25 +02:00
|
|
|
this.title = data.title;
|
2017-11-10 12:39:55 +01:00
|
|
|
ListNavigator.init(data.data);
|
|
|
|
}
|
2018-10-04 23:36:34 +02:00
|
|
|
|
2017-11-10 12:39:55 +01:00
|
|
|
this.initialized = true;
|
|
|
|
},
|
|
|
|
setFile: function(file){
|
|
|
|
this.currentFile = file.id;
|
2019-07-17 23:19:57 +02:00
|
|
|
var title = "";
|
|
|
|
if (this.isList) {
|
|
|
|
title = this.title + " ~ " + file.name;
|
|
|
|
} else {
|
|
|
|
title = file.name;
|
|
|
|
}
|
|
|
|
document.title = title + " ~ PixelDrain";
|
|
|
|
document.getElementById("file_viewer_headerbar_title").innerText = title;
|
2018-10-04 23:36:34 +02:00
|
|
|
|
2017-11-10 12:39:55 +01:00
|
|
|
$.get("/u/" + file.id + "/preview", function(response){
|
|
|
|
$("#filepreview").html(response);
|
|
|
|
});
|
2018-10-04 23:36:34 +02:00
|
|
|
|
2017-11-10 12:39:55 +01:00
|
|
|
DetailsWindow.setDetails(file);
|
|
|
|
}
|
2017-12-04 22:00:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Against XSS attacks
|
|
|
|
function escapeHTML(str) {
|
|
|
|
return String(str)
|
|
|
|
.replace(/&/g, '&')
|
|
|
|
.replace(/</g, '<')
|
|
|
|
.replace(/>/g, '>')
|
|
|
|
.replace(/"/g, '"');
|
2018-10-04 23:36:34 +02:00
|
|
|
}
|