Skip to content
This repository has been archived by the owner on Oct 14, 2022. It is now read-only.

Commit

Permalink
Pagination for bookmarks and generated story arcs!
Browse files Browse the repository at this point in the history
  • Loading branch information
scooterpsu committed Mar 24, 2019
1 parent 30408df commit 35797cf
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 66 deletions.
13 changes: 9 additions & 4 deletions comixology2/comixology.css
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ input[type=text], input[type=email], input[type=search], input[type=password], s
background-color: #eee;
}

.bookmarks .pager {
width: calc(100% - 17px);
}

.pager {
width: calc(100% - 14px);
margin: 0 7px;
Expand All @@ -495,7 +499,7 @@ input[type=text], input[type=email], input[type=search], input[type=password], s
text-align: right;
text-transform: uppercase;
float: right;
margin-top: 10px;
margin-top: 12px;
}

.imprintNav {
Expand Down Expand Up @@ -1277,7 +1281,7 @@ footer a {

.bookmarks {
min-height: 322px;
padding: 28px 8px 40px !important;
padding: 28px 8px 0 !important;
border: 0 !important;
background-color: #efefef !important;
}
Expand Down Expand Up @@ -1473,6 +1477,7 @@ footer a {
}

.dropdownmenu li a {
display: inline-block;
width: 100%;
color: #000;
}
Expand Down Expand Up @@ -1926,8 +1931,8 @@ strong, b {

#buttonBox {
position: absolute;
right: 10px;
bottom: 8px;
right: 15px;
top: 16px;
display: block;
}

Expand Down
2 changes: 1 addition & 1 deletion comixology2/mybooks.htm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<div id="buttonBox">
<div class="lv2-micro-item-detail lv2-micro-item-download-button">
<a onclick="exportBookmarksJSON();" class="lv2-light-button lv2-row-button lv2-action-download lv2-drm-backup" data-backup-type="cbz">Export JSON<img class="svg" src="download.svg" width="17" height="17"/></a>
<a onclick="exportBookmarks();" class="lv2-light-button lv2-row-button lv2-action-download lv2-drm-backup" data-backup-type="cbz">Export CSV<img class="svg" src="download.svg" width="17" height="17"/></a>
<!--<a onclick="exportBookmarks();" class="lv2-light-button lv2-row-button lv2-action-download lv2-drm-backup" data-backup-type="cbz">Export CSV<img class="svg" src="download.svg" width="17" height="17"/></a>-->
<a onclick="clearBookmarks();" class="lv2-light-button lv2-row-button lv2-action-download lv2-drm-backup" data-backup-type="cbz">Clear<img class="svg" src="trash.svg" width="17" height="17"/></a>
</div>
</div>
Expand Down
216 changes: 155 additions & 61 deletions comixology2/themeScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ loadScript(proxyPrefix+"/theme/js/jquery-3.3.1.min.js", function(){
}
if((Bookmarks.length > 0)&&(Bookmarks != undefined)){
$(makeSliderList('bookmarks','Bookmarks',proxyPrefix+'/theme/mybooks.htm')).css("zIndex",1).appendTo('.main_homepage_content');
for (i = 0; i < Bookmarks.length; i++) {
if(Bookmarks.length < homepageIssues){
var bookmarkLimit = Bookmarks.length;
}else{
var bookmarkLimit = homepageIssues;
}
for (i = 0; i < bookmarkLimit; i++) {
buildElement(Bookmarks[i][0],Bookmarks[i][1],Bookmarks[i][2],Bookmarks[i][3], i+1, '#bookmarks .list-content');
}
initializeControls('bookmarks');
Expand Down Expand Up @@ -199,7 +204,7 @@ loadScript(proxyPrefix+"/theme/js/jquery-3.3.1.min.js", function(){
}

/* Story Arc/Series page with json.cbr/json.epub */
if($('.cellcontainer .label:contains("json")').length){
if(($('.cellcontainer .label:contains("json")').length)||(!($('.cellcontainer').length)&&((window.location.href.indexOf("/comics/") != -1)||(window.location.href.indexOf("/books/") != -1)))){
var type;
if(window.location.href.indexOf("/comics/") != -1){
type = 'comic';
Expand Down Expand Up @@ -802,6 +807,15 @@ loadScript(proxyPrefix+"/theme/js/jquery-3.3.1.min.js", function(){
});
});
};
$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results==null){
return 0;
}
else{
return results[1] || 0;
}
}
$('img.svg').each(function(){
var $img = jQuery(this);
var imgID = $img.attr('id');
Expand Down Expand Up @@ -1007,71 +1021,77 @@ function hideSeries(){
$('a[href="'+proxyPrefix+'/books/'+seriesID+'/folderCover"]').parent().parent().remove();
}
function arcRunner(bookType){
if($(".cellcontainer .label:contains('json')").length){
var filename = $(".cellcontainer .label:contains('json')").parent().find('img').attr('src').split('?')[0];
$.get(filename, function(response) {
$("div").remove(".cellcontainer");
$('#group').removeClass('wrapped');
var arclist = JSON.parse(response);
$('#group').addClass('arcPage');
if(arclist.metadata){
arcname = arclist.metadata[0].arcname;
if(arclist.metadata[0].year){
arcname += " ("+arclist.metadata[0].year+")";
}
var description = arclist.metadata[0].description;
if($('#folderinfo').length){
$('.arcname').text(arcname);
var filename;
if(bookType == 'comic'){
filename = 'json.cbr';
}else if(bookType == 'book'){
filename = 'json.epub';
}
$.get('?folderinfo='+filename, function(response) {
$("div").remove(".cellcontainer");
$('#group').removeClass('wrapped');
var arclist = JSON.parse(response);
$('#group').addClass('arcPage');
if(arclist.metadata){
arcname = arclist.metadata[0].arcname;
if(arclist.metadata[0].year){
arcname += " ("+arclist.metadata[0].year+")";
}
var description = arclist.metadata[0].description;
if($('#folderinfo').length){
$('.arcname').text(arcname);

if(arclist.metadata[0].players){
description +="<br><br><b>Featured Characters:</b> "+arclist.metadata[0].players;
if(arclist.metadata[0].players){
description +="<br><br><b>Featured Characters:</b> "+arclist.metadata[0].players;
}
$('#desc').html(description);
$('#cover').attr('src','?folderinfo=folder.jpg');
$('#cover').on("error", function(){
$(this).attr('src', proxyPrefix+'/theme/folder.png');
});
$('#cover').attr('title', arcname);
}else if(settingsJSON['enableFolderMetadataDisplay']){
$('#group').addClass('scriptPage');
$('<div class="headerSection"></div>').insertBefore($('#group'));
if($('#group header').length){
$('#group').prepend($('#group header'));
}
var type;
if(useSimpleArcTemplate){
type = "comicArcSimple";
}else{
if(bookType == "book"){
type = "bookSeries";
}else if(bookType == "comic"){
type = "comicArc";
}
$('#desc').html(description);
}
$('<div>').load(proxyPrefix+'/theme/templates/'+type+'.html', function(){
$(".headerSection").html($(this).contents().contents());
$('#cover').attr('src','?folderinfo=folder.jpg');
$('#cover').on("error", function(){
$(this).attr('src', proxyPrefix+'/theme/folder.png');
});
$('#cover').on("error", function(){
$(this).attr('src', proxyPrefix+'/theme/folder.png');
});
$('#cover').attr('title', arcname);
}else if(settingsJSON['enableFolderMetadataDisplay']){
$('#group').addClass('scriptPage');
$('<div class="headerSection"></div>').insertBefore($('#group'));
if($('#group header').length){
$('#group').prepend($('#group header'));
}
var type;
if(useSimpleArcTemplate){
type = "comicArcSimple";
}else{
if(bookType == "book"){
type = "bookSeries";
}else if(bookType == "comic"){
type = "comicArc";
}
$('#publisher').attr('href', $('#arrowup').attr('href'));
$('.seriesname').text(arcname);
if(arclist.metadata[0].players){
description +="<br><br><b>Featured Characters:</b> "+arclist.metadata[0].players;
}
$('<div>').load(proxyPrefix+'/theme/templates/'+type+'.html', function(){
$(".headerSection").html($(this).contents().contents());
$('#cover').attr('src','?folderinfo=folder.jpg');
$('#cover').on("error", function(){
$(this).attr('src', proxyPrefix+'/theme/folder.png');
});
$('#cover').attr('title', arcname);
$('#publisher').attr('href', $('#arrowup').attr('href'));
$('.seriesname').text(arcname);
if(arclist.metadata[0].players){
description +="<br><br><b>Featured Characters:</b> "+arclist.metadata[0].players;
}
$('#desc').html(description);
});
}
$('#desc').html(description);
});
}
if(arclist.Issues){
for (i = 0; i < arclist.Issues.length; i++) {
buildElement("#","showHidePopupMenu('"+bookType+"details','searchbox','pageselector','settingsbox');load"+bookType.charAt(0).toUpperCase() + bookType.slice(1)+"Details("+arclist.Issues[i].dbnumber+",'"+ proxyPrefix +"/');return false;",proxyPrefix +"/"+bookType+"s/"+arclist.Issues[i].dbnumber+"/"+arclist.Issues[i].comicname+"?cover=true",arclist.Issues[i].label,i,"#group");
}
}
if(arclist.Issues){
for (i = 0; i < arclist.Issues.length; i++) {
buildElement("#","showHidePopupMenu('"+bookType+"details','searchbox','pageselector','settingsbox');load"+bookType.charAt(0).toUpperCase() + bookType.slice(1)+"Details("+arclist.Issues[i].dbnumber+",'"+ proxyPrefix +"/');return false;",proxyPrefix +"/"+bookType+"s/"+arclist.Issues[i].dbnumber+"/"+arclist.Issues[i].comicname+"?cover=true",arclist.Issues[i].label,i,"#group");
}
containerWrap('arc');
});
}
}
containerWrap('arc');
if($('.cellcontainer').length > itemsPerPage){
paginate(itemsPerPage);
}
});
}

/* Homepage Functions */
Expand Down Expand Up @@ -1399,13 +1419,23 @@ function rebuildBookmarks(){
if(Bookmarks.length){
$('.list-count').text(Bookmarks.length + ' Books');
}
var bookmarksPerPage = 15;
$('.pager').remove();
if($('.cellcontainer').length > bookmarksPerPage){
paginate(bookmarksPerPage);
}
}else{
if((Bookmarks.length > 0)&&(Bookmarks != undefined)){
if(!$('#bookmarks').length){
$(makeSliderList('bookmarks','Bookmarks',proxyPrefix+'/theme/mybooks.htm')).css("zIndex",1).appendTo('.main_homepage_content');
}
$( "#bookmarks .cellcontainer" ).remove();
for (i = 0; i < Bookmarks.length; i++) {
if(Bookmarks.length < homepageIssues){
var bookmarkLimit = Bookmarks.length;
}else{
var bookmarkLimit = homepageIssues;
}
for (i = 0; i < bookmarkLimit; i++) {
buildElement(Bookmarks[i][0],Bookmarks[i][1],Bookmarks[i][2],Bookmarks[i][3], i+1, '#bookmarks .list-content');
}
initializeControls('bookmarks');
Expand All @@ -1416,6 +1446,70 @@ function rebuildBookmarks(){
}
}

function paginate(thingsPerPage){
var startIndex = $.urlParam('index');
var currentPage = (startIndex / thingsPerPage) + 1;
var pageCount = Math.ceil($('.cellcontainer').length / thingsPerPage);
$('#group').append('<div class="pager"><a href="?index=0" id="arrowleft10" class="hidden pager-link">First</a><a href="?index='+(startIndex - thingsPerPage)+'" id="arrowleft" class="pager-link">&lt;</a><a href="?index='+(+startIndex + +thingsPerPage)+'" id="arrowright" class=" pager-link">&gt;</a><a href="?index='+((pageCount - 1) * thingsPerPage)+'" id="arrowright10" class="hidden pager-link">Last</a><div class="pager-jump-container"><label>Jump to:</label><input class="pager-jump" type="text" value="'+currentPage+'"> / '+pageCount+'</div><div class="pager-text">Page '+currentPage+' of '+pageCount+'</div></div>');
for (i = 0; i < pageCount; i++) {
if((i+1) == currentPage){
$('<div class="pagenumber currentpagenumber pager-link" style="">'+(i+1)+'</div>').insertBefore($('.pager #arrowright'));
}else{
$('<a href="?index='+(i*thingsPerPage)+'" class="pagenumber pager-link">'+(i+1)+'</a>').insertBefore($('.pager #arrowright'));
}
}
if(currentPage == 1){
$('.pager #arrowleft').addClass('hidden');
}
if(currentPage == pageCount){
$('.pager #arrowright').addClass('hidden');
}
if(currentPage > 2){
$('.pager #arrowleft10').removeClass('hidden');
}
if((pageCount > 2)&&(currentPage != pageCount)){
$('.pager #arrowright10').removeClass('hidden');
}
$('.pagenumber').hide();
if($('.pagenumber').index($('.currentpagenumber'))==2){
$('.pagenumber').slice(0, 5).show();
}else if($('.pagenumber').index($('.currentpagenumber'))+1==$('.pagenumber').length){
$('.pagenumber').slice(-5).show();
}else{
if($('.pagenumber').index($('.currentpagenumber')) != 0){
$('.pagenumber').eq($('.pagenumber').index($('.currentpagenumber'))-1).show();
}else{
$('.pagenumber').eq($('.pagenumber').index($('.currentpagenumber'))+4).show();
}
$('.currentpagenumber').show();
$('.pagenumber').eq($('.pagenumber').index($('.currentpagenumber'))+1).show();
if($('.pagenumber').index($('.currentpagenumber')) > 1){
$('.pagenumber').eq($('.pagenumber').index($('.currentpagenumber'))-2).show();
}else{
$('.pagenumber').eq($('.pagenumber').index($('.currentpagenumber'))+3).show();
}
if($('.pagenumber').index($('.currentpagenumber'))+1 != $('.pagenumber').length){
$('.pagenumber').eq($('.pagenumber').index($('.currentpagenumber'))+2).show();
}
if($('.pagenumber').index($('.currentpagenumber')) == $('.pagenumber').length-2){
$('.pagenumber').eq($('.pagenumber').index($('.currentpagenumber'))-3).show();
}
}
$(".pager-jump").keyup(function(e) {
if(e.which == 13){
if($('.pager-jump').val() <= pageCount){
window.location = window.location.href.split('?')[0]+"?index="+($('.pager-jump').val()*thingsPerPage-thingsPerPage);
}
}
});
$('.cellcontainer').hide();
$('.cellcontainer').each(function(index,element){
if((index >= startIndex)&&(index < (+startIndex + +thingsPerPage))){
$(this).show();
}
});
}

function resaveBookmarks(){
Bookmarks = [];
localStorage.setItem(bookmarkLocation,JSON.stringify([]));
Expand Down

0 comments on commit 35797cf

Please sign in to comment.