@@ -1,88 +1,105 | |||||
1 | var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5); |
|
1 | var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5); | |
2 |
|
2 | |||
3 | function addOption(theSel, theText, theValue) { |
|
3 | function addOption(theSel, theText, theValue) { | |
4 | var newOpt = new Option(theText, theValue); |
|
4 | var newOpt = new Option(theText, theValue); | |
5 | var selLength = theSel.length; |
|
5 | var selLength = theSel.length; | |
6 | theSel.options[selLength] = newOpt; |
|
6 | theSel.options[selLength] = newOpt; | |
7 | } |
|
7 | } | |
8 |
|
8 | |||
9 | function swapOptions(theSel, index1, index2) { |
|
9 | function swapOptions(theSel, index1, index2) { | |
10 | var text, value; |
|
10 | var text, value, selected; | |
11 | text = theSel.options[index1].text; |
|
11 | text = theSel.options[index1].text; | |
12 | value = theSel.options[index1].value; |
|
12 | value = theSel.options[index1].value; | |
|
13 | selected = theSel.options[index1].selected; | |||
13 | theSel.options[index1].text = theSel.options[index2].text; |
|
14 | theSel.options[index1].text = theSel.options[index2].text; | |
14 | theSel.options[index1].value = theSel.options[index2].value; |
|
15 | theSel.options[index1].value = theSel.options[index2].value; | |
|
16 | theSel.options[index1].selected = theSel.options[index2].selected; | |||
15 | theSel.options[index2].text = text; |
|
17 | theSel.options[index2].text = text; | |
16 | theSel.options[index2].value = value; |
|
18 | theSel.options[index2].value = value; | |
|
19 | theSel.options[index2].selected = selected; | |||
17 | } |
|
20 | } | |
18 |
|
21 | |||
19 | function deleteOption(theSel, theIndex) { |
|
22 | function deleteOption(theSel, theIndex) { | |
20 | var selLength = theSel.length; |
|
23 | var selLength = theSel.length; | |
21 | if (selLength > 0) { |
|
24 | if (selLength > 0) { | |
22 | theSel.options[theIndex] = null; |
|
25 | theSel.options[theIndex] = null; | |
23 | } |
|
26 | } | |
24 | } |
|
27 | } | |
25 |
|
28 | |||
26 | function moveOptions(theSelFrom, theSelTo) { |
|
29 | function moveOptions(theSelFrom, theSelTo) { | |
27 | var selLength = theSelFrom.length; |
|
30 | var selLength = theSelFrom.length; | |
28 | var selectedText = new Array(); |
|
31 | var selectedText = new Array(); | |
29 | var selectedValues = new Array(); |
|
32 | var selectedValues = new Array(); | |
30 | var selectedCount = 0; |
|
33 | var selectedCount = 0; | |
31 | var i; |
|
34 | var i; | |
32 | for (i = selLength - 1; i >= 0; i--) { |
|
35 | for (i = selLength - 1; i >= 0; i--) { | |
33 | if (theSelFrom.options[i].selected) { |
|
36 | if (theSelFrom.options[i].selected) { | |
34 | selectedText[selectedCount] = theSelFrom.options[i].text; |
|
37 | selectedText[selectedCount] = theSelFrom.options[i].text; | |
35 | selectedValues[selectedCount] = theSelFrom.options[i].value; |
|
38 | selectedValues[selectedCount] = theSelFrom.options[i].value; | |
36 | deleteOption(theSelFrom, i); |
|
39 | deleteOption(theSelFrom, i); | |
37 | selectedCount++; |
|
40 | selectedCount++; | |
38 | } |
|
41 | } | |
39 | } |
|
42 | } | |
40 | for (i = selectedCount - 1; i >= 0; i--) { |
|
43 | for (i = selectedCount - 1; i >= 0; i--) { | |
41 | addOption(theSelTo, selectedText[i], selectedValues[i]); |
|
44 | addOption(theSelTo, selectedText[i], selectedValues[i]); | |
42 | } |
|
45 | } | |
43 | if (NS4) history.go(0); |
|
46 | if (NS4) history.go(0); | |
44 | } |
|
47 | } | |
45 |
|
48 | |||
46 | function moveOptionUp(theSel) { |
|
49 | function moveOptionUp(theSel) { | |
47 | var index = theSel.selectedIndex; |
|
50 | var indexTop = 0; | |
48 | if (index > 0) { |
|
51 | for(var s=0; s<theSel.length; s++) { | |
49 | swapOptions(theSel, index-1, index); |
|
52 | if (theSel.options[s].selected) { | |
50 | theSel.selectedIndex = index-1; |
|
53 | if (s > indexTop) { | |
|
54 | swapOptions(theSel, s-1, s); | |||
|
55 | } | |||
|
56 | indexTop++; | |||
|
57 | } | |||
51 | } |
|
58 | } | |
52 | } |
|
59 | } | |
53 |
|
60 | |||
54 | function moveOptionTop(theSel) { |
|
61 | function moveOptionTop(theSel) { | |
55 | var index = theSel.selectedIndex; |
|
62 | var indexTop = 0; | |
56 |
|
63 | for(var s=0; s<theSel.length; s++) { | ||
57 | if (index > 0) { |
|
64 | if (theSel.options[s].selected) { | |
58 | for (i=index; i>0; i--) { |
|
65 | if (s > indexTop) { | |
59 | swapOptions(theSel, i-1, i); |
|
66 | for (var i=s; i>indexTop; i--) { | |
|
67 | swapOptions(theSel, i-1, i); | |||
|
68 | } | |||
|
69 | } | |||
|
70 | indexTop++; | |||
60 | } |
|
71 | } | |
61 | theSel.selectedIndex = 0; |
|
|||
62 | } |
|
72 | } | |
63 | } |
|
73 | } | |
64 |
|
74 | |||
65 | function moveOptionDown(theSel) { |
|
75 | function moveOptionDown(theSel) { | |
66 |
var index = theSel. |
|
76 | var indexBottom = theSel.length - 1; | |
67 | if (index < theSel.length - 1) { |
|
77 | for(var s=indexBottom; s>=0; s--) { | |
68 | swapOptions(theSel, index, index+1); |
|
78 | if (theSel.options[s].selected) { | |
69 | theSel.selectedIndex = index+1; |
|
79 | if (s < indexBottom) { | |
|
80 | swapOptions(theSel, s+1, s); | |||
|
81 | } | |||
|
82 | indexBottom--; | |||
|
83 | } | |||
70 | } |
|
84 | } | |
71 | } |
|
85 | } | |
72 |
|
86 | |||
73 | function moveOptionBottom(theSel) { |
|
87 | function moveOptionBottom(theSel) { | |
74 |
var index = theSel. |
|
88 | var indexBottom = theSel.length - 1; | |
75 | var indexTop = theSel.length - 1; |
|
89 | for(var s=indexBottom; s>=0; s--) { | |
76 | if (index < theSel.length - 1) { |
|
90 | if (theSel.options[s].selected) { | |
77 | for (i=index; i<indexTop; i++) { |
|
91 | if (s < indexBottom) { | |
78 | swapOptions(theSel, i+1, i); |
|
92 | for (i=s; i<indexBottom; i++) { | |
|
93 | swapOptions(theSel, i+1, i); | |||
|
94 | } | |||
|
95 | } | |||
|
96 | indexBottom--; | |||
79 | } |
|
97 | } | |
80 | theSel.selectedIndex = indexTop; |
|
|||
81 | } |
|
98 | } | |
82 | } |
|
99 | } | |
83 |
|
100 | |||
84 | // OK |
|
101 | // OK | |
85 | function selectAllOptions(id) { |
|
102 | function selectAllOptions(id) { | |
86 | var select = $('#'+id); |
|
103 | var select = $('#'+id); | |
87 | select.children('option').attr('selected', true); |
|
104 | select.children('option').attr('selected', true); | |
88 | } |
|
105 | } |
General Comments 0
You need to be logged in to leave comments.
Login now