projects/booket

changeset 26:8c2f3e72d514

Create new view for notifications

Create new view for notifications which handles the keyboard shortcuts
overlay message and the unsaved changes notification. This ensures that
the unsaved changes notification is always visible, even when the save
form expander is closed.
author Guido Berhoerster <guido+booket@berhoerster.name>
date Mon Oct 06 13:52:50 2014 +0200 (2014-10-06)
parents b2c9c4fb8d4c
children 780a8c711ff7
files booket.css booket.html booket.js
line diff
     1.1 --- a/booket.css	Mon Oct 06 12:19:52 2014 +0200
     1.2 +++ b/booket.css	Mon Oct 06 13:52:50 2014 +0200
     1.3 @@ -58,6 +58,10 @@
     1.4      border: none;
     1.5  }
     1.6  
     1.7 +strong {
     1.8 +    font-weight: bold;
     1.9 +}
    1.10 +
    1.11  h1 {
    1.12      font-size: 2em;
    1.13      margin: .67em 0
    1.14 @@ -154,6 +158,15 @@
    1.15      z-index: 10;
    1.16  }
    1.17  
    1.18 +.unsaved-changes-message {
    1.19 +    color: #a40000;
    1.20 +    background-color: rgba(239, 41, 41, .25);
    1.21 +    border: 1px solid #a40000;
    1.22 +    border-radius: .5em;
    1.23 +    padding: .5em;
    1.24 +    font-size: .75em;
    1.25 +}
    1.26 +
    1.27  #actions {
    1.28      margin: 1em 0 0 0;
    1.29  }
    1.30 @@ -186,16 +199,6 @@
    1.31      font-size: .75em;
    1.32  }
    1.33  
    1.34 -#save-form .unsaved-changes-message {
    1.35 -    margin: 0;
    1.36 -    font-size: .75em;
    1.37 -}
    1.38 -
    1.39 -.unsaved-changes-message strong {
    1.40 -    font-weight: bold;
    1.41 -    color: #a40000;
    1.42 -}
    1.43 -
    1.44  form.bookmark-editor-form img.bookmark-favicon {
    1.45      display: block;
    1.46      padding: 1px 0;
     2.1 --- a/booket.html	Mon Oct 06 12:19:52 2014 +0200
     2.2 +++ b/booket.html	Mon Oct 06 13:52:50 2014 +0200
     2.3 @@ -38,27 +38,32 @@
     2.4  
     2.5    <datalist id="tag-datalist"></datalist>
     2.6  
     2.7 -  <div id="keyboard-shortcuts">
     2.8 -    <h3>Keyboard Shortcuts</h3>
     2.9 -    <dl>
    2.10 -      <dt><kbd>Prefix</kbd>+<kbd>i</kbd></dt>
    2.11 -      <dd>Select bookmark file to load</dd>
    2.12 -      <dt><kbd>Prefix</kbd>+<kbd>l</kbd></dt>
    2.13 -      <dd>Load selected bookmark file</dd>
    2.14 -      <dt><kbd>Prefix</kbd>+<kbd>s</kbd></dt>
    2.15 -      <dd>Save bookmark file</dd>
    2.16 -      <dt><kbd>Prefix</kbd>+<kbd>a</kbd></dt>
    2.17 -      <dd>Focus bookmark editor</dd>
    2.18 -      <dt><kbd>Prefix</kbd>+<kbd>e</kbd></dt>
    2.19 -      <dd>Select bookmark file to import</dd>
    2.20 -      <dt><kbd>Prefix</kbd>+<kbd>m</kbd></dt>
    2.21 -      <dd>Import selected file</dd>
    2.22 -      <dt><kbd>Prefix</kbd>+<kbd>x</kbd></dt>
    2.23 -      <dd>Export selected file</dd>
    2.24 -      <dt><kbd>Prefix</kbd>+<kbd>f</kbd></dt>
    2.25 -      <dd>Focus search field</dd>
    2.26 -    </dl>
    2.27 -  </div>
    2.28 +  <section id="notifications">
    2.29 +    <div id="keyboard-shortcuts">
    2.30 +      <h3>Keyboard Shortcuts</h3>
    2.31 +      <dl>
    2.32 +        <dt><kbd>Prefix</kbd>+<kbd>i</kbd></dt>
    2.33 +        <dd>Select bookmark file to load</dd>
    2.34 +        <dt><kbd>Prefix</kbd>+<kbd>l</kbd></dt>
    2.35 +        <dd>Load selected bookmark file</dd>
    2.36 +        <dt><kbd>Prefix</kbd>+<kbd>s</kbd></dt>
    2.37 +        <dd>Save bookmark file</dd>
    2.38 +        <dt><kbd>Prefix</kbd>+<kbd>a</kbd></dt>
    2.39 +        <dd>Focus bookmark editor</dd>
    2.40 +        <dt><kbd>Prefix</kbd>+<kbd>e</kbd></dt>
    2.41 +        <dd>Select bookmark file to import</dd>
    2.42 +        <dt><kbd>Prefix</kbd>+<kbd>m</kbd></dt>
    2.43 +        <dd>Import selected file</dd>
    2.44 +        <dt><kbd>Prefix</kbd>+<kbd>x</kbd></dt>
    2.45 +        <dd>Export selected file</dd>
    2.46 +        <dt><kbd>Prefix</kbd>+<kbd>f</kbd></dt>
    2.47 +        <dd>Focus search field</dd>
    2.48 +      </dl>
    2.49 +    </div>
    2.50 +
    2.51 +    <p class="unsaved-changes-message" hidden="hidden"><strong>There are
    2.52 +    unsaved changes to your bookmarks.</strong></p>
    2.53 +  </section>
    2.54  
    2.55    <template id="tag-input-template">
    2.56      <li><label class="top-label">Tag <input type="text" name="tag"
    2.57 @@ -113,8 +118,6 @@
    2.58      <form id="save-form">
    2.59        <fieldset class="expander">
    2.60          <legend tabindex="0" class="expander-label">Save Bookmarks</legend>
    2.61 -        <p class="unsaved-changes-message" hidden="hidden"><strong>There are
    2.62 -        unsaved changes to your bookmarks.</strong></p>
    2.63          <a href="#" id="save-link" hidden="hidden"
    2.64          download="bookmarks.json"></a>
    2.65          <button type="submit" name="save-file"
     3.1 --- a/booket.js	Mon Oct 06 12:19:52 2014 +0200
     3.2 +++ b/booket.js	Mon Oct 06 13:52:50 2014 +0200
     3.3 @@ -921,15 +921,18 @@
     3.4   * view
     3.5   */
     3.6  
     3.7 -var KeyboardShortcutsView = function () {
     3.8 -    document.addEventListener('keydown', this);
     3.9 -    document.addEventListener('keyup', this);
    3.10 +var NotificationsView = function () {
    3.11 +    this.unsavedChangesElement =
    3.12 +        document.querySelector('#notifications .unsaved-changes-message');
    3.13  
    3.14      this.shortcutKeysOverlayElement =
    3.15          document.querySelector('#keyboard-shortcuts');
    3.16 +
    3.17 +    document.addEventListener('keydown', this);
    3.18 +    document.addEventListener('keyup', this);
    3.19  };
    3.20  
    3.21 -KeyboardShortcutsView.prototype.handleEvent = function (e) {
    3.22 +NotificationsView.prototype.handleEvent = function (e) {
    3.23      var elements;
    3.24      var i;
    3.25  
    3.26 @@ -943,6 +946,10 @@
    3.27      }
    3.28  };
    3.29  
    3.30 +NotificationsView.prototype.onUnsavedChangesChanged = function (unsavedChanges) {
    3.31 +    this.unsavedChangesElement.hidden = !unsavedChanges;
    3.32 +};
    3.33 +
    3.34  
    3.35  var TagView = function () {
    3.36      var tagsElement;
    3.37 @@ -1110,9 +1117,6 @@
    3.38      this.tagInputTemplate = document.querySelector('#tag-input-template');
    3.39      saveFormElement = document.querySelector('form#save-form');
    3.40  
    3.41 -    this.unsavedChangesElement =
    3.42 -        saveFormElement.querySelector('.unsaved-changes-message');
    3.43 -
    3.44      this.saveLinkElement = saveFormElement.querySelector('a#save-link');
    3.45  
    3.46      // create new editor form from template
    3.47 @@ -1321,10 +1325,6 @@
    3.48      window.alert('Failed to parse bookmark file:\n' + message);
    3.49  };
    3.50  
    3.51 -ActionsView.prototype.onUnsavedChangesChanged = function (unsavedChanges) {
    3.52 -    this.unsavedChangesElement.hidden = !unsavedChanges;
    3.53 -};
    3.54 -
    3.55  
    3.56  var BookmarkView = function () {
    3.57      var searchFormElement;
    3.58 @@ -1710,10 +1710,10 @@
    3.59   * controller
    3.60   */
    3.61  
    3.62 -var BooketController = function(bookmarkModel, keyboardShortcutsView,
    3.63 +var BooketController = function(bookmarkModel, notificationsView,
    3.64          actionsView, tagView, bookmarkView) {
    3.65      this.bookmarkModel = bookmarkModel;
    3.66 -    this.keyboardShortcutsView = keyboardShortcutsView;
    3.67 +    this.notificationsView = notificationsView;
    3.68      this.actionsView = actionsView;
    3.69      this.tagView = tagView;
    3.70      this.bookmarkView = bookmarkView;
    3.71 @@ -1734,7 +1734,7 @@
    3.72      this.bookmarkModel.addObserver('export-file',
    3.73          this.actionsView.onExportFile.bind(this.actionsView));
    3.74      this.bookmarkModel.addObserver('unsaved-changes-changed',
    3.75 -        this.actionsView.onUnsavedChangesChanged.bind(this.actionsView));
    3.76 +        this.notificationsView.onUnsavedChangesChanged.bind(this.notificationsView));
    3.77      this.bookmarkModel.addObserver('tag-added',
    3.78          this.tagView.onTagAdded.bind(this.tagView));
    3.79      this.bookmarkModel.addObserver('tag-count-changed',
    3.80 @@ -1899,18 +1899,18 @@
    3.81  document.addEventListener('DOMContentLoaded', function (e) {
    3.82      var controller;
    3.83      var bookmarkModel;
    3.84 -    var keyboardShortcutsView;
    3.85 +    var notificationsView;
    3.86      var actionsView;
    3.87      var tagView;
    3.88      var bookmarkView;
    3.89      var hashChangeEvent;
    3.90  
    3.91      bookmarkModel = new BookmarkModel();
    3.92 -    keyboardShortcutsView = new KeyboardShortcutsView();
    3.93 +    notificationsView = new NotificationsView();
    3.94      tagView = new TagView();
    3.95      actionsView = new ActionsView();
    3.96      bookmarkView = new BookmarkView();
    3.97 -    controller = new BooketController(bookmarkModel, keyboardShortcutsView,
    3.98 +    controller = new BooketController(bookmarkModel, notificationsView,
    3.99          actionsView, tagView, bookmarkView);
   3.100  
   3.101      // initialize state from the current URL