Created
May 22, 2015 11:35
Modified selectbox //
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.bulgaria-web-developers.com/projects/javascript/selectbox/ | |
selectbox : function() { | |
$('.selectbox').selectbox({ | |
onChange : function(val, inst) { selectChangeValidator( $(this), val ); }, | |
onOpen : function(inst) { modifySelectBox("open", inst); }, | |
onClose : function(inst) { modifySelectBox("close", inst); }, | |
effect : "fade" | |
}); | |
// Selectbox için arama kutusu ekleme | |
function modifySelectBox(option, inst) { | |
id = inst.uid; | |
if(option == "open") { | |
$(".sbOptions li").removeClass("notfound"); | |
scFirst = $("ul#sbOptions_" + id + " li:not(.selectBoxSearchContainer)").first(); | |
(inst.input[0].selectedIndex == 0) ? scFirst.hide() : scFirst.show(); | |
if($("#selectBoxSearch").length == 0) { | |
$("<li/>", { | |
'class' : 'selectBoxSearchContainer', | |
'html' : $("<input/>", { 'rel' : '-', 'id' : 'selectBoxSearch', 'type' : 'text' }) | |
}) | |
.prependTo("ul#sbOptions_" + id); | |
$("#selectBoxSearch").focus(); | |
} | |
} else { | |
window.setTimeout(function() { $("#selectBoxSearch").parent("li").remove(); }, 200); | |
} | |
$("#selectBoxSearch").on("input", function() { searchInput($(this)); }); | |
} | |
// Selectbox için arama kutusu fonksiyonu | |
function searchInput(input) { | |
filter = input.val().toUpperCase(); | |
var lis = $("#selectBoxSearch").parents("ul").find("li").not(".selectBoxSearchContainer").not("li:first"); | |
if(filter.length > 0) { | |
$.each(lis, function(i, v) { | |
var name = $(v).children("a").html(); | |
(name.toUpperCase().indexOf(filter) > -1) ? $(lis[i]).removeClass("notfound") : $(lis[i]).addClass("notfound"); | |
}); | |
} else { | |
$(lis).removeClass("notfound"); | |
} | |
} | |
// Selectbox değiştiğinde validate et | |
function selectChangeValidator(e, v) { | |
var id = e.attr("id"), s = $("#" + id), o = $("#" + id + " option"); | |
s.empty().removeClass("error"); | |
o.removeAttr("selected"); | |
s.append(o); | |
$.each(o, function(x, y) { | |
($(y).val() == v && $(y).val() != "") ? $(y).prop("selected", "selected") : $(y).removeAttr("selected"); | |
}); | |
// validation | |
if(form_validate.element("#" + id)) $("#" + id).removeClass("error"); | |
} | |
return this; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment