|
|
|
@ -22,9 +22,10 @@ import { mozL10n } from './ui_utils';
@@ -22,9 +22,10 @@ import { mozL10n } from './ui_utils';
|
|
|
|
|
* also sets up the appropriate events for the controls. Actual searching |
|
|
|
|
* is done by PDFFindController. |
|
|
|
|
*/ |
|
|
|
|
var PDFFindBar = (function PDFFindBarClosure() { |
|
|
|
|
function PDFFindBar(options) { |
|
|
|
|
class PDFFindBar { |
|
|
|
|
constructor(options) { |
|
|
|
|
this.opened = false; |
|
|
|
|
|
|
|
|
|
this.bar = options.bar || null; |
|
|
|
|
this.toggleButton = options.toggleButton || null; |
|
|
|
|
this.findField = options.findField || null; |
|
|
|
@ -44,66 +45,63 @@ var PDFFindBar = (function PDFFindBarClosure() {
@@ -44,66 +45,63 @@ var PDFFindBar = (function PDFFindBarClosure() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Add event listeners to the DOM elements.
|
|
|
|
|
var self = this; |
|
|
|
|
this.toggleButton.addEventListener('click', function() { |
|
|
|
|
self.toggle(); |
|
|
|
|
this.toggleButton.addEventListener('click', () => { |
|
|
|
|
this.toggle(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.findField.addEventListener('input', function() { |
|
|
|
|
self.dispatchEvent(''); |
|
|
|
|
this.findField.addEventListener('input', () => { |
|
|
|
|
this.dispatchEvent(''); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.bar.addEventListener('keydown', function(evt) { |
|
|
|
|
switch (evt.keyCode) { |
|
|
|
|
this.bar.addEventListener('keydown', (e) => { |
|
|
|
|
switch (e.keyCode) { |
|
|
|
|
case 13: // Enter
|
|
|
|
|
if (evt.target === self.findField) { |
|
|
|
|
self.dispatchEvent('again', evt.shiftKey); |
|
|
|
|
if (e.target === this.findField) { |
|
|
|
|
this.dispatchEvent('again', e.shiftKey); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 27: // Escape
|
|
|
|
|
self.close(); |
|
|
|
|
this.close(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.findPreviousButton.addEventListener('click', function() { |
|
|
|
|
self.dispatchEvent('again', true); |
|
|
|
|
this.findPreviousButton.addEventListener('click', () => { |
|
|
|
|
this.dispatchEvent('again', true); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.findNextButton.addEventListener('click', function() { |
|
|
|
|
self.dispatchEvent('again', false); |
|
|
|
|
this.findNextButton.addEventListener('click', () => { |
|
|
|
|
this.dispatchEvent('again', false); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.highlightAll.addEventListener('click', function() { |
|
|
|
|
self.dispatchEvent('highlightallchange'); |
|
|
|
|
this.highlightAll.addEventListener('click', () => { |
|
|
|
|
this.dispatchEvent('highlightallchange'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.caseSensitive.addEventListener('click', function() { |
|
|
|
|
self.dispatchEvent('casesensitivitychange'); |
|
|
|
|
this.caseSensitive.addEventListener('click', () => { |
|
|
|
|
this.dispatchEvent('casesensitivitychange'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.eventBus.on('resize', this._adjustWidth.bind(this)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
PDFFindBar.prototype = { |
|
|
|
|
reset: function PDFFindBar_reset() { |
|
|
|
|
reset() { |
|
|
|
|
this.updateUIState(); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dispatchEvent: function PDFFindBar_dispatchEvent(type, findPrev) { |
|
|
|
|
dispatchEvent(type, findPrev) { |
|
|
|
|
this.eventBus.dispatch('find', { |
|
|
|
|
source: this, |
|
|
|
|
type: type, |
|
|
|
|
type, |
|
|
|
|
query: this.findField.value, |
|
|
|
|
caseSensitive: this.caseSensitive.checked, |
|
|
|
|
phraseSearch: true, |
|
|
|
|
highlightAll: this.highlightAll.checked, |
|
|
|
|
findPrevious: findPrev |
|
|
|
|
findPrevious: findPrev, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
updateUIState: |
|
|
|
|
function PDFFindBar_updateUIState(state, previous, matchCount) { |
|
|
|
|
updateUIState(state, previous, matchCount) { |
|
|
|
|
var notFound = false; |
|
|
|
|
var findMsg = ''; |
|
|
|
|
var status = ''; |
|
|
|
@ -143,27 +141,25 @@ var PDFFindBar = (function PDFFindBarClosure() {
@@ -143,27 +141,25 @@ var PDFFindBar = (function PDFFindBarClosure() {
|
|
|
|
|
|
|
|
|
|
this.updateResultsCount(matchCount); |
|
|
|
|
this._adjustWidth(); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
updateResultsCount: function(matchCount) { |
|
|
|
|
updateResultsCount(matchCount) { |
|
|
|
|
if (!this.findResultsCount) { |
|
|
|
|
return; // no UI control is provided
|
|
|
|
|
return; // No UI control is provided.
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// If there are no matches, hide the counter
|
|
|
|
|
// If there are no matches, hide the counter.
|
|
|
|
|
if (!matchCount) { |
|
|
|
|
this.findResultsCount.classList.add('hidden'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Create the match counter
|
|
|
|
|
// Create and show the match counter.
|
|
|
|
|
this.findResultsCount.textContent = matchCount.toLocaleString(); |
|
|
|
|
|
|
|
|
|
// Show the counter
|
|
|
|
|
this.findResultsCount.classList.remove('hidden'); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
open: function PDFFindBar_open() { |
|
|
|
|
open() { |
|
|
|
|
if (!this.opened) { |
|
|
|
|
this.opened = true; |
|
|
|
|
this.toggleButton.classList.add('toggled'); |
|
|
|
@ -173,9 +169,9 @@ var PDFFindBar = (function PDFFindBarClosure() {
@@ -173,9 +169,9 @@ var PDFFindBar = (function PDFFindBarClosure() {
|
|
|
|
|
this.findField.focus(); |
|
|
|
|
|
|
|
|
|
this._adjustWidth(); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
close: function PDFFindBar_close() { |
|
|
|
|
close() { |
|
|
|
|
if (!this.opened) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -183,20 +179,20 @@ var PDFFindBar = (function PDFFindBarClosure() {
@@ -183,20 +179,20 @@ var PDFFindBar = (function PDFFindBarClosure() {
|
|
|
|
|
this.toggleButton.classList.remove('toggled'); |
|
|
|
|
this.bar.classList.add('hidden'); |
|
|
|
|
this.findController.active = false; |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
toggle: function PDFFindBar_toggle() { |
|
|
|
|
toggle() { |
|
|
|
|
if (this.opened) { |
|
|
|
|
this.close(); |
|
|
|
|
} else { |
|
|
|
|
this.open(); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @private |
|
|
|
|
*/ |
|
|
|
|
_adjustWidth: function PDFFindBar_adjustWidth() { |
|
|
|
|
_adjustWidth() { |
|
|
|
|
if (!this.opened) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -216,10 +212,8 @@ var PDFFindBar = (function PDFFindBarClosure() {
@@ -216,10 +212,8 @@ var PDFFindBar = (function PDFFindBarClosure() {
|
|
|
|
|
// wrap all of them to adjust the width of the find bar.
|
|
|
|
|
this.bar.classList.add('wrapContainers'); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
return PDFFindBar; |
|
|
|
|
})(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export { |
|
|
|
|
PDFFindBar, |
|
|
|
|