From: Mark Otto Date: Fri, 17 Jan 2014 04:01:28 +0000 (-0800) Subject: Merge branch 'bo-tooltip-viewport' of https://github.com/benogle/bootstrap into benog... X-Git-Tag: v3.1.0~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03f4534307988e0c46bd9ee5896977d0adcb7d41;p=thirdparty%2Fbootstrap.git Merge branch 'bo-tooltip-viewport' of https://github.com/benogle/bootstrap into benogle-bo-tooltip-viewport Conflicts: docs/javascript.html --- 03f4534307988e0c46bd9ee5896977d0adcb7d41 diff --cc docs/javascript.html index 2d8c0e7c61,9961a28519..9f8f8675c7 --- a/docs/javascript.html +++ b/docs/javascript.html @@@ -948,131 -960,147 +948,147 @@@ $('#example').tooltip(options {% endhighlight %} -

Options

-

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-animation="".

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Nametypedefaultdescription
animationbooleantrueapply a CSS fade transition to the tooltip
htmlbooleanfalseInsert HTML into the tooltip. If false, jQuery's text method will be used to insert content into the DOM. Use text if you're worried about XSS attacks.
placementstring | function'top'how to position the tooltip - top | bottom | left | right | auto.
When "auto" is specified, it will dynamically reorient the tooltip. For example, if placement is "auto left", the tooltip will display to the left when possible, otherwise it will display right.
selectorstringfalseIf a selector is provided, tooltip objects will be delegated to the specified targets.
titlestring | function''default title value if title attribute isn't present
triggerstring'hover focus'how tooltip is triggered - click | hover | focus | manual. You may pass multiple triggers; separate them with a space.
delaynumber | object0 -

delay showing and hiding the tooltip (ms) - does not apply to manual trigger type

-

If a number is supplied, delay is applied to both hide/show

-

Object structure is: delay: { show: 500, hide: 100 }

-
containerstring | falsefalse -

Appends the tooltip to a specific element. Example: container: 'body'

-
viewportstring'body' -

Keeps the tooltip within the bounds of this element. Example: viewport: '#viewport'

-
viewportPaddingnumber0 -

Pixel distance to keep the tooltip from the edges of the viewport element. Example: viewportPadding: 10

-
-
-
-

Data attributes for individual tooltips

-

Options for individual tooltips can alternatively be specified through the use of data attributes, as explained above.

-
+

Options

+

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-animation="".

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +
Nametypedefaultdescription
animationbooleantrueapply a CSS fade transition to the tooltip
htmlbooleanfalseInsert HTML into the tooltip. If false, jQuery's text method will be used to insert content into the DOM. Use text if you're worried about XSS attacks.
placementstring | function'top'how to position the tooltip - top | bottom | left | right | auto.
When "auto" is specified, it will dynamically reorient the tooltip. For example, if placement is "auto left", the tooltip will display to the left when possible, otherwise it will display right.
selectorstringfalseIf a selector is provided, tooltip objects will be delegated to the specified targets.
titlestring | function''default title value if title attribute isn't present
triggerstring'hover focus'how tooltip is triggered - click | hover | focus | manual. You may pass multiple triggers; separate them with a space.
delaynumber | object0 +

delay showing and hiding the tooltip (ms) - does not apply to manual trigger type

+

If a number is supplied, delay is applied to both hide/show

+

Object structure is: delay: { show: 500, hide: 100 }

+
containerstring | falsefalse +

Appends the tooltip to a specific element. Example: container: 'body'

+
viewportstring'body' ++

Keeps the tooltip within the bounds of this element. Example: viewport: '#viewport'

++
viewportPaddingnumber0 ++

Pixel distance to keep the tooltip from the edges of the viewport element. Example: viewportPadding: 10

++
+
+
+

Data attributes for individual tooltips

+

Options for individual tooltips can alternatively be specified through the use of data attributes, as explained above.

+
-

Methods

- -

$().tooltip(options)

-

Attaches a tooltip handler to an element collection.

- -

.tooltip('show')

-

Reveals an element's tooltip.

- {% highlight js %}$('#element').tooltip('show'){% endhighlight %} - -

.tooltip('hide')

-

Hides an element's tooltip.

- {% highlight js %}$('#element').tooltip('hide'){% endhighlight %} - -

.tooltip('toggle')

-

Toggles an element's tooltip.

- {% highlight js %}$('#element').tooltip('toggle'){% endhighlight %} - -

.tooltip('destroy')

-

