Policy 1707 commit to LF
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / CSS / bootstrap / docs / _includes / js / tooltips.html
1 <div class="bs-docs-section">
2   <h1 id="tooltips" class="page-header">Tooltips <small>tooltip.js</small></h1>
3   <p>Inspired by the excellent jQuery.tipsy plugin written by Jason Frame; Tooltips are an updated version, which don't rely on images, use CSS3 for animations, and data-attributes for local title storage.</p>
4   <p>Tooltips with zero-length titles are never displayed.</p>
5
6   <h2 id="tooltips-examples">Examples</h2>
7   <p>Hover over the links below to see tooltips:</p>
8   <div class="bs-example tooltip-demo">
9     <p>Tight pants next level keffiyeh <a href="#" data-toggle="tooltip" title="Default tooltip">you probably</a> haven't heard of them. Photo booth beard raw denim letterpress vegan messenger bag stumptown. Farm-to-table seitan, mcsweeney's fixie sustainable quinoa 8-bit american apparel <a href="#" data-toggle="tooltip" title="Another tooltip">have a</a> terry richardson vinyl chambray. Beard stumptown, cardigans banh mi lomo thundercats. Tofu biodiesel williamsburg marfa, four loko mcsweeney's cleanse vegan chambray. A really ironic artisan <a href="#" data-toggle="tooltip" title="Another one here too">whatever keytar</a>, scenester farm-to-table banksy Austin <a href="#" data-toggle="tooltip" title="The last tip!">twitter handle</a> freegan cred raw denim single-origin coffee viral.</p>
10   </div><!-- /example -->
11
12   <h3>Static tooltip</h3>
13   <p>Four options are available: top, right, bottom, and left aligned.</p>
14   <div class="bs-example bs-example-tooltip" data-example-id="static-tooltips">
15     <div class="tooltip left" role="tooltip">
16       <div class="tooltip-arrow"></div>
17       <div class="tooltip-inner">
18         Tooltip on the left
19       </div>
20     </div>
21     <div class="tooltip top" role="tooltip">
22       <div class="tooltip-arrow"></div>
23       <div class="tooltip-inner">
24         Tooltip on the top
25       </div>
26     </div>
27     <div class="tooltip bottom" role="tooltip">
28       <div class="tooltip-arrow"></div>
29       <div class="tooltip-inner">
30         Tooltip on the bottom
31       </div>
32     </div>
33     <div class="tooltip right" role="tooltip">
34       <div class="tooltip-arrow"></div>
35       <div class="tooltip-inner">
36         Tooltip on the right
37       </div>
38     </div>
39   </div>
40
41   <h3>Four directions</h3>
42   <div class="bs-example tooltip-demo">
43     <div class="bs-example-tooltips">
44       <button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="left" title="Tooltip on left">Tooltip on left</button>
45       <button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="Tooltip on top">Tooltip on top</button>
46       <button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="bottom" title="Tooltip on bottom">Tooltip on bottom</button>
47       <button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="right" title="Tooltip on right">Tooltip on right</button>
48     </div>
49   </div><!-- /example -->
50 {% highlight html %}
51 <button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="left" title="Tooltip on left">Tooltip on left</button>
52
53 <button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="Tooltip on top">Tooltip on top</button>
54
55 <button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="bottom" title="Tooltip on bottom">Tooltip on bottom</button>
56
57 <button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="right" title="Tooltip on right">Tooltip on right</button>
58 {% endhighlight %}
59
60   <div class="bs-callout bs-callout-danger" id="callout-tooltip-opt-in">
61     <h4>Opt-in functionality</h4>
62     <p>For performance reasons, the Tooltip and Popover data-apis are opt-in, meaning <strong>you must initialize them yourself</strong>.</p>
63     <p>One way to initialize all tooltips on a page would be to select them by their <code>data-toggle</code> attribute:</p>
64 {% highlight js %}
65 $(function () {
66   $('[data-toggle="tooltip"]').tooltip()
67 })
68 {% endhighlight %}
69
70   </div>
71   <div class="bs-callout bs-callout-warning" id="callout-tooltip-groups">
72     <h4>Tooltips in button groups and input groups require special setting</h4>
73     <p>When using tooltips on elements within a <code>.btn-group</code> or an <code>.input-group</code>, you'll have to specify the option <code>container: 'body'</code> (documented below) to avoid unwanted side effects (such as the element growing wider and/or losing its rounded corners when the tooltip is triggered).</p>
74   </div>
75   <div class="bs-callout bs-callout-warning" id="callout-tooltip-hidden">
76     <h4>Don't try to show tooltips on hidden elements</h4>
77     <p>Invoking <code>$(...).tooltip('show')</code> when the target element is <code>display: none;</code> will cause the tooltip to be incorrectly positioned.</p>
78   </div>
79   <div class="bs-callout bs-callout-info" id="callout-tooltip-disabled">
80     <h4>Tooltips on disabled elements require wrapper elements</h4>
81     <p>To add a tooltip to a <code>disabled</code> or <code>.disabled</code> element, put the element inside of a <code>&lt;div&gt;</code> and apply the tooltip to that <code>&lt;div&gt;</code> instead.</p>
82   </div>
83
84   <h2 id="tooltips-usage">Usage</h2>
85   <p>The tooltip plugin generates content and markup on demand, and by default places tooltips after their trigger element.</p>
86   <p>Trigger the tooltip via JavaScript:</p>
87 {% highlight js %}
88 $('#example').tooltip(options)
89 {% endhighlight %}
90
91   <h3>Markup</h3>
92   <p>The required markup for a tooltip is only a <code>data</code> attribute and <code>title</code> on the HTML element you wish to have a tooltip. The generated markup of a tooltip is rather simple, though it does require a position (by default, set to <code>top</code> by the plugin).</p>
93   <div class="bs-callout bs-callout-warning" id="callout-tooltip-multiline">
94     <h4>Multiple-line links</h4>
95     <p>Sometimes you want to add a tooltip to a hyperlink that wraps multiple lines. The default behavior of the tooltip plugin is to center it horizontally and vertically. Add <code>white-space: nowrap;</code> to your anchors to avoid this.</p>
96   </div>
97 {% highlight html %}
98 <!-- HTML to write -->
99 <a href="#" data-toggle="tooltip" title="Some tooltip text!">Hover over me</a>
100
101 <!-- Generated markup by the plugin -->
102 <div class="tooltip top" role="tooltip">
103   <div class="tooltip-arrow"></div>
104   <div class="tooltip-inner">
105     Some tooltip text!
106   </div>
107 </div>
108 {% endhighlight %}
109
110   <h3 id="tooltips-options">Options</h3>
111   <p>Options can be passed via data attributes or JavaScript. For data attributes, append the option name to <code>data-</code>, as in <code>data-animation=""</code>.</p>
112   <div class="table-responsive">
113     <table class="table table-bordered table-striped js-options-table">
114       <thead>
115         <tr>
116           <th>Name</th>
117           <th>Type</th>
118           <th>Default</th>
119           <th>Description</th>
120         </tr>
121       </thead>
122       <tbody>
123         <tr>
124           <td>animation</td>
125           <td>boolean</td>
126           <td>true</td>
127           <td>Apply a CSS fade transition to the tooltip</td>
128         </tr>
129         <tr>
130           <td>container</td>
131           <td>string | false</td>
132           <td>false</td>
133           <td>
134             <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>
135           </td>
136         </tr>
137         <tr>
138           <td>delay</td>
139           <td>number | object</td>
140           <td>0</td>
141           <td>
142             <p>Delay showing and hiding the tooltip (ms) - does not apply to manual trigger type</p>
143             <p>If a number is supplied, delay is applied to both hide/show</p>
144             <p>Object structure is: <code>delay: { "show": 500, "hide": 100 }</code></p>
145           </td>
146         </tr>
147         <tr>
148           <td>html</td>
149           <td>boolean</td>
150           <td>false</td>
151           <td>Insert HTML into the tooltip. If false, jQuery's <code>text</code> method will be used to insert content into the DOM. Use text if you're worried about XSS attacks.</td>
152         </tr>
153         <tr>
154           <td>placement</td>
155           <td>string | function</td>
156           <td>'top'</td>
157           <td>
158             <p>How to position the tooltip - top | bottom | left | right | auto.<br>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.</p>
159             <p>When a function is used to determine the placement, it is called with the tooltip DOM node as its first argument and the triggering element DOM node as its second. The <code>this</code> context is set to the tooltip instance.</p>
160           </td>
161         </tr>
162         <tr>
163           <td>selector</td>
164           <td>string</td>
165           <td>false</td>
166           <td>If a selector is provided, tooltip objects will be delegated to the specified targets. In practice, this is used to enable dynamic HTML content to have tooltips added. See <a href="https://github.com/twbs/bootstrap/issues/4215">this</a> and <a href="http://jsbin.com/zopod/1/edit">an informative example</a>.</td>
167         </tr>
168         <tr>
169           <td>template</td>
170           <td>string</td>
171           <td><code>'&lt;div class="tooltip" role="tooltip"&gt;&lt;div class="tooltip-arrow"&gt;&lt;/div&gt;&lt;div class="tooltip-inner"&gt;&lt;/div&gt;&lt;/div&gt;'</code></td>
172           <td>
173             <p>Base HTML to use when creating the tooltip.</p>
174             <p>The tooltip's <code>title</code> will be injected into the <code>.tooltip-inner</code>.</p>
175             <p><code>.tooltip-arrow</code> will become the tooltip's arrow.</p>
176             <p>The outermost wrapper element should have the <code>.tooltip</code> class.</p>
177           </td>
178         </tr>
179         <tr>
180           <td>title</td>
181           <td>string | function</td>
182           <td>''</td>
183           <td>
184             <p>Default title value if <code>title</code> attribute isn't present.</p>
185             <p>If a function is given, it will be called with its <code>this</code> reference set to the element that the tooltip is attached to.</p>
186           </td>
187         </tr>
188         <tr>
189           <td>trigger</td>
190           <td>string</td>
191           <td>'hover focus'</td>
192           <td>How tooltip is triggered - click | hover | focus | manual. You may pass multiple triggers; separate them with a space.</td>
193         </tr>
194         <tr>
195           <td>viewport</td>
196           <td>string | object</td>
197           <td>{ selector: 'body', padding: 0 }</td>
198           <td>
199             <p>Keeps the tooltip within the bounds of this element. Example: <code>viewport: '#viewport'</code> or <code>{ "selector": "#viewport", "padding": 0 }</code></p>
200           </td>
201         </tr>
202       </tbody>
203     </table>
204   </div><!-- /.table-responsive -->
205   <div class="bs-callout bs-callout-info" id="callout-tooltip-data">
206     <h4>Data attributes for individual tooltips</h4>
207     <p>Options for individual tooltips can alternatively be specified through the use of data attributes, as explained above.</p>
208   </div>
209
210   <h3 id="tooltips-methods">Methods</h3>
211
212   <h4><code>$().tooltip(options)</code></h4>
213   <p>Attaches a tooltip handler to an element collection.</p>
214
215   <h4><code>.tooltip('show')</code></h4>
216   <p>Reveals an element's tooltip. <strong>Returns to the caller before the tooltip has actually been shown</strong> (i.e. before the <code>shown.bs.tooltip</code> event occurs). This is considered a "manual" triggering of the tooltip. Tooltips with zero-length titles are never displayed.</p>
217   {% highlight js %}$('#element').tooltip('show'){% endhighlight %}
218
219   <h4><code>.tooltip('hide')</code></h4>
220   <p>Hides an element's tooltip. <strong>Returns to the caller before the tooltip has actually been hidden</strong> (i.e. before the <code>hidden.bs.tooltip</code> event occurs). This is considered a "manual" triggering of the tooltip.</p>
221   {% highlight js %}$('#element').tooltip('hide'){% endhighlight %}
222
223   <h4><code>.tooltip('toggle')</code></h4>
224   <p>Toggles an element's tooltip. <strong>Returns to the caller before the tooltip has actually been shown or hidden</strong> (i.e. before the <code>shown.bs.tooltip</code> or <code>hidden.bs.tooltip</code> event occurs). This is considered a "manual" triggering of the tooltip.</p>
225   {% highlight js %}$('#element').tooltip('toggle'){% endhighlight %}
226
227   <h4><code>.tooltip('destroy')</code></h4>
228   <p>Hides and destroys an element's tooltip. Tooltips that use delegation (which are created using <a href="#tooltips-options">the <code>selector</code> option</a>) cannot be individually destroyed on descendant trigger elements.</p>
229   {% highlight js %}$('#element').tooltip('destroy'){% endhighlight %}
230
231   <h3 id="tooltips-events">Events</h3>
232   <div class="table-responsive">
233     <table class="table table-bordered table-striped bs-events-table">
234       <thead>
235         <tr>
236           <th>Event Type</th>
237           <th>Description</th>
238         </tr>
239       </thead>
240       <tbody>
241         <tr>
242           <td>show.bs.tooltip</td>
243           <td>This event fires immediately when the <code>show</code> instance method is called.</td>
244         </tr>
245         <tr>
246           <td>shown.bs.tooltip</td>
247           <td>This event is fired when the tooltip has been made visible to the user (will wait for CSS transitions to complete).</td>
248         </tr>
249         <tr>
250           <td>hide.bs.tooltip</td>
251           <td>This event is fired immediately when the <code>hide</code> instance method has been called.</td>
252         </tr>
253         <tr>
254           <td>hidden.bs.tooltip</td>
255           <td>This event is fired when the tooltip has finished being hidden from the user (will wait for CSS transitions to complete).</td>
256         </tr>
257       </tbody>
258     </table>
259   </div><!-- /.table-responsive -->
260 {% highlight js %}
261 $('#myTooltip').on('hidden.bs.tooltip', function () {
262   // do something…
263 })
264 {% endhighlight %}
265 </div>