About this library

This library implements support for Bootstrap components using MooTools. It does not use the same data- tags as Bootstrap's native jQuery implementation, so be sure to read this document thoroughly. Not every component is included here (most notably Carousel and Scrollspy) because the author has not found need of them and thus hasn't gotten around to it. Pull requests are accepted and encouraged!

Plugin dependencies

All the plugins in MooTools Bootstrap require other portions of MooTools Core, MooTools More, Clientcide, and other Clientcide authored repositories like Behavior and (MooTools) More Behaviors. The depenendencies for everything are listed in the headers of each file and can be compiled with Packager (more on packager here). The library can also easily be built on dev.clientcide.com by selecting Bootstrap from the dropdown menu.

Backwards Compatibility

Bootstrap 3.0 introduced a few changes that preclude this libary from being automatically backwards compatible. If you wish to use the current version with Bootstrap 2.x layouts, you'll need to add Bootstrap.version = 2; to your own JavaScript. The only file that this affects (currently) is the modal library (Bootstrap.Popup) as its DOM differs in crucial was between Bootstrap 2 and 3.

Behavior and Data attributes

All the plugins are meant to be used with Behavior and can be invoked with data attributes. These are not the same attributes used with Bootstrap for its jQuery implementation. If someone wants to write a library that translates the same data attributes to work with this implementation go for it!

All the plugins here are also stand-alone MooTools classes, so you don't have to use Behavior and the data attributes if you don't want to. See the docs on Clientcide for how to invoke them manually.

Behavior is an extremely robust and well tested UI programming framework that provides events, plugin support and easy configuration. It is highly recommended that you read up on it and use it with this library.

Behavior Options

Behavior options can be set inline (data-filtername-option="value") or using JSON-like values like so:

<div data-behavior="FilterName" data-filtername-options="
  'string': 'foo',
  'number': 1,
  'object': { 'array': [1,2]}
">...</div>

Selectors

Selectors in Behavior filters and Delegator triggers are always relative to the element they modify. So if you want to find an element that is a child of that element, you can just use a regular selector, but if you need to find an element that is somewhere else in the DOM, use Slick's reverse combinators (!.someParent #someChildOfThatParent - e.g. !body #foo).

Examples

