-
Notifications
You must be signed in to change notification settings - Fork 410
/
SinglePageView.coffee
86 lines (73 loc) · 2.61 KB
/
SinglePageView.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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