Permalink
Browse files

if border or offest isNaN just use 0

  • Loading branch information...
1 parent 495f4ec commit d07ad82f050eaf2c1325b435cd1e5ac62551ab0b @jonrohan jonrohan committed Jan 1, 2013
Showing with 58 additions and 18 deletions.
  1. +8 −6 ZeroClipboard.js
  2. +1 −1 ZeroClipboard.min.js
  3. +3 −3 src/javascript/ZeroClipboard/client.js
  4. +13 −8 src/javascript/ZeroClipboard/position.js
  5. +33 −0 test/position.js
View
@@ -247,19 +247,21 @@
var info = {
left: 0,
top: 0,
- width: obj.width ? obj.width : obj.offsetWidth,
- height: obj.height ? obj.height : obj.offsetHeight,
+ width: obj.width || obj.offsetWidth || 0,
+ height: obj.height || obj.offsetHeight || 0,
zIndex: 9999
};
var zi = _getStyle(obj, "zIndex");
if (zi && zi != "auto") {
info.zIndex = parseInt(zi, 10);
}
while (obj) {
- info.left += obj.offsetLeft;
- info.left += _getStyle(obj, "borderLeftWidth") ? parseInt(_getStyle(obj, "borderLeftWidth"), 10) : 0;
- info.top += obj.offsetTop;
- info.top += _getStyle(obj, "borderTopWidth") ? parseInt(_getStyle(obj, "borderTopWidth"), 10) : 0;
+ var borderLeftWidth = parseInt(_getStyle(obj, "borderLeftWidth"), 10);
+ var borderTopWidth = parseInt(_getStyle(obj, "borderTopWidth"), 10);
+ info.left += isNaN(obj.offsetLeft) ? 0 : obj.offsetLeft;
+ info.left += isNaN(borderLeftWidth) ? 0 : borderLeftWidth;
+ info.top += isNaN(obj.offsetTop) ? 0 : obj.offsetTop;
+ info.top += isNaN(borderTopWidth) ? 0 : borderTopWidth;
obj = obj.offsetParent;
}
return info;
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -197,9 +197,9 @@ ZeroClipboard.Client.prototype.reposition = function () {
var pos = _getDOMObjectPosition(ZeroClipboard.currentElement);
// new css
- this.htmlBridge.style.top = pos.top + "px";
- this.htmlBridge.style.left = pos.left + "px";
- this.htmlBridge.style.width = pos.width + "px";
+ this.htmlBridge.style.top = pos.top + "px";
+ this.htmlBridge.style.left = pos.left + "px";
+ this.htmlBridge.style.width = pos.width + "px";
this.htmlBridge.style.height = pos.height + "px";
this.htmlBridge.style.zIndex = pos.zIndex + 1;
@@ -6,10 +6,10 @@
var _getDOMObjectPosition = function (obj) {
// get absolute coordinates for dom element
var info = {
- left: 0,
- top: 0,
- width: obj.width ? obj.width : obj.offsetWidth,
- height: obj.height ? obj.height : obj.offsetHeight,
+ left: 0,
+ top: 0,
+ width: obj.width || obj.offsetWidth || 0,
+ height: obj.height || obj.offsetHeight || 0,
zIndex: 9999
};
@@ -21,10 +21,15 @@ var _getDOMObjectPosition = function (obj) {
}
while (obj) {
- info.left += obj.offsetLeft;
- info.left += _getStyle(obj, "borderLeftWidth") ? parseInt(_getStyle(obj, "borderLeftWidth"), 10) : 0;
- info.top += obj.offsetTop;
- info.top += _getStyle(obj, "borderTopWidth") ? parseInt(_getStyle(obj, "borderTopWidth"), 10) : 0;
+
+ var borderLeftWidth = parseInt(_getStyle(obj, "borderLeftWidth"), 10);
+ var borderTopWidth = parseInt(_getStyle(obj, "borderTopWidth"), 10);
+
+ info.left += isNaN(obj.offsetLeft) ? 0 : obj.offsetLeft;
+ info.left += isNaN(borderLeftWidth) ? 0 : borderLeftWidth;
+ info.top += isNaN(obj.offsetTop) ? 0 : obj.offsetTop;
+ info.top += isNaN(borderTopWidth) ? 0 : borderTopWidth;
+
obj = obj.offsetParent;
}
View
@@ -0,0 +1,33 @@
+"use strict";
+
+require("./env")
+
+var zeroClipboard, clip;
+exports.position = {
+
+ setUp: function (callback) {
+ zeroClipboard = require("../ZeroClipboard");
+ clip = new zeroClipboard.Client();
+ callback();
+ },
+
+ tearDown: function (callback) {
+ zeroClipboard.destroy();
+ callback();
+ },
+
+ "when object borderWidth isNaN don't fail": function (test) {
+
+ clip.glue("#d_clip_button");
+
+ clip.setCurrent($("#d_clip_button")[0]);
+
+ // grabbed the right id
+ test.equal(clip.htmlBridge.style.top, "0px");
+ test.equal(clip.htmlBridge.style.left, "0px");
+ test.equal(clip.htmlBridge.style.width, "0px");
+ test.equal(clip.htmlBridge.style.height, "0px");
+
+ test.done();
+ }
+};

0 comments on commit d07ad82

Please sign in to comment.