home *** CD-ROM | disk | FTP | other *** search
- window.addEventListener("load", function () {
- var overLink = "";
- XULBrowserWindow.__defineGetter__("overLink", function () overLink);
- XULBrowserWindow.__defineSetter__("overLink", function (val) {
- overLink = val;
- if (!isElementVisible(this.statusTextField))
- LinkTargetDisplay.update();
- return val;
- });
- }, false);
-
- var LinkTargetDisplay = {
- get _35 () {
- delete this._35;
- return this._35 = (navigator.userAgent.indexOf("rv:1.9.1") > -1);
- },
-
- DELAY_SHOW: 50,
- DELAY_HIDE: 150,
-
- get popup () {
- delete this.popup;
- return this.popup = document.getElementById("linkTargetDisplay");
- },
-
- get label () {
- delete this.label;
- return this.label = this.popup.firstChild;
- },
-
- get isOpen () this.popup.state == "open" || this.popup.state == "showing",
-
- update: function () {
- if (this._timer) {
- clearTimeout(this._timer);
- this._timer = 0;
- }
-
- if (!XULBrowserWindow.overLink) {
- window.removeEventListener("mousemove", this, true);
- this._timer = setTimeout(function (self) {
- self._timer = 0;
- self.popup.hidePopup();
- self._mouseX = 0;
- self._mouseY = 0;
- }, this.DELAY_HIDE, this);
- return;
- }
-
- window.addEventListener("mousemove", this, true);
-
- if (this.isOpen) {
- this.label.value = XULBrowserWindow.overLink;
- return;
- }
-
- this._show();
- },
-
- handleEvent: function (event) {
- switch (event.type) {
- case "mousemove":
- this._mouseX = event.screenX;
- this._mouseY = event.screenY;
- if (this.isOpen)
- this._adjustPosition();
- else
- this._show();
- break;
- }
- },
-
- _show: function () {
- if (this._timer)
- clearTimeout(this._timer);
-
- this._timer = setTimeout(function (self) {
- self._timer = 0;
-
- self.label.value = XULBrowserWindow.overLink;
-
- var b = gBrowser.boxObject;
- self.popup.width = b.width / 3;
- self._rtl = (getComputedStyle(gBrowser, "").direction == "rtl");
- self._leftEdge = b.screenX;
- self._rightEdge = b.screenX + b.width;
- self._bottomEdge = b.screenY + b.height;
- self._adjustPosition();
-
- self.popup.openPopup(gBrowser, "end_after", 0, self._35 ? -3 : 0, false, false);
- }, this.DELAY_SHOW, this);
- },
-
- _adjustPosition: function () {
- const PADDING = 30;
- const HEIGHT = 24; // rough approximation
- const WIDTH = parseInt(this.popup.width);
- var mouseNearDefaultPos =
- this._mouseY > this._bottomEdge - (HEIGHT + PADDING) &&
- (this._rtl
- ? this._mouseX > this._rightEdge - (WIDTH + PADDING) &&
- this._mouseX < this._rightEdge
- : this._mouseX > this._leftEdge &&
- this._mouseX < this._leftEdge + WIDTH + PADDING);
- if (mouseNearDefaultPos)
- this.popup.style.MozMarginStart = (this._leftEdge - this._rightEdge) / 3 - (this._35 ? 3 : 0) + "px";
- else
- this.popup.style.MozMarginStart = (this._leftEdge - this._rightEdge) + "px";
- this.popup.setAttribute("where", (mouseNearDefaultPos == !this._rtl) ?
- "right" : "left");
- }
- };
-