/* * project: twitter bootstrap hover dropdown * author: cameron spear * contributors: mattia larentis * * dependencies?: twitter bootstrap's dropdown plugin * * a simple plugin to enable twitter bootstrap dropdowns to active on hover and provide a nice user experience. * * no license, do what you want. i'd love credit or a shoutout, though. * * http://cameronspear.com/blog/twitter-bootstrap-dropdown-on-hover-plugin/ */ ;(function($, window, undefined) { // outside the scope of the jquery plugin to // keep track of all dropdowns var $alldropdowns = $(); // if instantlycloseothers is true, then it will instantly // shut other nav items when a new one is hovered over $.fn.dropdownhover = function(options) { // the element we really care about // is the dropdown-toggle's parent $alldropdowns = $alldropdowns.add(this.parent()); return this.each(function() { var $this = $(this).parent(), defaults = { delay: 500, instantlycloseothers: true }, data = { delay: $(this).data('delay'), instantlycloseothers: $(this).data('close-others') }, options = $.extend(true, {}, defaults, options, data), timeout; $this.hover(function() { if(options.instantlycloseothers === true) $alldropdowns.removeclass('open'); window.cleartimeout(timeout); $(this).addclass('open'); }, function() { timeout = window.settimeout(function() { $this.removeclass('open'); }, options.delay); }); }); }; $('[data-hover="dropdown"]').dropdownhover(); })(jquery, this);