Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds option to specify body element #204

Conversation

pzuraq
Copy link

@pzuraq pzuraq commented Aug 29, 2016

This PR adds a new option, bodyElement, which can be used to specify which element the tether's should attach themselves to when moving within the DOM for positioning. This PR is intended to supersede #98 and #192, which were attempts to achieve the same effect. Given that this PR intends to only be a minor version bump, the code from #98 is left intact, but should probably be deprecated and removed in future versions.

Motivation

New Javascript frameworks like React and Ember oftentimes require more direct control over libraries that were originally intended to be used with just the DOM. In React's case in particular, the VirtualDOM has no document.body to speak of and references to it can be problematic. In Ember's case, Fastboot and server side rendering are also done in absence of browser APIs and a body. With Ember animation, things get even more complicated, and I can elaborate on that point if needed.

Tether.js has a single assumption about positioning - that everything is relative to the document.body. This allows it to dramatically simplify the logic of positioning. However, consider the following example:

<body>
  <div id="ember-app">
    <div style="position: absolute; top: 100px">
      <div id="element-to-tether">
        I'm a tether
      </div>
    </div>
  </div>
<body>

In this example, if we were to prevent the tethered element from moving at all, it would be placed 100px out of place, which is not ideal. However, assuming the ember-app div has no styles on it at all, then we could attach the tethered element to that div and it would be in the correct place. This is how React and Ember developers would be able to use the new feature to attach tether's within the confines of their applications:

const element = $('#element-to-tether')[0];
const bodyElement = $('#ember-app')[0];

const tether = new Tether({ element, bodyElement });

It would be up to the developers to ensure that whatever element is considered the bodyElement will have the correct characteristics for positioning (same size and position w/ respect to the body).

/cc @jpnelson @nadiam84 @TrevorBurnham @FezVrasta

@pzuraq pzuraq force-pushed the adds-option-to-specify-body-element branch from 071008e to d5b3242 Compare September 8, 2016 19:35
@pzuraq
Copy link
Author

pzuraq commented Sep 8, 2016

@TrevorBurnham @zackbloom Any word on this? Rebased it, so it's ready to merge. Happy to talk about potential consequences of this API and why it's necessary for frameworks like Ember and React to function properly.

@madchicken
Copy link

@TrevorBurnham I'd like to see the PR going on master. Any chance to get it merged soon?

@TrevorBurnham
Copy link
Contributor

@pzuraq This looks good! 👍 Could you rebase again to update against the latest master?

@pzuraq pzuraq force-pushed the adds-option-to-specify-body-element branch from d5b3242 to 4de1f5c Compare December 2, 2016 21:50
@pzuraq
Copy link
Author

pzuraq commented Dec 2, 2016

@TrevorBurnham updated! Thanks for looking over this 😄

@TrevorBurnham TrevorBurnham merged commit 3d7119e into shipshapecode:master Dec 2, 2016
@TrevorBurnham
Copy link
Contributor

Published as Tether 1.4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants