• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31WebInspector.PleaseWaitMessage = function()
32{
33    this.element = document.createElement("div");
34    this.element.className = "please-wait-msg";
35    this.element.textContent = WebInspector.UIString("Please wait\u2026");
36
37    this.cancelButton = document.createElement("button");
38    this.cancelButton.textContent = WebInspector.UIString("Cancel");
39    this.cancelButton.addEventListener("click", this._cancelClicked.bind(this), false);
40}
41
42WebInspector.PleaseWaitMessage.prototype = {
43    _cancelClicked: function()
44    {
45        if (this._cancelCallback) {
46            var cancelCallback = this._cancelCallback;
47            delete this._cancelCallback;
48            cancelCallback();
49        }
50    },
51
52    hide: function()
53    {
54        var instance = WebInspector.PleaseWaitMessage.prototype.instance;
55        var message = instance.element;
56        if (message.parentNode)
57            message.parentNode.removeChild(message);
58    },
59
60    get instance()
61    {
62        if (!("_instance" in WebInspector.PleaseWaitMessage.prototype))
63            WebInspector.PleaseWaitMessage.prototype._instance = new WebInspector.PleaseWaitMessage();
64        return WebInspector.PleaseWaitMessage.prototype._instance;
65    },
66
67    show: function(element, cancelCallback)
68    {
69        var instance = WebInspector.PleaseWaitMessage.prototype.instance;
70        var message = instance.element;
71        if (message.parentNode === element)
72            return;
73        else if (message.parentNode)
74            message.parentNode.removeChild(message);
75        if (message.childNodes.length > 1)
76            message.removeChild(instance.cancelButton);
77        if (cancelCallback) {
78            message.appendChild(instance.cancelButton);
79            instance._cancelCallback = cancelCallback;
80        }
81        element.appendChild(message);
82    },
83
84    startAction: function(element, actionCallback, cancelCallback)
85    {
86        var instance = WebInspector.PleaseWaitMessage.prototype.instance;
87        var message = instance.element;
88        if (message.parentNode === element) {
89            setTimeout(actionCallback, 0);
90            return;
91        }
92
93        function doAction()
94        {
95            try {
96                actionCallback();
97            } finally {
98                if (message.parentNode)
99                    message.parentNode.removeChild(message);
100            }
101        }
102
103        WebInspector.PleaseWaitMessage.prototype.show(element, cancelCallback);
104        setTimeout(doAction, 0);
105    }
106};
107
108