github.com/mssola/todo@v0.0.0-20181029153210-d25348dc3f48/public/javascripts/topics.js (about)

     1  /*
     2   * Copyright (C) 2014-2017 Miquel Sabaté Solà <mikisabate@gmail.com>
     3   *
     4   * This Source Code Form is subject to the terms of the Mozilla Public
     5   * License, v. 2.0. If a copy of the MPL was not distributed with this
     6   * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     7   */
     8  
     9  window.onload = function() {
    10    // The user wants to create a new topic.
    11    document.getElementById("create-button").onclick = function() {
    12      this.style.display = "none";
    13  
    14      var form = this.parentNode.getElementsByTagName("form")[0];
    15      form.style.display = "block";
    16      form.getElementsByClassName("tiny-text")[0].focus();
    17    };
    18  
    19    // When the user click the "rename" link, show the rename form.
    20    document.getElementById("rename").onclick = function() {
    21      var f = document.getElementById("rename-form");
    22      f.style.display = "block";
    23      f.getElementsByClassName("tiny-text")[0].focus();
    24      return false;
    25    };
    26  
    27    // When the user clicks the "edit" link, show the form to edit the topic.
    28    document.getElementById("edit").onclick = function() {
    29      var body = document.getElementById("edit-body");
    30      body.getElementsByClassName("contents-body")[0].style.display = "none";
    31      body.getElementsByClassName("contents-edit")[0].style.display = "block";
    32      document.getElementsByTagName("textarea")[0].focus();
    33      return false;
    34    };
    35  
    36    // When editing the topic, if the user clicks "Cancel", let's hide the whole
    37    // thing.
    38    document.getElementById("cancel-btn").onclick = function() {
    39      var body = document.getElementById("edit-body");
    40      body.getElementsByClassName("contents-edit")[0].style.display = "none";
    41      body.getElementsByClassName("contents-body")[0].style.display = "block";
    42    };
    43  
    44    // When the user clicks the "delete" link, show the confirmation form.
    45    document.getElementById("delete").onclick = function() {
    46      this.style.display = "none";
    47      document.getElementById("confirmation").style.display = "inline";
    48      return false;
    49    };
    50  
    51    // The current user really wants to delete this topic, do it.
    52    document.getElementById("delete-yes").onclick = function() {
    53      document.getElementById("delete-form").submit();
    54      return false;
    55    };
    56  
    57    // The current chickened out on deleting this topic.
    58    document.getElementById("delete-no").onclick = function() {
    59      document.getElementById("confirmation").style.display = "none";
    60      document.getElementById("delete").style.display = "inline";
    61      return false;
    62    };
    63  }