-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdropdownify.js
More file actions
45 lines (34 loc) · 1.09 KB
/
dropdownify.js
File metadata and controls
45 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(function($) {
$.fn.dropdownify = function() {
this.wrap('<div class="dropdownify" />');
this.each(function() {
var jEl, activeHtml, width;
jEl = $(this);
activeHtml = jEl.find('li.active a').html();
if (!activeHtml) {
activeHtml = jEl.find('li').first().find('a').html();
}
jEl.before('<p class="selected">' + activeHtml + '</p>');
width = jEl.parent().find('.selected').innerWidth();
jEl.width(width);
});
this.parent().find('.selected').on('click', function(ev) {
var jList = $(this).parent().find('ul');
if (jList.is(':hidden')) {
closeAllDropdowns();
jList.show();
}
else {
closeAllDropdowns();
}
ev.stopPropagation();
});
$(document).click(function(){
closeAllDropdowns();
});
return this;
}
function closeAllDropdowns() {
jQuery('.dropdownify ul').hide();
}
})(jQuery);