almost finished bookmark support (only next/prev bookmarks left to do)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-01-28 18:15:14 +04:00
parent a022c11743
commit c715262f0d
5 changed files with 109 additions and 14 deletions

View File

@ -6,6 +6,15 @@
[_] BUG: no drag threshold on excludedElements (TouchSwipe) [_] BUG: no drag threshold on excludedElements (TouchSwipe)
| stalled... | stalled...
[_] 80% general todo [_] 80% general todo
[_] 75% bookmarks
[_] add next/prev bookmark actions
[_] bookmark indicators in page view
[X] #bookmark anchor
[X] bookmark indicators in navigator
[X] bookmark indicators in thumbnails
[X] bookmark persistence
[X] set bookmark from keyboard...
[X] set bookmark touch control
[_] magazine loader and data format... [_] magazine loader and data format...
| this is simple, just use a restyled magazine viewer... | this is simple, just use a restyled magazine viewer...
[_] 0% populate an example issue [_] 0% populate an example issue

View File

@ -88,6 +88,7 @@ $(document).ready(function(){
$('.button.cover').swipe({click: goToMagazineCover}) $('.button.cover').swipe({click: goToMagazineCover})
$('.button.next-article').swipe({click: nextArticle}) $('.button.next-article').swipe({click: nextArticle})
$('.button.prev-article').swipe({click: prevArticle}) $('.button.prev-article').swipe({click: prevArticle})
$('.button.bookmark').swipe({click: function(){toggleBookmark()}})
loadState() loadState()
setupNavigator() setupNavigator()
@ -123,6 +124,7 @@ $(document).ready(function(){
<div class="button cover">Issue Cover</div> <div class="button cover">Issue Cover</div>
<div class="button prev-article">Prev Article</div> <div class="button prev-article">Prev Article</div>
<div class="button next-article">Next Article</div> <div class="button next-article">Next Article</div>
<div class="button bookmark">Bookmark</div>
</div> </div>
<div class="bottom-toolbar"> <div class="bottom-toolbar">
<!-- this is just an example--> <!-- this is just an example-->
@ -197,6 +199,7 @@ $(document).ready(function(){
<span name="example-layer" class="hidden"> <span name="example-layer" class="hidden">
<a href="#hideLayers">Hide all layers</a><br> <a href="#hideLayers">Hide all layers</a><br>
</span> </span>
<a href="#bookmark">Toggle bookmark</a><br>
<h3>Relative special anchors</h3> <h3>Relative special anchors</h3>
<p>These will get replaced by corresponding page numbers in the URL</p> <p>These will get replaced by corresponding page numbers in the URL</p>

View File

@ -74,6 +74,8 @@ var keybindings = {
32: 39, // Space 32: 39, // Space
190: 39, // > 190: 39, // >
66: toggleBookmark, // B
// combined navigation with actions.. // combined navigation with actions..
38: function(){togglePageView()}, // Up 38: function(){togglePageView()}, // Up
40: function(){togglePageView()}, // Down 40: function(){togglePageView()}, // Down

View File

@ -65,6 +65,28 @@ body {
transition: all 0.2s ease; transition: all 0.2s ease;
} }
.page .bookmark {
position: absolute;
font-size: 0px;
width: 50px;
height: 50px;
background: red;
/* XXX make this relative... */
margin-top: -50px;
margin-left: 750px;
z-index: 9999;
opacity: 0,5;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
.page-view-mode .page { .page-view-mode .page {
/* XXX change to relative units... */ /* XXX change to relative units... */
@ -74,6 +96,9 @@ body {
.page-view-mode .page .content { .page-view-mode .page .content {
} }
.page-view-mode .page .bookmark {
display: none;
}
/************************************************** general layout ***/ /************************************************** general layout ***/

View File

@ -168,16 +168,20 @@ function swipeHandler(evt, phase, direction, distance, duration, fingers){
// prev page... // prev page...
if(direction == 'right'){ if(direction == 'right'){
// two+ fingers moves to closest article... // two+ fingers moves to closest article...
if(fingers >= 2){ if(fingers == 2){
prevArticle() prevArticle()
} else if(fingers >= 3){
prevBookmark()
} else { } else {
setCurrentPage(Math.max(n-p, 0)) setCurrentPage(Math.max(n-p, 0))
} }
// next page... // next page...
} else if(direction == 'left'){ } else if(direction == 'left'){
// two+ fingers moves to closest article... // two+ fingers moves to closest article...
if(fingers >= 2){ if(fingers == 2){
nextArticle() nextArticle()
} else if(fingers >= 3){
nextBookmark()
} else { } else {
setCurrentPage(Math.min(n+p, pages.length-1)) setCurrentPage(Math.min(n+p, pages.length-1))
} }
@ -457,6 +461,18 @@ function loadURLState(){
prevArticle() prevArticle()
return getPageNumber() return getPageNumber()
} else if(anchor == 'nextBookmark') {
nextBookmark()
return getPageNumber()
} else if(anchor == 'prevBookmark') {
prevBookmark()
return getPageNumber()
} else if(anchor == 'bookmark'){
toggleBookmark()
return getPageNumber()
// hide all visible layers on current page... // hide all visible layers on current page...
} else if(anchor == 'hideLayers') { } else if(anchor == 'hideLayers') {
$('.current.page .shown') $('.current.page .shown')
@ -514,7 +530,7 @@ function loadStorageState(){
} }
function saveStorageState(){ function saveStorageState(){
$.jStorage.set('current_page', getPageNumber()) $.jStorage.set('current_page', getPageNumber())
$.jStorage.set('bookmarks', getBookmarkList()) $.jStorage.set('bookmarks', buildBookmarkList())
} }
@ -659,23 +675,63 @@ function makeBookmarkIndicator(n){
setCurrentPage(n) setCurrentPage(n)
}) })
return res
}
function clearBookmarkIndicators(){
$('.navigator .bar .bookmark').remove()
}
function removeBookmarkIndicator(n){
$('.navigator .bar .bookmark[page="'+n+'"]').remove()
}
// XXX move to actions...
function loadBookmarks(lst){
clearBookmarks()
$(lst).each(function(i, e){toggleBookmark(e)})
}
function clearBookmarks(){
$('.magazine .page .bookmark').remove()
clearBookmarkIndicators()
}
function buildBookmarkList(){
var res = []
$('.magazine .page .bookmark').each(function(_, e){
res.push(getPageNumber($(e).parents('.page')))
})
return res
}
function toggleBookmark(n){
if(n == null){
n = getPageNumber()
} else if(typeof(n) != typeof(1)){
n = getPageNumber(n)
}
var res
var cur = getPageAt(n)
if(cur.children('.bookmark').length == 0){
var res = $('<div/>')
.prependTo(cur)
.addClass('bookmark')
.click(function(){
toggleBookmark(n)
})
makeBookmarkIndicator(n)
} else {
cur.children('.bookmark').remove()
removeBookmarkIndicator(n)
}
// XXX should this be here??? // XXX should this be here???
saveState() saveState()
return res return res
} }
function loadBookmarks(lst){
$(lst).each(function(i, e){makeBookmarkIndicator(e)})
}
function getBookmarkList(){
var res = []
$('.navigator .bar .bookmark').each(function(_, e){res.push(parseInt($(e).attr('page')))})
return res
}
function clearBookmarkIndicators(){
$('.navigator .bar .bookmark').remove()
}
// XXX move this to actions... // XXX move this to actions...
function nextBookmark(){ function nextBookmark(){