diff --git a/files_reader/templates/.pdfreader.php.swp b/files_reader/templates/.pdfreader.php.swp deleted file mode 100644 index cf98255..0000000 Binary files a/files_reader/templates/.pdfreader.php.swp and /dev/null differ diff --git a/files_reader/vendor/pdfjs/.pdf.reader.js.swp b/files_reader/vendor/pdfjs/.pdf.reader.js.swp deleted file mode 100644 index 54c25cb..0000000 Binary files a/files_reader/vendor/pdfjs/.pdf.reader.js.swp and /dev/null differ diff --git a/files_reader/vendor/pdfjs/controllers/.outline_controller.js.swp b/files_reader/vendor/pdfjs/controllers/.outline_controller.js.swp deleted file mode 100644 index 40f430a..0000000 Binary files a/files_reader/vendor/pdfjs/controllers/.outline_controller.js.swp and /dev/null differ diff --git a/files_reader/vendor/pdfjs/controllers/outline_controller.js b/files_reader/vendor/pdfjs/controllers/outline_controller.js index 2bada46..3a0f1c9 100644 --- a/files_reader/vendor/pdfjs/controllers/outline_controller.js +++ b/files_reader/vendor/pdfjs/controllers/outline_controller.js @@ -4,78 +4,10 @@ PDFJS.reader.OutlineController = function(_outline) { book = this.book, outline = _outline || []; - var outlineView = document.getElementById("outlineView"), - baseUrl = location.href.split('#')[0], - lastToggleIsShow; + var outlineView = document.getElementById("outlineView"); var DEFAULT_TITLE = '\u2013'; - var bindLink = function (element, item) { - - var destination = item.dest; - - if (item.url) { - - PDFJS.addLinkAttributes (element, { - url: item.url, - target: (item.newWindow - ? PDFJS.LinkTarget.BLANK - : undefined), - }); - - return; - } else { - - element.href = getDestinationHash(destination); - element.onclick = function () { - if (destination) { - reader.navigateTo(destination); - } - - return false; - }; - } - }; - - var setStyles = function (element, item) { - - var styleStr = ""; - - if (item.bold) { - styleStr += 'font-weight: bold;'; - } - - if (item.italic) { - styleStr += 'font-style: italic;'; - } - - if (styleStr) { - element.setAttribute('style', styleStr); - } - }; - - var getDestinationHash = function (destination) { - - var url = baseUrl || "", - str; - - if (typeof destination === 'string') { - - url += "#" - + (parseInt(destination) === destination) - ? "nameddest=" - : "" - + escape(destination); - - } else if (destination instanceof Array) { - - url += "#" - + escape(JSON.stringify(destination)); - } - - return url; - }; - var generateOutlineItems = function (outline, level) { var container = document.createElement("ul"); @@ -83,6 +15,7 @@ PDFJS.reader.OutlineController = function(_outline) { if(!level) level = 1; outline.forEach(function (chapter) { + var listitem = document.createElement("li"), link = document.createElement("a"), toggle = document.createElement("a"), @@ -92,8 +25,8 @@ PDFJS.reader.OutlineController = function(_outline) { listitem.classList.add('list_item'); link.textContent = PDFJS.removeNullCharacters(chapter.title) || DEFAULT_TITLE; - bindLink(link, chapter); - setStyles(link, chapter); + reader.bindLink(link, chapter); + reader.setStyles(link, chapter); link.classList.add('outline_link'); listitem.appendChild(link); diff --git a/files_reader/vendor/pdfjs/controllers/search_controller.js b/files_reader/vendor/pdfjs/controllers/search_controller.js index af2912a..d2ce383 100644 --- a/files_reader/vendor/pdfjs/controllers/search_controller.js +++ b/files_reader/vendor/pdfjs/controllers/search_controller.js @@ -152,6 +152,7 @@ PDFJS.reader.SearchController = function () { matches.push(matchIdx); } this.pageMatches[pageIndex] = matches; + }; var calcFindWordMatch = function ( @@ -189,6 +190,55 @@ PDFJS.reader.SearchController = function () { this.pageMatchesLength[pageIndex]); }; + var getSnippet = function (pageIndex, position) { + + var ellipse = '…', + match_length = this.state.query.length, + span = '', + span_close = '', + limit = 160 + span.length + span_close.length, + leader, + trailer, + context; + + leader = this.pageContents[pageIndex].substring(position - limit/2, position); + leader = leader.slice(leader.indexOf(" ")); + trailer = this.pageContents[pageIndex].substring(position + match_length, position + limit/2 + match_length); + query = this.pageContents[pageIndex].substring(position, position + match_length); + + context = ellipse + leader + span + query + span_close + trailer; + + return reader.ellipsize(context, context.length - 10); + }; + + var createItem = function (pageIndex, position) { + + var listitem = document.createElement("li"), + link = document.createElement("a"), + id = parseInt(pageIndex + 1) + ":" + position, + item = { + url: null, + dest: null, + bold: null, + italic: null + }; + + // for now only the pageIndex is used + item.dest = [pageIndex,position]; + + //link.textContent = getSnippet(pageIndex, position); + link.innerHTML = getSnippet(pageIndex, position); + listitem.classList.add("list_item"); + listitem.id = "search-"+id; + listitem.dataset.position = position; + reader.bindLink(link, item); + link.classList.add("search_link"); + listitem.appendChild(link); + + return listitem; + }; + + var calcFindMatch = function (pageIndex) { var pageContent = normalize(this.pageContents[pageIndex]); var query = normalize(this.state.query); @@ -211,18 +261,6 @@ PDFJS.reader.SearchController = function () { } else { calcFindWordMatch(query, pageIndex, pageContent); } - - updatePage(pageIndex); - if (this.resumePageIdx === pageIndex) { - this.resumePageIdx = null; - nextPageMatch(); - } - - // Update the matches count - if (this.pageMatches[pageIndex].length > 0) { - this.matchCount += this.pageMatches[pageIndex].length; - updateUIResultsCount(); - } }; var extractText = function () { @@ -253,19 +291,12 @@ PDFJS.reader.SearchController = function () { } // Store the pageContent as a string. - self.pageContents.push(str.join('')); + self.pageContents.push(str.join(' ').replace(/\s\s+/g, ' ')); extractTextPromisesResolves[pageIndex](pageIndex); if ((pageIndex + 1) < reader.settings.numPages) { - console.log("extracting text from page " + parseInt(pageIndex + 1)); extractPageText(pageIndex + 1); - } else { - console.log("finished extracting text"); - for (var i=0;i < reader.settings.numPages;i++) { - console.log("PAGE: " + parseInt(i + 1)); - console.log(self.pageContents[i]); - } - } + } } ); } @@ -287,7 +318,8 @@ PDFJS.reader.SearchController = function () { clearTimeout(this.findTimeout); if (cmd === 'find') { // Only trigger the find action after 250ms of silence. - this.findTimeout = setTimeout(nextMatch.bind(this), 250); + //this.findTimeout = setTimeout(nextMatch.bind(this), 250); + generateMatchList(); } else { nextMatch(); } @@ -309,6 +341,39 @@ PDFJS.reader.SearchController = function () { //} }; + var generateMatchList = function () { + + var container = document.getElementById("searchResults"), + numPages = reader.settings.numPages, + self = this; + + for (var i = 0; i < numPages; i++) { + //var placeholder = document.createElement("li"); + //placeholder.style.display = "none"; + //container.appendChild(placeholder); + if (!(i in this.pendingFindMatches)) { + this.pendingFindMatches[i] = true; + this.extractTextPromises[i].then(function(pageIdx) { + delete self.pendingFindMatches[pageIdx]; + calcFindMatch(pageIdx); + if (self.pageMatches[pageIdx].length > 0) { + reader.pageMatches[pageIdx] = self.pageMatches[pageIdx]; + var fragment = document.createDocumentFragment(); + var listitem = document.createElement("li"); + listitem.textContent="page " + parseInt(pageIdx + 1); + listitem.classList.add("search_page_header"); + fragment.appendChild(listitem); + self.pageMatches[pageIdx].forEach(function (match) { + fragment.appendChild(createItem(pageIdx, match)); + }); + + container.appendChild(fragment); + } + }); + } + } + }; + var nextMatch = function () { var previous = this.state.findPrevious; @@ -501,22 +566,20 @@ PDFJS.reader.SearchController = function () { q = $searchBox.val(); } - if (q == '') { + if (q === '') { clear(); return; } reader.SidebarController.changePanelTo("Search"); + reset(); $searchResults.empty(); - $searchResults.append("
Searching...