See the Bootstrap docs for a static example of this (i.e. one that doesn't actually pop up). You can use Bootstrap.Popup to manually controll these or use the Behavior implementation displayed here.

Live demo

Toggle a modal via JavaScript by clicking the button below. It will slide down and fade in from the top of the page.

Usage

Via data attributes

Activate a modal without writing JavaScript. Set data-behavior="BS.Popup" on the modal and then on a controller element, like a button, set data-trigger="BS.showPopup" with href="#foo" to target a specific modal to toggle.

<button type="button" data-trigger="BS.showPopup" href="#myModal">Launch modal</button>

Example:

<!-- sample modal content -->
<div data-behavior="BS.Popup" id="myModal" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">

      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title" id="myModalLabel">Modal Heading</h4>
      </div>
      <div class="modal-body">
        <h4>Text in a modal</h4>
        <p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula.</p>

        <h4>Popover in a modal</h4>
        <p>This <a role="button" class="btn btn-default popover-test" title="A Title" data-behavior="BS.Popover" data-bs-popover-options="
            'content': 'And here\'s some amazing content. It\'s very engaging. right?',
            'trigger': 'click'
          ">button</a> should trigger a popover on click.</p>

        <h4>Tooltips in a modal</h4>
        <p><a href="#" class="tooltip-test" title="Tooltip" data-behavior="BS.Tooltip">This link</a> and <a href="#" class="tooltip-test" title="Tooltip" data-behavior="BS.Tooltip">that link</a> should have tooltips on hover.</p>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>

    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<div class="bs-example" style="padding-bottom: 24px;">
  <a data-trigger="BS.showPopup" href="#myModal" class="btn btn-primary btn-lg">Launch demo modal</a>
</div><!-- /example -->

Behavior Options

These options apply only to the data- tag invocation. See the documentation on dev.clientcide.com for JavaScript options, methods, and events.

Name type default description
persist boolean true If false the popup and its modal layer will be destroyed when it is closed. Useful when you are fetching the popup with Ajax.
hide boolean false Do not show the Popup immediately.
mask boolean true Includes a modal-backdrop element.
animate boolean true Slides the window into and out of view with a smooth transition.
closeOnClickOut boolean true Close the popup when the user clicks out of it (on the mask or, if it's not used, the document body outside the popup).
closeOnEsc boolean false Closes the modal when escape key is pressed
focusOnShow string input[type=text], select, textarea A selector (string) to find an element relative to the root of the popup whose `select` method will be called on show.

Show your popup on load... or not

This implementation mirrors that found in Twitter's JS library. It uses CSS transitions when available (generally speaking, every browser but IE). Add the .fade class to your element to have it transition in. You can alternately specify the animate option in the behavior filter settings listed above. If you do not specify either of these, you should add the .hide class unless you want your element visible immediately.

Elements that close your popup

Any element in your content with the class .close or .dismiss will close the popup. The reason for both is that Bootstrap provides styles for .close elements (the *x* in the upper right corner) that you may not want applied to your element. By default, the default behavior for the click event on these elements is NOT stopped (so if they are submit buttons or actual links with href properties, those actions will occur). Add the class stopEvent to have the class call Event.preventDefault for you.

Via JavaScript

Call a modal with id myModal with a single line of JavaScript:

new Bootstrap.Popup(myElement, options).show();

Add dropdown menus to nearly anything with this simple plugin, including the navbar, tabs, and pills.

Within a navbar

Within tabs

Via data attributes

Add data-behavior="BS.Dropdown" to the top level .dropdown element, then add data-toggle="dropdown" to a link or button to toggle a dropdown.

<div class="dropdown">
  <a data-toggle="dropdown" href="#">Dropdown trigger</a>
  <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
    ...
  </ul>
</div>

Via JavaScript

Call the dropdowns via JavaScript:

new Bootstrap.Dropdown(containerElement, options);

Options

None

There is currently no support for the Scrollspy functionality found in Bootstrap.

Example tabs

Add quick, dynamic tab functionality to transition through panes of local content, even via dropdown menus.

Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.

Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.

Usage

You can activate a tab or pill navigation without writing any JavaScript by simply specifying data-behavior="BS.Tabs" on the .nav.nav-tabs or .nav.nav-pillselement.

<ul class="nav nav-tabs" data-behavior="BS.Tabs">
  <li><a href="#home">Home</a></li>
  <li><a href="#profile">Profile</a></li>
  <li><a href="#messages">Messages</a></li>
  <li><a href="#settings">Settings</a></li>
</ul>

Behavior Options

Name type default description
tabs-selector string ">li" A selector to find the tab elements that the user clicks.
sections-selector string "+.tab-content > div" A selector to find the sections that correlate to each tab.
smooth boolean false Fade in the content when the tabs are switched.
smoothSize boolean false Transition the height of each tab section as its displayed.
selectedClass string "active" The class added to the active tab.
hash string -- If defined, will add a hash value to the window location so that if the user reloads the selected tab will be selected by default.

via Javascript

This behavior implements the TabSwapper class from the Clientcide repo.

new TabSwapper(container, options);

Examples

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.

Hover over the links below to see tooltips:

Tight pants next level keffiyeh you probably 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 have 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 whatever keytar, scenester farm-to-table banksy Austin twitter handle freegan cred raw denim single-origin coffee viral.

Four directions

Usage

Via data attributes

<a href="#" data-behavior="BS.Tooltip" title="first tooltip">Hover over me</a>

Behavior Options

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

Name type default description
content string 'title' the content of the tip, if not defined, will use the title property of the element
animate boolean true apply a css fade transition to the tooltip
delayIn number 200 delay before showing tooltip (ms)
delayOut number 0 delay before hiding tooltip (ms)
location string 'above' how to position the tooltip - above | below | left | right
offset number 0 pixel offset of tooltip from target element
trigger string 'hover' how tooltip is triggered - hover | focus | manual
onOverflow boolean false Only show the tip if the element's content is overflown (i.e. it's scroll-height or scroll-width is greater than the height or width of the element)

via JavaScript

new Bootstrap.Tooltip(element, options).show();

Examples

Add small overlays of content, like those on the iPad, to any element for housing secondary information.

Static popover

Four options are available: top, right, bottom, and left aligned.

Popover top

Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.

Popover right

Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.

Popover bottom

Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.

Popover left

Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.

Live demo

Four directions

Usage

<a class="btn btn-lg btn-danger" data-behavior="BS.Popover" title="A Title" data-bs-popover-options="
  'content': 'And here\'s some amazing content. It\'s very engaging. right?',
  'location': 'below'
">Mouseover to toggle popover</a>

Behavior Options

Name type default description
title string -- the title of the popover, if not defined, will use the title property of the element
content string -- the content of the popover
titleElement string -- A css selector relative to the behavior element that should be used for the title of the popup.
contentElement string -- A css selector relative to the behavior element that should be used for the content of the popup.
animate boolean true apply a css fade transition to the tooltip
delayIn number 200 delay before showing tooltip (ms)
delayOut number 0 delay before hiding tooltip (ms)
location string 'above' how to position the tooltip - above | below | left | right
offset number 10 pixel offset of tooltip from target element
trigger string 'hover' how tooltip is triggered - hover | focus | click | manual
onOverflow boolean false Only show the tip if the element's content is overflown (i.e. it's scroll-height or scroll-width is greater than the height or width of the element)

