1/* 2 * Project: Twitter Bootstrap Hover Dropdown 3 * Author: Cameron Spear 4 * Contributors: Mattia Larentis 5 * 6 * Dependencies?: Twitter Bootstrap's Dropdown plugin 7 * 8 * A simple plugin to enable twitter bootstrap dropdowns to active on hover and provide a nice user experience. 9 * 10 * No license, do what you want. I'd love credit or a shoutout, though. 11 * 12 * http://cameronspear.com/blog/twitter-bootstrap-dropdown-on-hover-plugin/ 13 */ 14;(function($, window, undefined) { 15 // outside the scope of the jQuery plugin to 16 // keep track of all dropdowns 17 var $allDropdowns = $(); 18 19 // if instantlyCloseOthers is true, then it will instantly 20 // shut other nav items when a new one is hovered over 21 $.fn.dropdownHover = function(options) { 22 23 // the element we really care about 24 // is the dropdown-toggle's parent 25 $allDropdowns = $allDropdowns.add(this.parent()); 26 27 return this.each(function() { 28 var $this = $(this), 29 $parent = $this.parent(), 30 defaults = { 31 delay: 0, 32 instantlyCloseOthers: true 33 }, 34 data = { 35 delay: $(this).data('delay'), 36 instantlyCloseOthers: $(this).data('close-others') 37 }, 38 settings = $.extend(true, {}, defaults, options, data), 39 timeout; 40 41 $parent.hover(function(event) { 42 // so a neighbor can't open the dropdown 43 if(!$parent.hasClass('open') && !$this.is(event.target)) { 44 return true; 45 } 46 47 if(shouldHover()) { 48 if(settings.instantlyCloseOthers === true) 49 $allDropdowns.removeClass('open'); 50 51 window.clearTimeout(timeout); 52 $parent.addClass('open'); 53 } 54 }, function() { 55 if(shouldHover()) { 56 timeout = window.setTimeout(function() { 57 $parent.removeClass('open'); 58 }, settings.delay); 59 } 60 }); 61 62 $parent.find('.dropdown-submenu').each(function(){ 63 var subTimeout; 64 $(this).hover(function() { 65 if(shouldHover()) { 66 window.clearTimeout(subTimeout); 67 } 68 $(this).children('.dropdown-menu').show(); 69 }, function() { 70 var $submenu = $(this).children('.dropdown-menu'); 71 if(shouldHover()) { 72 subTimeout = window.setTimeout(function() { 73 $submenu.hide(); 74 }, settings.delay); 75 } else { 76 // emulate Twitter Bootstrap's default behavior 77 $submenu.hide(); 78 } 79 }); 80 }); 81 }); 82 }; 83 84 // helper function to see if we should hover 85 var shouldHover = function() { return !!$('#cwspear-is-awesome').height(); }; 86 $(document).ready(function() { 87 // apply dropdownHover to all elements with the data-hover="dropdown" attribute 88 $('[data-hover="dropdown"]').dropdownHover(); 89 90 // pure win here: we create these spans so we can test if we have the responsive css loaded 91 // this is my attempt to hopefully make sure the IDs are unique 92 $('<div class="nav-collapse collapse" style="visibility:hidden;position:fixed" id="cwspear-is-awesome">.</div>').appendTo('body'); 93 }); 94 95 // for the submenu to close on delay, we need to override Bootstrap's CSS in this case 96 var css = '.dropdown-submenu:hover>.dropdown-menu{display:none}'; 97 var style = document.createElement('style'); 98 style.type = 'text/css'; 99 if (style.styleSheet) { 100 style.styleSheet.cssText = css; 101 } else { 102 style.appendChild(document.createTextNode(css)); 103 } 104 $('head')[0].appendChild(style); 105})(jQuery, this);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.