// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

function load() {
  $('unlock-passphrase-button').onclick = function(event) {
    chrome.send('checkPassphrase', [$('passphrase-entry').value]);
  };
  $('cancel-passphrase-button').onclick = function(event) {
    // TODO(akuegel): Replace by closeDialog.
    chrome.send('DialogClose');
  };
  $('passphrase-entry').oninput = function(event) {
    $('unlock-passphrase-button').disabled = $('passphrase-entry').value == '';
    $('incorrect-passphrase-warning').hidden = true;
  };
}

function passphraseCorrect() {
  chrome.send('DialogClose', ['true']);
}

function passphraseIncorrect() {
  $('incorrect-passphrase-warning').hidden = false;
  $('passphrase-entry').focus();
}

window.addEventListener('DOMContentLoaded', load);

// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

function load() {
  var checkPassphrase = function(event) {
    chrome.send('checkPassphrase', [$('passphrase-entry').value]);
  };
  var closeDialog = function(event) {
    // TODO(akuegel): Replace by closeDialog.
    chrome.send('DialogClose');
  };
  // Directly set the focus on the input box so the user can start typing right
  // away.
  $('passphrase-entry').focus();
  $('unlock-passphrase-button').onclick = checkPassphrase;
  $('cancel-passphrase-button').onclick = closeDialog;
  $('passphrase-entry').oninput = function(event) {
    $('unlock-passphrase-button').disabled = $('passphrase-entry').value == '';
    $('incorrect-passphrase-warning').hidden = true;
  };
  $('passphrase-entry').onkeypress = function(event) {
    if (!event)
      return;
    // Check if the user pressed enter.
    if (event.keyCode == 13)
      checkPassphrase(event);
  };

  // Pressing escape anywhere in the frame should work.
  document.onkeyup = function(event) {
    if (!event)
      return;
    // Check if the user pressed escape.
    if (event.keyCode == 27)
      closeDialog(event);
  };
}

function passphraseCorrect() {
  chrome.send('DialogClose', ['true']);
}

function passphraseIncorrect() {
  $('incorrect-passphrase-warning').hidden = false;
  $('passphrase-entry').focus();
}

window.addEventListener('DOMContentLoaded', load);

Improve usability in passphrase input dialog.
Improve usability in passphrase input dialog.

Add the possiblity to press Enter to submit the dialog and to press Escape to
dismiss it.

R=akuegel@chromium.org, jhawkins@chromium.org
BUG=171370


Review URL: https://chromiumcodereview.appspot.com/12321166

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@185194 0039d316-1c4b-4281-b951-d872f2087c98
