forked from entropillc/bootstrap-flyout-list
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap-flyout-list.js
65 lines (51 loc) · 1.61 KB
/
bootstrap-flyout-list.js
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
$(function() {
// TODO: Determine if this can be delegated.
$('ul.flyout-list > li > a').each(function(evt) {
var $this = $(this);
var $listItem = $this.parent();
var href = $this.attr('href');
var $modal = $(href);
var $primaryButton = $modal.find('a.btn.primary');
$modal.bind('hidden', function(evt) {
$listItem.removeClass('active');
});
$primaryButton.bind('click', function(evt) {
$modal.modal('hide');
});
});
var $flyoutLists = $('ul.flyout-list');
var isMouseDown = false;
$flyoutLists.delegate('a', 'mousedown touchstart', function(evt) {
isMouseDown = true;
evt.preventDefault();
});
$flyoutLists.delegate('a', 'mousemove touchmove', function(evt) {
if (!isMouseDown) return;
isMouseDown = false;
});
$flyoutLists.delegate('a', 'mouseup touchend', function(evt) {
if (!isMouseDown) return;
isMouseDown = false;
$(this).trigger('click');
});
$flyoutLists.delegate('a', 'click', function(evt) {
var $this = $(this);
var $listItem = $this.parent();
var $list = $listItem.parent();
var $slidingDrawer = $list.parents('.drawer:first');
var href = $this.attr('href');
var $modal = $(href);
$listItem.addClass('active');
$modal.modal({
backdrop: true,
keyboard: true,
show: true
});
// TODO: REMOVE THIS!! - TEMP FIX TO AUTO-CLOSE DRAWER ON MODAL LAUNCH.
if ($slidingDrawer.size() === 1) {
var closeDrawer = $slidingDrawer.data('closeDrawer');
if (closeDrawer) closeDrawer();
}
evt.preventDefault();
});
});