1 | |
---|
2 | |
---|
3 | /** |
---|
4 | * sorry, tagListSelector is coded like a pork, but I don't have the time to |
---|
5 | * code something better... ^^; |
---|
6 | */ |
---|
7 | function tagListSelector(optionsToSet) |
---|
8 | { |
---|
9 | this.options = { |
---|
10 | itemId:'', |
---|
11 | selectorId:'', |
---|
12 | width:'auto', |
---|
13 | height:'auto', |
---|
14 | maxHeight:250, |
---|
15 | selectedClass:'gcText3', |
---|
16 | selectorClass:'ruleTypeM gcTextInput gcBgInput gcBorderInput', |
---|
17 | selectorItems:'ruleTypeM', |
---|
18 | onSelect:null, |
---|
19 | }; |
---|
20 | |
---|
21 | this.init = function (optionsToSet) |
---|
22 | { |
---|
23 | if(typeof optionsToSet=='object') |
---|
24 | { |
---|
25 | this.options = jQuery.extend(this.options, optionsToSet); |
---|
26 | } |
---|
27 | |
---|
28 | $('body').append("<div id='iTLSDiv' class='"+this.options.selectorClass+"' style='padding:0px;z-index:5000;overflow:auto;display:none;position:absolute;max-height:"+this.options.maxHeight+"px'></div>"); |
---|
29 | $('#iTLSDiv') |
---|
30 | .prepend($('#'+this.options.itemId)) |
---|
31 | .bind('mouseleave', function () |
---|
32 | { |
---|
33 | $('#iTLSDiv').css('display', 'none'); |
---|
34 | } |
---|
35 | ); |
---|
36 | $('#'+this.options.itemId).css('display', 'block'); |
---|
37 | $('#iTLSDiv li').bind('click', this.options, function (event) |
---|
38 | { |
---|
39 | $('#'+event.data.selectorId).attr('value', $(this).attr('value')); |
---|
40 | $('#'+event.data.selectorId+' span.ruleContent').html($(this).html()); |
---|
41 | $('#iTLSDiv').css('display', 'none'); |
---|
42 | if(event.data.onSelect!=null && jQuery.isFunction(event.data.onSelect)) event.data.onSelect($(this).attr('value')); |
---|
43 | } |
---|
44 | ); |
---|
45 | }; |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | this.display = function (fromId) |
---|
50 | { |
---|
51 | selectedItem=$('#'+fromId).attr('value'); |
---|
52 | |
---|
53 | var top=$('#'+fromId).offset().top+$('#'+fromId).outerHeight()-1, |
---|
54 | left=$('#'+fromId).offset().left, |
---|
55 | width=$('#'+fromId).innerWidth(); |
---|
56 | $('#iTLSDiv li').removeClass(this.options.selectedClass); |
---|
57 | $('#iTagListItem'+selectedItem).addClass(this.options.selectedClass); |
---|
58 | $('#iTLSDiv').css( |
---|
59 | { |
---|
60 | top:top+'px', |
---|
61 | left:left+'px', |
---|
62 | width:width+'px', |
---|
63 | display:'block' |
---|
64 | } |
---|
65 | ); |
---|
66 | this.options.selectorId=fromId; |
---|
67 | }; |
---|
68 | |
---|
69 | |
---|
70 | this.init(optionsToSet); |
---|
71 | } |
---|