-
Notifications
You must be signed in to change notification settings - Fork 6
/
jquery_list.js
55 lines (44 loc) · 1.4 KB
/
jquery_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
function jquery_list(list, msg, callback) {
var selectBoxContainer = $("#"+list);
//add the header box <div> to the list
selectBoxContainer.append("<div class='list_head'></div>");
//assign the default message to the list header
var selectBox = selectBoxContainer.find('.list_head');
selectBox.html(msg);
selectBoxContainer.attr('value',msg);
//process the list
var dropDown = selectBoxContainer.find('.list_view');
//console.log(dropDown);
//selectBoxContainer.append(dropDown.hide());
dropDown.hide();
dropDown.bind('show',function(){
selectBox.addClass('expanded');
dropDown.fadeIn();
}).bind('hide',function(){
selectBox.removeClass('expanded');
dropDown.fadeOut();
}).bind('toggle',function(){
if (selectBox.hasClass('expanded')) dropDown.trigger('hide');
else dropDown.trigger('show');
});
selectBox.click(function(){
dropDown.trigger('toggle');
return false;
});
$(document).click(function(){
dropDown.trigger('hide');
});
//process all the list elements
dropDown.find('li').each(function(i) {
var li = $(this);
li.click(function(){
selectBox.html(li.html());
selectBoxContainer.attr('value',li.html());
//selectBoxContainer.attr('value',i);
dropDown.trigger('hide');
//my function
callback("list",i);
return false;
});
});
}