Skip to content

Commit

Permalink
Initial commit of new-style one-page view plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jgsmith committed Sep 21, 2011
1 parent 5b1ca1a commit 6b4ae14
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 0 deletions.
86 changes: 86 additions & 0 deletions BookReader/Plugins/SinglePageView/SinglePageView.coffee
@@ -0,0 +1,86 @@
class SinglePageViewPlugin
constructor: () ->
@bookReaderObject = null
@parentElement = null
@imageElement = null
@currentIndex = null
@previousIndex = null

###
* init(bookReaderObject, parentElement)
*
* input: bookReaderObject representing the core book reader manager
* parentElement representing the HTML DOM element within which the plugin can do what it wants
*
* init(...) will initialize the DOM and display the page associated with the current index
*
###
init: (bookReaderObject, parentElement) ->
@bookReaderObject = bookReaderObject
@parentElement = parentElement

@viewContainer = $("<div class='single-page-view'></div>")

leftPageEl = $("<div class='left-page'></div>")
rightPageEl = $("<div class='right-page'></div>")
@imageElement = $("<img />")
@imageContainer = $("<div class='image'></div>")
@imageContainer.append @imageElement
@viewContainer.append leftPageEl
@viewContainer.append rightPageEl
@viewContainer.append @imageContainer
@parentElement.append @viewContainer

@currentIndex = @bookReaderObject.getCurrentIndex()

@bookReaderObject.parentElement.bind 'indexUpdated', (data) =>
@previousIndex = @currentIndex
@currentIndex = @bookReaderObject.getCurrentIndex()
@eventIndexUpdated()

@parentElement.bind 'left', () =>
if @currentIndex > 1
@bookReaderObject.jumpToIndex @currentIndex-1

parentElement.bind 'right', () =>
if @currentIndex < @bookReaderObject.getNumPages()
@bookReaderObject.jumpToIndex @currentIndex+1

leftPageEl.bind 'click', () =>
@parentElement.trigger 'left'

rightPageEl.bind 'click', () =>
@parentElement.trigger 'right'

###
* We may need to bind to events that handle advancing and retreating pages
* since the presentation/view plugin knows how many pages are being shown
###
@showCurrentIndex()

###
* showCurrentIndex()
*
* showCurrentIndex() will update the height, width, and href attributes of the <img/>
* tag that is displaying the current page
###
showCurrentIndex: () ->
@imageElement.attr
height: @bookReaderObject.getPageHeight @currentIndex
width: @bookReaderObject.getPageWidth @currentIndex
src: @bookReaderObject.getPageURI @currentIndex
@viewContainer.width 40 + @bookReaderObject.getPageWidth @currentIndex
@imageContainer.width @bookReaderObject.getPageWidth @currentIndex

###
* eventIndexUpdated()
*
* eventIndexUpdated() will update the current index and the DOM. This is where
* page turning animations can be tied in.
###
eventIndexUpdated: () ->
@showCurrentIndex()

this.SinglePageViewPlugin = SinglePageViewPlugin
if br?
br.registerPluginClass SinglePageViewPlugin
90 changes: 90 additions & 0 deletions BookReader/Plugins/SinglePageView/SinglePageView.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6b4ae14

Please sign in to comment.