Skip to content

Instantly share code, notes, and snippets.

@icai
Created June 24, 2014 03:36
Show Gist options
  • Save icai/077cb29c1b51154e74bc to your computer and use it in GitHub Desktop.
Save icai/077cb29c1b51154e74bc to your computer and use it in GitHub Desktop.
bootstrap dropdown submenu
http://www.jeffmould.com/2014/01/09/responsive-multi-level-bootstrap-menu/
https://github.com/jeffmould/multi-level-bootstrap-menu
function clearMenus() {
$(backdrop).remove()
$(toggle).each(function (e) {
var $parent = getParent($(this))
if (!$parent.hasClass('open')) return
$parent.trigger(e = $.Event('hide.bs.dropdown'))
if (e.isDefaultPrevented()) return
// Remove the following line of code for support of multi-level menus
//$parent.removeClass('open').trigger('hidden.bs.dropdown')
})
}
function clearAllMenus() {
$(backdrop).remove()
$(toggle).each(function (e) {
var $parent = getParent($(this))
if (!$parent.hasClass('open')) return
$parent.trigger(e = $.Event('hide.bs.dropdown'))
if (e.isDefaultPrevented()) return
$parent.removeClass('open').trigger('hidden.bs.dropdown')
})
}
// events bind
$(document)
.on('click.bs.dropdown.data-api', clearMenus)
.on('click.bs.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
.on('click.bs.dropdown.data-api' , toggle, Dropdown.prototype.toggle)
.on('keydown.bs.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown)
.on('click', clearAllMenus)
.dropdown-submenu{
position:relative;
>.dropdown-menu{
top:0;
left:100%;
-webkit-border-radius:0 6px 6px 6px;
-moz-border-radius:0 6px 6px 6px;
border-radius:0 6px 6px 6px;
}
>a:after {
display:block;
content:" ";
float:right;
width:0;
height:0;
border-color:transparent;
border-style:solid;
border-width:5px 0 5px 5px;
border-left-color:#cccccc;
margin-top:5px;
margin-right:-10px;
}
&:active>.dropdown-menu {
display:block;
}
&:active>a:after {
border-left-color:#ffffff;
}
&.pull-left {
float:none;
}
&.pull-left>.dropdown-menu {
left:-100%;
margin-left:10px;
-webkit-border-radius:6px 0 6px 6px;
-moz-border-radius:6px 0 6px 6px;
border-radius:6px 0 6px 6px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment