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.

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

mercurial