2013-01-23 01:37:39 +04:00
|
|
|
/**********************************************************************
|
2013-01-27 03:40:00 +04:00
|
|
|
*
|
|
|
|
|
* XXX add copyright and licence info...
|
|
|
|
|
*
|
2013-01-23 01:37:39 +04:00
|
|
|
**********************************************************************/
|
|
|
|
|
|
2013-01-26 22:48:59 +04:00
|
|
|
//var DEBUG = DEBUG != null ? DEBUG : true
|
2013-01-23 01:37:39 +04:00
|
|
|
|
2013-01-25 18:19:44 +04:00
|
|
|
// number of pages to display in ribbon...
|
2013-01-29 20:45:16 +04:00
|
|
|
// NOTE: it is best to keep this odd-ish, so as to give the user the
|
|
|
|
|
// impession of pages continuing off-screen...
|
|
|
|
|
var PAGES_IN_RIBBON = 4.0
|
2013-01-23 01:37:39 +04:00
|
|
|
|
2013-01-25 18:19:44 +04:00
|
|
|
// if true, expand a page to fit the whole view in single page mode...
|
2013-01-26 22:48:59 +04:00
|
|
|
var FIT_PAGE_TO_VIEW = true
|
2013-01-25 18:19:44 +04:00
|
|
|
|
2013-02-06 17:27:22 +04:00
|
|
|
// default page alignment in full view...
|
|
|
|
|
// supported values:
|
|
|
|
|
// - 'center'
|
|
|
|
|
// - 'left'
|
|
|
|
|
// - 'right'
|
|
|
|
|
// NOTE: page local align values take priority over this.
|
|
|
|
|
// NOTE: this has no effect on thumbnail view.
|
|
|
|
|
// NOTE: this has no effect if FIT_PAGE_TO_VIEW is true.
|
|
|
|
|
var FULL_PAGE_ALIGN = 'center'
|
|
|
|
|
|
2013-01-26 15:05:33 +04:00
|
|
|
// if true will make page resizes after window resize animated...
|
|
|
|
|
var ANIMATE_WINDOW_RESIZE = true
|
2013-01-25 18:19:44 +04:00
|
|
|
|
2013-01-26 22:48:59 +04:00
|
|
|
// if true will disable page dragging in single page mode...
|
2013-01-28 03:36:10 +04:00
|
|
|
var DRAG_FULL_PAGE = true
|
2013-01-26 22:48:59 +04:00
|
|
|
|
2013-01-28 03:01:20 +04:00
|
|
|
// XXX make this default and remove the option...
|
|
|
|
|
// XXX this produces a funny animation that gets more ampletude the farther
|
|
|
|
|
// we get to the right from the no-resize element...
|
|
|
|
|
// ...think the reason is .no-resize page centering...
|
2013-01-28 03:25:04 +04:00
|
|
|
// XXX still buggy on togglePageView to TN after funny sized pages...
|
2013-02-06 19:25:57 +04:00
|
|
|
// ...the most probable reason is that we waste too much time between
|
|
|
|
|
// setting different values to elements...
|
|
|
|
|
// need to keep wrights as tight as possible...
|
2013-01-29 15:50:52 +04:00
|
|
|
//var USE_REAL_PAGE_SIZES = true
|
|
|
|
|
var USE_REAL_PAGE_SIZES = false
|
2013-01-23 01:37:39 +04:00
|
|
|
|
2013-02-05 17:56:34 +04:00
|
|
|
// if true this will make each page flip update the hash url...
|
|
|
|
|
// if false, only direct linking will update the url.
|
2013-02-05 19:06:01 +04:00
|
|
|
// NOTE: this can slow down navigation...
|
|
|
|
|
var UPDATE_HASH_URL_POSITION = false
|
|
|
|
|
|
|
|
|
|
// if true this will enable history for local page navigation regardless
|
|
|
|
|
// of weather UPDATE_HASH_URL_POSITION state.
|
|
|
|
|
// NOTE: UPDATE_HASH_URL_POSITION implicitly enables full browser history
|
|
|
|
|
// based navigation.
|
2013-02-05 20:59:15 +04:00
|
|
|
// NOTE: this, if enabled, can slow down navigation...
|
2013-02-05 19:06:01 +04:00
|
|
|
// NOTE: partial history navigation over links will still work.
|
|
|
|
|
var FULL_HISTORY_ENABLED = false
|
2013-02-05 17:56:34 +04:00
|
|
|
|
2013-01-24 03:15:54 +04:00
|
|
|
|
2013-01-29 21:41:26 +04:00
|
|
|
|
2013-01-29 22:25:51 +04:00
|
|
|
/*********************************************************** modes ***/
|
|
|
|
|
|
2013-01-25 18:19:44 +04:00
|
|
|
// toggles .dragging CSS class on the viewer while dragging is in
|
|
|
|
|
// progress.
|
|
|
|
|
// NOTE: this is used mostly for styling and drag assisting...
|
2013-01-31 02:46:02 +04:00
|
|
|
var togglePageDragging = createCSSClassToggler('.viewer', 'dragging')
|
|
|
|
|
|
|
|
|
|
|
2013-01-31 03:47:11 +04:00
|
|
|
// toggles the editor mode, used for inline magazine editor...
|
2013-01-31 02:46:02 +04:00
|
|
|
var toggleEditorMode = createCSSClassToggler('.viewer', 'editor-mode noSwipe')
|
2013-01-23 01:37:39 +04:00
|
|
|
|
|
|
|
|
|
2013-01-27 00:04:29 +04:00
|
|
|
// this is here only for speed, helps with dragging...
|
|
|
|
|
// DO NOT USE DIRECTLY!
|
|
|
|
|
var _PAGE_VIEW
|
|
|
|
|
|
2013-01-25 18:19:44 +04:00
|
|
|
// toggle between the two main modes:
|
|
|
|
|
// - single page mode (.page-view-mode)
|
|
|
|
|
// - thumbnail/ribbon mode
|
2013-01-31 02:46:02 +04:00
|
|
|
var togglePageView = createCSSClassToggler(
|
2013-01-23 01:37:39 +04:00
|
|
|
'.viewer',
|
|
|
|
|
'page-view-mode',
|
|
|
|
|
null,
|
|
|
|
|
// post-change callback...
|
2013-01-26 15:05:33 +04:00
|
|
|
function(action){
|
|
|
|
|
if(action == 'on'){
|
2013-01-26 22:48:59 +04:00
|
|
|
fitNPages(1, !FIT_PAGE_TO_VIEW)
|
2013-01-27 00:04:29 +04:00
|
|
|
_PAGE_VIEW = true
|
2013-01-23 01:37:39 +04:00
|
|
|
} else {
|
2013-01-25 18:19:44 +04:00
|
|
|
fitNPages(PAGES_IN_RIBBON)
|
2013-01-27 00:04:29 +04:00
|
|
|
_PAGE_VIEW = false
|
2013-01-23 01:37:39 +04:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2013-01-25 10:09:58 +04:00
|
|
|
|
2013-01-29 21:30:53 +04:00
|
|
|
// this will simply update the current view...
|
2013-01-26 21:46:49 +04:00
|
|
|
function updateView(){
|
|
|
|
|
return togglePageView(togglePageView('?'))
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-25 18:19:44 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************* helpers ***/
|
|
|
|
|
|
2013-02-06 17:27:22 +04:00
|
|
|
function getPageAlign(page){
|
|
|
|
|
if(page == null){
|
|
|
|
|
page = $('.current.page')
|
|
|
|
|
}
|
|
|
|
|
return (page.hasClass('page-align-center') ? 'center'
|
|
|
|
|
: page.hasClass('page-align-left') ? 'left'
|
|
|
|
|
: page.hasClass('page-align-right') ? 'right'
|
|
|
|
|
: FULL_PAGE_ALIGN)
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-06 19:25:57 +04:00
|
|
|
// XXX need a way to get the title without a magazine loaded...
|
|
|
|
|
// ...something like a current magazine option...
|
|
|
|
|
function getMagazineTitle(){
|
|
|
|
|
return ($('.magazine').attr('title')
|
|
|
|
|
|| $('.magazine').attr('name'))
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-06 17:27:22 +04:00
|
|
|
|
2013-01-23 01:37:39 +04:00
|
|
|
function getPageScale(){
|
|
|
|
|
return getElementScale($('.scaler'))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-02-01 02:51:14 +04:00
|
|
|
// NOTE: if page is not given get the current page number...
|
2013-01-25 18:19:44 +04:00
|
|
|
function getPageNumber(page){
|
|
|
|
|
if(page == null){
|
|
|
|
|
page = $('.current.page')
|
|
|
|
|
}
|
|
|
|
|
return $('.page').index(page)
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-29 13:58:27 +04:00
|
|
|
|
2013-01-31 05:38:38 +04:00
|
|
|
// NOTE: negative values will yield results from the tail...
|
2013-01-28 17:14:47 +04:00
|
|
|
function getPageAt(n){
|
2013-01-31 05:38:38 +04:00
|
|
|
var page = $('.page')
|
|
|
|
|
if(n < 0){
|
|
|
|
|
n = page.length + n
|
|
|
|
|
}
|
|
|
|
|
return $(page[n])
|
2013-01-28 17:14:47 +04:00
|
|
|
}
|
2013-01-25 18:19:44 +04:00
|
|
|
|
|
|
|
|
|
2013-01-29 13:58:27 +04:00
|
|
|
|
2013-01-25 18:19:44 +04:00
|
|
|
/************************************************** event handlers ***/
|
|
|
|
|
|
2013-02-01 02:51:14 +04:00
|
|
|
// #URL handler...
|
2013-02-06 15:44:09 +04:00
|
|
|
var RELATIVE_URLS = [
|
|
|
|
|
'back', 'forward',
|
|
|
|
|
'next', 'prev',
|
|
|
|
|
'nextArticle', 'prevArticle',
|
|
|
|
|
'nextBookmark', 'prevBookmark',
|
|
|
|
|
'bookmark',
|
|
|
|
|
'hideLayers'
|
|
|
|
|
]
|
2013-01-27 00:04:29 +04:00
|
|
|
// NOTE: most of the handling actually happens in loadURLState...
|
2013-01-26 23:48:57 +04:00
|
|
|
function hashChangeHandler(e){
|
|
|
|
|
e.preventDefault()
|
2013-02-06 15:44:09 +04:00
|
|
|
|
|
|
|
|
var anchor = window.location.hash.split('#')[1]
|
|
|
|
|
|
|
|
|
|
// skip empty #URL...
|
|
|
|
|
if(anchor == ''){
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-26 23:48:57 +04:00
|
|
|
var r = loadURLState()
|
2013-02-06 15:44:09 +04:00
|
|
|
var n = getPageNumber()
|
|
|
|
|
|
|
|
|
|
// for relative #URLs remove them from hash...
|
|
|
|
|
if(RELATIVE_URLS.indexOf(anchor) >= 0 && !UPDATE_HASH_URL_POSITION){
|
|
|
|
|
window.location.hash = ''
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-26 23:48:57 +04:00
|
|
|
// if we are dealing with history actions the browser will
|
|
|
|
|
// do the work for us...
|
|
|
|
|
if(r == 'back'){
|
2013-02-01 02:51:14 +04:00
|
|
|
// we shift by 2 to compensate for the back/forward URL itself...
|
2013-01-26 23:48:57 +04:00
|
|
|
window.history.go(-2)
|
|
|
|
|
} else if(r == 'forward'){
|
|
|
|
|
window.history.go(2)
|
2013-02-06 15:44:09 +04:00
|
|
|
} else if(r != n){
|
|
|
|
|
|
|
|
|
|
/* XXX this will put this into an endless loop...
|
|
|
|
|
* ...mainly because it changes the #URL from within the handler
|
|
|
|
|
if(!UPDATE_HASH_URL_POSITION){
|
|
|
|
|
// push current position...
|
|
|
|
|
// NOTE: this will enable partial history navigation, but only
|
|
|
|
|
// on actions envolving actual links...
|
|
|
|
|
window.history.pushState(null, null, '#' + getPageNumber())
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
2013-01-26 23:48:57 +04:00
|
|
|
setCurrentPage(r)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-27 03:40:00 +04:00
|
|
|
|
|
|
|
|
// window resize event handler...
|
2013-01-27 01:25:20 +04:00
|
|
|
function viewResizeHandler(){
|
|
|
|
|
if(ANIMATE_WINDOW_RESIZE){
|
|
|
|
|
updateView()
|
|
|
|
|
} else {
|
|
|
|
|
unanimated($('.scaler'), updateView, 30)()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-26 23:48:57 +04:00
|
|
|
|
2013-01-26 22:48:59 +04:00
|
|
|
// swipe state handler
|
|
|
|
|
// this handles single and double finger swipes and dragging
|
2013-01-27 22:06:39 +04:00
|
|
|
// while draggign this triggers magazineDragging event on the viewer...
|
2013-01-29 21:30:53 +04:00
|
|
|
// NOTE: this will trigger 'magazineDragging' event on the viewer on
|
|
|
|
|
// each call while dragging...
|
|
|
|
|
// XXX for some reason with finger count of 3 and greater, touchSwipe
|
|
|
|
|
// dies on android...
|
2013-01-25 18:19:44 +04:00
|
|
|
function swipeHandler(evt, phase, direction, distance, duration, fingers){
|
|
|
|
|
var pages = $('.page')
|
|
|
|
|
var cur = $('.current.page')
|
|
|
|
|
var n = pages.index(cur)
|
|
|
|
|
var scale = getPageScale()
|
|
|
|
|
var mag = $('.magazine')
|
2013-01-27 18:24:30 +04:00
|
|
|
var pos = $('.navigator .bar .indicator')
|
2013-01-25 18:19:44 +04:00
|
|
|
|
2013-01-26 22:48:59 +04:00
|
|
|
if(phase=='move'
|
|
|
|
|
// see if wee need to drag the page and allways drag the ribbon...
|
2013-01-27 00:04:29 +04:00
|
|
|
&& (DRAG_FULL_PAGE || !_PAGE_VIEW)
|
2013-01-26 22:48:59 +04:00
|
|
|
&& (direction=='left' || direction=='right')){
|
2013-01-25 18:19:44 +04:00
|
|
|
if(direction == 'left'){
|
2013-01-29 13:58:27 +04:00
|
|
|
mag.css({left: -cur.position()['left']/scale - distance/scale})
|
2013-01-25 18:19:44 +04:00
|
|
|
} else if(direction == 'right') {
|
2013-01-29 13:58:27 +04:00
|
|
|
mag.css({left: -cur.position()['left']/scale + distance/scale})
|
2013-01-25 18:19:44 +04:00
|
|
|
}
|
2013-01-27 22:06:39 +04:00
|
|
|
|
|
|
|
|
$('.viewer').trigger('magazineDragging')
|
2013-01-25 18:19:44 +04:00
|
|
|
|
2013-01-27 03:44:45 +04:00
|
|
|
} else if(phase == 'start'){
|
2013-02-01 02:51:14 +04:00
|
|
|
// NOTE: this is used with the "unanimated" trick, we will make
|
|
|
|
|
// dragging real-time...
|
2013-01-25 18:19:44 +04:00
|
|
|
togglePageDragging('on')
|
|
|
|
|
|
2013-01-27 03:44:45 +04:00
|
|
|
} else if(phase == 'cancel'){
|
2013-01-25 18:19:44 +04:00
|
|
|
togglePageDragging('off')
|
|
|
|
|
setCurrentPage()
|
|
|
|
|
|
2013-01-27 03:44:45 +04:00
|
|
|
} else if(phase =='end' ){
|
2013-01-25 18:19:44 +04:00
|
|
|
togglePageDragging('off')
|
|
|
|
|
// see which page is closer to the middle of the screen and set it...
|
|
|
|
|
// do this based on how much we dragged...
|
|
|
|
|
var p = Math.ceil((distance/scale)/cur.width())
|
|
|
|
|
|
|
|
|
|
// prev page...
|
2013-01-27 03:44:45 +04:00
|
|
|
if(direction == 'right'){
|
2013-02-01 02:51:14 +04:00
|
|
|
// 2 fingers moves to closest article...
|
2013-01-28 18:15:14 +04:00
|
|
|
if(fingers == 2){
|
2013-01-25 18:19:44 +04:00
|
|
|
prevArticle()
|
2013-02-01 02:51:14 +04:00
|
|
|
// 3+ fingers moves to bookmark...
|
2013-01-28 18:15:14 +04:00
|
|
|
} else if(fingers >= 3){
|
|
|
|
|
prevBookmark()
|
2013-01-25 18:19:44 +04:00
|
|
|
} else {
|
|
|
|
|
setCurrentPage(Math.max(n-p, 0))
|
|
|
|
|
}
|
|
|
|
|
// next page...
|
|
|
|
|
} else if(direction == 'left'){
|
2013-01-28 18:15:14 +04:00
|
|
|
if(fingers == 2){
|
2013-01-25 18:19:44 +04:00
|
|
|
nextArticle()
|
2013-01-28 18:15:14 +04:00
|
|
|
} else if(fingers >= 3){
|
|
|
|
|
nextBookmark()
|
2013-01-25 18:19:44 +04:00
|
|
|
} else {
|
|
|
|
|
setCurrentPage(Math.min(n+p, pages.length-1))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************** layout ***/
|
|
|
|
|
|
2013-01-29 21:30:53 +04:00
|
|
|
// NOTE: if n is not given then it defaults to 1
|
|
|
|
|
// NOTE: if n > 1 and fit_to_content is not given it defaults to true
|
|
|
|
|
// NOTE: if n is 1 then fit_to_content bool argument controls wether:
|
|
|
|
|
// - the page will be stretched to viewer (false)
|
|
|
|
|
// - or to content (true)
|
|
|
|
|
// XXX on USE_REAL_PAGE_SIZES offset is a bit off...
|
2013-01-30 02:41:51 +04:00
|
|
|
// this is most noticable when going into full page mode...
|
2013-01-25 09:59:53 +04:00
|
|
|
function fitNPages(n, fit_to_content){
|
|
|
|
|
if(n == null){
|
2013-01-23 01:37:39 +04:00
|
|
|
n = 1
|
|
|
|
|
}
|
2013-01-25 09:59:53 +04:00
|
|
|
if(n > 1 && fit_to_content == null){
|
|
|
|
|
fit_to_content = true
|
|
|
|
|
}
|
2013-01-23 01:37:39 +04:00
|
|
|
var view = $('.viewer')
|
2013-01-29 15:50:52 +04:00
|
|
|
if(USE_REAL_PAGE_SIZES){
|
2013-01-28 03:01:20 +04:00
|
|
|
var page = $('.page:not(.no-resize)')
|
|
|
|
|
} else {
|
|
|
|
|
var page = $('.page')
|
|
|
|
|
}
|
2013-01-23 01:37:39 +04:00
|
|
|
var content = $('.content')
|
2013-01-28 03:01:20 +04:00
|
|
|
var cur = $('.current.page')
|
2013-01-23 01:37:39 +04:00
|
|
|
|
2013-01-25 09:59:53 +04:00
|
|
|
var W = view.width()
|
|
|
|
|
var H = view.height()
|
2013-01-23 01:37:39 +04:00
|
|
|
var cW = content.width()
|
|
|
|
|
var cH = content.height()
|
2013-01-25 09:59:53 +04:00
|
|
|
|
|
|
|
|
var rW = cW
|
|
|
|
|
var scale = getPageScale()
|
|
|
|
|
|
2013-01-27 18:58:05 +04:00
|
|
|
// to compensate for transitions, no data sampling should be beyound
|
|
|
|
|
// this point, as we will start changing things next...
|
2013-01-27 03:40:00 +04:00
|
|
|
|
2013-01-25 09:59:53 +04:00
|
|
|
if(fit_to_content){
|
2013-01-29 15:50:52 +04:00
|
|
|
if(USE_REAL_PAGE_SIZES){
|
2013-01-28 03:25:04 +04:00
|
|
|
page.width('auto')
|
|
|
|
|
page.height('auto')
|
|
|
|
|
} else {
|
|
|
|
|
page.width(cW)
|
|
|
|
|
page.height(cH)
|
|
|
|
|
}
|
2013-01-25 09:59:53 +04:00
|
|
|
if(W/H > (cW*n)/cH){
|
|
|
|
|
scale = H/cH
|
|
|
|
|
} else {
|
|
|
|
|
scale = W/(cW*n)
|
|
|
|
|
}
|
2013-01-25 10:09:58 +04:00
|
|
|
// resulting page width...
|
2013-01-25 09:59:53 +04:00
|
|
|
var rW = cW
|
2013-01-27 18:58:05 +04:00
|
|
|
|
2013-01-25 09:59:53 +04:00
|
|
|
} else {
|
|
|
|
|
// need to calc width only...
|
|
|
|
|
if(W/H > (cW*n)/cH){
|
|
|
|
|
scale = H/cH
|
|
|
|
|
page.width(W/scale)
|
|
|
|
|
page.height(cH)
|
2013-01-27 18:58:05 +04:00
|
|
|
|
2013-01-25 09:59:53 +04:00
|
|
|
// need to calc height only...
|
|
|
|
|
} else if(W/H > (cW*n)/cH){
|
|
|
|
|
scale = W/(cW*n)
|
|
|
|
|
page.height(H/scale)
|
|
|
|
|
page.width(cW)
|
2013-01-27 18:58:05 +04:00
|
|
|
|
2013-01-25 09:59:53 +04:00
|
|
|
// set both width and height to defaults (content and page ratios match)...
|
|
|
|
|
} else {
|
|
|
|
|
scale = W/(cW*n)
|
|
|
|
|
page.height(cH)
|
|
|
|
|
page.width(cW)
|
|
|
|
|
}
|
|
|
|
|
// resulting page width...
|
|
|
|
|
var rW = W/scale
|
2013-01-23 01:37:39 +04:00
|
|
|
}
|
2013-01-29 18:55:21 +04:00
|
|
|
if(USE_REAL_PAGE_SIZES){
|
|
|
|
|
$('.page.no-resize').width('auto')
|
|
|
|
|
}
|
2013-01-23 01:37:39 +04:00
|
|
|
|
2013-01-29 18:55:21 +04:00
|
|
|
// NOTE: we need to calculate the offset as the actual widths during
|
2013-02-01 02:51:14 +04:00
|
|
|
// the animation are not correct... so just looking at .position()
|
|
|
|
|
// will be counterproductive...
|
|
|
|
|
// XXX still there is some error (rounding, page zoom?)...
|
2013-02-06 17:27:22 +04:00
|
|
|
// calculate offset...
|
2013-01-29 18:55:21 +04:00
|
|
|
if(!USE_REAL_PAGE_SIZES && fit_to_content){
|
2013-01-28 03:01:20 +04:00
|
|
|
var offset = rW * getPageNumber()-1
|
|
|
|
|
} else {
|
|
|
|
|
// calculate the target offset...
|
2013-01-29 15:50:52 +04:00
|
|
|
if(USE_REAL_PAGE_SIZES){
|
2013-01-28 03:01:20 +04:00
|
|
|
var rpages = $('.page:not(.no-resize), .current.page')
|
|
|
|
|
} else {
|
|
|
|
|
var rpages = page
|
|
|
|
|
}
|
|
|
|
|
var i = rpages.index(cur)
|
|
|
|
|
var offset = rW * i-1
|
2013-01-29 18:55:21 +04:00
|
|
|
// now do the no-resize elements...
|
2013-01-29 15:50:52 +04:00
|
|
|
if(USE_REAL_PAGE_SIZES){
|
2013-01-28 03:01:20 +04:00
|
|
|
var nrpages = $('.page.no-resize, .current.page')
|
|
|
|
|
i = nrpages.index(cur)
|
|
|
|
|
nrpages.splice(i)
|
|
|
|
|
nrpages.each(function(_, e){
|
2013-01-29 18:55:21 +04:00
|
|
|
offset += $(e).children('.content').width()
|
2013-01-28 03:01:20 +04:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-29 15:50:52 +04:00
|
|
|
if(USE_REAL_PAGE_SIZES){
|
2013-01-28 03:36:10 +04:00
|
|
|
if(cur.hasClass('no-resize')){
|
2013-02-06 17:27:22 +04:00
|
|
|
var align = getPageAlign(cur)
|
|
|
|
|
|
|
|
|
|
// center align if explicitly required or if we are in a ribbon...
|
|
|
|
|
if(n > 1 || align == 'center'){
|
|
|
|
|
rW = cur.children('.content').width()
|
|
|
|
|
|
|
|
|
|
// align left...
|
|
|
|
|
} else if(align == 'left'){
|
|
|
|
|
rW = $('.viewer').width()/scale
|
|
|
|
|
|
|
|
|
|
// align right...
|
|
|
|
|
} else if(align == 'right'){
|
|
|
|
|
var v = $('.viewer')
|
|
|
|
|
rW = (v.width()/scale/2 - (v.width()/scale-cur.width()))*2
|
|
|
|
|
}
|
2013-01-28 03:36:10 +04:00
|
|
|
}
|
2013-01-28 03:01:20 +04:00
|
|
|
}
|
2013-01-23 01:37:39 +04:00
|
|
|
|
2013-01-25 09:59:53 +04:00
|
|
|
// do the scaling...
|
2013-01-23 01:37:39 +04:00
|
|
|
setElementScale($('.scaler'), scale)
|
2013-01-25 09:59:53 +04:00
|
|
|
// fix position...
|
2013-01-28 03:01:20 +04:00
|
|
|
setCurrentPage(null, offset, rW)
|
2013-01-23 01:37:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-25 18:19:44 +04:00
|
|
|
/********************************************************* actions ***/
|
2013-01-23 01:37:39 +04:00
|
|
|
|
2013-01-29 21:30:53 +04:00
|
|
|
// NOTE: "width" is used ONLY to center the page.
|
2013-01-27 18:58:05 +04:00
|
|
|
// NOTE: if n is not given it will be set to current page number
|
|
|
|
|
// NOTE: if width is not given it will be set to current page width.
|
|
|
|
|
// NOTE: n can be:
|
|
|
|
|
// - page number
|
|
|
|
|
// - page element
|
2013-01-29 21:30:53 +04:00
|
|
|
// NOTE: this will fire a 'pageChanged(n)' event on the viewer each time
|
2013-01-27 18:38:00 +04:00
|
|
|
// it is called...
|
2013-01-31 05:38:38 +04:00
|
|
|
// NOTE: this now supports negative indexes to count pages from the end...
|
2013-01-28 03:01:20 +04:00
|
|
|
function setCurrentPage(n, offset, width){
|
2013-01-31 05:38:38 +04:00
|
|
|
var page = $('.page')
|
2013-02-01 02:51:14 +04:00
|
|
|
// setup n and cur...
|
|
|
|
|
// no n is given, do the defaultdance
|
2013-01-23 01:37:39 +04:00
|
|
|
if(n == null){
|
|
|
|
|
var cur = $('.current.page')
|
2013-01-31 05:38:38 +04:00
|
|
|
// no current page...
|
|
|
|
|
// try to land on the magazine cover...
|
|
|
|
|
if(cur.length == 0){
|
|
|
|
|
cur = $('.magazine > .cover')
|
|
|
|
|
}
|
|
|
|
|
// try the first cover...
|
|
|
|
|
if(cur.length == 0){
|
|
|
|
|
cur = $('.cover.page')
|
|
|
|
|
}
|
|
|
|
|
// try first page...
|
|
|
|
|
if(cur.length == 0){
|
|
|
|
|
cur = page.first()
|
|
|
|
|
}
|
|
|
|
|
// no pages to work with...
|
|
|
|
|
if(cur.length == 0){
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
n = page.index(cur)
|
2013-02-01 02:51:14 +04:00
|
|
|
|
|
|
|
|
// n is a number...
|
2013-01-23 01:37:39 +04:00
|
|
|
} else if(typeof(n) == typeof(1)) {
|
2013-02-01 02:51:14 +04:00
|
|
|
// normalize n...
|
2013-01-31 05:38:38 +04:00
|
|
|
if(n >= page.length){
|
|
|
|
|
n = page.length-1
|
|
|
|
|
} else if(-n > page.length){
|
|
|
|
|
n = 0
|
|
|
|
|
}
|
2013-01-28 17:14:47 +04:00
|
|
|
var cur = getPageAt(n)
|
2013-02-01 02:51:14 +04:00
|
|
|
|
|
|
|
|
// n is an element, likely...
|
2013-01-23 01:37:39 +04:00
|
|
|
} else {
|
|
|
|
|
var cur = $(n)
|
|
|
|
|
n = $('.page').index(cur)
|
2013-02-06 17:27:22 +04:00
|
|
|
//n = page.index(cur)
|
2013-01-23 01:37:39 +04:00
|
|
|
}
|
2013-02-01 02:51:14 +04:00
|
|
|
|
|
|
|
|
// default width...
|
2013-01-28 03:01:20 +04:00
|
|
|
if(width == null){
|
|
|
|
|
width = cur.width()
|
2013-02-06 17:27:22 +04:00
|
|
|
if(USE_REAL_PAGE_SIZES && togglePageView('?') == 'on'){
|
|
|
|
|
var align = getPageAlign(cur)
|
|
|
|
|
var scale = getPageScale()
|
|
|
|
|
if(align == 'center'){
|
|
|
|
|
width = cur.width()
|
|
|
|
|
|
|
|
|
|
} else if(align == 'left'){
|
|
|
|
|
width = $('.viewer').width()/scale
|
|
|
|
|
|
|
|
|
|
} else if(align == 'right'){
|
|
|
|
|
var v = $('.viewer')
|
|
|
|
|
width = (v.width()/scale/2 - (v.width()/scale-cur.width()))*2
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-01-28 03:01:20 +04:00
|
|
|
}
|
2013-01-23 01:37:39 +04:00
|
|
|
|
|
|
|
|
$('.current.page').removeClass('current')
|
|
|
|
|
cur.addClass('current')
|
|
|
|
|
|
|
|
|
|
var mag = $('.magazine')
|
2013-02-01 02:51:14 +04:00
|
|
|
mag.css({
|
|
|
|
|
// NOTE: this will be wrong during a transition, that's why we
|
|
|
|
|
// can pass the pre-calculated offset as an argument...
|
|
|
|
|
left: -(offset == null ? cur.position()['left']/getPageScale() : offset)
|
|
|
|
|
})
|
2013-01-28 03:01:20 +04:00
|
|
|
|
|
|
|
|
// center the pages correctly...
|
2013-02-01 02:51:14 +04:00
|
|
|
// NOTE: this is the main reason we need width, and we can get it
|
|
|
|
|
// pre-calculated because of ongoing transitions make it
|
|
|
|
|
// pointless to read it...
|
2013-01-28 03:01:20 +04:00
|
|
|
$('.magazine').css({
|
|
|
|
|
'margin-left': -width/2
|
|
|
|
|
})
|
2013-01-23 01:37:39 +04:00
|
|
|
|
2013-01-27 18:38:00 +04:00
|
|
|
$('.viewer').trigger('pageChanged', n)
|
2013-01-27 17:59:33 +04:00
|
|
|
|
2013-01-23 01:37:39 +04:00
|
|
|
return cur
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-25 18:19:44 +04:00
|
|
|
|
|
|
|
|
function goToMagazineCover(){
|
2013-02-01 02:51:14 +04:00
|
|
|
return setCurrentPage(0)
|
2013-01-25 18:19:44 +04:00
|
|
|
}
|
2013-01-27 22:41:06 +04:00
|
|
|
function goToMagazineEnd(){
|
2013-02-02 08:36:54 +04:00
|
|
|
return setCurrentPage(-1)
|
2013-01-27 22:41:06 +04:00
|
|
|
}
|
2013-01-25 18:19:44 +04:00
|
|
|
function goToArticleCover(){
|
2013-02-01 02:51:14 +04:00
|
|
|
// try and get the actual first cover...
|
|
|
|
|
var cover = $('.current.page').parents('.article').children('.cover.page').first()
|
|
|
|
|
if(cever.length == 0){
|
|
|
|
|
// no cover, get the first page...
|
|
|
|
|
return setCurrentPage($('.current.page').parents('.article').children('.page').first())
|
|
|
|
|
} else {
|
|
|
|
|
return setCurrentPage(cover)
|
|
|
|
|
}
|
2013-01-23 01:37:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function nextPage(){
|
|
|
|
|
var pages = $('.page')
|
|
|
|
|
var cur = $('.current.page')
|
|
|
|
|
return setCurrentPage(Math.min(pages.index(cur)+1, pages.length-1))
|
|
|
|
|
}
|
|
|
|
|
function prevPage(){
|
|
|
|
|
var pages = $('.page')
|
|
|
|
|
var cur = $('.current.page')
|
|
|
|
|
return setCurrentPage(Math.max(pages.index(cur)-1, 0))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function nextArticle(){
|
|
|
|
|
var cur = $('.current.page').parents('.article')
|
2013-01-23 23:17:29 +04:00
|
|
|
// we are at the magazine cover...
|
2013-01-23 01:37:39 +04:00
|
|
|
if(cur.length == 0){
|
|
|
|
|
return setCurrentPage(
|
2013-01-27 17:59:33 +04:00
|
|
|
$('.magazine .article .page:first-child').first())
|
2013-01-23 01:37:39 +04:00
|
|
|
}
|
|
|
|
|
// just find the next one...
|
2013-01-27 17:59:33 +04:00
|
|
|
var articles = $('.magazine .article')
|
2013-01-23 01:37:39 +04:00
|
|
|
return setCurrentPage(
|
|
|
|
|
$(articles[Math.min(articles.index(cur)+1, articles.length-1)])
|
|
|
|
|
.children('.page')
|
|
|
|
|
.first())
|
|
|
|
|
}
|
|
|
|
|
function prevArticle(){
|
|
|
|
|
var cur = $('.current.page').parents('.article')
|
2013-01-23 23:17:29 +04:00
|
|
|
// we are at the magazine cover...
|
2013-01-23 01:37:39 +04:00
|
|
|
if(cur.length == 0){
|
2013-01-23 23:17:29 +04:00
|
|
|
//return $('.current.page')
|
|
|
|
|
return setCurrentPage()
|
2013-01-23 01:37:39 +04:00
|
|
|
}
|
|
|
|
|
// just find the prev one...
|
2013-01-27 17:59:33 +04:00
|
|
|
var articles = $('.magazine .article')
|
2013-01-23 01:37:39 +04:00
|
|
|
return setCurrentPage(
|
|
|
|
|
$(articles[Math.max(articles.index(cur)-1, 0)])
|
|
|
|
|
.children('.page')
|
|
|
|
|
.first())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-29 21:30:53 +04:00
|
|
|
/******************************************************* bookmarks ***/
|
|
|
|
|
|
2013-01-30 01:40:54 +04:00
|
|
|
// setup bookmarking active zones in page...
|
|
|
|
|
function setupBookmarkTouchZones(){
|
|
|
|
|
$('.bookmark-toggler').remove()
|
|
|
|
|
var page = $('.page')
|
|
|
|
|
page.each(function(i, e){
|
|
|
|
|
$('<div/>')
|
2013-01-30 02:41:51 +04:00
|
|
|
.prependTo($(e))
|
2013-01-30 01:40:54 +04:00
|
|
|
.addClass('bookmark-toggler')
|
|
|
|
|
.attr({
|
|
|
|
|
title: 'Toggle bookmark (B)'
|
|
|
|
|
})
|
2013-01-30 03:17:45 +04:00
|
|
|
.swipe({
|
|
|
|
|
click: function(){
|
|
|
|
|
toggleBookmark($(e))
|
|
|
|
|
}
|
2013-01-30 01:40:54 +04:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-29 21:30:53 +04:00
|
|
|
// load bookmarks from list...
|
|
|
|
|
function loadBookmarks(lst){
|
|
|
|
|
clearBookmarks()
|
2013-02-01 02:51:14 +04:00
|
|
|
// setup/set bookmarks...
|
2013-01-29 21:30:53 +04:00
|
|
|
$(lst).each(function(i, e){toggleBookmark(e)})
|
|
|
|
|
}
|
|
|
|
|
// build bookmark list...
|
|
|
|
|
function buildBookmarkList(){
|
|
|
|
|
var res = []
|
|
|
|
|
$('.magazine .page .bookmark').each(function(_, e){
|
|
|
|
|
res.push(getPageNumber($(e).parents('.page')))
|
|
|
|
|
})
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: will trigger 'bookmarksCleared' event on the viewer
|
|
|
|
|
function clearBookmarks(){
|
|
|
|
|
$('.magazine .page .bookmark').remove()
|
|
|
|
|
|
|
|
|
|
$('.viewer').trigger('bookmarksCleared')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: this will trigger events on the viewer:
|
|
|
|
|
// - bookmarkAdded(n)
|
|
|
|
|
// - bookmarkRemoved(n)
|
|
|
|
|
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 justcreated')
|
2013-01-29 22:25:51 +04:00
|
|
|
.attr({
|
|
|
|
|
title: 'Toggle bookmark (B)'
|
|
|
|
|
})
|
2013-01-29 21:30:53 +04:00
|
|
|
|
|
|
|
|
$('.viewer').trigger('bookmarkAdded', n)
|
|
|
|
|
|
|
|
|
|
setTimeout(function(){
|
|
|
|
|
res.removeClass('justcreated')
|
|
|
|
|
}, 1000)
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
cur.children('.bookmark').remove()
|
|
|
|
|
|
|
|
|
|
$('.viewer').trigger('bookmarkRemoved', n)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function nextBookmark(){
|
|
|
|
|
var pages = $('.page')
|
|
|
|
|
pages = $(pages.splice(getPageNumber()+1))
|
|
|
|
|
page = pages.children('.bookmark').first().parents('.page')
|
|
|
|
|
if(page.length != 0){
|
|
|
|
|
return setCurrentPage(page)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function prevBookmark(){
|
|
|
|
|
var pages = $('.page')
|
|
|
|
|
pages.splice(getPageNumber())
|
|
|
|
|
page = pages.children('.bookmark').last().parents('.page')
|
|
|
|
|
if(page.length != 0){
|
|
|
|
|
return setCurrentPage(page)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-01 03:08:13 +04:00
|
|
|
/*********************************************************** state ****
|
|
|
|
|
*
|
|
|
|
|
* Local state consists of:
|
|
|
|
|
* - current page
|
|
|
|
|
* - bookmarks
|
|
|
|
|
*
|
|
|
|
|
* Two types of store are used for local state:
|
|
|
|
|
* - #URL
|
|
|
|
|
* stores current page number
|
|
|
|
|
* is used for special URLs like #home, #next, etc.
|
|
|
|
|
* - localStorage
|
|
|
|
|
* stores current page (overriden by #URL if both are present)
|
|
|
|
|
* stores bookmarks
|
|
|
|
|
*
|
|
|
|
|
* NOTE: localStorage is magazine specific.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
**********************************************************************/
|
2013-01-25 18:19:44 +04:00
|
|
|
|
2013-02-01 02:14:40 +04:00
|
|
|
// XXX make URLs magazine-specific...
|
|
|
|
|
// ...for extrnal linking we'll need the magazine ID, or make each
|
|
|
|
|
// magazine a seporate path...
|
2013-02-01 02:51:14 +04:00
|
|
|
// the #URL should be of the form:
|
|
|
|
|
// #<Name> - local links
|
|
|
|
|
// #<magazine>/<name> - global urls
|
|
|
|
|
// the later can be conviniently searched with:
|
|
|
|
|
// $('[title="<magazine>"] [name="<name>"]')
|
2013-01-23 05:53:42 +04:00
|
|
|
// XXX BUG: if the hash url part coresponds to a real anchor the browser
|
2013-01-23 04:10:05 +04:00
|
|
|
// shifts the page, need to disable this...
|
2013-01-23 01:37:39 +04:00
|
|
|
// URL state managers...
|
2013-02-06 15:44:09 +04:00
|
|
|
// NOTE: loadURLState will have no side-effects on the URL, it will just
|
|
|
|
|
// get the state from the URL and return it.
|
2013-02-06 17:27:22 +04:00
|
|
|
// NOTE: this will also do the apropriate action depending on #URL...
|
2013-01-23 01:37:39 +04:00
|
|
|
function loadURLState(){
|
|
|
|
|
if(window.location.hash == ''){
|
|
|
|
|
return null
|
|
|
|
|
}
|
2013-01-23 04:10:05 +04:00
|
|
|
var anchor = window.location.hash.split('#')[1]
|
|
|
|
|
var n = parseInt(anchor)
|
|
|
|
|
if(typeof(n) == typeof(1) && n >= 0){
|
2013-01-23 01:37:39 +04:00
|
|
|
return n
|
2013-02-05 17:56:34 +04:00
|
|
|
}
|
|
|
|
|
|
2013-01-23 04:10:05 +04:00
|
|
|
// XXX add real external aliases...
|
2013-02-05 17:56:34 +04:00
|
|
|
if(anchor == 'thumbnails') {
|
2013-01-23 04:10:05 +04:00
|
|
|
togglePageView('off')
|
|
|
|
|
return getPageNumber()
|
2013-01-23 05:53:42 +04:00
|
|
|
|
2013-01-23 04:10:05 +04:00
|
|
|
} else if(anchor == 'home') {
|
|
|
|
|
return 0
|
2013-01-23 05:53:42 +04:00
|
|
|
|
2013-01-23 04:10:05 +04:00
|
|
|
} else if(anchor == 'end') {
|
|
|
|
|
return $('.page').length-1
|
2013-01-23 05:53:42 +04:00
|
|
|
|
2013-01-26 23:45:38 +04:00
|
|
|
// history...
|
2013-01-26 23:48:57 +04:00
|
|
|
// NOTE: these are handled by hashChangeHandler()
|
2013-01-26 23:45:38 +04:00
|
|
|
} else if(anchor == 'back') {
|
|
|
|
|
return anchor
|
|
|
|
|
} else if(anchor == 'forward') {
|
|
|
|
|
return anchor
|
|
|
|
|
|
2013-01-23 05:53:42 +04:00
|
|
|
// relative URLs...
|
|
|
|
|
} else if(anchor == 'next') {
|
|
|
|
|
nextPage()
|
|
|
|
|
return getPageNumber()
|
|
|
|
|
|
|
|
|
|
} else if(anchor == 'prev') {
|
|
|
|
|
prevPage()
|
|
|
|
|
return getPageNumber()
|
|
|
|
|
|
|
|
|
|
} else if(anchor == 'nextArticle') {
|
|
|
|
|
nextArticle()
|
|
|
|
|
return getPageNumber()
|
|
|
|
|
|
|
|
|
|
} else if(anchor == 'prevArticle') {
|
|
|
|
|
prevArticle()
|
|
|
|
|
return getPageNumber()
|
|
|
|
|
|
2013-01-28 18:15:14 +04:00
|
|
|
} else if(anchor == 'nextBookmark') {
|
|
|
|
|
nextBookmark()
|
|
|
|
|
return getPageNumber()
|
|
|
|
|
|
|
|
|
|
} else if(anchor == 'prevBookmark') {
|
|
|
|
|
prevBookmark()
|
|
|
|
|
return getPageNumber()
|
|
|
|
|
|
|
|
|
|
} else if(anchor == 'bookmark'){
|
|
|
|
|
toggleBookmark()
|
|
|
|
|
return getPageNumber()
|
|
|
|
|
|
2013-01-23 05:53:42 +04:00
|
|
|
// hide all visible layers on current page...
|
|
|
|
|
} else if(anchor == 'hideLayers') {
|
|
|
|
|
$('.current.page .shown')
|
|
|
|
|
.addClass('hidden')
|
|
|
|
|
.removeClass('shown')
|
|
|
|
|
return getPageNumber()
|
|
|
|
|
|
2013-01-23 01:37:39 +04:00
|
|
|
} else {
|
2013-01-23 05:53:42 +04:00
|
|
|
var elem = $('[name='+anchor+']')
|
|
|
|
|
n = getPageNumber(elem.parents('.page'))
|
|
|
|
|
// toggle hidden/shown elements...
|
|
|
|
|
if(elem.hasClass('hidden')){
|
|
|
|
|
elem
|
|
|
|
|
.addClass('shown')
|
|
|
|
|
.removeClass('hidden')
|
|
|
|
|
} else if(elem.hasClass('shown')){
|
|
|
|
|
elem
|
|
|
|
|
.addClass('hidden')
|
|
|
|
|
.removeClass('shown')
|
|
|
|
|
}
|
|
|
|
|
return n
|
2013-01-23 01:37:39 +04:00
|
|
|
}
|
|
|
|
|
}
|
2013-02-06 15:44:09 +04:00
|
|
|
// save current state to URL...
|
2013-01-23 01:37:39 +04:00
|
|
|
function saveURLState(){
|
2013-01-23 04:10:05 +04:00
|
|
|
var anchor = window.location.hash.split('#')[1]
|
2013-01-23 05:53:42 +04:00
|
|
|
var elem = $('[name='+anchor+']')
|
|
|
|
|
var page = elem
|
2013-01-23 04:10:05 +04:00
|
|
|
if(!page.hasClass('page')){
|
|
|
|
|
page = page.parents('.page')
|
|
|
|
|
}
|
|
|
|
|
var n = getPageNumber()
|
2013-01-23 05:53:42 +04:00
|
|
|
|
|
|
|
|
// decide which #URLs stay in the URL and which get replaces with a
|
|
|
|
|
// page number...
|
|
|
|
|
if(!elem.hasClass('shown') && !elem.hasClass('hidden')){
|
|
|
|
|
// XXX use real aliases...
|
|
|
|
|
// do not replace these urls with page numbers...
|
2013-01-25 18:19:44 +04:00
|
|
|
if(n == getPageNumber(page)
|
2013-01-23 05:53:42 +04:00
|
|
|
|| (anchor == 'home' && n == 0)
|
|
|
|
|
|| (anchor == 'end' && n == $('.page').length-1)){
|
|
|
|
|
return anchor
|
|
|
|
|
}
|
2013-01-23 04:10:05 +04:00
|
|
|
}
|
2013-02-05 21:14:07 +04:00
|
|
|
|
|
|
|
|
// set the #URL to current mapge number...
|
2013-02-05 17:56:34 +04:00
|
|
|
if(UPDATE_HASH_URL_POSITION){
|
|
|
|
|
window.location.hash = n
|
2013-02-05 21:14:07 +04:00
|
|
|
|
|
|
|
|
// push history state...
|
2013-02-05 19:06:01 +04:00
|
|
|
} else if(FULL_HISTORY_ENABLED){
|
|
|
|
|
window.history.pushState(null, null, '#' + n)
|
2013-02-05 21:14:07 +04:00
|
|
|
|
|
|
|
|
// clear the url if it does not match the current page...
|
2013-02-05 20:59:15 +04:00
|
|
|
} else {
|
2013-02-05 21:35:21 +04:00
|
|
|
// XXX need to do this AFTER the page is changed, and not befor...
|
2013-02-05 21:32:27 +04:00
|
|
|
if(n != parseInt(anchor)
|
|
|
|
|
// do not remove linked pages...
|
|
|
|
|
|| (elem.hasClass('page') && n != getPageNumber(elem))
|
2013-02-06 15:16:48 +04:00
|
|
|
|| n != getPageNumber($(elem).parents('.page'))){
|
2013-02-05 20:59:15 +04:00
|
|
|
window.location.hash = ''
|
|
|
|
|
}
|
2013-02-05 17:56:34 +04:00
|
|
|
}
|
2013-01-23 05:53:42 +04:00
|
|
|
return n
|
2013-01-23 01:37:39 +04:00
|
|
|
}
|
|
|
|
|
|
2013-01-25 18:19:44 +04:00
|
|
|
|
2013-01-23 01:37:39 +04:00
|
|
|
// local storage state managers...
|
2013-02-06 19:25:57 +04:00
|
|
|
function loadStorageState(title){
|
|
|
|
|
if(title == null){
|
|
|
|
|
title = getMagazineTitle()
|
|
|
|
|
}
|
2013-01-31 04:13:25 +04:00
|
|
|
var data = $.jStorage.get(title, {})
|
|
|
|
|
// set the defaults...
|
|
|
|
|
if(data.current_page == null){
|
|
|
|
|
data.current_page = 0
|
2013-01-28 17:14:47 +04:00
|
|
|
}
|
2013-01-31 04:13:25 +04:00
|
|
|
if(data.bookmarks == null){
|
|
|
|
|
data.bookmarks = []
|
|
|
|
|
}
|
|
|
|
|
return data
|
2013-01-23 01:37:39 +04:00
|
|
|
}
|
2013-02-06 19:25:57 +04:00
|
|
|
function saveStorageState(title){
|
|
|
|
|
if(title == null){
|
|
|
|
|
title = getMagazineTitle()
|
|
|
|
|
}
|
|
|
|
|
var data = $.jStorage.get(title, {})
|
|
|
|
|
$.extend(data, {
|
2013-01-31 04:13:25 +04:00
|
|
|
current_page: getPageNumber(),
|
|
|
|
|
bookmarks: buildBookmarkList()
|
|
|
|
|
})
|
2013-02-06 19:25:57 +04:00
|
|
|
$.jStorage.set(title, data)
|
|
|
|
|
return data
|
2013-01-23 01:37:39 +04:00
|
|
|
}
|
2013-02-06 19:25:57 +04:00
|
|
|
function resetStorageState(title){
|
|
|
|
|
if(title == null){
|
|
|
|
|
title = getMagazineTitle()
|
|
|
|
|
}
|
2013-01-31 04:13:25 +04:00
|
|
|
$.jStorage.deleteKey(title)
|
2013-01-30 03:35:34 +04:00
|
|
|
}
|
2013-01-23 01:37:39 +04:00
|
|
|
|
2013-01-25 18:19:44 +04:00
|
|
|
|
2013-02-06 19:25:57 +04:00
|
|
|
// JSON state on local storage...
|
|
|
|
|
// NOTE: these will only load the data, bookmarks and position are
|
|
|
|
|
// ignored...
|
|
|
|
|
function saveJSONStorage(title){
|
|
|
|
|
if(title == null){
|
|
|
|
|
title = getMagazineTitle()
|
|
|
|
|
}
|
|
|
|
|
var data = $.jStorage.get(title, {})
|
|
|
|
|
$.extend(data, {
|
|
|
|
|
// XXX do we need to stringify this??
|
|
|
|
|
'magazine-data': buildJSON()
|
|
|
|
|
})
|
|
|
|
|
$.jStorage.set(title, data)
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
// load JSON magazine data from storage...
|
|
|
|
|
// XXX we're losing the bookmarks at some point...
|
|
|
|
|
function loadJSONStorage(title){
|
|
|
|
|
if(title == null){
|
|
|
|
|
title = getMagazineTitle()
|
|
|
|
|
}
|
|
|
|
|
var data = $.jStorage.get(title, {})
|
|
|
|
|
// NOTE: we are caching the data here because the actual structure
|
|
|
|
|
// is persistent and may get overwritten by loadJSON(...)
|
|
|
|
|
var bookmarks = data.bookmarks
|
|
|
|
|
var current_page = data.current_page
|
|
|
|
|
var json = data['magazine-data']
|
|
|
|
|
if(json != null){
|
|
|
|
|
loadJSON(json)
|
|
|
|
|
loadMagazineUserData(current_page, bookmarks)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// remove JSON magazine data from storage...
|
|
|
|
|
// NOTE: this will resave curent values but will remove the JSON data...
|
|
|
|
|
function clearJSONStorage(title){
|
|
|
|
|
if(title == null){
|
|
|
|
|
title = getMagazineTitle()
|
|
|
|
|
}
|
|
|
|
|
var data = $.jStorage.get(title, {})
|
|
|
|
|
var json = data['magazine-data']
|
|
|
|
|
if(json != null){
|
|
|
|
|
delete data['magazine-data']
|
|
|
|
|
$.jStorage.set(title, data)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-31 22:48:17 +04:00
|
|
|
// generic state managers...
|
|
|
|
|
function loadState(){
|
|
|
|
|
var n = loadURLState()
|
|
|
|
|
var state = loadStorageState()
|
2013-02-06 19:25:57 +04:00
|
|
|
if(n == null){
|
|
|
|
|
n = state.current_page
|
2013-01-31 22:48:17 +04:00
|
|
|
}
|
2013-02-06 19:25:57 +04:00
|
|
|
loadMagazineUserData(n, state.bookmarks)
|
2013-01-31 22:48:17 +04:00
|
|
|
}
|
|
|
|
|
function saveState(){
|
|
|
|
|
saveURLState()
|
|
|
|
|
saveStorageState()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resetState(){
|
|
|
|
|
resetStorageState()
|
|
|
|
|
loadState()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-01 03:08:13 +04:00
|
|
|
/********************************************** JSON serialization ****
|
|
|
|
|
*
|
|
|
|
|
* JSON is used to load/store the magazine data and state.
|
|
|
|
|
*
|
|
|
|
|
* This format may also include local state, like current page number
|
|
|
|
|
* and bookmarks.
|
|
|
|
|
*
|
|
|
|
|
* Format:
|
|
|
|
|
* {
|
|
|
|
|
* title: <magazine-title>,
|
|
|
|
|
* bookmarks: [
|
|
|
|
|
* <page-numer>,
|
|
|
|
|
* ...
|
|
|
|
|
* ],
|
|
|
|
|
* // this is optional...
|
|
|
|
|
* position: <page-number>
|
2013-02-01 17:02:14 +04:00
|
|
|
* // XXX urls are not yet supported...
|
|
|
|
|
* url: <URL>,
|
2013-02-01 03:08:13 +04:00
|
|
|
* pages: [
|
|
|
|
|
* // root <page>...
|
|
|
|
|
* {
|
|
|
|
|
* type: 'page' | 'cover',
|
|
|
|
|
* // classes set on the page element...
|
|
|
|
|
* class: [...]
|
2013-02-01 17:02:14 +04:00
|
|
|
* // XXX urls are not yet supported...
|
|
|
|
|
* url: <URL>,
|
2013-02-01 03:08:13 +04:00
|
|
|
* content: <page-content>
|
|
|
|
|
* },
|
|
|
|
|
*
|
|
|
|
|
* // article...
|
|
|
|
|
* {
|
|
|
|
|
* type: 'article',
|
|
|
|
|
* // classes set on the article element...
|
|
|
|
|
* class: [...]
|
2013-02-01 17:02:14 +04:00
|
|
|
* // XXX urls are not yet supported...
|
|
|
|
|
* url: <URL>,
|
2013-02-01 03:08:13 +04:00
|
|
|
* pages: [
|
|
|
|
|
* <page>,
|
|
|
|
|
* ...
|
|
|
|
|
* ]
|
|
|
|
|
* },
|
|
|
|
|
* ...
|
|
|
|
|
* ]
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* NOTE: content classes are stored in the content...
|
|
|
|
|
* NOTE: at this point all page classes will be stored, but .current
|
|
|
|
|
* will be ignored on restore...
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
2013-02-02 05:46:31 +04:00
|
|
|
var JSON_FORMAT_VERSION = 0.1
|
|
|
|
|
|
|
|
|
|
|
2013-02-01 18:10:24 +04:00
|
|
|
// there are two type of metadata handlers:
|
|
|
|
|
// - 'as-is', this is a trivial read and write value
|
|
|
|
|
// - explicit reader/writer, this will convert the data from html to JSON
|
|
|
|
|
// data and back...
|
|
|
|
|
JSONMetadata = {
|
|
|
|
|
name: 'as-is',
|
|
|
|
|
title: 'as-is',
|
|
|
|
|
authors: {
|
|
|
|
|
reader: function(data){
|
|
|
|
|
// NOTE: this might look odd, but we are using JS .map instead
|
|
|
|
|
// of the jQuery .map, and they have different signatures...
|
|
|
|
|
// ...(index, elem) in jQuery vs. (elem, index) in JS.
|
|
|
|
|
return data.split(',').map(function(e){return e.trim()})
|
|
|
|
|
},
|
|
|
|
|
writer: function(data){
|
|
|
|
|
return data.join(', ')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-02 07:05:21 +04:00
|
|
|
|
|
|
|
|
|
2013-02-01 18:10:24 +04:00
|
|
|
function readMetadata(elem, res, metadata){
|
|
|
|
|
if(res == null){
|
|
|
|
|
res = {}
|
|
|
|
|
}
|
|
|
|
|
if(metadata == null){
|
|
|
|
|
metadata = JSONMetadata
|
|
|
|
|
}
|
|
|
|
|
for(var a in metadata){
|
|
|
|
|
if(elem.attr(a)){
|
|
|
|
|
if(metadata[a] == 'as-is'){
|
|
|
|
|
res[a] = elem.attr(a)
|
|
|
|
|
} else {
|
|
|
|
|
res[a] = metadata[a].reader(elem.attr(a))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
function writeMetadata(elem, res, metadata){
|
|
|
|
|
if(metadata == null){
|
|
|
|
|
metadata = JSONMetadata
|
|
|
|
|
}
|
|
|
|
|
for(var a in metadata){
|
2013-02-06 19:25:57 +04:00
|
|
|
if(res[a] != null){
|
2013-02-01 18:10:24 +04:00
|
|
|
if(metadata[a] == 'as-is'){
|
2013-02-06 19:25:57 +04:00
|
|
|
elem.attr(a, res[a])
|
2013-02-01 18:10:24 +04:00
|
|
|
} else {
|
2013-02-06 19:25:57 +04:00
|
|
|
elem.attr(a, metadata[e].writer(res[a]))
|
2013-02-01 18:10:24 +04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return elem
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-02 07:05:21 +04:00
|
|
|
|
2013-01-31 22:48:17 +04:00
|
|
|
function buildJSON(export_bookmarks, export_position){
|
2013-01-31 17:30:12 +04:00
|
|
|
function _getContent(_, elem){
|
|
|
|
|
elem = $(elem)
|
2013-02-01 17:02:14 +04:00
|
|
|
// page...
|
2013-01-31 17:30:12 +04:00
|
|
|
if(elem.hasClass('page')){
|
2013-02-01 17:02:14 +04:00
|
|
|
var res = {
|
2013-01-31 17:30:12 +04:00
|
|
|
type: elem.hasClass('cover') ? 'cover' : 'page',
|
2013-01-31 17:46:44 +04:00
|
|
|
'class': elem.attr('class'),
|
2013-01-31 17:30:12 +04:00
|
|
|
content: elem.children('.content')[0].outerHTML
|
|
|
|
|
}
|
2013-02-01 17:02:14 +04:00
|
|
|
|
|
|
|
|
// article...
|
2013-01-31 17:30:12 +04:00
|
|
|
} else if(elem.hasClass('article')){
|
2013-02-01 17:02:14 +04:00
|
|
|
var res = {
|
2013-01-31 17:30:12 +04:00
|
|
|
type: 'article',
|
2013-01-31 17:46:44 +04:00
|
|
|
'class': elem.attr('class'),
|
2013-01-31 17:30:12 +04:00
|
|
|
pages: elem.children('.page').map(_getContent).toArray()
|
|
|
|
|
}
|
2013-02-01 17:02:14 +04:00
|
|
|
|
|
|
|
|
// other...
|
2013-02-01 18:10:24 +04:00
|
|
|
// NOTE: with how the selector that maps this is constructed
|
|
|
|
|
// we'll never go into here, but for future compatibility
|
|
|
|
|
// and idiot-proofness this code will stay... for now...
|
2013-02-01 17:02:14 +04:00
|
|
|
} else {
|
|
|
|
|
var res = {
|
|
|
|
|
type: 'raw-html',
|
|
|
|
|
'class': elem.attr('class'),
|
|
|
|
|
content: elem.html()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// metadata...
|
2013-02-01 18:10:24 +04:00
|
|
|
readMetadata(elem, res)
|
2013-02-01 17:02:14 +04:00
|
|
|
|
|
|
|
|
return res
|
2013-01-31 17:30:12 +04:00
|
|
|
}
|
2013-02-01 18:10:24 +04:00
|
|
|
// read the basic metadata set for the magazine...
|
|
|
|
|
var res = readMetadata($('.magazine'))
|
|
|
|
|
res.pages = $('.magazine > .page, .magazine > .article').map(_getContent).toArray(),
|
|
|
|
|
res.bookmarks = export_bookmarks ? buildBookmarkList() : []
|
|
|
|
|
|
2013-02-02 05:46:31 +04:00
|
|
|
res['format-version'] = JSON_FORMAT_VERSION
|
2013-02-02 01:51:08 +04:00
|
|
|
|
2013-01-31 17:30:12 +04:00
|
|
|
if(export_position){
|
|
|
|
|
res.position = getPageNumber()
|
|
|
|
|
}
|
|
|
|
|
return res
|
2013-01-27 23:18:27 +04:00
|
|
|
}
|
2013-01-31 22:48:17 +04:00
|
|
|
|
2013-02-02 08:36:54 +04:00
|
|
|
function loadJSON(data, load_user_data){
|
2013-01-31 17:30:12 +04:00
|
|
|
function _build(block, elem){
|
2013-02-01 18:10:24 +04:00
|
|
|
|
|
|
|
|
// page...
|
2013-01-31 17:30:12 +04:00
|
|
|
if(elem.type == 'page'){
|
2013-02-01 17:02:14 +04:00
|
|
|
var res = createPage(elem.content)
|
2013-01-31 17:46:44 +04:00
|
|
|
.addClass(elem['class'])
|
|
|
|
|
.appendTo(block)
|
2013-01-31 17:30:12 +04:00
|
|
|
|
2013-02-01 18:10:24 +04:00
|
|
|
// cover...
|
2013-01-31 17:30:12 +04:00
|
|
|
} else if(elem.type == 'cover'){
|
2013-02-01 17:02:14 +04:00
|
|
|
var res = createCoverPage(elem.content)
|
2013-01-31 17:46:44 +04:00
|
|
|
.addClass(elem['class'])
|
|
|
|
|
.appendTo(block)
|
2013-01-31 17:30:12 +04:00
|
|
|
|
2013-02-01 18:10:24 +04:00
|
|
|
// article...
|
2013-01-31 17:30:12 +04:00
|
|
|
} else if(elem.type == 'article') {
|
|
|
|
|
// buiold an article...
|
2013-02-01 17:02:14 +04:00
|
|
|
var res = createEmptyArticle()
|
2013-01-31 17:46:44 +04:00
|
|
|
.addClass(elem['class'])
|
2013-01-31 17:30:12 +04:00
|
|
|
.appendTo(block)
|
|
|
|
|
// populate article with pages...
|
|
|
|
|
$(elem.pages).each(function(_, e){
|
2013-02-01 17:02:14 +04:00
|
|
|
_build(res, e)
|
2013-01-31 17:30:12 +04:00
|
|
|
})
|
2013-02-01 18:10:24 +04:00
|
|
|
|
|
|
|
|
// other...
|
|
|
|
|
// NOTE: on a wll-formed JSON we'll never go in here, but just
|
|
|
|
|
// in case...
|
|
|
|
|
} else if(elem.type == 'raw-html') {
|
2013-02-01 17:02:14 +04:00
|
|
|
var res = createPage(elem.content)
|
|
|
|
|
.addClass(elem['class'])
|
|
|
|
|
.appendTo(block)
|
|
|
|
|
}
|
2013-02-01 18:10:24 +04:00
|
|
|
|
2013-02-01 17:02:14 +04:00
|
|
|
// metadata...
|
2013-02-01 18:10:24 +04:00
|
|
|
writeMetadata(elem, res)
|
2013-01-31 17:30:12 +04:00
|
|
|
}
|
2013-02-01 18:10:24 +04:00
|
|
|
|
2013-02-02 01:51:08 +04:00
|
|
|
// XXX check version...
|
2013-02-02 05:46:31 +04:00
|
|
|
var version = data['format-version']
|
2013-02-02 07:16:44 +04:00
|
|
|
if(version != JSON_FORMAT_VERSION){
|
2013-02-02 07:05:21 +04:00
|
|
|
// XXX this might be a good spot to add data conversion between
|
|
|
|
|
// versions...
|
2013-02-02 01:51:08 +04:00
|
|
|
console.warn('WARNING: JSON Format Version Mismatch.')
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-01 18:10:24 +04:00
|
|
|
// create an empty magazine...
|
2013-01-31 18:19:33 +04:00
|
|
|
var mag = createEmptyMagazine(data.title)
|
2013-02-06 19:25:57 +04:00
|
|
|
// XXX for some reason this does not restore name/title...
|
2013-02-01 18:10:24 +04:00
|
|
|
writeMetadata(mag, data)
|
|
|
|
|
// build the actual strcture...
|
2013-01-31 17:30:12 +04:00
|
|
|
$(data.pages).each(function(_, e){
|
|
|
|
|
_build(mag, e)
|
|
|
|
|
})
|
2013-01-31 17:46:44 +04:00
|
|
|
// remove service classes...
|
|
|
|
|
mag.children('.current.page').removeClass('current')
|
2013-01-31 22:39:45 +04:00
|
|
|
loadMagazineData(mag)
|
|
|
|
|
|
2013-02-02 08:36:54 +04:00
|
|
|
if(load_user_data){
|
|
|
|
|
loadMagazineUserData(data.position, data.bookmarks)
|
2013-01-31 22:39:45 +04:00
|
|
|
}
|
2013-01-27 23:18:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-01-25 18:19:44 +04:00
|
|
|
|
2013-01-31 18:19:33 +04:00
|
|
|
/***************************************************** constructor ***/
|
|
|
|
|
// These function will construct detached magazine building blocks...
|
2013-01-28 18:15:14 +04:00
|
|
|
|
2013-01-31 06:35:23 +04:00
|
|
|
// basic constructors...
|
2013-01-31 18:19:33 +04:00
|
|
|
function createEmptyMagazine(title){
|
2013-01-31 06:35:23 +04:00
|
|
|
return $('<div/>')
|
|
|
|
|
.addClass('magazine')
|
|
|
|
|
.attr({
|
|
|
|
|
title: title
|
|
|
|
|
})
|
|
|
|
|
}
|
2013-01-31 18:19:33 +04:00
|
|
|
function createMagazine(title, magazine_cover, article_cover){
|
2013-01-31 06:35:23 +04:00
|
|
|
if(magazine_cover == null){
|
|
|
|
|
magazine_cover = title
|
|
|
|
|
}
|
|
|
|
|
if(article_cover == null){
|
|
|
|
|
article_cover = 'Article'
|
|
|
|
|
}
|
2013-01-31 18:19:33 +04:00
|
|
|
return createEmptyMagazine(title)
|
2013-01-31 06:35:23 +04:00
|
|
|
// a magazine by default has a cover...
|
2013-01-31 18:19:33 +04:00
|
|
|
.append(createCoverPage(magazine_cover))
|
|
|
|
|
.append(createArticle(article_cover))
|
2013-01-31 06:35:23 +04:00
|
|
|
}
|
2013-02-01 03:08:13 +04:00
|
|
|
|
|
|
|
|
|
2013-01-31 18:19:33 +04:00
|
|
|
function createEmptyArticle(){
|
2013-01-31 06:35:23 +04:00
|
|
|
return $('<div/>')
|
|
|
|
|
.addClass('article')
|
|
|
|
|
}
|
2013-01-31 18:19:33 +04:00
|
|
|
function createArticle(template){
|
|
|
|
|
return createEmptyArticle()
|
|
|
|
|
.append(createCoverPage(template))
|
2013-01-31 06:35:23 +04:00
|
|
|
}
|
2013-02-01 03:08:13 +04:00
|
|
|
|
|
|
|
|
|
2013-01-31 22:39:45 +04:00
|
|
|
function createPage(data){
|
|
|
|
|
var page = $('<div/>')
|
2013-01-31 06:35:23 +04:00
|
|
|
.addClass('page')
|
2013-01-31 22:39:45 +04:00
|
|
|
|
|
|
|
|
var jdata = $(data)
|
|
|
|
|
if(jdata.hasClass('content')){
|
|
|
|
|
return page.append(jdata)
|
|
|
|
|
} else {
|
|
|
|
|
return page.append($('<div/>')
|
2013-01-31 06:35:23 +04:00
|
|
|
.addClass('content')
|
2013-01-31 22:39:45 +04:00
|
|
|
.html(data))
|
|
|
|
|
}
|
2013-01-31 06:35:23 +04:00
|
|
|
}
|
2013-01-31 22:39:45 +04:00
|
|
|
function createCoverPage(data){
|
|
|
|
|
return createPage(data).addClass('cover')
|
2013-01-31 06:35:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-01-31 18:19:33 +04:00
|
|
|
|
|
|
|
|
|
2013-02-02 07:35:17 +04:00
|
|
|
/******************************************************* templates ***/
|
2013-02-02 05:46:31 +04:00
|
|
|
|
2013-02-02 06:46:33 +04:00
|
|
|
// NOTE: for these to be self-aplicable they must only replace the content
|
|
|
|
|
// of the matched elements and not touch the element itself.
|
2013-02-02 05:46:31 +04:00
|
|
|
var MagazineTemplates = {
|
|
|
|
|
|
|
|
|
|
// setup titles...
|
|
|
|
|
'.magazine-title-text': function(elem){
|
2013-02-06 19:28:18 +04:00
|
|
|
elem.text(getMagazineTitle()
|
2013-02-02 05:46:31 +04:00
|
|
|
|| 'PortableMag')
|
|
|
|
|
},
|
|
|
|
|
|
2013-02-02 06:46:33 +04:00
|
|
|
// setup page numbers...
|
|
|
|
|
'.page-number-text': function(elem){
|
|
|
|
|
elem.each(function(_, e){
|
|
|
|
|
var e = $(e)
|
|
|
|
|
e.text(getPageNumber(e.parents('.page')))
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// magazine index...
|
2013-02-02 06:57:26 +04:00
|
|
|
// XXX ugly code, revise...
|
2013-02-02 06:25:27 +04:00
|
|
|
'.article-index': function(elem){
|
|
|
|
|
var list = $('<ul/>')
|
|
|
|
|
var mag = $('.magazine')
|
|
|
|
|
// get the articles...
|
|
|
|
|
$('.magazine .article .cover h1').each(function(i, e){
|
|
|
|
|
e = $(e)
|
|
|
|
|
var lnk = $('<a/>')
|
|
|
|
|
.attr('href', '#' + getPageNumber(e.parents('.page').first()))
|
|
|
|
|
// XXX is this the right way to go?
|
|
|
|
|
.text(e.text() || 'No title')
|
|
|
|
|
|
|
|
|
|
list.append(
|
|
|
|
|
$('<li/>')
|
|
|
|
|
.append(lnk))
|
|
|
|
|
})
|
|
|
|
|
var root = $('<ul/>')
|
|
|
|
|
.append($('<li/>')
|
|
|
|
|
.append($('<a/>')
|
|
|
|
|
.attr('href', '#' + getPageNumber($('.magazine > .cover').first()))
|
|
|
|
|
// XXX is this the right way to go?
|
2013-02-06 19:28:18 +04:00
|
|
|
.text(getMagazineTitle()
|
2013-02-02 06:25:27 +04:00
|
|
|
|| 'Magazine')))
|
|
|
|
|
root.append(list)
|
|
|
|
|
elem
|
2013-02-02 06:46:33 +04:00
|
|
|
// remove the original content...
|
2013-02-02 06:25:27 +04:00
|
|
|
.html('')
|
|
|
|
|
// cover...
|
|
|
|
|
.append(root)
|
2013-02-02 06:46:33 +04:00
|
|
|
}
|
2013-02-02 05:46:31 +04:00
|
|
|
}
|
|
|
|
|
|
2013-02-02 06:46:33 +04:00
|
|
|
|
2013-02-02 05:46:31 +04:00
|
|
|
function runMagazineTemplates(){
|
|
|
|
|
for(var tpl in MagazineTemplates){
|
|
|
|
|
MagazineTemplates[tpl]($(tpl))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-02-02 08:36:54 +04:00
|
|
|
|
2013-02-02 07:35:17 +04:00
|
|
|
/******************************************* basic magazine editor ***/
|
2013-02-02 08:36:54 +04:00
|
|
|
// NOTE: these are mostly needed for loading magazines...
|
2013-01-31 18:19:33 +04:00
|
|
|
|
2013-02-01 03:08:13 +04:00
|
|
|
// load the data...
|
2013-01-31 22:39:45 +04:00
|
|
|
function loadMagazineData(mag){
|
2013-01-31 18:19:33 +04:00
|
|
|
removeMagazine()
|
|
|
|
|
mag.appendTo($('.aligner'))
|
2013-02-02 08:36:54 +04:00
|
|
|
$('.viewer').trigger('magazineDataLoaded')
|
2013-01-31 22:39:45 +04:00
|
|
|
return mag
|
|
|
|
|
}
|
2013-02-02 07:35:17 +04:00
|
|
|
|
2013-02-02 08:36:54 +04:00
|
|
|
// NOTE: this needs to be called once per magazine load...
|
|
|
|
|
function loadMagazineChrome(){
|
|
|
|
|
setupBookmarkTouchZones()
|
|
|
|
|
runMagazineTemplates()
|
|
|
|
|
updateView()
|
|
|
|
|
$('.viewer').trigger('magazineChromeLoaded')
|
|
|
|
|
}
|
2013-02-02 07:35:17 +04:00
|
|
|
|
2013-02-01 03:08:13 +04:00
|
|
|
// load chrome elements like bookmarks and navigator....
|
2013-02-02 08:36:54 +04:00
|
|
|
function loadMagazineUserData(position, bookmarks){
|
2013-02-02 05:46:31 +04:00
|
|
|
if(position){
|
|
|
|
|
setCurrentPage(position)
|
|
|
|
|
}
|
|
|
|
|
if(bookmarks){
|
|
|
|
|
loadBookmarks(bookmarks != null ? bookmarks : [])
|
|
|
|
|
}
|
2013-01-31 22:39:45 +04:00
|
|
|
}
|
|
|
|
|
|
2013-01-31 18:19:33 +04:00
|
|
|
|
2013-01-29 21:36:19 +04:00
|
|
|
// XXX some things get really surprized when this is called, make things
|
|
|
|
|
// work with the mag cleared...
|
2013-01-31 18:19:33 +04:00
|
|
|
// XXX do we need to clear the event handlers here?
|
2013-02-01 02:14:40 +04:00
|
|
|
// ...this mostly concerns bookmarking and how jQuery handles events
|
|
|
|
|
// on removed elements -- unbind and remove or just forget about it?
|
2013-01-31 18:19:33 +04:00
|
|
|
function removeMagazine(){
|
2013-01-29 21:30:53 +04:00
|
|
|
$('.magazine').remove()
|
2013-02-02 08:36:54 +04:00
|
|
|
$('.viewer').trigger('magazineRemoved')
|
2013-01-28 17:14:47 +04:00
|
|
|
}
|
|
|
|
|
|
2013-01-23 01:37:39 +04:00
|
|
|
|
2013-01-25 18:19:44 +04:00
|
|
|
|
2013-01-23 01:37:39 +04:00
|
|
|
/*********************************************************************/
|
|
|
|
|
// vim:set ts=4 sw=4 :
|