tether-rails 1.3.0 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de93ccccb7666876b9d68581ce49a5df0c5cf475
4
- data.tar.gz: 8a0732631e09bd1e1c980be57d3c51839d163cd6
3
+ metadata.gz: ddb250f38f344b84e3d27862a8532aa42a87622e
4
+ data.tar.gz: 2eb9af52801f54c97f1778abd413bc391987cf95
5
5
  SHA512:
6
- metadata.gz: 028f121b23f8893ddc6abe0583381bc3cb614de3106fb5737662fa97319f63dbe86251565d3f206b5e93af09d11ea42a1d3a318593bc3b6b8f65eeb065a32bb4
7
- data.tar.gz: 190be216ade2240c328c34869153342386158b8f7f66282ab62ec21475a9481a492f4efe476e1b90664424bf0bb1c8330c50a500bb1aae07c795b0ee2ecfdf11
6
+ metadata.gz: 9a24b0ee1b645bdea205f23b4e571136afcdaf965c2992dd48f56bb4aca505463b847da382b1310838bf5e0c4163d8e2d0414cd920aa6022943628592d979f6f
7
+ data.tar.gz: 17045483706d99cb68f7423940ca057d68f99d1ac922225bdf2ddae08bee30114fd6106f494c5a877ab190ac57286e433517ae115f500bc051e7fac4ea960ab9
@@ -1,3 +1,3 @@
1
1
  module TetherRails
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.3'
3
3
  end
@@ -1,4 +1,4 @@
1
- /*! tether 1.3.0 */
1
+ /*! tether 1.3.3 */
2
2
 
