Skip to content

Instantly share code, notes, and snippets.

@Zmetser
Created January 7, 2014 15:25
Show Gist options
  • Save Zmetser/8300940 to your computer and use it in GitHub Desktop.
Save Zmetser/8300940 to your computer and use it in GitHub Desktop.
Dropdown plugin for foundation with hover functionality only.
;(function ($, window, document, undefined) {
'use strict';
Foundation.libs.dropdownhover = $.extend({}, Foundation.libs.dropdown, {
name : 'dropdownhover',
version : '1.0.0',
init: function (scope, method, options) {
Foundation.inherit(this, 'throttle');
this.bindings(method, options, scope);
},
events: function () {
var self = this;
$(this.scope)
.off('.dropdownhover')
.on('mouseenter.fndtn.dropdownhover', '[data-dropdownhover], [data-dropdownhover-content]', function () {
var $this = $(this), dropdown, target;
window.clearTimeout(self.timeout);
if ($this.data('dropdownhover')) {
dropdown = $('#' + $this.data('dropdownhover'));
target = $this;
} else {
dropdown = $this;
target = $('[data-dropdownhover="' + dropdown.attr('id') + '"]');
}
self.open.apply(self, [dropdown, target]);
})
.on('mouseleave.fndtn.dropdownhover', '[data-dropdownhover], [data-dropdownhover-content]', function () {
var $this = $(this);
self.timeout = window.setTimeout(function () {
if ($this.data('dropdownhover')) {
self.close.call(self, $('#' + $this.data('dropdownhover')));
} else {
self.close.call(self, $this);
}
}.bind(this), 150);
})
.on('opened.fndtn.dropdownhover', '[data-dropdownhover-content]', this.settings.opened)
.on('closed.fndtn.dropdownhover', '[data-dropdownhover-content]', this.settings.closed);
$(window)
.off('.dropdownhover')
.on('resize.fndtn.dropdownhover', self.throttle(function () {
self.resize.call(self);
}, 50)).trigger('resize');
}
});
}(jQuery, this, this.document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment