Adds option to specify body element #204
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: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: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