Hides and destroys an element's tooltip.

- {% highlight js %}$('#element').tooltip('destroy'){% endhighlight %} - -

Events

-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Event TypeDescription
show.bs.tooltipThis event fires immediately when the show instance method is called.
shown.bs.tooltipThis event is fired when the tooltip has been made visible to the user (will wait for CSS transitions to complete).
hide.bs.tooltipThis event is fired immediately when the hide instance method has been called.
hidden.bs.tooltipThis event is fired when the tooltip has finished being hidden from the user (will wait for CSS transitions to complete).
-
+

Methods

+ +

$().tooltip(options)

+

Attaches a tooltip handler to an element collection.

+ +

.tooltip('show')

+

Reveals an element's tooltip.

+ {% highlight js %}$('#element').tooltip('show'){% endhighlight %} + +

.tooltip('hide')

+

Hides an element's tooltip.

+ {% highlight js %}$('#element').tooltip('hide'){% endhighlight %} + +

.tooltip('toggle')

+

Toggles an element's tooltip.

+ {% highlight js %}$('#element').tooltip('toggle'){% endhighlight %} + +

.tooltip('destroy')

+

Hides and destroys an element's tooltip.

+ {% highlight js %}$('#element').tooltip('destroy'){% endhighlight %} + +

Events

+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Event TypeDescription
show.bs.tooltipThis event fires immediately when the show instance method is called.
shown.bs.tooltipThis event is fired when the tooltip has been made visible to the user (will wait for CSS transitions to complete).
hide.bs.tooltipThis event is fired immediately when the hide instance method has been called.
hidden.bs.tooltipThis event is fired when the tooltip has finished being hidden from the user (will wait for CSS transitions to complete).
+
{% highlight js %} $('#myTooltip').on('hidden.bs.tooltip', function () { // do something… diff --cc js/tests/unit/tooltip.js index b9b003dd1d,94b881bd71..9fab6c61f5 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@@ -347,12 -347,69 +347,73 @@@ $(function () .tooltip('show'), tooltip = container.find('.tooltip') - ok( Math.round(target.offset().top + (target[0].offsetHeight / 2) - (tooltip[0].offsetHeight / 2)) === Math.round(tooltip.offset().top) ) + // this is some dumb hack shit because sub pixels in firefox + var top = Math.round(target.offset().top + (target[0].offsetHeight / 2) - (tooltip[0].offsetHeight / 2)) + var top2 = Math.round(tooltip.offset().top) + var topDiff = top - top2 + ok(topDiff <= 1 && topDiff >= -1) target.tooltip('hide') + $('head #test').remove() + }) + + test('should adjust the tip\'s top when up against the top of the viewport', function () { + $('head').append('') + + var container = $('
').appendTo('body'), + target = $('') + .appendTo(container) + .tooltip({placement: 'right', viewportPadding: 12}) + .tooltip('show'), + tooltip = container.find('.tooltip') + + ok( Math.round(tooltip.offset().top) === 12 ) + target.tooltip('hide') + $('head #test').remove() + }) + + test('should adjust the tip\'s top when up against the bottom of the viewport', function () { + $('head').append('') + + var container = $('
').appendTo('body'), + target = $('') + .appendTo(container) + .tooltip({placement: 'right', viewportPadding: 12}) + .tooltip('show'), + tooltip = container.find('.tooltip') + + ok( Math.round(tooltip.offset().top) === Math.round($(window).height() - 12 - tooltip[0].offsetHeight) ) + target.tooltip('hide') + $('head #test').remove() + }) + + test('should adjust the tip\'s left when up against the left of the viewport', function () { + $('head').append('') + + var container = $('
').appendTo('body'), + target = $('') + .appendTo(container) + .tooltip({placement: 'bottom', viewportPadding: 12}) + .tooltip('show'), + tooltip = container.find('.tooltip') + + ok( Math.round(tooltip.offset().left) === 12 ) + target.tooltip('hide') + $('head #test').remove() + }) + + test('should adjust the tip\'s left when up against the right of the viewport', function () { + $('head').append('') + + var container = $('
').appendTo('body'), + target = $('') + .appendTo(container) + .tooltip({placement: 'bottom', viewportPadding: 12}) + .tooltip('show'), + tooltip = container.find('.tooltip') + + ok( Math.round(tooltip.offset().left) === Math.round($(window).width() - 12 - tooltip[0].offsetWidth) ) + target.tooltip('hide') + $('head #test').remove() }) test('tooltip title test #1', function () {