Skip to content

Commit ffb3118

Browse files
author
pzuraq
committed
Updates positioning to only move tethered element if it's offset parent is not the body
1 parent fad4137 commit ffb3118

File tree

6 files changed

+44
-18
lines changed

6 files changed

+44
-18
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tether",
3-
"version": "1.0.3",
3+
"version": "1.1.0",
44
"homepage": "http://github.hubspot.com/tether",
55
"authors": [
66
"Zack Bloom <zackbloom@gmail.com>",

component.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tether",
33
"repo": "HubSpot/tether",
4-
"version": "1.0.3",
4+
"version": "1.1.0",
55
"description": "A client-side library to make absolutely positioned elements attach to elements in the page efficiently.",
66
"authors": [
77
"Zack Bloom <zackbloom@gmail.com>",

dist/js/tether.js

+24-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! tether 1.0.3 */
1+
/*! tether 1.1.0 */
22

33
(function(root, factory) {
44
if (typeof define === 'function' && define.amd) {
@@ -182,7 +182,7 @@ function getScrollBarSize() {
182182
}
183183

184184
function extend() {
185-
var out = arguments[0] === undefined ? {} : arguments[0];
185+
var out = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
186186

187187
var args = [];
188188

@@ -285,7 +285,7 @@ var Evented = (function () {
285285
_createClass(Evented, [{
286286
key: 'on',
287287
value: function on(event, handler, ctx) {
288-
var once = arguments[3] === undefined ? false : arguments[3];
288+
var once = arguments.length <= 3 || arguments[3] === undefined ? false : arguments[3];
289289

290290
if (typeof this.bindings === 'undefined') {
291291
this.bindings = {};
@@ -397,7 +397,7 @@ var flush = _TetherBase$Utils.flush;
397397
var getScrollBarSize = _TetherBase$Utils.getScrollBarSize;
398398

399399
function within(a, b) {
400-
var diff = arguments[2] === undefined ? 1 : arguments[2];
400+
var diff = arguments.length <= 2 || arguments[2] === undefined ? 1 : arguments[2];
401401

402402
return a + diff >= b && b >= a - diff;
403403
}
@@ -590,7 +590,7 @@ var TetherClass = (function () {
590590
_createClass(TetherClass, [{
591591
key: 'getClass',
592592
value: function getClass() {
593-
var key = arguments[0] === undefined ? '' : arguments[0];
593+
var key = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0];
594594
var classes = this.options.classes;
595595

596596
if (typeof classes !== 'undefined' && classes[key]) {
@@ -606,7 +606,7 @@ var TetherClass = (function () {
606606
value: function setOptions(options) {
607607
var _this2 = this;
608608

609-
var pos = arguments[1] === undefined ? true : arguments[1];
609+
var pos = arguments.length <= 1 || arguments[1] === undefined ? true : arguments[1];
610610

611611
var defaults = {
612612
offset: '0 0',
@@ -788,7 +788,7 @@ var TetherClass = (function () {
788788
}, {
789789
key: 'enable',
790790
value: function enable() {
791-
var pos = arguments[0] === undefined ? true : arguments[0];
791+
var pos = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
792792

793793
if (!(this.options.addTargetClasses === false)) {
794794
addClass(this.target, this.getClass('enabled'));
@@ -887,7 +887,7 @@ var TetherClass = (function () {
887887
value: function position() {
888888
var _this5 = this;
889889

890-
var flushChanges = arguments[0] === undefined ? true : arguments[0];
890+
var flushChanges = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
891891

892892
// flushChanges commits the changes immediately, leave true unless you are positioning multiple
893893
// tethers (in which case call Tether.Utils.flush yourself when you're done)
@@ -1165,9 +1165,22 @@ var TetherClass = (function () {
11651165
transcribe({ top: true, left: true }, pos.page);
11661166
}
11671167

1168-
if (!moved && this.element.parentNode.tagName !== 'BODY') {
1169-
this.element.parentNode.removeChild(this.element);
1170-
document.body.appendChild(this.element);
1168+
if (!moved) {
1169+
var offsetParentIsBody = true;
1170+
var currentNode = this.element.parentNode;
1171+
while (currentNode && currentNode.tagName !== 'BODY') {
1172+
if (getComputedStyle(currentNode).position !== 'static') {
1173+
offsetParentIsBody = false;
1174+
break;
1175+
}
1176+
1177+
currentNode = currentNode.parentNode;
1178+
}
1179+
1180+
if (!offsetParentIsBody) {
1181+
this.element.parentNode.removeChild(this.element);
1182+
document.body.appendChild(this.element);
1183+
}
11711184
}
11721185

11731186
// Any css change will trigger a repaint, so let's avoid one if nothing changed

dist/js/tether.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tether",
3-
"version": "1.0.3",
3+
"version": "1.1.0",
44
"description": "A client-side library to make absolutely positioned elements attach to elements in the page efficiently.",
55
"authors": [
66
"Zack Bloom <zackbloom@gmail.com>",

src/js/tether.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,22 @@ class TetherClass {
730730
transcribe({top: true, left: true}, pos.page);
731731
}
732732

733-
if(!moved && this.element.parentNode.tagName !== 'BODY') {
734-
this.element.parentNode.removeChild(this.element);
735-
document.body.appendChild(this.element);
733+
if (!moved) {
734+
let offsetParentIsBody = true;
735+
let currentNode = this.element.parentNode;
736+
while (currentNode && currentNode.tagName !== 'BODY') {
737+
if (getComputedStyle(currentNode).position !== 'static') {
738+
offsetParentIsBody = false;
739+
break;
740+
}
741+
742+
currentNode = currentNode.parentNode;
743+
}
744+
745+
if (!offsetParentIsBody) {
746+
this.element.parentNode.removeChild(this.element);
747+
document.body.appendChild(this.element);
748+
}
736749
}
737750

738751
// Any css change will trigger a repaint, so let's avoid one if nothing changed

0 commit comments

Comments
 (0)