[Pkg-mozext-commits] [itsalltext] 167/459: I think I finally understand the problem with the gumdrop and have fixed it. It's because offsets are relative to the containing Block (aka offsetParent in DOM-speak). If the offsetParents are the same for the element and the gumdrop, then all is well. Otherwise, heck breaks out.

David Prévot taffit at moszumanska.debian.org
Tue Feb 24 23:26:18 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository itsalltext.

commit 3e9c04ddce15fd4eaa983855f6bf055f12e8bcce
Author: Christian Höltje <docwhat at gerf.org>
Date:   Sat Mar 17 23:44:20 2007 -0400

    I think I finally understand the problem with the gumdrop and have
    fixed it.  It's because offsets are relative to the containing
    Block (aka offsetParent in DOM-speak).  If the offsetParents are the
    same for the element and the gumdrop, then all is well.  Otherwise,
    heck breaks out.
---
 chrome/content/cacheobj.js   | 15 ++++++++++++---
 chrome/content/itsalltext.js | 20 ++++++++++++++++++++
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/chrome/content/cacheobj.js b/chrome/content/cacheobj.js
index 0df322d..0ea943f 100644
--- a/chrome/content/cacheobj.js
+++ b/chrome/content/cacheobj.js
@@ -138,7 +138,7 @@ CacheObj.prototype.initFromExistingFile = function() {
         this.setExtension(ext);
         this._is_watching = true;
     }
-}
+};
 
 /**
  * Returns a unique identifier for the node, within the document.
@@ -486,6 +486,7 @@ CacheObj.prototype.adjust = function() {
         }
         return;
     }
+
     var style    = gumdrop.style;
     if (!gumdrop || !el) { return; }
     var display  = '';
@@ -500,8 +501,16 @@ CacheObj.prototype.adjust = function() {
     }
 
     /* Reposition the gumdrops incase the dom changed. */
-    var left = el.offsetLeft+Math.max(1, el.offsetWidth-this.gumdrop_width);
-    var top  = el.offsetTop+el.offsetHeight;
+    var left = Math.max(1, el.offsetWidth-this.gumdrop_width);
+    var top  = el.offsetHeight;
+    if (el.offsetParent === gumdrop.offsetParent) {
+        left += el.offsetLeft;
+        top  += el.offsetTop;
+    } else {
+        var coord = ItsAllText.getContainingBlockOffset(el, gumdrop.offsetParent);
+        left += coord[0];
+        top  += coord[1];
+    }
     if(left && top) {
         left = [left,'px'].join('');
         top  = [top,'px'].join('');
diff --git a/chrome/content/itsalltext.js b/chrome/content/itsalltext.js
index 8cd14aa..fb56213 100644
--- a/chrome/content/itsalltext.js
+++ b/chrome/content/itsalltext.js
@@ -459,6 +459,26 @@ var ItsAllText = function() {
     };
 
     /**
+     * Returns the offset from the containing block.
+     * @param {Object} node A DOM element.
+     * @param {Object} container If unset, then this will use the offsetParent of node. Pass in null to go all the way to the root.
+     * @return {Array} The X & Y page offsets
+     */
+    that.getContainingBlockOffset = function(node, container) {
+        if(typeof(container) == 'undefined') {
+            container = node.offsetParent;
+        }
+        var pos = [node.offsetLeft, node.offsetTop];
+        var pnode = node.offsetParent;
+        while(pnode && (container === null || pnode != container)) {
+            pos[0] += pnode.offsetLeft || 0;
+            pos[1] += pnode.offsetTop || 0;
+            pnode = pnode.offsetParent;
+        }
+        return pos;
+    };
+
+    /**
      * This function is called regularly to watch changes to web documents.
      */
     that.monitor = {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/itsalltext.git



More information about the Pkg-mozext-commits mailing list