2011-01-08 07:03:27 -08:00
|
|
|
var AlertsHelper = {
|
|
|
|
_timeoutID: -1,
|
|
|
|
_listener: null,
|
|
|
|
_cookie: "",
|
|
|
|
_clickable: false,
|
|
|
|
get container() {
|
|
|
|
delete this.container;
|
|
|
|
let container = document.getElementById("alerts-container");
|
|
|
|
|
|
|
|
// Move the popup on the other side if we are in RTL
|
|
|
|
let [leftSidebar, rightSidebar] = [Elements.tabs.getBoundingClientRect(), Elements.controls.getBoundingClientRect()];
|
2011-02-23 10:13:51 -08:00
|
|
|
if (leftSidebar.left > rightSidebar.left)
|
2011-01-08 07:03:27 -08:00
|
|
|
container.setAttribute("left", "0");
|
2011-02-23 10:13:51 -08:00
|
|
|
else
|
|
|
|
container.setAttribute("right", "0");
|
2011-01-08 07:03:27 -08:00
|
|
|
|
|
|
|
let self = this;
|
|
|
|
container.addEventListener("transitionend", function() {
|
|
|
|
self.alertTransitionOver();
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
return this.container = container;
|
|
|
|
},
|
|
|
|
|
|
|
|
showAlertNotification: function ah_show(aImageURL, aTitle, aText, aTextClickable, aCookie, aListener) {
|
|
|
|
this._clickable = aTextClickable || false;
|
|
|
|
this._listener = aListener || null;
|
|
|
|
this._cookie = aCookie || "";
|
|
|
|
|
2011-02-23 10:13:51 -08:00
|
|
|
// Reset the container settings from the last time so layout can happen naturally
|
|
|
|
let container = this.container;
|
|
|
|
container.removeAttribute("width");
|
|
|
|
let alertText = document.getElementById("alerts-text");
|
|
|
|
alertText.style.whiteSpace = "";
|
|
|
|
|
2011-01-08 07:03:27 -08:00
|
|
|
document.getElementById("alerts-image").setAttribute("src", aImageURL);
|
|
|
|
document.getElementById("alerts-title").value = aTitle;
|
2011-02-23 10:13:51 -08:00
|
|
|
alertText.textContent = aText;
|
2011-01-08 07:03:27 -08:00
|
|
|
|
|
|
|
container.hidden = false;
|
2011-02-23 10:13:51 -08:00
|
|
|
let bcr = container.getBoundingClientRect();
|
|
|
|
if (bcr.width > window.innerWidth - 50) {
|
|
|
|
// If the window isn't wide enough, we need to re-layout
|
|
|
|
container.setAttribute("width", window.innerWidth - 50); // force a max width
|
|
|
|
alertText.style.whiteSpace = "pre-wrap"; // wrap text as needed
|
|
|
|
bcr = container.getBoundingClientRect(); // recalculate the bcr
|
|
|
|
}
|
|
|
|
container.setAttribute("width", bcr.width); // redundant but cheap
|
|
|
|
container.setAttribute("height", bcr.height);
|
|
|
|
|
|
|
|
#ifdef ANDROID
|
|
|
|
let offset = (window.innerWidth - container.width) / 2;
|
2011-03-23 20:50:48 -07:00
|
|
|
if (offset < 0)
|
|
|
|
Cu.reportError("showAlertNotification called before the window is ready");
|
|
|
|
else if (container.hasAttribute("left"))
|
2011-02-23 10:13:51 -08:00
|
|
|
container.setAttribute("left", offset);
|
|
|
|
else
|
|
|
|
container.setAttribute("right", offset);
|
|
|
|
#endif
|
|
|
|
|
2011-01-08 07:03:27 -08:00
|
|
|
container.classList.add("showing");
|
|
|
|
|
|
|
|
let timeout = Services.prefs.getIntPref("alerts.totalOpenTime");
|
|
|
|
let self = this;
|
|
|
|
if (this._timeoutID)
|
|
|
|
clearTimeout(this._timeoutID);
|
|
|
|
this._timeoutID = setTimeout(function() { self._timeoutAlert(); }, timeout);
|
|
|
|
},
|
|
|
|
|
|
|
|
_timeoutAlert: function ah__timeoutAlert() {
|
|
|
|
this._timeoutID = -1;
|
|
|
|
|
|
|
|
this.container.classList.remove("showing");
|
|
|
|
if (this._listener)
|
|
|
|
this._listener.observe(null, "alertfinished", this._cookie);
|
|
|
|
},
|
|
|
|
|
|
|
|
alertTransitionOver: function ah_alertTransitionOver() {
|
|
|
|
let container = this.container;
|
|
|
|
if (!container.classList.contains("showing")) {
|
|
|
|
container.height = 0;
|
|
|
|
container.hidden = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
click: function ah_click(aEvent) {
|
|
|
|
if (this._clickable && this._listener)
|
|
|
|
this._listener.observe(null, "alertclickcallback", this._cookie);
|
|
|
|
|
|
|
|
if (this._timeoutID != -1) {
|
|
|
|
clearTimeout(this._timeoutID);
|
|
|
|
this._timeoutAlert();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|