house keeping and cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-02-26 22:50:52 +04:00
parent c677045d3f
commit e7028f2d65
3 changed files with 51 additions and 18 deletions

View File

@ -28,7 +28,8 @@ var togglePageFitMode = createCSSClassToggler(
if(action == 'on'){
var n = getPageNumber()
var scale = getMagazineScale()
$('.page:not(.no-resize)').width($('.viewer').width()/scale)
$('.page:not(.no-resize)')
.width($('.viewer').width() / scale)
} else {
var n = getPageNumber()
$('.page:not(.no-resize)').width('')
@ -205,11 +206,15 @@ function handleScrollRelease(evt, data){
} else {
if(at > first){
//animateElementTo(mag, first, DEFAULT_TRANSITION_DURATION, 'ease-in')
animateElementTo(mag, first, DEFAULT_TRANSITION_DURATION, 'cubic-bezier(0.33,0.66,0.66,1)')
animateElementTo(mag, first,
DEFAULT_TRANSITION_DURATION,
'cubic-bezier(0.33,0.66,0.66,1)')
} else if(at < last){
//animateElementTo(mag, last, DEFAULT_TRANSITION_DURATION, 'ease-in')
animateElementTo(mag, last, DEFAULT_TRANSITION_DURATION, 'cubic-bezier(0.33,0.66,0.66,1)')
animateElementTo(mag, last,
DEFAULT_TRANSITION_DURATION,
'cubic-bezier(0.33,0.66,0.66,1)')
}
}
}
@ -317,7 +322,7 @@ function setMagazineScale(scale){
/********************************************************* actions ***/
function setCurrentPage(n){
function setCurrentPage(n, use_transitions){
if(n == null){
n = getPageNumber()
}
@ -329,6 +334,9 @@ function setCurrentPage(n){
n = n < 0 ? l - n : n
n = n < -l ? 0 : n
n = n >= l ? l - 1 : n
use_transitions = use_transitions != null ?
use_transitions
: USE_TRANSITIONS_FOR_ANIMATION
$('.current.page').removeClass('current')
$($('.page')[n]).addClass('current')
@ -339,7 +347,7 @@ function setCurrentPage(n){
var align = togglePageView('?') == 'off' ? 'center' : null
var left = getMagazineOffset(cur, null, align)
if(USE_TRANSITIONS_FOR_ANIMATION){
if(use_transitions){
setElementTransform($('.magazine'), left)
} else {

View File

@ -309,7 +309,9 @@ function setElementTransform(elem, offset, scale, duration){
var scale = getElementScale(elem)
}
if(USE_TRANSFORM){
var transform = 'translate('+ Math.round(offset.left) +'px, '+ Math.round(offset.top) +'px) scale('+ scale +') ' + t3d
var transform = 'translate('+
Math.round(offset.left) +'px, '+
Math.round(offset.top) +'px) scale('+ scale +') ' + t3d
elem.css({
'-ms-transform' : transform,
'-webkit-transform' : transform,
@ -347,11 +349,14 @@ var USE_TRANSITIONS_FOR_ANIMATION = false
// XXX make this a drop-in replacement for setElementTransform...
// XXX cleanup, still flacky...
function animateElementTo(elem, to, duration, easing, speed){
function animateElementTo(elem, to, duration, easing, speed, use_transitions){
// stop all ongoing animations on the current elem...
stopAnimation(elem)
use_transitions = use_transitions != null ?
use_transitions
: USE_TRANSITIONS_FOR_ANIMATION
// use transition for animation...
if(USE_TRANSITIONS_FOR_ANIMATION){
if(use_transitions){
setTransitionEasing(elem, easing)
duration == null && setTransitionDuration(elem, duration)
setElementTransform(elem, to)
@ -526,7 +531,7 @@ var getAnimationFrame = (window.requestAnimationFrame
|| window.oRequestAnimationFrame
|| window.msRequestAnimationFrame
|| function(callback){
window.setTimeout(callback, 1000 / 60)
setTimeout(callback, 1000/60)
})
var cancelAnimationFrame = (window.cancelRequestAnimationFrame

View File

@ -637,7 +637,9 @@ function setCurrentPage(n, offset, width){
// NOTE: this will be wrong during a transition, that's why we
// can pass the pre-calculated offset as an argument...
shiftMagazineTo(-(offset == null ? cur.position()['left']/getMagazineScale() : offset))
shiftMagazineTo(-(offset == null ?
cur.position()['left']/getMagazineScale()
: offset))
// center the pages correctly...
// NOTE: this is the main reason we need width, and we can get it
@ -661,10 +663,17 @@ function goToMagazineEnd(){
}
function goToArticleCover(){
// try and get the actual first cover...
var cover = $('.current.page').parents('.article').find('.cover.page').first()
var cover = $('.current.page')
.parents('.article')
.find('.cover.page')
.first()
if(cover.length == 0){
// no cover, get the first page...
return setCurrentPage($('.current.page').parents('.article').find('.page').first())
return setCurrentPage(
$('.current.page')
.parents('.article')
.find('.page')
.first())
} else {
return setCurrentPage(cover)
}
@ -1227,7 +1236,10 @@ function buildJSON(export_bookmarks, export_position){
var res = {
type: 'group',
'class': elem.attr('class'),
pages: elem.children('.page').map(_getContent).toArray()
pages: elem
.children('.page')
.map(_getContent)
.toArray()
}
// article...
@ -1235,7 +1247,10 @@ function buildJSON(export_bookmarks, export_position){
var res = {
type: 'article',
'class': elem.attr('class'),
pages: elem.children('.page, .group').map(_getContent).toArray()
pages: elem
.children('.page, .group')
.map(_getContent)
.toArray()
}
// other...
@ -1256,7 +1271,9 @@ function buildJSON(export_bookmarks, export_position){
}
// read the basic metadata set for the magazine...
var res = readMetadata($('.magazine'))
res.pages = $('.magazine > .page, .magazine > .article').map(_getContent).toArray(),
res.pages = $('.magazine > .page, .magazine > .article')
.map(_getContent)
.toArray(),
res.bookmarks = export_bookmarks ? buildBookmarkList() : []
res['format-version'] = JSON_FORMAT_VERSION
@ -1439,9 +1456,11 @@ var MagazineTemplates = {
$('.magazine .article .cover h1').each(function(i, e){
e = $(e)
var lnk = $('<a/>')
.attr('href', '#' + getPageNumber(e.parents('.page').first()))
.attr('href', '#' +
getPageNumber(e.parents('.page').first()))
// XXX is this the right way to go?
.text(e.text() || 'No title')
.text(e.text()
|| 'No title')
list.append(
$('<li/>')
@ -1450,7 +1469,8 @@ var MagazineTemplates = {
var root = $('<ul/>')
.append($('<li/>')
.append($('<a/>')
.attr('href', '#' + getPageNumber($('.magazine > .cover').first()))
.attr('href', '#' +
getPageNumber($('.magazine > .cover').first()))
// XXX is this the right way to go?
.text(getMagazineTitle()
|| 'Magazine')))