|
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 |
|
6 |
|
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, |
|
16 |
|
17 /** |
|
18 * Contains undo information. |
|
19 */ |
|
20 _undoData: null, |
|
21 |
|
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 }, |
|
32 |
|
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); |
|
40 |
|
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 }; |
|
47 |
|
48 this._undoContainer.removeAttribute("undo-disabled"); |
|
49 this._undoButton.removeAttribute("tabindex"); |
|
50 this._undoCloseButton.removeAttribute("tabindex"); |
|
51 this._undoRestoreButton.removeAttribute("tabindex"); |
|
52 }, |
|
53 |
|
54 /** |
|
55 * Hides the undo dialog. |
|
56 */ |
|
57 hide: function UndoDialog_hide() { |
|
58 if (!this._undoData) |
|
59 return; |
|
60 |
|
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 }, |
|
68 |
|
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 }, |
|
86 |
|
87 /** |
|
88 * Undo the last blocked site. |
|
89 */ |
|
90 _undo: function UndoDialog_undo() { |
|
91 if (!this._undoData) |
|
92 return; |
|
93 |
|
94 let {index, wasPinned, blockedLink} = this._undoData; |
|
95 gBlockedLinks.unblock(blockedLink); |
|
96 |
|
97 if (wasPinned) { |
|
98 gPinnedLinks.pin(blockedLink, index); |
|
99 } |
|
100 |
|
101 gUpdater.updateGrid(); |
|
102 this.hide(); |
|
103 }, |
|
104 |
|
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 }; |
|
115 |
|
116 gUndoDialog.init(); |