]> git.mxchange.org Git - friendica.git/commitdiff
getOffset() now falls back to old slower version for CSS layouts which cannot figure...
authorMats Sjöberg <mats@sjoberg.fi>
Wed, 23 Oct 2013 16:21:53 +0000 (19:21 +0300)
committerMats Sjöberg <mats@sjoberg.fi>
Wed, 23 Oct 2013 16:21:53 +0000 (19:21 +0300)
js/ajaxupload.js

index 67c4a56fb7fb882b39f3a57f9b625a15171dbf6f..1c34b11b9ed87483669acd2faa0c6c62936da49d 100644 (file)
             timeout = setTimeout(fn, 100);                        
         });
     }    
+
+    // Get offset adding all offsets, slow fall-back method
+    var getOffsetSlow = function(el){
+        var top = 0, left = 0;
+        do {
+            top += el.offsetTop || 0;
+            left += el.offsetLeft || 0;
+            el = el.offsetParent;
+        } while (el);
+        
+        return {
+            left: left,
+            top: top
+        };
+    };
+
     
     // Needs more testing, will be rewriten for next version        
     // getOffset function copied from jQuery lib (http://jquery.com/)
                 var bound = body.getBoundingClientRect();
                 zoom = (bound.right - bound.left) / body.clientWidth;
             }
+
+            // some CSS layouts gives 0 width and/or bounding boxes
+            // in this case we fall back to the slow method
+            if (zoom == 0 || body.clientWidth == 0)
+                return getOffsetSlow(el);
             
             if (zoom > 1) {
                 clientTop = 0;
             };
         };        
     } else {
-        // Get offset adding all offsets 
-        var getOffset = function(el){
-            var top = 0, left = 0;
-            do {
-                top += el.offsetTop || 0;
-                left += el.offsetLeft || 0;
-                el = el.offsetParent;
-            } while (el);
-            
-            return {
-                left: left,
-                top: top
-            };
-        };
+      var getOffset = getOffsetSlow;
     }
     
     /**