- option to resume/start from beginning at the title view

- option to toggle read/unread status at the title view
- move all embeded JS to public/
This commit is contained in:
Alex Ling
2020-02-16 03:19:29 +00:00
parent 08a1052ca4
commit 93e6d7cae6
9 changed files with 176 additions and 78 deletions

25
public/js/admin.js Normal file
View File

@@ -0,0 +1,25 @@
var scanning = false;
function scan() {
scanning = true;
$('#scan-status > div').removeAttr('hidden');
$('#scan-status > span').attr('hidden', '');
var color = $('#scan').css('color');
$('#scan').css('color', 'gray');
$.post('/api/admin/scan', function (data) {
var ms = data.milliseconds;
var titles = data.titles;
$('#scan-status > span').text('Scanned ' + titles + ' titles in ' + ms + 'ms');
$('#scan-status > span').removeAttr('hidden');
$('#scan').css('color', color);
$('#scan-status > div').attr('hidden', '');
scanning = false;
});
}
$(function() {
$('li').click(function() {
url = $(this).attr('data-url');
if (url) {
$(location).attr('href', url);
}
});
});

49
public/js/title.js Normal file
View File

@@ -0,0 +1,49 @@
function showModal(title, zipPath, pages, percentage, title, entry) {
$('#modal button, #modal a').each(function(){
$(this).removeAttr('hidden');
});
if (percentage === 0) {
$('#continue-btn').attr('hidden', '');
$('#unread-btn').attr('hidden', '');
}
else {
$('#continue-btn').text('Continue from ' + percentage + '%');
}
if (percentage === 100) {
$('#read-btn').attr('hidden', '');
}
$('#modal-title').text(title);
$('#path-text').text(zipPath);
$('#pages-text').text(pages + ' pages');
$('#beginning-btn').attr('href', '/reader/' + title + '/' + entry + '/1');
$('#continue-btn').attr('href', '/reader/' + title + '/' + entry);
$('#read-btn').click(function(){
updateProgress(title, entry, pages);
});
$('#unread-btn').click(function(){
updateProgress(title, entry, 0);
});
UIkit.modal($('#modal')).show();
}
function updateProgress(title, entry, page) {
$.post('/api/progress/' + title + '/' + entry + '/' + page, function(data) {
if (data.success) {
location.reload();
}
else {
error = data.error;
alert('danger', error);
}
});
}
function alert(level, text) {
hideAlert();
var html = '<div class="uk-alert-' + level + '" uk-alert><a class="uk-alert-close" uk-close></a><p>' + text + '</p></div>';
$('#alert').append(html);
}
function hideAlert() {
$('#alert').empty();
}

16
public/js/user-edit.js Normal file
View File

@@ -0,0 +1,16 @@
$(function(){
var target = '/admin/user/edit';
if (username) target += username;
$('form').attr('action', target);
function alert(level, text) {
hideAlert();
var html = '<div class="uk-alert-' + level + '" uk-alert><a class="uk-alert-close" uk-close></a><p>' + text + '</p></div>';
$('#alert').append(html);
}
function hideAlert() {
$('#alert').empty();
}
if (error) alert('danger', error);
});

19
public/js/user.js Normal file
View File

@@ -0,0 +1,19 @@
function alert(level, text) {
hideAlert();
var html = '<div class="uk-alert-' + level + '" uk-alert><a class="uk-alert-close" uk-close></a><p>' + text + '</p></div>';
$('#alert').append(html);
}
function hideAlert() {
$('#alert').empty();
}
function remove(username) {
$.post('/api/admin/user/delete/' + username, function(data) {
if (data.success) {
location.reload();
}
else {
error = data.error;
alert('danger', error);
}
});
}