(function($) { var arr = new Array(); $.fn.selectList = function(options) { var o = $.extend( {}, $.fn.selectList.defaults, options); var $this = $(this); arr[$this.attr("id")] = o; var appDiv = $(o.appendDiv); $this.bind( { click : function() { var objId = $(this).attr("id"); var curOpt = arr[objId]; var ids = ''; if (curOpt.type == 0) { ids = $('#' + objId + 'Id').val(); } else { $('input[name^="' + curOpt.idsName + '"]', appDiv).each( function() { ids += "," + $(this).val(); } ) } var url = curOpt.url + "?type=" + curOpt.type + "&idsName='" + curOpt.idsName + "'&defaultLen=" + curOpt.defaultLen +"&substring=" + curOpt.substring + "&titleType=" + curOpt.titleType + "&selectItemWidth=" + (curOpt.itemWidth + 30)+ '&date=' + new Date() +'&ids=' + ids+'&differ=' + curOpt.idsName; if (curOpt.data) { url += "&" + curOpt.data; } /*var result = window.showModalDialog(url, ids, 'dialogWidth:' + curOpt.width + 'px;dialogHeight:' + curOpt.height + 'px;status:no;resizable:yes');*/ document.getElementById("userrole").innerHTML=""; $("#url").attr("src",url); $("#userrole").show(); }, keydown : function(event) { if (event.which == 192) { $(this).trigger("click"); } } }) return $this; } $.fn.selectList.defaults = { type : 0, url : "", itemClass : "item", idsName : "ids", appendDiv : "body", data : "", itemWidth : 60, width : 550, height : 400, substring : true, titleType : 1, defaultLen : 0 }; function addLabel(objId, id, name, title,index,name1) { var curOpt = arr[objId]; var itemLabel = $("
", { "class" : curOpt.itemClass }); var nameDiv = $("", { width : curOpt.itemWidth, display : "block", text : name }).css( { "float" : "left" }); if (curOpt.substring == true) { nameDiv.css( { "white-space" : "nowrap", "text-overflow" : "ellipsis", "overflow" : "hidden" }) } if (title) { itemLabel.attr("title", title); } else { if (curOpt.titleType == 0) { nameDiv.attr("title", id); } else if (curOpt.titleType == 1) { nameDiv.attr("title", name); } else if (curOpt.titleType == 2) { nameDiv.attr("title", id + ":" + name); } else if (curOpt.titleType == 3) { nameDiv.attr("title", name + ":" + id); } } itemLabel.append(nameDiv); var delBtn = $("", { "class" : "delBtn", text : "\xd7" }).css( { "cursor" : "pointer" }) delBtn.bind("click", function() { if (curOpt.type == 2){ var ind; $(this).parents().nextAll().each(function(i,itme){ var input=$(this).find("input[name^='"+curOpt.idsName+"']"); if(input.size() >0){ var name=input.attr("name"); ind = name.substring(name.length-2,name.length-1)-1; input.attr("name",curOpt.idsName+"["+ind+"]"); } }) curOpt.defaultLen = curOpt.defaultLen -1; } $(this).closest("." + curOpt.itemClass).remove(); }) itemLabel.append(delBtn); var hiddenId = $(''); if (curOpt.type == 2){ if(name1 != ""){ hiddenId = $(''); } if(index != ""){ hiddenId = $(''); } } itemLabel.append(hiddenId); itemLabel.css( { "float" : "left", "margin" : 1, "padding" : 2, "font-size":12, "background-color" : "#d3eaef", "border" : "solid 1px #b5d6e6" }); $(curOpt.appendDiv).append(itemLabel); //alert($(curOpt.appendDiv).html()); } $.fn.addItem = function(id, name, title,index) { var objId = $(this).attr("id"); addLabel(objId, id, name, title,index); return $(this); } $.fn.setParam = function(attr, value) { var objId = $(this).attr("id"); var curOpt = arr[objId]; curOpt[attr] = value; return $(this); } })(jQuery);