-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.selectoul.js
63 lines (49 loc) · 2.31 KB
/
jquery.selectoul.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
(function($){
$.fn.selectoul = function(options) {
var options = $.extend({},$.fn.selectoul.defaults, options);
function convertSelectToUl(theSelectID){
$('#' + theSelectID + ' option').each(function(index) {
var lista = '<li>' + $(this).text() + "</li>";
$("."+ theSelectID +"").append(lista);
});
$('#' + theSelectID).remove();
}
function findTheSelect () {
$("select."+options.selectClass).each(function(){
var theSelectID = $("." + options.selectClass).attr("id");
var theSelectName = $("." + options.selectClass).attr("name");
var selectedItem = $('#' + theSelectID + ' :selected').text();
$(this).after("<div class='"+options.ulWrapClass+"'><input class='hidval' name='"+theSelectName+"' type='hidden' value='"+selectedItem+"'><span class='"+options.selectedItemClass+"'><b>" + selectedItem + "</b></span><ul class='"+ options.ulClass +" "+ theSelectID + "'></ul></div>");
convertSelectToUl(theSelectID)
});
}
findTheSelect()
/* the dropdown effect */
$('.'+ options.ulClass).hide(); //hiding the already converded dropdowns
$('.'+ options.selectedItemClass).click(function(){
$(this).parent().find("ul").show();
$('.'+ options.selectedItemClass).mouseout(function(){
//$(this).parent().find("ul").hide();
})
$(this).parent().find("ul").mouseover(function(){
$(this).parent().find("ul").show();
}).mouseout(function(){
//$(this).parent().find("ul").hide();
});
});
//clicking on the dropdown's elements
$('.'+ options.ulClass +' li').click(function(){
$(this).parent().hide();
clickedItem = $(this).text();
$(this).parent().parent().find(".hidval").val(clickedItem);
$(this).parent().parent().find("." + options.selectedItemClass + " b").html(clickedItem);
})
};
/* setting up the default values */
$.fn.selectoul.defaults = {
selectClass: "convertToUl", //the class of SELECT element to be converted [select]
ulWrapClass: "fancyDrpDwn", //choose a class for the genereated's list wrapper [div]
ulClass: "exSelect", //choose a class for the genereated's list [ul]
selectedItemClass: "selectedFromList" //choose a class for the selected item box [span]
};
})(jQuery);