1
|
(function ($, undefined) {
|
2
|
$.widget('eo.divmenu', {
|
3
|
options: {
|
4
|
},
|
5
|
_create: function () {
|
6
|
this.elements = $('> *', this.element);
|
7
|
this._select = 0;
|
8
|
},
|
9
|
_closed: 1,
|
10
|
_opened: 0,
|
11
|
_init: function() {
|
12
|
this.element.addClass('eo-divmenu-container');
|
13
|
this.elements.addClass('eo-divmenu-element');
|
14
|
this.element.on('change.eo-divmenu', '.eo-divmenu-element input, .eo-divmenu-element select',
|
15
|
$.proxy(function (e) {
|
16
|
$('input, select', this.element).not(e.target).val('');
|
17
|
this._refresh();
|
18
|
}, this)
|
19
|
);
|
20
|
this.state = this.closed;
|
21
|
this._refresh();
|
22
|
},
|
23
|
open: function () {
|
24
|
this.state = this._opened;
|
25
|
var new_height = 0;
|
26
|
for (var i = 0; i < this.elements.length; i++) {
|
27
|
new_height += $(this.elements.get(i)).outerHeight(true);
|
28
|
}
|
29
|
this.element.animate({ height: new_height });
|
30
|
},
|
31
|
close: function () {
|
32
|
this.state = this.closed;
|
33
|
var $selected = $(this.elements.get(this._select));
|
34
|
/* Move element in place */
|
35
|
var scrollTop = 0;
|
36
|
if (this.element.css('position') != 'static') {
|
37
|
scrollTop = $selected.position().top + this.element.scrollTop();
|
38
|
} else {
|
39
|
scrollTop = $selected.position().top - this.element.position().top + this.element.scrollTop();
|
40
|
}
|
41
|
var new_properties = {
|
42
|
height: $selected.outerHeight(true),
|
43
|
width: $selected.outerWidth(true),
|
44
|
scrollTop: scrollTop,
|
45
|
};
|
46
|
this.element.animate(new_properties);
|
47
|
},
|
48
|
toggle: function () {
|
49
|
if (this.state == this.closed) {
|
50
|
this.open();
|
51
|
} else {
|
52
|
this.close();
|
53
|
}
|
54
|
},
|
55
|
select: function (i) {
|
56
|
if (typeof(i) != 'number') {
|
57
|
i = this.elements.index(i);
|
58
|
}
|
59
|
this._select = i;
|
60
|
this._refresh();
|
61
|
},
|
62
|
_refresh: function () {
|
63
|
if (this.state == this.closed) {
|
64
|
this.close();
|
65
|
}
|
66
|
},
|
67
|
destroy: function () {
|
68
|
this.element.removeClass('eo-divmenu-container');
|
69
|
this.elements.removeClass('eo-divmenu-element');
|
70
|
$('*', this.element).off('.eo-divmenu');
|
71
|
}
|
72
|
})
|
73
|
})(window.jQuery)
|