|
|
|
@ -26,35 +26,7 @@ var FindStates = {
@@ -26,35 +26,7 @@ var FindStates = {
|
|
|
|
|
var FIND_SCROLL_OFFSET_TOP = -50; |
|
|
|
|
var FIND_SCROLL_OFFSET_LEFT = -400; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Provides "search" or "find" functionality for the PDF. |
|
|
|
|
* This object actually performs the search for a given string. |
|
|
|
|
*/ |
|
|
|
|
var PDFFindController = (function PDFFindControllerClosure() { |
|
|
|
|
function PDFFindController(options) { |
|
|
|
|
this.startedTextExtraction = false; |
|
|
|
|
this.extractTextPromises = []; |
|
|
|
|
this.pendingFindMatches = Object.create(null); |
|
|
|
|
this.active = false; // If active, find results will be highlighted.
|
|
|
|
|
this.pageContents = []; // Stores the text for each page.
|
|
|
|
|
this.pageMatches = []; |
|
|
|
|
this.matchCount = 0; |
|
|
|
|
this.selected = { // Currently selected match.
|
|
|
|
|
pageIdx: -1, |
|
|
|
|
matchIdx: -1 |
|
|
|
|
}; |
|
|
|
|
this.offset = { // Where the find algorithm currently is in the document.
|
|
|
|
|
pageIdx: null, |
|
|
|
|
matchIdx: null |
|
|
|
|
}; |
|
|
|
|
this.pagesToSearch = null; |
|
|
|
|
this.resumePageIdx = null; |
|
|
|
|
this.state = null; |
|
|
|
|
this.dirtyMatch = false; |
|
|
|
|
this.findTimeout = null; |
|
|
|
|
this.pdfViewer = options.pdfViewer || null; |
|
|
|
|
this.integratedFind = options.integratedFind || false; |
|
|
|
|
this.charactersToNormalize = { |
|
|
|
|
var CHARACTERS_TO_NORMALIZE = { |
|
|
|
|
'\u2018': '\'', // Left single quotation mark
|
|
|
|
|
'\u2019': '\'', // Right single quotation mark
|
|
|
|
|
'\u201A': '\'', // Single low-9 quotation mark
|
|
|
|
@ -66,11 +38,22 @@ var PDFFindController = (function PDFFindControllerClosure() {
@@ -66,11 +38,22 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
|
|
|
|
'\u00BC': '1/4', // Vulgar fraction one quarter
|
|
|
|
|
'\u00BD': '1/2', // Vulgar fraction one half
|
|
|
|
|
'\u00BE': '3/4', // Vulgar fraction three quarters
|
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Provides "search" or "find" functionality for the PDF. |
|
|
|
|
* This object actually performs the search for a given string. |
|
|
|
|
*/ |
|
|
|
|
var PDFFindController = (function PDFFindControllerClosure() { |
|
|
|
|
function PDFFindController(options) { |
|
|
|
|
this.pdfViewer = options.pdfViewer || null; |
|
|
|
|
this.integratedFind = options.integratedFind || false; |
|
|
|
|
this.findBar = options.findBar || null; |
|
|
|
|
|
|
|
|
|
// Compile the regular expression for text normalization once
|
|
|
|
|
var replace = Object.keys(this.charactersToNormalize).join(''); |
|
|
|
|
this.reset(); |
|
|
|
|
|
|
|
|
|
// Compile the regular expression for text normalization once.
|
|
|
|
|
var replace = Object.keys(CHARACTERS_TO_NORMALIZE).join(''); |
|
|
|
|
this.normalizationRegex = new RegExp('[' + replace + ']', 'g'); |
|
|
|
|
|
|
|
|
|
var events = [ |
|
|
|
@ -79,10 +62,6 @@ var PDFFindController = (function PDFFindControllerClosure() {
@@ -79,10 +62,6 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
|
|
|
|
'findhighlightallchange', |
|
|
|
|
'findcasesensitivitychange' |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
this.firstPagePromise = new Promise(function (resolve) { |
|
|
|
|
this.resolveFirstPage = resolve; |
|
|
|
|
}.bind(this)); |
|
|
|
|
this.handleEvent = this.handleEvent.bind(this); |
|
|
|
|
|
|
|
|
|
for (var i = 0, len = events.length; i < len; i++) { |
|
|
|
@ -98,13 +77,33 @@ var PDFFindController = (function PDFFindControllerClosure() {
@@ -98,13 +77,33 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
|
|
|
|
reset: function PDFFindController_reset() { |
|
|
|
|
this.startedTextExtraction = false; |
|
|
|
|
this.extractTextPromises = []; |
|
|
|
|
this.active = false; |
|
|
|
|
this.pendingFindMatches = Object.create(null); |
|
|
|
|
this.active = false; // If active, find results will be highlighted.
|
|
|
|
|
this.pageContents = []; // Stores the text for each page.
|
|
|
|
|
this.pageMatches = []; |
|
|
|
|
this.matchCount = 0; |
|
|
|
|
this.selected = { // Currently selected match.
|
|
|
|
|
pageIdx: -1, |
|
|
|
|
matchIdx: -1 |
|
|
|
|
}; |
|
|
|
|
this.offset = { // Where the find algorithm currently is in the document.
|
|
|
|
|
pageIdx: null, |
|
|
|
|
matchIdx: null |
|
|
|
|
}; |
|
|
|
|
this.pagesToSearch = null; |
|
|
|
|
this.resumePageIdx = null; |
|
|
|
|
this.state = null; |
|
|
|
|
this.dirtyMatch = false; |
|
|
|
|
this.findTimeout = null; |
|
|
|
|
|
|
|
|
|
this.firstPagePromise = new Promise(function (resolve) { |
|
|
|
|
this.resolveFirstPage = resolve; |
|
|
|
|
}.bind(this)); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
normalize: function PDFFindController_normalize(text) { |
|
|
|
|
var self = this; |
|
|
|
|
return text.replace(this.normalizationRegex, function (ch) { |
|
|
|
|
return self.charactersToNormalize[ch]; |
|
|
|
|
return CHARACTERS_TO_NORMALIZE[ch]; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|