bootstrap-demo.js is a simple (and also unofficial) solution to schooling those pesky end-users we've all heard about.
It allows you to easily create demos and tutorials for your own applications via invocation using javascript or data-attributes.
Since it's a combination of some higlighting, Twitter Bootstrap popovers and cookies, you can use any of the default popover functionality.
bootstrap-demo.js also manages demo display through the use of cookies: all you need to do is provide an ID for a demo and you're set!
Clone the repo, cd to the directory and copy the minified script to wherever you actually need it to be. Standard practice, really.
git clone git://github.com/kalmanolah/bootstrap-demo.js.git
cp bootstrap-demo.js/src/bootstrap-demo.min.js /path/to/my/app/assets/js/
$('#selector').demo({
id: 2,
placement: 'top',
content: 'This is a tip with <strong>html</strong>',
title: 'WARNING <i class="icon-warning-sign"></i>'
});
<div
data-provide="demo"
data-id="3"
data-html="false"
data-placement="bottom"
data-title="ProTip (tm)"
data-content="Click me!">
...
Content goes here.
...
</div>
<script>
demo.options.persist = false;
demo.options.title = 'ProTip (tm)';
</script>
Here are some examples that demonstrate the capabilities of bootstrap-demo.js.
$('#home .btn-default, #home .btn-success').demo({
id: '1-1',
content: 'This is the first demo!'
});
Run
$('#home .btn-default').demo({
id: '1-1',
content: 'Are you ready for some chaining?',
callback: function() {
$('#home .btn-success').demo({
id: '1-2',
content: 'Here goes...',
callback: function() {
$('#about').demo({
id: '1-3',
content: 'Wham!'
});
}
});
}
});
Run
$('#home .btn-default').demo({
id: '1-1',
content: 'This is an example demo!'
});
$('#home .btn-success').demo({
id: '1-2',
content: 'As is this one!'
});
Run
Option | Type | Default | Description |
---|---|---|---|
id | string | integer | false | false | Unique ID of the demo, used to determine whether it has been viewed. Only required in conjunction with the "persist" option. |
persist | boolean | true | Whether to save the ID of a demo that has been viewed in a cookie, in order for it not to be shown again. |
cookie_name | string | '_demo' | Name of the cookie used to store the IDs of viewed demos. |
cookie_days | integer | 365 | Lifetime of the cookie used to store the IDs of viewed demos, in days. |
callback | function(e) | false | false | Callback to execute once a viewed demo is dismissed. This callback is passed the click event. |
prevent_default | boolean | true | Whether to prevent the some default action from occurring until demos are dismissed. These actions include scrolling, clicking and submitting. |
html | boolean | true | Whether to allow HTML inside the created popover. |
placement | 'top' | 'left' | 'right' | 'bottom' | 'auto' | 'auto' | Placement of the created popover. |
title | string | '<i class="glyphicon glyphicon-bell"></i> TIP' | Title of the created popover. |
content | string | 'Click anywhere inside of the <span class="text-danger">highlighted</span> area to dismiss this popup. | Content of the created popover. |
styles | string |
|
Styles to append to the head of the page. You can use this option to override the highlighting styles. |
bootstrap-demo.js is released under the MIT license:
Copyright (c) 2013-2014 Kalman Olah
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.