Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Skinned Viewers to Change Find Bar without Changing Javascript #5803

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions web/pdf_find_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,23 @@ var PDFFindBar = (function PDFFindBarClosure() {
'PDFFindController instance.');
}

function addListenerSafely(object, event, func) {
if (object) {
return object.addEventListener(event, func);
}
}

// Add event listeners to the DOM elements.
var self = this;
this.toggleButton.addEventListener('click', function() {
addListenerSafely(this.toggleButton, 'click', function() {
self.toggle();
});

this.findField.addEventListener('input', function() {
addListenerSafely(this.findField, 'input', function() {
self.dispatchEvent('');
});

this.bar.addEventListener('keydown', function(evt) {
addListenerSafely(this.bar, 'keydown', function(evt) {
switch (evt.keyCode) {
case 13: // Enter
if (evt.target === self.findField) {
Expand All @@ -65,19 +71,19 @@ var PDFFindBar = (function PDFFindBarClosure() {
}
});

this.findPreviousButton.addEventListener('click', function() {
addListenerSafely(this.findPreviousButton, 'click', function() {
self.dispatchEvent('again', true);
});

this.findNextButton.addEventListener('click', function() {
addListenerSafely(this.findNextButton, 'click', function() {
self.dispatchEvent('again', false);
});

this.highlightAll.addEventListener('click', function() {
addListenerSafely(this.highlightAll, 'click', function() {
self.dispatchEvent('highlightallchange');
});

this.caseSensitive.addEventListener('click', function() {
addListenerSafely(this.caseSensitive, 'click', function() {
self.dispatchEvent('casesensitivitychange');
});
}
Expand All @@ -87,8 +93,8 @@ var PDFFindBar = (function PDFFindBarClosure() {
var event = document.createEvent('CustomEvent');
event.initCustomEvent('find' + type, true, true, {
query: this.findField.value,
caseSensitive: this.caseSensitive.checked,
highlightAll: this.highlightAll.checked,
caseSensitive: this.caseSensitive ? this.caseSensitive.checked : false,
highlightAll: this.highlightAll ? this.highlightAll.checked : false,
findPrevious: findPrev
});
return window.dispatchEvent(event);
Expand Down