JavaScript

Enable popovers via JavaScript:

new Bootstrap.Popover(element, options).show();

Example alerts

Add dismiss functionality to all alert messages with this plugin.

Holy guacamole! Best check yo self, you're not looking too good.

Oh snap! You got an error!

Change this and that and try again. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum.

Take this action Or do this

Usage

This makes use of the Fx.Reveal method .nix() found in MooTools More. Just add data-trigger="nix" data-nix-target="!.alert" to the closing element.

Note: Be sure to require More-Behaviors/Delegator.Nix when you build your library.
<div class="alert alert-warning fade in">
  <button type="button" class="close" data-trigger="nix" data-nix-target="!.alert">×</button>
  <strong>Holy guacamole!</strong> Best check yo self, you're not looking too good.
</div>

Bootstrap provides helpers for setting button states that are not entirely provided by this libary. However, it is possible to reproduce most of the functionality using existing Behaviors from this library and the (MooTools) More Behaviors library. Demonstrated here is how to reproduce most of the effects supported in Bootstrap, but not all.

Example uses

Do more with buttons. Control button states or create groups of buttons for more components like toolbars.

Stateful

In Bootstrap, you can change a button's state to "loading..." by adding data-loading-text to it. While this would be trivial to reproduce using Behavior and MooTools, the author hasn't found need for it and so hasn't done so (pull requests accepted!).

Single toggle

Add data-trigger="toggleClass" data-toggleclass-class="active" to activate toggling on a single button.

Note: Be sure to require More-Behaviors/Delegator.ToggleClass when you build your library.
<button type="button" class="btn btn-primary" data-trigger="toggleClass" data-toggleclass-class="active">Single toggle</button>

Checkbox

This one's a little wierd. When used with a label and checkbox, you have to put the trigger on the input. This is because browsers see the click on the label and fire that event there, but then they also fire the click event on the input (even if your mouse didn't actually click it). This triggers the delegator twice toggling your class twice, so nothing happens. Instead, you must specify both data-toggleclass-class and data-toggleclass-target (or, better yet, use the data-toggleclass-options method to declare your configuration; see example).

<label class="btn btn-primary">
  <input type="checkbox" data-trigger="toggleClass" data-toggleclass-options="
    'class': 'active',
    'target': '!label'
  "> Option 1
