From dcf75697ecd243517b23d8ef440f772d91f699c0 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sun, 22 Jul 2012 18:28:39 -0700 Subject: some progress on affix plugin --- docs/javascript.html | 107 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 91 insertions(+), 16 deletions(-) (limited to 'docs/javascript.html') diff --git a/docs/javascript.html b/docs/javascript.html index 9b2897699..bc17456ea 100644 --- a/docs/javascript.html +++ b/docs/javascript.html @@ -85,7 +85,8 @@ ================================================== -->
-

Individual or compiled

-

If you have downloaded the latest version of Bootstrap, both bootstrap.js and bootstrap.min.js contain all of these plugins.

+

If you have downloaded the latest version of Bootstrap, both bootstrap.js and bootstrap.min.js contain all of the plugins listed on this page.

Data attributes

-

...

+

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.

+ +

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 body namespaced with `'data-api'`. This looks like this: + +

+  $('body').off('.data-api')
+
+ +

Alternatively, to target a specific plugin, just include the plugins name as a namespace along with the data-api namespace like this:

+ +
+  $('body').off('.alert.data-api')
+

Programmatic API

-

...

+

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.

+ +
+  $(".btn.danger").button("toggle").addClass("fat")
+
+ +

All methods should accept an optional options object, a string which targets a particular method, or nothing (which initiates a plugin with default behavior):

+
+  $("#myModal").modal()                       // initialized with defaults
+  $("#myModal").modal({ keyboard: false })   // initialized with no keyboard
+  $("#myModal").modal('show')                // initializes and invokes show immediately

+
+

Each plugin also exposes it's raw constructor on a `Constructor` property: $.fn.popover.Constructor. If you'd like to get a particular plugin instance, retrieve it directly from an element: $('[rel=popover]').data('popover').

+ + +

Events

+

Bootstrap provides custom events for most plugin's unique actions. Generally, these come in an infinitive and past participle form - where the infinitive (ex. show) is triggered at the start of an event, and it's past participle form (ex. shown) is trigger on the completion of an action.

+ +

All infinitive events provide preventDefault functionality. This provides the abililty to stop the execution of an action before it starts.

+ +
+  $('#myModal').on('show', function (e) {
+      if (!data) return e.preventDefault() // stops modal from being shown
+  })
+
@@ -849,7 +886,7 @@ $('a[data-toggle="tab"]').on('shown', function (e) {

Toggles an element's tooltip.

$('#element').tooltip('toggle')

.tooltip('destroy')

-

Destroys an element's tooltip.

+

Hides and destroys an element's tooltip.

$('#element').tooltip('destroy')
@@ -1004,7 +1041,7 @@ $('a[data-toggle="tab"]').on('shown', function (e) {

Toggles an elements popover.

$('#element').popover('toggle')

.popover('destroy')

-

Destroys an element's popover.

+

Hides and destroys an element's popover.

$('#element').popover('destroy')
@@ -1581,23 +1618,60 @@ $('.carousel').carousel({ ================================================== -->
-

...

-

...

-
+

Example

+

The subnavigation on the left is a live demo of the affix plugin.

+ +
+ +

Usage

+ +

Via data attributes

+

To easily add affix behavior to any element, just add data-spy="affix" to the element you want to spy on. When the affix offsets are satisified, an .affix class is added to the element.

+ +
<div data-spy="affix">...</body>
+ +
+ Heads up! + It's up to you to maintain the dimensions of an element when toggling between relative and fixed positions. To see how this is done, refer to this pages subnavigation.
+ +

Via javascript

+

Call the affix plugin via javascript:

+
$('#navbar').affix()
+ +

Methods

+

.scrollspy('refresh')

+

When using affix in conjunction with adding or removing of elements from the DOM, you'll need to call the refresh method like so:

-...
+$('[data-spy="affix"]').each(function () {
+  $(this).affix('refresh')
+});
 
-
- +

Options

+

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

+ + + + + + + + + + + + + + + + + +
Nametypedefaultdescription
offsetnumber | object10Pixels to offset from screen when calculating position of scroll. If a single number is provide, the offset will be applied in both top and left directions. To listen for a single direction, or multiple unique offsets, just provided an object offset: { x: 10 }.
@@ -1642,6 +1716,7 @@ $('.carousel').carousel({ + -- cgit v1.2.3