Dropdown Menus Enhancement
Enhancing functionality of dropdown menus.
Enhancing functionality of dropdown menus.
Added the following improvements:
To start using the improvements you need to include a modified dropdown-enhancement.js and dropdown-enhancement.css file.
Important dropdown-enhancement.css
only have enhancement rules and depends entirely on the original style of Bootstrap dropdowns.
For more information, see the examples below.
dropdown-enhancement.js
does not depend on the original dropdown.js
. It adds support for sub-menu, radio and checkboxes, and centering menus that can not be is achieved by means of css.
Has been improved close menu function. It only closes menus opened by the module, also considers the submenus. Function clearMenus (close all menus) been preserved and made public. Available as $.fn.dropdown.clearMenus
.
Dropdown Events are not available at the moment.
Important You do not need to include the original Bootstrap dropdown.js
If you like my work, please buy me a beer.
Enable sub-menu functionality.
Add class .dropdown-submenu
to items with sub-menu.
Resize window to view effect.
The only thing that is required for proper operation, is to comply with certain markup conditions. Input
elements should be located outside of the label and label must have a correct for
attribute.
<div class="btn-group">
<button data-toggle="dropdown" class="btn btn-default dropdown-toggle">Checked option <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><input type="radio" id="ID" name="NAME" value="VALUE"><label for="ID">Label</label></li>
<!-- Other items -->
</ul>
</div>
Do not close the menu on click on radio add class .noclose
.
<div class="btn-group">
<button data-toggle="dropdown" class="btn btn-default dropdown-toggle">Checked option <span class="caret"></span></button>
<ul class="dropdown-menu noclose">
<li><input type="radio" id="ID" name="NAME" value="VALUE"><label for="ID">Label</label></li>
<!-- Other items -->
</ul>
</div>
Use html5 attribute data-placeholder
to specify a default label. Uncheck checkbox in example bellow
to see effect.
<div class="btn-group">
<button data-toggle="dropdown" class="btn dropdown-toggle" data-placeholder="Please select">Checked option <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><input type="checkbox" id="ID"><label for="ID" name="NAME" value="VALUE">Label</label></li>
<!-- Other items -->
</ul>
</div>
Using html5 attribute data-label-placement
you can specify the container for label. See examples
below.
<div class="btn-group">
<button class="btn btn-primary" data-label-placement>Checked option</button>
<button data-toggle="dropdown" class="btn btn-primary dropdown-toggle"><span class="caret"></span></button>
<ul class="dropdown-menu">
<li><input type="checkbox" id="ID" name="NAME" value="VALUE"><label for="ID">Label</label></li>
<!-- Other items -->
</ul>
</div>
Set data-placeholder="false"
to disable label replacement. See examples below.
<div class="btn-group">
<button class="btn btn-primary">Checked option</button>
<button data-toggle="dropdown" class="btn btn-primary dropdown-toggle" data-placeholder="false"><span class="caret"></span></button>
<ul class="dropdown-menu">
<li><input type="checkbox" id="ID" name="NAME" value="VALUE"><label for="ID">Label</label></li>
<!-- Other items -->
</ul>
</div>
Add class .data-label
to desired element.
<div class="btn-group">
<button data-toggle="dropdown" class="btn dropdown-toggle">Checked option <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><input type="radio" id="ID" name="NAME" value="VALUE"><label for="ID"><span class="data-label">Label</span> Other text</label></li>
<!-- Other items -->
</ul>
</div>
Use extra classes for advanced positioning of dropdown menus. Classes: .pull-top
, .pull-right
.pull-right
.pull-top
.pull-top.pull-right
This classes use a small piece of javascript for correct positioning. Classes: .pull-center
, .pull-middle
.pull-center
.pull-center.pull-top
.pull-middle
.pull-middle.pull-right"
.pull-middle.pull-center"
To add bullet just add class .bullet
to the dropdown menu, .pull-right
.bullet
.bullet.pull-right
.bullet.pull-top
.bullet.pull-top.pull-right
.bullet.pull-center
.bullet.pull-center.pull-top
.bullet.pull-middle
.bullet.pull-middle.pull-right"
.bullet
Ignored.pull-middle.pull-center"