diff --git a/BookReader/Plugins/SinglePageView/SinglePageView.coffee b/BookReader/Plugins/SinglePageView/SinglePageView.coffee new file mode 100644 index 000000000..60e8590b9 --- /dev/null +++ b/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 = $("
") + + leftPageEl = $("
") + rightPageEl = $("
") + @imageElement = $("") + @imageContainer = $("
") + @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 +* 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 \ No newline at end of file diff --git a/BookReader/Plugins/SinglePageView/SinglePageView.js b/BookReader/Plugins/SinglePageView/SinglePageView.js new file mode 100644 index 000000000..a2890b782 --- /dev/null +++ b/BookReader/Plugins/SinglePageView/SinglePageView.js @@ -0,0 +1,90 @@ +(function() { + var SinglePageViewPlugin; + var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; + SinglePageViewPlugin = (function() { + function SinglePageViewPlugin() { + this.bookReaderObject = null; + this.parentElement = null; + this.imageElement = null; + this.currentIndex = null; + this.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 + * + */ + SinglePageViewPlugin.prototype.init = function(bookReaderObject, parentElement) { + var leftPageEl, rightPageEl; + this.bookReaderObject = bookReaderObject; + this.parentElement = parentElement; + this.viewContainer = $("
"); + leftPageEl = $("
"); + rightPageEl = $("
"); + this.imageElement = $(""); + this.imageContainer = $("
"); + this.imageContainer.append(this.imageElement); + this.viewContainer.append(leftPageEl); + this.viewContainer.append(rightPageEl); + this.viewContainer.append(this.imageContainer); + this.parentElement.append(this.viewContainer); + this.currentIndex = this.bookReaderObject.getCurrentIndex(); + this.bookReaderObject.parentElement.bind('indexUpdated', __bind(function(data) { + this.previousIndex = this.currentIndex; + this.currentIndex = this.bookReaderObject.getCurrentIndex(); + return this.eventIndexUpdated(); + }, this)); + this.parentElement.bind('left', __bind(function() { + if (this.currentIndex > 1) { + return this.bookReaderObject.jumpToIndex(this.currentIndex - 1); + } + }, this)); + parentElement.bind('right', __bind(function() { + if (this.currentIndex < this.bookReaderObject.getNumPages()) { + return this.bookReaderObject.jumpToIndex(this.currentIndex + 1); + } + }, this)); + leftPageEl.bind('click', __bind(function() { + return this.parentElement.trigger('left'); + }, this)); + rightPageEl.bind('click', __bind(function() { + return this.parentElement.trigger('right'); + }, this)); + /* + * 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 + */ + return this.showCurrentIndex(); + }; + /* + * showCurrentIndex() + * + * showCurrentIndex() will update the height, width, and href attributes of the + * tag that is displaying the current page + */ + SinglePageViewPlugin.prototype.showCurrentIndex = function() { + this.imageElement.attr({ + height: this.bookReaderObject.getPageHeight(this.currentIndex), + width: this.bookReaderObject.getPageWidth(this.currentIndex), + src: this.bookReaderObject.getPageURI(this.currentIndex) + }); + this.viewContainer.width(40 + this.bookReaderObject.getPageWidth(this.currentIndex)); + return this.imageContainer.width(this.bookReaderObject.getPageWidth(this.currentIndex)); + }; + /* + * eventIndexUpdated() + * + * eventIndexUpdated() will update the current index and the DOM. This is where + * page turning animations can be tied in. + */ + SinglePageViewPlugin.prototype.eventIndexUpdated = function() { + return this.showCurrentIndex(); + }; + return SinglePageViewPlugin; + })(); + this.SinglePageViewPlugin = SinglePageViewPlugin; +}).call(this);