123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- ;
- (function($, window, undefined) {
- var $allDropdowns = $();
-
-
- $.fn.dropdownHover = function(options) {
-
-
- if ('ontouchstart' in document)
- return this;
-
-
- $allDropdowns = $allDropdowns.add(this.parent());
- return this.each(function() {
- var $this = $(this),
- $parent = $this.parent(),
- defaults = {
- delay: 500,
- instantlyCloseOthers: true
- },
- data = {
- delay: $(this).data('delay'),
- instantlyCloseOthers: $(this).data('close-others')
- },
- showEvent = 'show.bs.dropdown',
- hideEvent = 'hide.bs.dropdown',
-
-
- settings = $.extend(true, {}, defaults, options, data),
- timeout;
- $parent.hover(function(event) {
-
- if (!$parent.hasClass('open') && !$this.is(event.target)) {
-
-
- return true;
- }
- openDropdown(event);
- }, function() {
- if ($(document).width() > 768) {
- timeout = window.setTimeout(function() {
- $parent.removeClass('open');
- $this.trigger(hideEvent);
- }, settings.delay);
- }
- });
-
- $this.hover(function(event) {
-
-
- if (!$parent.hasClass('open') && !$parent.is(event.target)) {
-
-
- return true;
- }
- openDropdown(event);
- });
-
- $parent.find('.dropdown-submenu').each(function() {
- var $this = $(this);
- var subTimeout;
- $this.hover(function() {
- window.clearTimeout(subTimeout);
- $this.children('.dropdown-menu').show();
-
- $this.siblings().children('.dropdown-menu').hide();
- }, function() {
- var $submenu = $this.children('.dropdown-menu');
- subTimeout = window.setTimeout(function() {
- $submenu.hide();
- }, settings.delay);
- });
- });
- function openDropdown(event) {
- if ($(document).width() > 760) {
- $allDropdowns.find(':focus').blur();
- if (settings.instantlyCloseOthers === true)
- $allDropdowns.removeClass('open');
- window.clearTimeout(timeout);
- $parent.addClass('open');
- $this.trigger(showEvent);
- }
- }
- });
- };
- $(document).ready(function() {
-
- $('[data-hover="dropdown"]').dropdownHover();
- });
- })(jQuery, this);
|