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

View File

@ -309,7 +309,9 @@ function setElementTransform(elem, offset, scale, duration){
var scale = getElementScale(elem) var scale = getElementScale(elem)
} }
if(USE_TRANSFORM){ 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({ elem.css({
'-ms-transform' : transform, '-ms-transform' : transform,
'-webkit-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 make this a drop-in replacement for setElementTransform...
// XXX cleanup, still flacky... // 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... // stop all ongoing animations on the current elem...
stopAnimation(elem) stopAnimation(elem)
use_transitions = use_transitions != null ?
use_transitions
: USE_TRANSITIONS_FOR_ANIMATION
// use transition for animation... // use transition for animation...
if(USE_TRANSITIONS_FOR_ANIMATION){ if(use_transitions){
setTransitionEasing(elem, easing) setTransitionEasing(elem, easing)
duration == null && setTransitionDuration(elem, duration) duration == null && setTransitionDuration(elem, duration)
setElementTransform(elem, to) setElementTransform(elem, to)
@ -526,7 +531,7 @@ var getAnimationFrame = (window.requestAnimationFrame
|| window.oRequestAnimationFrame || window.oRequestAnimationFrame
|| window.msRequestAnimationFrame || window.msRequestAnimationFrame
|| function(callback){ || function(callback){
window.setTimeout(callback, 1000 / 60) setTimeout(callback, 1000/60)
}) })
var cancelAnimationFrame = (window.cancelRequestAnimationFrame 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 // NOTE: this will be wrong during a transition, that's why we
// can pass the pre-calculated offset as an argument... // 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... // center the pages correctly...
// NOTE: this is the main reason we need width, and we can get it // NOTE: this is the main reason we need width, and we can get it
@ -661,10 +663,17 @@ function goToMagazineEnd(){
} }
function goToArticleCover(){ function goToArticleCover(){
// try and get the actual first cover... // 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){ if(cover.length == 0){
// no cover, get the first page... // 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 { } else {
return setCurrentPage(cover) return setCurrentPage(cover)
} }
@ -1227,7 +1236,10 @@ function buildJSON(export_bookmarks, export_position){
var res = { var res = {
type: 'group', type: 'group',
'class': elem.attr('class'), 'class': elem.attr('class'),
pages: elem.children('.page').map(_getContent).toArray() pages: elem
.children('.page')
.map(_getContent)
.toArray()
} }
// article... // article...
@ -1235,7 +1247,10 @@ function buildJSON(export_bookmarks, export_position){
var res = { var res = {
type: 'article', type: 'article',
'class': elem.attr('class'), 'class': elem.attr('class'),
pages: elem.children('.page, .group').map(_getContent).toArray() pages: elem
.children('.page, .group')
.map(_getContent)
.toArray()
} }
// other... // other...
@ -1256,7 +1271,9 @@ function buildJSON(export_bookmarks, export_position){
} }
// read the basic metadata set for the magazine... // read the basic metadata set for the magazine...
var res = readMetadata($('.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.bookmarks = export_bookmarks ? buildBookmarkList() : []
res['format-version'] = JSON_FORMAT_VERSION res['format-version'] = JSON_FORMAT_VERSION
@ -1439,9 +1456,11 @@ var MagazineTemplates = {
$('.magazine .article .cover h1').each(function(i, e){ $('.magazine .article .cover h1').each(function(i, e){
e = $(e) e = $(e)
var lnk = $('<a/>') 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? // XXX is this the right way to go?
.text(e.text() || 'No title') .text(e.text()
|| 'No title')
list.append( list.append(
$('<li/>') $('<li/>')
@ -1450,7 +1469,8 @@ var MagazineTemplates = {
var root = $('<ul/>') var root = $('<ul/>')
.append($('<li/>') .append($('<li/>')
.append($('<a/>') .append($('<a/>')
.attr('href', '#' + getPageNumber($('.magazine > .cover').first())) .attr('href', '#' +
getPageNumber($('.magazine > .cover').first()))
// XXX is this the right way to go? // XXX is this the right way to go?
.text(getMagazineTitle() .text(getMagazineTitle()
|| 'Magazine'))) || 'Magazine')))