michael@0: #ifdef 0 michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #endif michael@0: michael@0: /** michael@0: * Dialog allowing to undo the removal of single site or to completely restore michael@0: * the grid's original state. michael@0: */ michael@0: let gUndoDialog = { michael@0: /** michael@0: * The undo dialog's timeout in miliseconds. michael@0: */ michael@0: HIDE_TIMEOUT_MS: 15000, michael@0: michael@0: /** michael@0: * Contains undo information. michael@0: */ michael@0: _undoData: null, michael@0: michael@0: /** michael@0: * Initializes the undo dialog. michael@0: */ michael@0: init: function UndoDialog_init() { michael@0: this._undoContainer = document.getElementById("newtab-undo-container"); michael@0: this._undoContainer.addEventListener("click", this, false); michael@0: this._undoButton = document.getElementById("newtab-undo-button"); michael@0: this._undoCloseButton = document.getElementById("newtab-undo-close-button"); michael@0: this._undoRestoreButton = document.getElementById("newtab-undo-restore-button"); michael@0: }, michael@0: michael@0: /** michael@0: * Shows the undo dialog. michael@0: * @param aSite The site that just got removed. michael@0: */ michael@0: show: function UndoDialog_show(aSite) { michael@0: if (this._undoData) michael@0: clearTimeout(this._undoData.timeout); michael@0: michael@0: this._undoData = { michael@0: index: aSite.cell.index, michael@0: wasPinned: aSite.isPinned(), michael@0: blockedLink: aSite.link, michael@0: timeout: setTimeout(this.hide.bind(this), this.HIDE_TIMEOUT_MS) michael@0: }; michael@0: michael@0: this._undoContainer.removeAttribute("undo-disabled"); michael@0: this._undoButton.removeAttribute("tabindex"); michael@0: this._undoCloseButton.removeAttribute("tabindex"); michael@0: this._undoRestoreButton.removeAttribute("tabindex"); michael@0: }, michael@0: michael@0: /** michael@0: * Hides the undo dialog. michael@0: */ michael@0: hide: function UndoDialog_hide() { michael@0: if (!this._undoData) michael@0: return; michael@0: michael@0: clearTimeout(this._undoData.timeout); michael@0: this._undoData = null; michael@0: this._undoContainer.setAttribute("undo-disabled", "true"); michael@0: this._undoButton.setAttribute("tabindex", "-1"); michael@0: this._undoCloseButton.setAttribute("tabindex", "-1"); michael@0: this._undoRestoreButton.setAttribute("tabindex", "-1"); michael@0: }, michael@0: michael@0: /** michael@0: * The undo dialog event handler. michael@0: * @param aEvent The event to handle. michael@0: */ michael@0: handleEvent: function UndoDialog_handleEvent(aEvent) { michael@0: switch (aEvent.target.id) { michael@0: case "newtab-undo-button": michael@0: this._undo(); michael@0: break; michael@0: case "newtab-undo-restore-button": michael@0: this._undoAll(); michael@0: break; michael@0: case "newtab-undo-close-button": michael@0: this.hide(); michael@0: break; michael@0: } michael@0: }, michael@0: michael@0: /** michael@0: * Undo the last blocked site. michael@0: */ michael@0: _undo: function UndoDialog_undo() { michael@0: if (!this._undoData) michael@0: return; michael@0: michael@0: let {index, wasPinned, blockedLink} = this._undoData; michael@0: gBlockedLinks.unblock(blockedLink); michael@0: michael@0: if (wasPinned) { michael@0: gPinnedLinks.pin(blockedLink, index); michael@0: } michael@0: michael@0: gUpdater.updateGrid(); michael@0: this.hide(); michael@0: }, michael@0: michael@0: /** michael@0: * Undo all blocked sites. michael@0: */ michael@0: _undoAll: function UndoDialog_undoAll() { michael@0: NewTabUtils.undoAll(function() { michael@0: gUpdater.updateGrid(); michael@0: this.hide(); michael@0: }.bind(this)); michael@0: } michael@0: }; michael@0: michael@0: gUndoDialog.init();