3
3
  (function(root, factory) {
4
4
  if (typeof define === 'function' && define.amd) {
@@ -23,6 +23,32 @@ if (typeof TetherBase === 'undefined') {
23
23
 
24
24
  var zeroElement = null;
25
25
 
26
+ // Same as native getBoundingClientRect, except it takes into account parent <frame> offsets
27
+ // if the element lies within a nested document (<frame> or <iframe>-like).
28
+ function getActualBoundingClientRect(node) {
29
+ var boundingRect = node.getBoundingClientRect();
30
+
31
+ // The original object returned by getBoundingClientRect is immutable, so we clone it
32
+ // We can't use extend because the properties are not considered part of the object by hasOwnProperty in IE9
33
+ var rect = {};
34
+ for (var k in boundingRect) {
35
+ rect[k] = boundingRect[k];
36
+ }
37
+
38
+ if (node.ownerDocument !== document) {
39
+ var _frameElement = node.ownerDocument.defaultView.frameElement;
40
+ if (_frameElement) {
41
+ var frameRect = getActualBoundingClientRect(_frameElement);
42
+ rect.top += frameRect.top;
43
+ rect.bottom += frameRect.top;
44
+ rect.left += frameRect.left;
45
+ rect.right += frameRect.left;
46
+ }
47
+ }
48
+
49
+ return rect;
50
+ }
51
+
26
52
  function getScrollParents(el) {
27
53
  // In firefox if the el is inside an iframe with display: none; window.getComputedStyle() will return null;
28
54
  // https://bugzilla.mozilla.org/show_bug.cgi?id=548397
@@ -58,7 +84,13 @@ function getScrollParents(el) {
58
84
  }
59
85
  }
60
86
 
61
- parents.push(document.body);
87
+ parents.push(el.ownerDocument.body);
88
+
89
+ // If the node is within a frame, account for the parent window scroll
90
+ if (el.ownerDocument !== document) {
91
+ parents.push(el.ownerDocument.defaultView);
92
+ }
93
+
62
94
  return parents;
63
95
  }
64
96
 
@@ -92,13 +124,7 @@ var getOrigin = function getOrigin() {
92
124
 
93
125
  var id = node.getAttribute('data-tether-id');
94
126
  if (typeof zeroPosCache[id] === 'undefined') {
95
- zeroPosCache[id] = {};
96
-
97
- var rect = node.getBoundingClientRect();
98
- for (var k in rect) {
99
- // Can't use extend, as on IE9, elements don't resolve to be hasOwnProperty
100
- zeroPosCache[id][k] = rect[k];
101
- }
127
+ zeroPosCache[id] = getActualBoundingClientRect(node);
102
128
 
103
129
  // Clear the cache when this position call is done
104
130
  defer(function () {
@@ -110,8 +136,10 @@ var getOrigin = function getOrigin() {
110
136
  };
111
137
 
112
138
  function removeUtilElements() {
113
- document.body.removeChild(zeroElement);
114
- zeroElement = undefined;
139
+ if (zeroElement) {
140
+ document.body.removeChild(zeroElement);
141
+ }
142
+ zeroElement = null;
115
143
  };
116
144
 
117
145
  function getBounds(el) {
@@ -125,13 +153,7 @@ function getBounds(el) {
125
153
 
126
154
  var docEl = doc.documentElement;
127
155
 
128
- var box = {};
129
- // The original object returned by getBoundingClientRect is immutable, so we clone it
130
- // We can't use extend because the properties are not considered part of the object by hasOwnProperty in IE9
131
- var rect = el.getBoundingClientRect();
132
- for (var k in rect) {
133
- box[k] = rect[k];
134
- }
156
+ var box = getActualBoundingClientRect(el);
135
157
 
136
158
  var origin = getOrigin();
137
159
 
@@ -250,7 +272,9 @@ function hasClass(el, name) {
250
272
  }
251
273
 
252
274
  function getClassName(el) {
253
- if (el.className instanceof SVGAnimatedString) {
275
+ // Can't use just SVGAnimatedString here since nodes within a Frame in IE have
276
+ // completely separately SVGAnimatedString base classes
277
+ if (el.className instanceof el.ownerDocument.defaultView.SVGAnimatedString) {
254
278
  return el.className.baseVal;
255
279
  }
256
280
  return el.className;
@@ -315,7 +339,7 @@ var Evented = (function () {
315
339
  }, {
316
340
  key: 'off',
317
341
  value: function off(event, handler) {
318
- if (typeof this.bindings !== 'undefined' && typeof this.bindings[event] !== 'undefined') {
342
+ if (typeof this.bindings === 'undefined' || typeof this.bindings[event] === 'undefined') {
319
343
  return;
320
344
  }
321
345
 
@@ -369,6 +393,7 @@ var Evented = (function () {
369
393
  })();
370
394
 
371
395
  TetherBase.Utils = {
396
+ getActualBoundingClientRect: getActualBoundingClientRect,
372
397
  getScrollParents: getScrollParents,
373
398
  getBounds: getBounds,
374
399
  getOffsetParent: getOffsetParent,
@@ -427,7 +452,7 @@ var transformKey = (function () {
427
452
  }
428
453
  var el = document.createElement('div');
429
454
 
430
- var transforms = ['transform', 'webkitTransform', 'OTransform', 'MozTransform', 'msTransform'];
455
+ var transforms = ['transform', 'WebkitTransform', 'OTransform', 'MozTransform', 'msTransform'];
431
456
  for (var i = 0; i < transforms.length; ++i) {
432
457
  var key = transforms[i];
433
458
  if (el.style[key] !== undefined) {
@@ -472,7 +497,7 @@ function now() {
472
497
  return;
473
498
  }
474
499
 
475
- if (typeof pendingTimeout !== 'undefined') {
500
+ if (pendingTimeout != null) {
476
501
  clearTimeout(pendingTimeout);
477
502
  pendingTimeout = null;
478
503
  }
@@ -826,7 +851,7 @@ var TetherClass = (function (_Evented) {
826
851
  this.enabled = true;
827
852
 
828
853
  this.scrollParents.forEach(function (parent) {
829
- if (parent !== document) {
854
+ if (parent !== _this3.target.ownerDocument) {
830
855
  parent.addEventListener('scroll', _this3.position);
831
856
  }
832
857
  });
@@ -1026,21 +1051,24 @@ var TetherClass = (function (_Evented) {
1026
1051
  }
1027
1052
  };
1028
1053
 
1054
+ var doc = this.target.ownerDocument;
1055
+ var win = doc.defaultView;
1056
+
1029
1057
  var scrollbarSize = undefined;
1030
- if (document.body.scrollWidth > window.innerWidth) {
1058
+ if (doc.body.scrollWidth > win.innerWidth) {
1031
1059
  scrollbarSize = this.cache('scrollbar-size', getScrollBarSize);
1032
1060
  next.viewport.bottom -= scrollbarSize.height;
1033
1061
  }
1034
1062
 
1035
- if (document.body.scrollHeight > window.innerHeight) {
1063
+ if (doc.body.scrollHeight > win.innerHeight) {
1036
1064
  scrollbarSize = this.cache('scrollbar-size', getScrollBarSize);
1037
1065
  next.viewport.right -= scrollbarSize.width;
1038
1066
  }
1039
1067
 
1040
- if (['', 'static'].indexOf(document.body.style.position) === -1 || ['', 'static'].indexOf(document.body.parentElement.style.position) === -1) {
1068
+ if (['', 'static'].indexOf(doc.body.style.position) === -1 || ['', 'static'].indexOf(doc.body.parentElement.style.position) === -1) {
1041
1069
  // Absolute positioning in the body will be relative to the page, not the 'initial containing block'
1042
- next.page.bottom = document.body.scrollHeight - top - height;
1043
- next.page.right = document.body.scrollWidth - left - width;
1070
+ next.page.bottom = doc.body.scrollHeight - top - height;
1071
+ next.page.right = doc.body.scrollWidth - left - width;
1044
1072
  }
1045
1073
 
1046
1074
  if (typeof this.options.optimizations !== 'undefined' && this.options.optimizations.moveElement !== false && !(typeof this.targetModifier !== 'undefined')) {
@@ -1059,8 +1087,8 @@ var TetherClass = (function (_Evented) {
1059
1087
  offsetBorder[side.toLowerCase()] = parseFloat(offsetParentStyle['border' + side + 'Width']);
1060
1088
  });
1061
1089
 
1062
- offsetPosition.right = document.body.scrollWidth - offsetPosition.left - offsetParentSize.width + offsetBorder.right;
1063
- offsetPosition.bottom = document.body.scrollHeight - offsetPosition.top - offsetParentSize.height + offsetBorder.bottom;
1090
+ offsetPosition.right = doc.body.scrollWidth - offsetPosition.left - offsetParentSize.width + offsetBorder.right;
1091
+ offsetPosition.bottom = doc.body.scrollHeight - offsetPosition.top - offsetParentSize.height + offsetBorder.bottom;
1064
1092
 
1065
1093
  if (next.page.top >= offsetPosition.top + offsetBorder.top && next.page.bottom >= offsetPosition.bottom) {
1066
1094
  if (next.page.left >= offsetPosition.left + offsetBorder.left && next.page.right >= offsetPosition.right) {
@@ -1218,7 +1246,7 @@ var TetherClass = (function (_Evented) {
1218
1246
 
1219
1247
  if (!offsetParentIsBody) {
1220
1248
  this.element.parentNode.removeChild(this.element);
1221
- document.body.appendChild(this.element);
1249
+ this.element.ownerDocument.body.appendChild(this.element);
1222
1250
  }
1223
1251
  }
1224
1252
 
@@ -1278,12 +1306,22 @@ function getBoundingRect(tether, to) {
1278
1306
 
1279
1307
  if (typeof to.nodeType !== 'undefined') {
1280
1308
  (function () {
1309
+ var node = to;
1281
1310
  var size = getBounds(to);
1282
1311
  var pos = size;
1283
1312
  var style = getComputedStyle(to);
1284
1313
 
1285
1314
  to = [pos.left, pos.top, size.width + pos.left, size.height + pos.top];
1286
1315
 
1316
+ // Account any parent Frames scroll offset
1317
+ if (node.ownerDocument !== document) {
1318
+ var win = node.ownerDocument.defaultView;
1319
+ to[0] += win.pageXOffset;
1320
+ to[1] += win.pageYOffset;
1321
+ to[2] += win.pageXOffset;
1322
+ to[3] += win.pageYOffset;
1323
+ }
1324
+
1287
1325
  BOUNDS_FORMAT.forEach(function (side, i) {
1288
1326
  side = side[0].toUpperCase() + side.substr(1);
1289
1327
  if (side === 'Top' || side === 'Left') {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tether-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Gavin