Skip to content

Commit

Permalink
Handling edge case of zero remainder to the start of the book
Browse files Browse the repository at this point in the history
  • Loading branch information
marvindanig committed Dec 3, 2016
1 parent 100a13a commit 47c5969
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
35 changes: 25 additions & 10 deletions lib/flippy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import '../modules/graph.js'
}

flip(page_no) {
_book.current_page = page_no
console.log(_book.current_page)
_book.currentPage = page_no
console.log(_book.currentPage)
//TODO: Calculate pages and print the book
}
}
Expand Down Expand Up @@ -51,9 +51,9 @@ import '../modules/graph.js'

console.log('STARTPAGE', settings.start_page)

_book.current_page = (settings.start_page === undefined) ? 1 : parseInt(settings.start_page) > 0 ? (parseInt(settings.start_page) % parseInt(_book.pages.length)) : parseInt(_book.pages.length) + parseInt(settings.start_page) % parseInt(_book.pages.length)
_book.currentPage = (settings.start_page === undefined) ? 1 : parseInt(settings.start_page) > 0 ? parseInt(settings.start_page) % parseInt(_book.pages.length) : (parseInt(settings.start_page) % parseInt(_book.pages.length) !== 0) ? parseInt(_book.pages.length) + 1 + parseInt(settings.start_page) % parseInt(_book.pages.length) : 1

_setViewAndRange(_book.current_page)
_setViewAndRange(_book.currentPage)

_printBook()

Expand Down Expand Up @@ -94,18 +94,33 @@ import '../modules/graph.js'
return newWrapper
}

function _setViewAndRange(current_page = 1) {
function _setViewAndRange(currentPage = 1) {

/***
@range = _book.pages.slice(P , Q) where:
P & Q are integers
P & Q may or may not lie in the range 0 < VALUES < 2N (_book.length)
***/


switch (_book.mode) {
case 'portrait':
_book.view = [parseInt(current_page)]
_book.range = _book.pages.slice(parseInt(_book.view[0]) - 3, parseInt(_book.view[0]) + 3)
_book.view = [parseInt(currentPage)]

// _book.range = _book.pages.slice(parseInt(_book.view[0]) - 3, parseInt(_book.view[0]) + 3)

let p = 'a'
let q = 'b'

console.log('P, Q= ' + p + ' , ' + q)

// _book.range = _book.pages.slice(parseInt(p, q))

break

case 'landscape':
if (isEven(parseInt(current_page))) { _book.view = [parseInt(current_page), parseInt(current_page + 1)] }
if (isOdd(parseInt(current_page))) { _book.view = [parseInt(current_page - 1), parseInt(current_page)] }
if (isEven(parseInt(currentPage))) { _book.view = [parseInt(currentPage), parseInt(currentPage + 1)] }
if (isOdd(parseInt(currentPage))) { _book.view = [parseInt(currentPage - 1), parseInt(currentPage)] }

_book.range = _book.pages.slice(parseInt(_book.view[0]) - 3, parseInt(_book.view[1]) + 2)

Expand All @@ -128,7 +143,7 @@ import '../modules/graph.js'
// _printView(_book.node)


console.log('CURRENT PAGE', _book.current_page)
console.log('CURRENT PAGE', _book.currentPage)

console.log('VIEW', _book.view)

Expand Down
2 changes: 1 addition & 1 deletion lib/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import '../lib/flippy.js'
/****** Initialize Flippy ********/
/**********************************/

let settings = { duration: 100, animation: true, curl: true, peel: true, zoom: false, start_page: -4 }
let settings = { duration: 100, animation: true, curl: true, peel: true, zoom: false, start_page: -1 }

let node = document.getElementById('book')

Expand Down

0 comments on commit 47c5969

Please sign in to comment.