browser/base/content/newtab/undo.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 #ifdef 0
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     4  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #endif
     7 /**
     8  * Dialog allowing to undo the removal of single site or to completely restore
     9  * the grid's original state.
    10  */
    11 let gUndoDialog = {
    12   /**
    13    * The undo dialog's timeout in miliseconds.
    14    */
    15   HIDE_TIMEOUT_MS: 15000,
    17   /**
    18    * Contains undo information.
    19    */
    20   _undoData: null,
    22   /**
    23    * Initializes the undo dialog.
    24    */
    25   init: function UndoDialog_init() {
    26     this._undoContainer = document.getElementById("newtab-undo-container");
    27     this._undoContainer.addEventListener("click", this, false);
    28     this._undoButton = document.getElementById("newtab-undo-button");
    29     this._undoCloseButton = document.getElementById("newtab-undo-close-button");
    30     this._undoRestoreButton = document.getElementById("newtab-undo-restore-button");
    31   },
    33   /**
    34    * Shows the undo dialog.
    35    * @param aSite The site that just got removed.
    36    */
    37   show: function UndoDialog_show(aSite) {
    38     if (this._undoData)
    39       clearTimeout(this._undoData.timeout);
    41     this._undoData = {
    42       index: aSite.cell.index,
    43       wasPinned: aSite.isPinned(),
    44       blockedLink: aSite.link,
    45       timeout: setTimeout(this.hide.bind(this), this.HIDE_TIMEOUT_MS)
    46     };
    48     this._undoContainer.removeAttribute("undo-disabled");
    49     this._undoButton.removeAttribute("tabindex");
    50     this._undoCloseButton.removeAttribute("tabindex");
    51     this._undoRestoreButton.removeAttribute("tabindex");
    52   },
    54   /**
    55    * Hides the undo dialog.
    56    */
    57   hide: function UndoDialog_hide() {
    58     if (!this._undoData)
    59       return;
    61     clearTimeout(this._undoData.timeout);
    62     this._undoData = null;
    63     this._undoContainer.setAttribute("undo-disabled", "true");
    64     this._undoButton.setAttribute("tabindex", "-1");
    65     this._undoCloseButton.setAttribute("tabindex", "-1");
    66     this._undoRestoreButton.setAttribute("tabindex", "-1");
    67   },
    69   /**
    70    * The undo dialog event handler.
    71    * @param aEvent The event to handle.
    72    */
    73   handleEvent: function UndoDialog_handleEvent(aEvent) {
    74     switch (aEvent.target.id) {
    75       case "newtab-undo-button":
    76         this._undo();
    77         break;
    78       case "newtab-undo-restore-button":
    79         this._undoAll();
    80         break;
    81       case "newtab-undo-close-button":
    82         this.hide();
    83         break;
    84     }
    85   },
    87   /**
    88    * Undo the last blocked site.
    89    */
    90   _undo: function UndoDialog_undo() {
    91     if (!this._undoData)
    92       return;
    94     let {index, wasPinned, blockedLink} = this._undoData;
    95     gBlockedLinks.unblock(blockedLink);
    97     if (wasPinned) {
    98       gPinnedLinks.pin(blockedLink, index);
    99     }
   101     gUpdater.updateGrid();
   102     this.hide();
   103   },
   105   /**
   106    * Undo all blocked sites.
   107    */
   108   _undoAll: function UndoDialog_undoAll() {
   109     NewTabUtils.undoAll(function() {
   110       gUpdater.updateGrid();
   111       this.hide();
   112     }.bind(this));
   113   }
   114 };
   116 gUndoDialog.init();

mercurial