Skip to content

Commit

Permalink
Merge branch 'container-tooltip-option' into v4-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mdo committed Nov 27, 2016
2 parents 181e124 + 0ded703 commit 87a0749
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/components/tooltips.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap
</tr>
<tr>
<td>container</td>
<td>string | false</td>
<td>string | element | false</td>
<td>false</td>
<td>
<p>Appends the tooltip to a specific element. Example: <code>container: 'body'</code>. This option is particularly useful in that it allows you to position the tooltip in the flow of the document near the triggering element - which will prevent the tooltip from floating away from the triggering element during a window resize.</p>
Expand Down
10 changes: 7 additions & 3 deletions js/src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ const Tooltip = (($) => {
selector : false,
placement : 'top',
offset : '0 0',
constraints : []
constraints : [],
container : false
}

const DefaultType = {
Expand All @@ -59,7 +60,8 @@ const Tooltip = (($) => {
selector : '(string|boolean)',
placement : '(string|function)',
offset : 'string',
constraints : 'array'
constraints : 'array',
container : '(string|element|boolean)'
}

const AttachmentMap = {
Expand Down Expand Up @@ -274,9 +276,11 @@ const Tooltip = (($) => {

const attachment = this._getAttachment(placement)

const container = this.config.container === false ? document.body : $(this.config.container)

$(tip)
.data(this.constructor.DATA_KEY, this)
.appendTo(document.body)
.appendTo(container)

$(this.element).trigger(this.constructor.Event.INSERTED)

Expand Down

0 comments on commit 87a0749

Please sign in to comment.