X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=BookReader%2FBookReader.js;fp=BookReader%2FBookReader.js;h=1d3509eac53e0a5c1502557a4fe5d4ec0fc2a707;hb=0a80175ec8aa59d62021557e9ed63ccaa364d77a;hp=9940cddfb182ff7226427df8d0339039211aa858;hpb=ad068777d10a9e927ffcd8f8347f9c3684a23892;p=bookreader.git diff --git a/BookReader/BookReader.js b/BookReader/BookReader.js index 9940cdd..1d3509e 100644 --- a/BookReader/BookReader.js +++ b/BookReader/BookReader.js @@ -74,7 +74,7 @@ function BookReader() { this.printPopup = null; this.searchTerm = ''; - this.searchResults = {}; + this.searchResults = null; this.firstIndex = null; @@ -2635,92 +2635,40 @@ BookReader.prototype.getPageWidth2UP = function(index) { // search() //______________________________________________________________________________ BookReader.prototype.search = function(term) { - term = term.replace(/\//g, ' '); // strip slashes + //console.log('search called with term=' + term); + var url = 'http://'+this.server.replace(/:.+/, ''); //remove the port and userdir + url += '/~edward/inside_jsonp.php?item_id='+this.bookId; + url += '&doc='+this.subPrefix; //TODO: test with subitem + url += '&path='+this.bookPath.replace(new RegExp('/'+this.subPrefix+'$'), ''); //remove subPrefix from end of path + url += '&q='+escape(term); + //console.log('search url='+url); + + term = term.replace(/\//g, ' '); // strip slashes, since this goes in the url this.searchTerm = term; - $('#BookReaderSearchScript').remove(); - var script = document.createElement("script"); - script.setAttribute('id', 'BookReaderSearchScript'); - script.setAttribute("type", "text/javascript"); - script.setAttribute("src", 'http://'+this.server+'/BookReader/flipbook_search_br.php?url='+escape(this.bookPath + '_djvu.xml')+'&term='+term+'&format=XML&callback=br.BRSearchCallback'); - document.getElementsByTagName('head')[0].appendChild(script); - $('#BookReaderSearchBox').val(term); - $('#BookReaderSearchResults').html('Searching...'); + + this.removeSearchResults(); + this.showProgressPopup(); + this.ttsAjax = $.ajax({url:url, dataType:'jsonp', jsonpCallback:'BRSearchCallback'}); } // BRSearchCallback() //______________________________________________________________________________ -BookReader.prototype.BRSearchCallback = function(txt) { - //alert(txt); - if (jQuery.browser.msie) { - var dom=new ActiveXObject("Microsoft.XMLDOM"); - dom.async="false"; - dom.loadXML(txt); - } else { - var parser = new DOMParser(); - var dom = parser.parseFromString(txt, "text/xml"); - } - - $('#BookReaderSearchResults').empty(); - $('#BookReaderSearchResults').append(''); - - // $$$ update again for case of loading search URL in new browser window (search box may not have been ready yet) - $('#BookReaderSearchBox').val(this.searchTerm); - - this.updateSearchHilites(); + br.updateSearchHilites(); + br.removeProgressPopup(); } + // updateSearchHilites() //______________________________________________________________________________ BookReader.prototype.updateSearchHilites = function() { @@ -2734,30 +2682,39 @@ BookReader.prototype.updateSearchHilites = function() { // showSearchHilites1UP() //______________________________________________________________________________ BookReader.prototype.updateSearchHilites1UP = function() { - - for (var key in this.searchResults) { - - if (jQuery.inArray(parseInt(key), this.displayedIndices) >= 0) { - var result = this.searchResults[key]; - if (null == result.div) { - result.div = document.createElement('div'); - $(result.div).attr('className', 'BookReaderSearchHilite').appendTo('#pagediv'+key); - //console.log('appending ' + key); - } - $(result.div).css({ - width: (result.r-result.l)/this.reduce + 'px', - height: (result.b-result.t)/this.reduce + 'px', - left: (result.l)/this.reduce + 'px', - top: (result.t)/this.reduce +'px' - }); - - } else { - //console.log(key + ' not displayed'); - this.searchResults[key].div=null; + var results = this.searchResults; + if (null == results) return; + var i, j; + for (i=0; i= 0) { + if (null == box.div) { + //create a div for the search highlight, and stash it in the box object + box.div = document.createElement('div'); + $(box.div).attr('className', 'BookReaderSearchHilite').appendTo('#pagediv'+pageIndex); + } + $(box.div).css({ + width: (box.r-box.l)/this.reduce + 'px', + height: (box.b-box.t)/this.reduce + 'px', + left: (box.l)/this.reduce + 'px', + top: (box.t)/this.reduce +'px' + }); + } else { + if (null != box.div) { + //console.log('removing search highlight div'); + $(box.div).remove(); + box.div=null; + } + } } } + } + // twoPageGutter() //______________________________________________________________________________ // Returns the position of the gutter (line between the page images) @@ -2885,31 +2842,36 @@ BookReader.prototype.twoPagePlaceFlipAreas = function() { }); } -// showSearchHilites2UP() +// showSearchHilites2UPNew() //______________________________________________________________________________ BookReader.prototype.updateSearchHilites2UP = function() { - - for (var key in this.searchResults) { - key = parseInt(key, 10); - if (jQuery.inArray(key, this.displayedIndices) >= 0) { - var result = this.searchResults[key]; - if (null == result.div) { - result.div = document.createElement('div'); - $(result.div).attr('className', 'BookReaderSearchHilite').css('zIndex', 3).appendTo('#BRtwopageview'); - //console.log('appending ' + key); - } - - this.setHilightCss2UP(result.div, key, result.l, result.r, result.t, result.b); - - } else { - //console.log(key + ' not displayed'); - if (null != this.searchResults[key].div) { - //console.log('removing ' + key); - $(this.searchResults[key].div).remove(); + //console.log('updateSearchHilites2UP results = ' + this.searchResults); + var results = this.searchResults; + if (null == results) return; + var i, j; + for (i=0; i= 0) { + if (null == box.div) { + //create a div for the search highlight, and stash it in the box object + box.div = document.createElement('div'); + $(box.div).attr('className', 'BookReaderSearchHilite').css('zIndex', 3).appendTo('#BRtwopageview'); + //console.log('appending new div'); + } + this.setHilightCss2UP(box.div, pageIndex, box.l, box.r, box.t, box.b); + } else { + if (null != box.div) { + //console.log('removing search highlight div'); + $(box.div).remove(); + box.div=null; + } } - this.searchResults[key].div=null; } } + } // setHilightCss2UP() @@ -2944,14 +2906,21 @@ BookReader.prototype.setHilightCss2UP = function(div, index, left, right, top, b // removeSearchHilites() //______________________________________________________________________________ BookReader.prototype.removeSearchHilites = function() { - for (var key in this.searchResults) { - if (null != this.searchResults[key].div) { - $(this.searchResults[key].div).remove(); - this.searchResults[key].div=null; - } - } + var results = this.searchResults; + if (null == results) return; + var i, j; + for (i=0; i$1') + $('