</label>

Radio

Same thing as checkboxen, but with a hitch. Because we need to remove the class for the radio that is unchecked whenever we click another one, we must remove the class from all the labels before we select the one we clicked. Simple enough, just also add the removeClass trigger to the container. See example.

<div class="bs-example" style="padding-bottom: 24px;">
  <div class="btn-group" data-toggle="buttons"  data-trigger="removeClass" data-removeclass-options="
    'class': 'active',
    'targets': 'label'
  ">
    <label class="btn btn-primary">
      <input type="radio" name="options" id="option1" data-trigger="toggleClass" data-toggleclass-options="
        'class': 'active',
        'target': '!label'
      "> Option 1
    </label>
    <label class="btn btn-primary">
      <input type="radio" name="options" id="option2" data-trigger="toggleClass" data-toggleclass-options="
        'class': 'active',
        'target': '!label'
      "> Option 2
    </label>
    <label class="btn btn-primary">
      <input type="radio" name="options" id="option3" data-trigger="toggleClass" data-toggleclass-options="
        'class': 'active',
        'target': '!label'
      "> Option 3
    </label>
  </div>
</div>

About

Get base styles and flexible support for collapsible components like accordions and navigation.

Plugin dependency

Note: Be sure to require More-Behaviors/Behavior.Accordion when you build your library.

Bootstrap Class Name Divergence

Note: Don't give your panels the .collapse class. This implementation doesn't use CSS classes as it's based on the JS based Fx.Accordion from MooTools. The author may at some future point include a CSS version as Bootstrap currently has (pull requests accepted!).

Example accordion

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
<div class="panel-group" id="accordion" data-behavior="Accordion" data-accordion-options="
  'headers': 'a.accordion-toggle',
  'sections': '.panel-collapse'
">
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a class="accordion-toggle">
          Collapsible Group Item #1
        </a>
      </h4>
    </div>
    <div id="collapseOne" class="panel-collapse">
      <div class="panel-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a class="accordion-toggle">
          Collapsible Group Item #2
        </a>
      </h4>
    </div>
    <div id="collapseTwo" class="panel-collapse">
      <div class="panel-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a class="accordion-toggle">
          Collapsible Group Item #3
        </a>
      </h4>
    </div>
    <div id="collapseThree" class="panel-collapse">
      <div class="panel-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
</div>

If you just want to do a single element, make a button toggle the expanding and collapsing of another element with the Delegator.toggleReveal trigger.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

Usage

See the docs for Fx.Accordion in MooTools More and the docs for Behavior.Accordion on dev.clientcide.com

There is currently no support for the Scrollspy functionality found in Bootstrap.

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-behavior="BS.Affix" to the element you want to spy on. Then use offsets to define when to toggle the pinning of an element on and off.

<div data-behavior="BS.Affix" data-offset-top="200">...</div>

Requires independent styling ;)

Affix toggles between three states/classes: affix, affix-top, and affix-bottom. You must provide the styles for these classes yourself (independent of this plugin). The affix-top class should be in the regular flow of the document. The affix class should be fixed to the page. And affix-bottom should be positioned absolute. Note, affix-bottom is special in that the plugin will place the element with JS relative to the offset: { bottom: number } option you've provided.

Via JavaScript

Call the affix plugin via JavaScript:

new Bootstrap.Affix(element, { top: 0 });

Options

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

Name type default description
top Number 0 The distance from the top that the user must scroll before the affix class is added and the affix-top class is removed.
bottom Number null The distance from the top that the user must scroll before the affix class is removed and the affix-bottom class is added. Specify a negative number to have it measure from the bottom of the window height.
classNames Object
{
  top: "affix-top",
  bottom: "affix-bottom",
  affixed: "affix"
}
The class names to apply in the various states.
onPin / onUnPin function(s) ~ Events fired for the pin and unpin actions. the UnPin event is passed a boolean isBottom which is true if the bottom class is added.