2017-11-10 12:39:55 +01:00
|
|
|
/* global ListNavigator, Toolbar, DetailsWindow */
|
|
|
|
|
|
|
|
var Viewer = {
|
|
|
|
currentFile: "",
|
|
|
|
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
|
|
|
|
if($("#filepreview").width() < 400 && Toolbar.visible){
|
|
|
|
window.setTimeout(function(){
|
|
|
|
Toolbar.toggle();
|
|
|
|
}, 800);
|
|
|
|
}
|
2018-10-04 23:36:34 +02:00
|
|
|
|
2017-11-10 12:39:55 +01:00
|
|
|
if(type === "file"){
|
|
|
|
this.isFile = true;
|
|
|
|
this.currentFile = data.id;
|
|
|
|
this.setFile(data);
|
|
|
|
} else if (type === "list") {
|
|
|
|
this.isList = true;
|
|
|
|
this.listId = data.id;
|
|
|
|
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;
|
2018-10-04 23:36:34 +02:00
|
|
|
document.title = file.name + " ~ PixelDrain";
|
|
|
|
|
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);
|
|
|
|
Toolbar.setViews(file.views);
|
|
|
|
}
|
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
|
|
|
}
|