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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
;(function ($, window, undefined) {
'use strict';
$.fn.foundationButtons = function (options) {
var $doc = $(document),
config = $.extend({
dropdownAsToggle:false,
activeClass:'active'
}, options),
// close all dropdowns except for the dropdown passed
closeDropdowns = function (dropdown) {
// alert(dropdown.html());
$('.button.dropdown').find('ul').not(dropdown).removeClass('show-dropdown');
},
// reset all toggle states except for the button passed
resetToggles = function (button) {
// alert(button.html());
var buttons = $('.button.dropdown').not(button);
buttons.add($('> span.' + config.activeClass, buttons)).removeClass(config.activeClass);
};
// Prevent event propagation on disabled buttons
$doc.on('click.fndtn', '.button.disabled', function (e) {
e.preventDefault();
});
$('.button.dropdown > ul', this).addClass('no-hover');
// reset other active states
$doc.on('click.fndtn', '.button.dropdown:not(.split), .button.dropdown.split span', function (e) {
var $el = $(this),
button = $el.closest('.button.dropdown'),
dropdown = $('> ul', button);
// If the click is registered on an actual link or on button element then do not preventDefault which stops the browser from following the link
if ($.inArray(e.target.nodeName, ['A', 'BUTTON'])){
e.preventDefault();
}
// close other dropdowns
setTimeout(function () {
closeDropdowns(config.dropdownAsToggle ? '' : dropdown);
dropdown.toggleClass('show-dropdown');
if (config.dropdownAsToggle) {
resetToggles(button);
$el.toggleClass(config.activeClass);
}
}, 0);
});
// close all dropdowns and deactivate all buttons
$doc.on('click.fndtn', 'body, html', function (e) {
if (undefined == e.originalEvent) { return; }
// check original target instead of stopping event propagation to play nice with other events
if (!$(e.originalEvent.target).is('.button.dropdown:not(.split), .button.dropdown.split span')) {
closeDropdowns();
if (config.dropdownAsToggle) {
resetToggles();
}
}
});
// Positioning the Flyout List
var normalButtonHeight = $('.button.dropdown:not(.large):not(.small):not(.tiny):visible', this).outerHeight() - 1,
largeButtonHeight = $('.button.large.dropdown:visible', this).outerHeight() - 1,
smallButtonHeight = $('.button.small.dropdown:visible', this).outerHeight() - 1,
tinyButtonHeight = $('.button.tiny.dropdown:visible', this).outerHeight() - 1;
$('.button.dropdown:not(.large):not(.small):not(.tiny) > ul', this).css('top', normalButtonHeight);
$('.button.dropdown.large > ul', this).css('top', largeButtonHeight);
$('.button.dropdown.small > ul', this).css('top', smallButtonHeight);
$('.button.dropdown.tiny > ul', this).css('top', tinyButtonHeight);
$('.button.dropdown.up:not(.large):not(.small):not(.tiny) > ul', this).css('top', 'auto').css('bottom', normalButtonHeight - 2);
$('.button.dropdown.up.large > ul', this).css('top', 'auto').css('bottom', largeButtonHeight - 2);
$('.button.dropdown.up.small > ul', this).css('top', 'auto').css('bottom', smallButtonHeight - 2);
$('.button.dropdown.up.tiny > ul', this).css('top', 'auto').css('bottom', tinyButtonHeight - 2);
};
})( jQuery, this );
|