autofit: 'auto'
};
- // Text-to-Speech params
- this.ttsPosition = -1;
-
return this;
};
//console.log('appending ' + key);
}
- this.setHilightCss2UP(result.div, key, result.l, result.r, result.t, result.b);
+ // We calculate the reduction factor for the specific page because it can be different
+ // for each page in the spread
+ var height = this._getPageHeight(key);
+ var width = this._getPageWidth(key)
+ var reduce = this.twoPage.height/height;
+ var scaledW = parseInt(width*reduce);
+
+ var gutter = this.twoPageGutter();
+ var pageL;
+ if ('L' == this.getPageSide(key)) {
+ pageL = gutter-scaledW;
+ } else {
+ pageL = gutter;
+ }
+ var pageT = this.twoPageTop();
+
+ $(result.div).css({
+ width: (result.r-result.l)*reduce + 'px',
+ height: (result.b-result.t)*reduce + 'px',
+ left: pageL+(result.l)*reduce + 'px',
+ top: pageT+(result.t)*reduce +'px'
+ });
} else {
//console.log(key + ' not displayed');
}
}
-// setHilightCss2UP()
-//______________________________________________________________________________
-//position calculation shared between search and text-to-speech functions
-BookReader.prototype.setHilightCss2UP = function(div, index, left, right, top, bottom) {
-
- // We calculate the reduction factor for the specific page because it can be different
- // for each page in the spread
- var height = this._getPageHeight(index);
- var width = this._getPageWidth(index)
- var reduce = this.twoPage.height/height;
- var scaledW = parseInt(width*reduce);
-
- var gutter = this.twoPageGutter();
- var pageL;
- if ('L' == this.getPageSide(index)) {
- pageL = gutter-scaledW;
- } else {
- pageL = gutter;
- }
- var pageT = this.twoPageTop();
-
- $(div).css({
- width: (right-left)*reduce + 'px',
- height: (bottom-top)*reduce + 'px',
- left: pageL+left*reduce + 'px',
- top: pageT+top*reduce +'px'
- });
-}
-
// removeSearchHilites()
//______________________________________________________________________________
BookReader.prototype.removeSearchHilites = function() {
$("#BookReader").append("<div id='BRtoolbar'>"
+ "<span id='BRtoolbarbuttons' style='float: right'>"
- + "<button class='BRicon rollover read_aloud' onclick='br.ttsStart(); return false;'/>"
+ "<button class='BRicon print rollover' /> <button class='BRicon rollover embed' />"
+ "<form class='BRpageform' action='javascript:' onsubmit='br.jumpToPage(this.elements[0].value)'> <span class='label'>Page:<input id='BRpagenum' type='text' size='3' onfocus='br.autoStop();'></input></span></form>"
+ "<div class='BRtoolbarmode2' style='display: none'><button class='BRicon rollover book_leftmost' /><button class='BRicon rollover book_left' /><button class='BRicon rollover book_right' /><button class='BRicon rollover book_rightmost' /></div>"
}
// The final property here must NOT have a comma after it - IE7
}
-
-
-// ttsStart()
-//______________________________________________________________________________
-BookReader.prototype.ttsStart = function () {
- console.log('starting readAloud');
- var url = 'http://'+this.server+'/BookReader/BookReaderGetTextWrapper.php?path='+this.bookPath+'_djvu.xml&page='+this.currentIndex();
- console.log('url is ' + url);
- $.ajax({url:url, dataType:'jsonp'});
-}
-
-// ttsGetTextCB(): text-to-speech callback
-//______________________________________________________________________________
-BookReader.prototype.ttsGetTextCB = function (data) {
- console.log('ttsGetTextCB got data:');
- console.log(data);
- this.ttsChunks = data;
- this.ttsHilites = [];
- //$.ajax({url:'http://'+this.ttsServer+'/renderAudio.py', data:{string:data[0][0], format:'ogg'}, dataType:'json'});
-
- this.ttsPosition = -1;
- var snd = soundManager.createSound({
- id: 'chunk0',
- //url: 'http://home.us.archive.org/~rkumar/arctic.ogg',
- url: 'http://home.us.archive.org/~rkumar/getOgg.php?string=' + escape(data[0][0]) + '&f=.ogg', //the .ogg is to trick SoundManager2 to use the HTML5 audio player
- autoLoad: true
- });
- snd.br = this;
- snd.load();
- this.ttsNextChunk();
-}
-
-// ttsNextChunk()
-//______________________________________________________________________________
-BookReader.prototype.ttsNextChunk = function () {
- console.log(this);
- console.log(this.ttsPosition);
- this.ttsPosition++;
- console.log('next chunk is ');
- console.log(this.ttsPosition);
-
- if (this.ttsPosition >= this.ttsChunks.length) {
- console.log('tts stop');
- return;
- }
-
- var chunk = this.ttsChunks[this.ttsPosition];
-
- //remove old hilights
- $(this.ttsHilites).remove();
- this.ttsHilites = [];
-
- if (2 == this.mode) {
- this.ttsHilite2UP(chunk);
- } else {
- alert('only 2 page mode supported for TTS..');
- }
-
- //preload next chunk
- var nextPos = this.ttsPosition+1;
- if (nextPos < this.ttsChunks.length) {
- var snd = soundManager.createSound({
- id: 'chunk'+nextPos,
- url: 'http://home.us.archive.org/~rkumar/getOgg.php?string=' + escape(this.ttsChunks[nextPos][0]) + '&f=.ogg', //the .ogg is to trick SoundManager2 to use the HTML5 audio player
- //url: 'http://home.us.archive.org/~rkumar/arctic.ogg',
- autoload: true
- });
- snd.br = this;
- snd.load()
- }
-
- //play current chunk
- var self = this;
- var foo = function() {console.log(this.br); br.ttsNextChunk();}
- soundManager.play('chunk'+this.ttsPosition,{onfinish:foo});
-}
-
-
-// ttsHilite2UP()
-//______________________________________________________________________________
-BookReader.prototype.ttsHilite2UP = function (chunk) {
- var i;
- for (i=0; i<chunk.length; i++) {
- //each rect is an array of l,b,r,t coords (djvu.xml ordering...)
- var l = chunk[i][0];
- var b = chunk[i][1];
- var r = chunk[i][2];
- var t = chunk[i][3];
-
- var div = document.createElement('div');
- this.ttsHilites.push(div);
- $(div).attr('className', 'BookReaderSearchHilite').css('zIndex', 3).appendTo('#BRtwopageview');
- this.setHilightCss2UP(div, this.currentIndex(), l, r, t, b);
- }
-}