105 lines
3.7 KiB
JavaScript
105 lines
3.7 KiB
JavaScript
var curpath = "/";
|
|
var parentpath = "/";
|
|
var foldername = "";
|
|
|
|
// This function is executed after the page load completes on the client
|
|
$(document).ready(function() {
|
|
$("#path").click(function() { changeFolder(parentpath, parentpath); });
|
|
getFolderContents();
|
|
});
|
|
|
|
var lightbox = null;
|
|
|
|
function redirectToLogin() {
|
|
console.log("Redirecting for login...");
|
|
window.location.replace("index.php");
|
|
}
|
|
|
|
function getFolderContents() {
|
|
$("#list").html("");
|
|
toastr.info("Loading folder contents. Comics containing a large number of issues, or issues with a large number of pages, that have not been opened recently may take some time to load. Thank you for your patience!", "Loading Contents...", {timeOut: 15000});
|
|
$.ajax({
|
|
url : 'ajax/getfoldercontents.php',
|
|
dataType : 'json',
|
|
success : function(data, stat, jqo) {
|
|
if ( !data.validated ) redirectToLogin();
|
|
curpath = data.compath;
|
|
updatePathNavigator();
|
|
data.contents.forEach(function(entry, index) {
|
|
$("#list").append(entry.div);
|
|
});
|
|
$(".folder").click(function() { changeFolder($(this).data("name"), $(this).data("path")); });
|
|
$(".issue").click(function() { $(this).parent().addClass("readborder"); showComic($(this).data("relcomic"), $(this).data("comname")); });
|
|
toastr.remove();
|
|
}
|
|
});
|
|
}
|
|
|
|
function updatePathNavigator() {
|
|
var navpath = "";
|
|
if ( curpath == "/" ) {
|
|
navpath = "/";
|
|
} else {
|
|
navpath = "/Comics" + parentpath;
|
|
}
|
|
$("#path").html(navpath);
|
|
}
|
|
|
|
function changeFolder(name, path) {
|
|
if ( path == curpath ) return;
|
|
toastr.success("Opening comic \"" + name + "\"<br>If this is the first time it may take a while to generate thumbnails.");
|
|
$.ajax({
|
|
url : 'ajax/setpath.php',
|
|
data : {path: path},
|
|
dataType : 'json',
|
|
success : function(data, stat, jqo) {
|
|
console.log(data.message);
|
|
if ( !data.validated ) redirectToLogin();
|
|
curpath = path;
|
|
parentpath = data.parentpath;
|
|
foldername = data.foldername;
|
|
getFolderContents();
|
|
}
|
|
});
|
|
}
|
|
|
|
function updateCurrentPage() {
|
|
var currentPage = lightbox.currentPosition;
|
|
$.ajax({
|
|
url : 'ajax/setpage.php',
|
|
data : {page: currentPage},
|
|
dataType : 'json',
|
|
success : function(data, stat, jqo) {
|
|
if ( !data.validated ) redirectToLogin();
|
|
console.log(data.message);
|
|
}
|
|
});
|
|
}
|
|
|
|
//
|
|
// This JS function is called when a user clicks on a comic.
|
|
// "showcomic.php" is called with the comic to view as a parameter.
|
|
// It returns a JSON object representing the collection of images.
|
|
// If in debug mode the javascript code is displayed in the browser.
|
|
// If not in debug mode a lightbox object is created to display the comic.
|
|
//
|
|
function showComic(comic, name) {
|
|
toastr.success("Extracting and showing the comic \"" + name + "\"...", "Showing Comic");
|
|
$.ajax({
|
|
url : 'ajax/showcomic.php',
|
|
data : {comic: comic},
|
|
dataType : 'json',
|
|
success : function(data, stat, jqo) {
|
|
if ( !data.validated ) redirectToLogin();
|
|
// Clear out the debug DIV and start the fancybox.
|
|
$("#debug").html("");
|
|
lightbox = SimpleLightbox.open({
|
|
items: data.images,
|
|
captions: data.captions,
|
|
startAt: data.startindex,
|
|
beforeSetContent: updateCurrentPage
|
|
});
|
|
}
|
|
});
|
|
}
|