Skip to content

Commit

Permalink
Updates positioning to only move tethered element if it's offset pare…
Browse files Browse the repository at this point in the history
…nt is not the body
  • Loading branch information
pzuraq committed Jul 15, 2015
1 parent fad4137 commit ffb3118
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 18 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tether",
"version": "1.0.3",
"version": "1.1.0",
"homepage": "http://github.hubspot.com/tether",
"authors": [
"Zack Bloom <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tether",
"repo": "HubSpot/tether",
"version": "1.0.3",
"version": "1.1.0",
"description": "A client-side library to make absolutely positioned elements attach to elements in the page efficiently.",
"authors": [
"Zack Bloom <[email protected]>",
Expand Down
35 changes: 24 additions & 11 deletions dist/js/tether.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! tether 1.0.3 */
/*! tether 1.1.0 */

(function(root, factory) {
if (typeof define === 'function' && define.amd) {
Expand Down Expand Up @@ -182,7 +182,7 @@ function getScrollBarSize() {
}

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

var args = [];

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

if (typeof this.bindings === 'undefined') {
this.bindings = {};
Expand Down Expand Up @@ -397,7 +397,7 @@ var flush = _TetherBase$Utils.flush;
var getScrollBarSize = _TetherBase$Utils.getScrollBarSize;

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

return a + diff >= b && b >= a - diff;
}
Expand Down Expand Up @@ -590,7 +590,7 @@ var TetherClass = (function () {
_createClass(TetherClass, [{
key: 'getClass',
value: function getClass() {
var key = arguments[0] === undefined ? '' : arguments[0];
var key = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0];
var classes = this.options.classes;

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

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

var defaults = {
offset: '0 0',
Expand Down Expand Up @@ -788,7 +788,7 @@ var TetherClass = (function () {
}, {
key: 'enable',
value: function enable() {
var pos = arguments[0] === undefined ? true : arguments[0];
var pos = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];

if (!(this.options.addTargetClasses === false)) {
addClass(this.target, this.getClass('enabled'));
Expand Down Expand Up @@ -887,7 +887,7 @@ var TetherClass = (function () {
value: function position() {
var _this5 = this;

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

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

if (!moved && this.element.parentNode.tagName !== 'BODY') {
this.element.parentNode.removeChild(this.element);
document.body.appendChild(this.element);
if (!moved) {
var offsetParentIsBody = true;
var currentNode = this.element.parentNode;
while (currentNode && currentNode.tagName !== 'BODY') {
if (getComputedStyle(currentNode).position !== 'static') {
offsetParentIsBody = false;
break;
}

currentNode = currentNode.parentNode;
}

if (!offsetParentIsBody) {
this.element.parentNode.removeChild(this.element);
document.body.appendChild(this.element);
}
}

// Any css change will trigger a repaint, so let's avoid one if nothing changed
Expand Down
2 changes: 1 addition & 1 deletion dist/js/tether.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tether",
"version": "1.0.3",
"version": "1.1.0",
"description": "A client-side library to make absolutely positioned elements attach to elements in the page efficiently.",
"authors": [
"Zack Bloom <[email protected]>",
Expand Down
19 changes: 16 additions & 3 deletions src/js/tether.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,9 +730,22 @@ class TetherClass {
transcribe({top: true, left: true}, pos.page);
}

if(!moved && this.element.parentNode.tagName !== 'BODY') {
this.element.parentNode.removeChild(this.element);
document.body.appendChild(this.element);
if (!moved) {
let offsetParentIsBody = true;
let currentNode = this.element.parentNode;
while (currentNode && currentNode.tagName !== 'BODY') {
if (getComputedStyle(currentNode).position !== 'static') {
offsetParentIsBody = false;
break;
}

currentNode = currentNode.parentNode;
}

if (!offsetParentIsBody) {
this.element.parentNode.removeChild(this.element);
document.body.appendChild(this.element);
}
}

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

0 comments on commit ffb3118

Please sign in to comment.