+
+pettanr.reader = pettanr.view.registerApplication( function(){
+ var jqWrap, jqPanelContainer,
+ windowW, windowH,
+ headerH = pettanr.util.getElementSize( document.getElementById( 'comic-reader-header' ) ).height,
+ consoleH = pettanr.util.getElementSize( document.getElementById( 'comic-reader-console' ) ).height,
+ panelMargin,
+ elmContainer = document.getElementById( 'comic-reader-panel-container' ),
+ elmTitle = document.getElementById( 'comic-reader-title' ).firstChild,
+ elmAuthor = document.getElementById( 'comic-reader-author' ).firstChild,
+ elmBackButton = document.getElementById( 'comic-reader-back-button' ),
+ elmNextButton = document.getElementById( 'comic-reader-forward-button' ),
+ ID = 'comicReader',
+ bindWorker = null,
+ currentFile = null;
+ comicData = null,
+ currentPanel = null,
+ currentIndex = 0,
+ numPanel = 0,
+ instance = this;
+
+ function onBackClick(){
+ currentIndex -= ( currentIndex > 0 ? 1 : 0 );
+ slide();
+ return false;
+ }
+ function onNextClick(){
+ currentIndex += ( currentIndex < numPanel - 1 ? 1 : 0 );
+ slide();
+ return false;
+ }
+ function slide(){
+ var elm = elmContainer.childNodes[ currentIndex ],
+ h = windowH - headerH - consoleH,
+ top = headerH;
+ if( elm ){
+ top = headerH - elm.offsetTop + Math.floor( ( h - elm.offsetHeight ) / 2 );
+ }
+
+ jqPanelContainer.stop().animate( {
+ top: top
+ });
+ }
+ function getCurrentTopPosition(){
+
+ }
+ function draw(){
+ var fileData, title, author;
+
+ if( pettanr.driver.isPettanrFileInstance( currentFile ) === true ){
+ if( currentFile.getType() === pettanr.driver.FILE_TYPE.COMIC ){
+ fileData = currentFile.read();
+ title = fileData.title;
+ author = fileData.author.name;
+ comicData = fileData;
+ numPanel = currentFile.getChildFileLength();
+ } else
+ if( currentFile.getType() === pettanr.driver.FILE_TYPE.PANEL ){
+ fileData = currentFile.read();
+ title = fileData.comic.title;
+ author = fileData.comic.author.name;
+ comicData = fileData;
+ numPanel = 1;
+ }
+ } else {
+
+ }
+
+ if( comicData !== null ){
+ elmTitle.data = title;
+ elmAuthor.data = author;
+ bindWorker.json( comicData );
+ window.setTimeout( asyncResize, 0 );
+ }
+ }
+ function asyncResize(){
+ instance.onPaneResize( windowW, windowH );
+ }
+
+ /* grobal method */
+ // this.rootElement = elmWrap;
+ this.displayName = ID;
+ this.ID = ID;
+ this.rootElement = document.getElementById( 'comic-reader-wrapper' );
+ this.MIN_WIDTH = 320;
+ this.MIN_HEIGHT = 320;
+ this.init = function(){
+ jqWrap = $( instance.rootElement );
+ jqPanelContainer = $( elmContainer );
+
+ elmBackButton.onclick = onBackClick;
+ elmNextButton.onclick = onNextClick;
+
+ bindWorker = pettanr.bind.createBindWorker( elmContainer, null, false, false );
+
+ delete instance.init;
+ }
+ this.onOpen = function( _w, _h, _file ){
+ instance.init && instance.init();
+ numPanel = currentIndex = 0;
+
+ jqWrap.show();
+ jqPanelContainer.css({
+ left: _w / 2,
+ top: _h
+ });
+ windowW = _w;
+ windowH = _h;
+ if( pettanr.file.isFileInstance( _file ) === true ){
+ currentFile = _file;
+ _file.addEventListener( pettanr.file.FILE_EVENT.GET_SEQENTIAL_FILES, draw );
+ draw();
+ }
+ }
+ this.onPaneResize = function( _windowW, _windowH ){
+ windowW = _windowW;
+ windowH = _windowH;
+ var panelH = elmContainer.offsetHeight,
+ panelW = elmContainer.offsetWidth,
+ h = _windowH - headerH - consoleH;
+ jqPanelContainer.stop().animate(
+ {
+ left: Math.floor( ( _windowW - panelW ) / 2 ),
+ top: headerH + ( panelH < h ? Math.floor( ( h - panelH ) / 2 ) : 0 )
+ }
+ );
+ }
+ this.onClose = function(){
+ jqWrap.hide();
+ currentFile.addEventListener( pettanr.file.FILE_EVENT.GET_SEQENTIAL_FILES, draw );
+ currentFile = comicData = currentPanel = null;
+ }
+});
+