Browse Source

Convert the password prompt to ES6 syntax

Tim van der Meij 8 years ago
parent
commit
e3796f6f41
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762
  1. 41
      web/password_prompt.js

41
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,19 +48,18 @@ 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.type = 'password'; this.input.type = 'password';
this.input.focus(); this.input.focus();
@ -77,33 +72,29 @@ var PasswordPrompt = (function PasswordPromptClosure() {
} }
this.label.textContent = promptString; this.label.textContent = promptString;
}.bind(this)); });
}, }
close: function PasswordPrompt_close() { close() {
OverlayManager.close(this.overlayName).then(function () { OverlayManager.close(this.overlayName).then(() => {
this.input.value = ''; this.input.value = '';
this.input.type = ''; this.input.type = '';
}.bind(this)); });
}, }
verify: function PasswordPrompt_verify() { verify() {
var password = this.input.value; var password = this.input.value;
if (password && password.length > 0) { if (password && password.length > 0) {
this.close(); this.close();
return this.updateCallback(password); return this.updateCallback(password);
} }
}, }
setUpdateCallback: setUpdateCallback(updateCallback, reason) {
function PasswordPrompt_setUpdateCallback(updateCallback, reason) {
this.updateCallback = updateCallback; this.updateCallback = updateCallback;
this.reason = reason; this.reason = reason;
} }
}; }
return PasswordPrompt;
})();
export { export {
PasswordPrompt, PasswordPrompt,

Loading…
Cancel
Save