diff options
| author | Mark Otto <[email protected]> | 2013-12-14 15:38:21 -0800 |
|---|---|---|
| committer | Mark Otto <[email protected]> | 2013-12-14 15:38:21 -0800 |
| commit | a54dbfdf2a08ff04fc65f8e4f77ee5dc76bf4ef3 (patch) | |
| tree | 9b1c5697a731543a86711b016e1986ec1e81dad4 /javascript.html | |
| parent | 80e86442308b2cc86ba948de87e854057933e3ab (diff) | |
| parent | f1869771bc8b8e8a6c7a98385ec58e0bf0d2d98e (diff) | |
| download | bootstrap-a54dbfdf2a08ff04fc65f8e4f77ee5dc76bf4ef3.tar.xz bootstrap-a54dbfdf2a08ff04fc65f8e4f77ee5dc76bf4ef3.zip | |
Merge branch 'master' into pr/10951
Conflicts:
dist/css/bootstrap.min.css
less/modals.less
Diffstat (limited to 'javascript.html')
| -rw-r--r-- | javascript.html | 154 |
1 files changed, 107 insertions, 47 deletions
diff --git a/javascript.html b/javascript.html index ff07387fd..39dbc6e8e 100644 --- a/javascript.html +++ b/javascript.html @@ -30,7 +30,7 @@ base_url: "../" <h3 id="js-data-attrs">Data attributes</h3> <p>You can use all Bootstrap plugins purely through the markup API without writing a single line of JavaScript. This is Bootstrap's first-class API and should be your first consideration when using a plugin.</p> - <p>That said, in some situations it may be desirable to turn this functionality off. Therefore, we also provide the ability to disable the data attribute API by unbinding all events on the document namespaced with <code>data-api</code>. This looks like this: + <p>That said, in some situations it may be desirable to turn this functionality off. Therefore, we also provide the ability to disable the data attribute API by unbinding all events on the document namespaced with <code>data-api</code>. This looks like this:</p> {% highlight js %} $(document).off('.data-api') {% endhighlight %} @@ -43,14 +43,14 @@ $(document).off('.alert.data-api') <h3 id="js-programmatic-api">Programmatic API</h3> <p>We also believe you should be able to use all Bootstrap plugins purely through the JavaScript API. All public APIs are single, chainable methods, and return the collection acted upon.</p> {% highlight js %} -$(".btn.danger").button("toggle").addClass("fat") +$('.btn.danger').button('toggle').addClass('fat') {% endhighlight %} <p>All methods should accept an optional options object, a string which targets a particular method, or nothing (which initiates a plugin with default behavior):</p> {% highlight js %} -$("#myModal").modal() // initialized with defaults -$("#myModal").modal({ keyboard: false }) // initialized with no keyboard -$("#myModal").modal('show') // initializes and invokes show immediately</p> +$('#myModal').modal() // initialized with defaults +$('#myModal').modal({ keyboard: false }) // initialized with no keyboard +$('#myModal').modal('show') // initializes and invokes show immediately {% endhighlight %} <p>Each plugin also exposes its raw constructor on a <code>Constructor</code> property: <code>$.fn.popover.Constructor</code>. If you'd like to get a particular plugin instance, retrieve it directly from an element: <code>$('[rel=popover]').data('popover')</code>.</p> @@ -104,6 +104,15 @@ $('#myModal').on('show.bs.modal', function (e) { <h2 id="modals-examples">Examples</h2> <p>Modals are streamlined, but flexible, dialog prompts with the minimum required functionality and smart defaults.</p> + <div class="bs-callout bs-callout-warning" id="callout-stacked-modals"> + <h4>Overlapping modals not supported</h4> + <p>Be sure not to open a modal while another is still visible. Showing more than one modal at a time requires custom code.</p> + </div> + <div class="bs-callout bs-callout-warning"> + <h4>Mobile device caveats</h4> + <p>There are some caveats regarding using modals on mobile devices. <a href="{{ page.base_url }}getting-started#mobile-modals">See our browser support docs</a> for details.</p> + </div> + <h3>Static example</h3> <p>A rendered modal with header, body, and set of actions in the footer.</p> <div class="bs-example bs-example-modal"> @@ -227,6 +236,7 @@ $('#myModal').on('show.bs.modal', function (e) { </div> <h2 id="modals-usage">Usage</h2> + <p>The modal plugin toggles your hidden content on demand, via data attributes or JavaScript. It also adds <code>.model-open</code> to the <code><body></code> to override default scrolling behavior and generates a <code>.modal-backdrop</code> to provide a click area for dismissing shown modals when clicking outside the modal.</p> <h3>Via data attributes</h3> <p>Activate a modal without writing JavaScript. Set <code>data-toggle="modal"</code> on a controller element, like a button, along with a <code>data-target="#foo"</code> or <code>href="#foo"</code> to target a specific modal to toggle.</p> @@ -253,7 +263,7 @@ $('#myModal').on('show.bs.modal', function (e) { <tbody> <tr> <td>backdrop</td> - <td>boolean</td> + <td>boolean or the string <code>'static'</code></td> <td>true</td> <td>Includes a modal-backdrop element. Alternatively, specify <code>static</code> for a backdrop which doesn't close the modal on click.</td> </tr> @@ -294,15 +304,15 @@ $('#myModal').modal({ {% endhighlight %} <h4>.modal('toggle')</h4> - <p>Manually toggles a modal.</p> + <p>Manually toggles a modal. <strong>Returns to the caller before the modal has actually been shown or hidden</strong> (i.e. before the <code>shown.bs.modal</code> or <code>hidden.bs.modal</code> event occurs).</p> {% highlight js %}$('#myModal').modal('toggle'){% endhighlight %} <h4>.modal('show')</h4> - <p>Manually opens a modal.</p> + <p>Manually opens a modal. <strong>Returns to the caller before the modal has actually been shown</strong> (i.e. before the <code>shown.bs.modal</code> event occurs).</p> {% highlight js %}$('#myModal').modal('show'){% endhighlight %} <h4>.modal('hide')</h4> - <p>Manually hides a modal.</p> + <p>Manually hides a modal. <strong>Returns to the caller before the modal has actually been hidden</strong> (i.e. before the <code>hidden.bs.modal</code> event occurs).</p> {% highlight js %}$('#myModal').modal('hide'){% endhighlight %} <h3>Events</h3> @@ -318,11 +328,11 @@ $('#myModal').modal({ <tbody> <tr> <td>show.bs.modal</td> - <td>This event fires immediately when the <code>show</code> instance method is called.</td> + <td>This event fires immediately when the <code>show</code> instance method is called. If caused by a click, the clicked element is available as the <code>relatedTarget</code> property of the event.</td> </tr> <tr> <td>shown.bs.modal</td> - <td>This event is fired when the modal has been made visible to the user (will wait for CSS transitions to complete).</td> + <td>This event is fired when the modal has been made visible to the user (will wait for CSS transitions to complete). If caused by a click, the clicked element is available as the <code>relatedTarget</code> property of the event.</td> </tr> <tr> <td>hide.bs.modal</td> @@ -336,8 +346,8 @@ $('#myModal').modal({ </table> </div><!-- /.table-responsive --> {% highlight js %} -$('#myModal').on('hidden.bs.modal', function () { - // do something… +$('#myModal').on('hidden.bs.modal', function (e) { + // do something... }) {% endhighlight %} </div> @@ -405,7 +415,7 @@ $('#myModal').on('hidden.bs.modal', function () { </nav> <!-- /navbar-example --> </div> <!-- /example --> - <h3>Within tabs</h3> + <h3>Within pills</h3> <div class="bs-example"> <ul class="nav nav-pills"> <li class="active"><a href="#">Regular link</a></li> @@ -439,11 +449,12 @@ $('#myModal').on('hidden.bs.modal', function () { <li role="presentation"><a role="menuitem" tabindex="-1" href="http://twitter.com/fat">Separated link</a></li> </ul> </li> - </ul> <!-- /tabs --> + </ul> <!-- /pills --> </div> <!-- /example --> <h2 id="dropdowns-usage">Usage</h2> + <p>Via data attributes or JavaScript, the dropdown plugin toggles hidden content (dropdown menus) by toggling the <code>.open</code> class on the parent list item. When opened, the plugin also adds <code>.dropdown-backdrop</code> as a click area for closing dropdown menus when clicking outside the menu.</p> <h3>Via data attributes</h3> <p>Add <code>data-toggle="dropdown"</code> to a link or button to toggle a dropdown.</p> @@ -518,6 +529,7 @@ $('#myDropdown').on('show.bs.dropdown', function () { {% endhighlight %} </div> + <!-- ScrollSpy ================================================== --> <div class="bs-docs-section"> @@ -577,7 +589,13 @@ $('#myDropdown').on('show.bs.dropdown', function () { <h3>Via data attributes</h3> <p>To easily add scrollspy behavior to your topbar navigation, add <code>data-spy="scroll"</code> to the element you want to spy on (most typically this would be the <code><body></code>). Then add the <code>data-target</code> attribute with the ID or class of the parent element of any Bootstrap <code>.nav</code> component.</p> {% highlight html %} -<body data-spy="scroll" data-target="#navbar-example"> +<body data-spy="scroll" data-target=".navbar-example"> + ... + <div class="navbar-example"> + <ul class="nav nav-tabs"> + ... + </ul> + </div> ... </body> {% endhighlight %} @@ -585,7 +603,7 @@ $('#myDropdown').on('show.bs.dropdown', function () { <h3>Via JavaScript</h3> <p>Call the scrollspy via JavaScript:</p> {% highlight js %} -$('body').scrollspy({ target: '#navbar-example' }) +$('body').scrollspy({ target: '.navbar-example' }) {% endhighlight %} <div class="bs-callout bs-callout-danger"> @@ -836,15 +854,27 @@ $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { </div> <div class="bs-callout bs-callout-info"> <h4>Tooltips on disabled elements require wrapper elements</h4> - <p>To add a tooltip to a <code>disabled</code> or <code>.disabled</code> element, put the element inside of a <code><div></code> or <code><span></code>, and apply the tooltip to that element instead.</p> + <p>To add a tooltip to a <code>disabled</code> or <code>.disabled</code> element, put the element inside of a <code><div></code> and apply the tooltip to that <code><div></code> instead.</p> </div> <h2 id="tooltips-usage">Usage</h2> + <p>The tooltip plugin generates content and markup on demand, and by default places tooltips after their trigger element.</p> <p>Trigger the tooltip via JavaScript:</p> {% highlight js %} $('#example').tooltip(options) {% endhighlight %} + <h3>Markup</h3> + <p>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> +{% highlight html linenos %} +<div class="tooltip"> + <div class="tooltip-inner"> + Tooltip! + </div> + <div class="tooltip-arrow"></div> +</div> +{% endhighlight %} + <h3>Options</h3> <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> <div class="table-responsive"> @@ -1006,7 +1036,7 @@ $('#myTooltip').on('hidden.bs.tooltip', function () { </div> <div class="bs-callout bs-callout-info"> <h4>Popovers on disabled elements require wrapper elements</h4> - <p>To add a popover to a <code>disabled</code> or <code>.disabled</code> element, put the element inside of a <code><div></code> or <code><span></code>, and apply the popover to that element instead.</p> + <p>To add a popover to a <code>disabled</code> or <code>.disabled</code> element, put the element inside of a <code><div></code> and apply the popover to that <code><div></code> instead.</p> </div> <h3>Static popover</h3> @@ -1093,7 +1123,7 @@ $('#myTooltip').on('hidden.bs.tooltip', function () { <td>animation</td> <td>boolean</td> <td>true</td> - <td>apply a CSS fade transition to the tooltip</td> + <td>apply a CSS fade transition to the popover</td> </tr> <tr> <td>html</td> @@ -1111,7 +1141,7 @@ $('#myTooltip').on('hidden.bs.tooltip', function () { <td>selector</td> <td>string</td> <td>false</td> - <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 popovers added. See <a href="https://github.com/twbs/bootstrap/issues/4215">this</a> and <a href="http://jsfiddle.net/fScua/">an informative example</a>.</td> + <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 popovers added. See <a href="https://github.com/twbs/bootstrap/issues/4215">this</a> and <a href="http://jsfiddle.net/fScua/">an informative example</a>.</td> </tr> <tr> <td>trigger</td> @@ -1304,14 +1334,23 @@ $('#my-alert').bind('closed.bs.alert', function () { <h4>Stateful</h4> <p>Add <code>data-loading-text="Loading..."</code> to use a loading state on a button.</p> <div class="bs-example" style="padding-bottom: 24px;"> - <button type="button" id="fat-btn" data-loading-text="Loading..." class="btn btn-primary"> + <button type="button" id="loading-example-btn" data-loading-text="Loading..." class="btn btn-primary"> Loading state </button> </div><!-- /example --> {% highlight html %} -<button type="button" data-loading-text="Loading..." class="btn btn-primary"> +<button type="button" id="loading-example-btn" data-loading-text="Loading..." class="btn btn-primary"> Loading state </button> +<script> + $('#loading-example-btn').click(function () { + var btn = $(this); + btn.button('loading'); + $.ajax(...).always(function () { + btn.button('reset'); + }); + }); +</script> {% endhighlight %} <h4>Single toggle</h4> @@ -1385,7 +1424,7 @@ $('#my-alert').bind('closed.bs.alert', function () { <h2 id="buttons-usage">Usage</h2> <p>Enable buttons via JavaScript:</p> {% highlight js %} -$('.btn-group').button() +$('.btn').button() {% endhighlight %} <h3>Markup</h3> @@ -1403,14 +1442,23 @@ $('.btn-group').button() <p>You can enable auto toggling of a button by using the <code>data-toggle</code> attribute.</p> </div> {% highlight html %} -<button type="button" class="btn" data-toggle="button">...</button> +<button type="button" class="btn btn-primary" data-toggle="button">...</button> {% endhighlight %} <h4>$().button('loading')</h4> <p>Sets button state to loading - disables button and swaps text to loading text. Loading text should be defined on the button element using the data attribute <code>data-loading-text</code>. </p> {% highlight html %} -<button type="button" class="btn" data-loading-text="loading stuff...">...</button> +<button id="loading-example-btn" type="button" class="btn btn-primary" data-loading-text="loading stuff...">...</button> +<script> + $('#loading-example-btn').click(function () { + var btn = $(this); + btn.button('loading'); + $.ajax(...).always(function () { + btn.button('reset'); + }); + }); +</script> {% endhighlight %} <div class="bs-callout bs-callout-danger"> @@ -1424,7 +1472,7 @@ $('.btn-group').button() <h4>$().button(string)</h4> <p>Resets button state - swaps text to any data defined text state.</p> {% highlight html %} -<button type="button" class="btn" data-complete-text="finished!" >...</button> +<button type="button" class="btn btn-primary" data-complete-text="finished!" >...</button> <script> $('.btn').button('complete') </script> @@ -1555,6 +1603,13 @@ $('.btn-group').button() <h2 id="collapse-usage">Usage</h2> + <p>The collapse plugin utilizes a few classes to handle the heavy lifting:</p> + <ul> + <li><code>.collapse</code> hides the content</li> + <li><code>.collapse.in</code> shows the content</li> + <li><code>.collapsing</code> is added when the transition starts, and removed when it finishes</li> + </ul> + <p>These classes can be found in <code>component-animations.less</code>.</p> <h3>Via data attributes</h3> <p>Just add <code>data-toggle="collapse"</code> and a <code>data-target</code> to element to automatically assign control of a collapsible element. The <code>data-target</code> attribute accepts a CSS selector to apply the collapse to. Be sure to add the class <code>collapse</code> to the collapsible element. If you'd like it to default open, add the additional class <code>in</code>.</p> @@ -1563,7 +1618,7 @@ $('.btn-group').button() <h3>Via JavaScript</h3> <p>Enable manually with:</p> {% highlight js %} -$(".collapse").collapse() +$('.collapse').collapse() {% endhighlight %} <h3>Options</h3> @@ -1665,7 +1720,7 @@ $('#myCollapsible').on('hidden.bs.collapse', function () { <h2 id="carousel-examples">Examples</h2> <p>The slideshow below shows a generic plugin and component for cycling through elements like a carousel.</p> <div class="bs-example"> - <div id="carousel-example-generic" class="carousel slide bs-docs-carousel-example"> + <div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> <ol class="carousel-indicators"> <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li> <li data-target="#carousel-example-generic" data-slide-to="1"></li> @@ -1673,13 +1728,13 @@ $('#myCollapsible').on('hidden.bs.collapse', function () { </ol> <div class="carousel-inner"> <div class="item active"> - <img src="data:image/png;base64," data-src="holder.js/900x500/auto/#777:#555/text:First slide" alt="First slide"> + <img data-src="holder.js/900x500/auto/#777:#555/text:First slide" alt="First slide"> </div> <div class="item"> - <img src="data:image/png;base64," data-src="holder.js/900x500/auto/#666:#444/text:Second slide" alt="Second slide"> + <img data-src="holder.js/900x500/auto/#666:#444/text:Second slide" alt="Second slide"> </div> <div class="item"> - <img src="data:image/png;base64," data-src="holder.js/900x500/auto/#555:#333/text:Third slide" alt="Third slide"> + <img data-src="holder.js/900x500/auto/#555:#333/text:Third slide" alt="Third slide"> </div> </div> <a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"> @@ -1691,7 +1746,7 @@ $('#myCollapsible').on('hidden.bs.collapse', function () { </div> </div><!-- /example --> {% highlight html %} -<div id="carousel-example-generic" class="carousel slide"> +<div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> <!-- Indicators --> <ol class="carousel-indicators"> <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li> @@ -1727,7 +1782,7 @@ $('#myCollapsible').on('hidden.bs.collapse', function () { <h3>Optional captions</h3> <p>Add captions to your slides easily with the <code>.carousel-caption</code> element within any <code>.item</code>. Place just about any optional HTML within there and it will be automatically aligned and formatted.</p> <div class="bs-example"> - <div id="carousel-example-captions" class="carousel slide bs-docs-carousel-example"> + <div id="carousel-example-captions" class="carousel slide" data-ride="carousel"> <ol class="carousel-indicators"> <li data-target="#carousel-example-captions" data-slide-to="0" class="active"></li> <li data-target="#carousel-example-captions" data-slide-to="1"></li> @@ -1735,21 +1790,21 @@ $('#myCollapsible').on('hidden.bs.collapse', function () { </ol> <div class="carousel-inner"> <div class="item active"> - <img data-src="holder.js/900x500/auto/#777:#777" src="data:image/png;base64," alt="First slide image"> + <img data-src="holder.js/900x500/auto/#777:#777" alt="First slide image"> <div class="carousel-caption"> <h3>First slide label</h3> <p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p> </div> </div> <div class="item"> - <img data-src="holder.js/900x500/auto/#666:#666" src="data:image/png;base64," alt="Second slide image"> + <img data-src="holder.js/900x500/auto/#666:#666" alt="Second slide image"> <div class="carousel-caption"> <h3>Second slide label</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> </div> </div> <div class="item"> - <img data-src="holder.js/900x500/auto/#555:#5555" src="data:image/png;base64," alt="Third slide image"> + <img data-src="holder.js/900x500/auto/#555:#5555" alt="Third slide image"> <div class="carousel-caption"> <h3>Third slide label</h3> <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p> @@ -1896,22 +1951,27 @@ $('#myCarousel').on('slide.bs.carousel', function () { <hr class="bs-docs-separator"> <h2 id="affix-usage">Usage</h2> + <p>Use the affix plugin via data attributes or manually with your own JavaScript. <strong>In both situations, you must provide CSS for the positioning of your content.</strong></p> + + <h3>Positioning via CSS</h3> + <p>The affix plugin toggles between three classes, each representing a particular state: <code>.affix</code>, <code>.affix-top</code>, and <code>.affix-bottom</code>. You must provide the styles for these classes yourself (independent of this plugin) to handle the actual positions.</p> + <p>Here's how the affix plugin works:</p> + <ol> + <li>To start, the plugin adds <code>.affix-top</code> to indicate the element is in it's top-most position. At this point no CSS positioning is required.</li> + <li>Scrolling past the element you want affixed should trigger the actual affixing. This is where <code>.affix</code> replaces <code>.affix-top</code> and sets <code>position: fixed;</code> (provided by Bootstrap's code CSS).</li> + <li>If a bottom offset is defined, scrolling past that should replace <code>.affix</code> with <code>.affix-bottom</code>. Since offsets are optional, setting one requires you to set the appropriate CSS. In this case, add <code>position: absolute;</code> when necessary. The plugin uses the data attribute or JavaScript option to determine where to position the element from there.</li> + </ol> + <p>Follow the above steps to set your CSS for either of the usage options below.</p> <h3>Via data attributes</h3> - <p>To easily add affix behavior to any element, just add <code>data-spy="affix"</code> to the element you want to spy on. Then use offsets to define when to toggle the pinning of an element on and off.</p> + <p>To easily add affix behavior to any element, just add <code>data-spy="affix"</code> to the element you want to spy on. Use offsets to define when to toggle the pinning of an element.</p> {% highlight html %} -<div data-spy="affix" data-offset-top="200">...</div> +<div data-spy="affix" data-offset-top="60" data-offset-bottom="200"> + ... +</div> {% endhighlight %} - <div class="bs-callout bs-callout-warning"> - <h4>Requires independent styling ;)</h4> - <p> - Affix toggles between three states/classes: <code>.affix</code>, <code>.affix-top</code>, and <code>.affix-bottom</code>. You must provide the styles for these classes yourself (independent of this plugin). - The <code>.affix-top</code> class should be in the regular flow of the document. The <code>.affix</code> class should be <code>position: fixed</code>. And <code>.affix-bottom</code> should be <code>position: absolute</code>. Note: <code>.affix-bottom</code> is special in that the plugin will place the element with JS relative to the <code>offset: { bottom: number }</code> option you've provided. - </p> - </div> - <h3>Via JavaScript</h3> <p>Call the affix plugin via JavaScript:</p> {% highlight js %} |
