Browse Source

Merge pull request #8293 from timvandermeij/es6-password-prompt

Convert the password prompt to ES6 syntax
Jonas Jenwald 8 years ago committed by GitHub
parent
commit
10592a311a
  1. 75
      web/password_prompt.js
  2. 3
      web/viewer.html

75
web/password_prompt.js

@ -30,15 +30,11 @@ import { PasswordResponses } from './pdfjs';
* entry. * entry.
*/ */
/** class PasswordPrompt {
* @class
*/
var PasswordPrompt = (function PasswordPromptClosure() {
/** /**
* @constructs PasswordPrompt
* @param {PasswordPromptOptions} options * @param {PasswordPromptOptions} options
*/ */
function PasswordPrompt(options) { constructor(options) {
this.overlayName = options.overlayName; this.overlayName = options.overlayName;
this.container = options.container; this.container = options.container;
this.label = options.label; this.label = options.label;
@ -52,58 +48,51 @@ var PasswordPrompt = (function PasswordPromptClosure() {
// Attach the event listeners. // Attach the event listeners.
this.submitButton.addEventListener('click', this.verify.bind(this)); this.submitButton.addEventListener('click', this.verify.bind(this));
this.cancelButton.addEventListener('click', this.close.bind(this)); this.cancelButton.addEventListener('click', this.close.bind(this));
this.input.addEventListener('keydown', function (e) { this.input.addEventListener('keydown', (e) => {
if (e.keyCode === 13) { // Enter key if (e.keyCode === 13) { // Enter key
this.verify(); this.verify();
} }
}.bind(this)); });
OverlayManager.register(this.overlayName, this.container, OverlayManager.register(this.overlayName, this.container,
this.close.bind(this), true); this.close.bind(this), true);
} }
PasswordPrompt.prototype = { open() {
open: function PasswordPrompt_open() { OverlayManager.open(this.overlayName).then(() => {
OverlayManager.open(this.overlayName).then(function () { this.input.focus();
this.input.type = 'password';
this.input.focus();
var promptString = mozL10n.get('password_label', null,
'Enter the password to open this PDF file.');
if (this.reason === PasswordResponses.INCORRECT_PASSWORD) { var promptString = mozL10n.get('password_label', null,
promptString = mozL10n.get('password_invalid', null, 'Enter the password to open this PDF file.');
'Invalid password. Please try again.');
}
this.label.textContent = promptString; if (this.reason === PasswordResponses.INCORRECT_PASSWORD) {
}.bind(this)); promptString = mozL10n.get('password_invalid', null,
}, 'Invalid password. Please try again.');
}
close: function PasswordPrompt_close() { this.label.textContent = promptString;
OverlayManager.close(this.overlayName).then(function () { });
this.input.value = ''; }
this.input.type = '';
}.bind(this));
},
verify: function PasswordPrompt_verify() { close() {
var password = this.input.value; OverlayManager.close(this.overlayName).then(() => {
if (password && password.length > 0) { this.input.value = '';
this.close(); });
return this.updateCallback(password); }
}
},
setUpdateCallback: verify() {
function PasswordPrompt_setUpdateCallback(updateCallback, reason) { var password = this.input.value;
this.updateCallback = updateCallback; if (password && password.length > 0) {
this.reason = reason; this.close();
return this.updateCallback(password);
} }
}; }
return PasswordPrompt; setUpdateCallback(updateCallback, reason) {
})(); this.updateCallback = updateCallback;
this.reason = reason;
}
}
export { export {
PasswordPrompt, PasswordPrompt,

3
web/viewer.html

@ -307,8 +307,7 @@ See https://github.com/adobe-type-tools/cmap-resources
<p id="passwordText" data-l10n-id="password_label">Enter the password to open this PDF file:</p> <p id="passwordText" data-l10n-id="password_label">Enter the password to open this PDF file:</p>
</div> </div>
<div class="row"> <div class="row">
<!-- The type="password" attribute is set via script, to prevent warnings in Firefox for all http:// documents. --> <input type="password" id="password" class="toolbarField">
<input id="password" class="toolbarField">
</div> </div>
<div class="buttonRow"> <div class="buttonRow">
<button id="passwordCancel" class="overlayButton"><span data-l10n-id="password_cancel">Cancel</span></button> <button id="passwordCancel" class="overlayButton"><span data-l10n-id="password_cancel">Cancel</span></button>

Loading…
Cancel
Save