OSDN Git Service

ereg_replaceをpreg_replaceに変更
[nucleus-jp/nucleus-plugins.git] / trunk / NP_MultipleCategories / multiplecategories / orderlist.js
1 function getSelectedValues (select) {
2   var r = new Array();
3   for (var i = 0; i < select.options.length; i++)
4     if (select.options[i].selected)
5       r[r.length] = select.options[i].value;
6   return r;
7 }
8
9
10 function submitCatOrder(){
11     selectAllOptions(document.ordform.order);
12     document.ordform.orderList.value = getSelectedValues(document.ordform.order);
13     document.ordform.order.value = '';
14
15 }
16
17
18 function selectAllOptions(obj) {
19         for (var i=0; i<obj.options.length; i++) {
20                 obj.options[i].selected = true;
21                 }
22         }
23
24 function swapOptions(obj,i,j) {
25         var o = obj.options;
26         var i_selected = o[i].selected;
27         var j_selected = o[j].selected;
28         var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
29         var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
30         o[i] = temp2;
31         o[j] = temp;
32         o[i].selected = j_selected;
33         o[j].selected = i_selected;
34         }
35
36 function moveOptionUp(obj) {
37         // If > 1 option selected, do nothing
38         var selectedCount=0;
39         for (i=0; i<obj.options.length; i++) {
40                 if (obj.options[i].selected) {
41                         selectedCount++;
42                         }
43                 }
44         if (selectedCount > 1) {
45                 return;
46                 }
47         // If this is the first item in the list, do nothing
48         var i = obj.selectedIndex;
49         if (i == 0) {
50                 return;
51                 }
52         swapOptions(obj,i,i-1);
53         obj.options[i-1].selected = true;
54         }
55
56 function moveOptionDown(obj) {
57         // If > 1 option selected, do nothing
58         var selectedCount=0;
59         for (i=0; i<obj.options.length; i++) {
60                 if (obj.options[i].selected) {
61                         selectedCount++;
62                         }
63                 }
64         if (selectedCount > 1) {
65                 return;
66                 }
67         // If this is the last item in the list, do nothing
68         var i = obj.selectedIndex;
69         if (i == (obj.options.length-1)) {
70                 return;
71                 }
72         swapOptions(obj,i,i+1);
73         obj.options[i+1].selected = true;
74         }
75
76 //<sato(na)0.402j>
77 function setScatDat(id, sname, sdesc) {
78         this.id     = id;
79         this.sname  = sname;
80         this.sdesc  = sdesc;
81 }
82 function scatListRefresh(scatDat){
83         //del
84         optionsLength = document.ordform.order.options.length;
85         for (i=0; i<=optionsLength; i++) document.ordform.order.options[0] = null;
86         //add
87         for(var i = 0; i < scatDat.length; i++) {
88                 label = scatDat[i].id + " [ " + scatDat[i].sname + " ] " + scatDat[i].sdesc;
89                 document.ordform.order.options[i] = new Option(label, scatDat[i].id);
90         }
91 }
92 function sortidASC(a, b) {
93         if (b.id == a.id) return 0;
94         return a.id - b.id;
95 }
96 function sortidDESC(a, b) {
97         if (b.id == a.id) return 0;
98         return b.id - a.id;
99 }
100 function sortsnameASC(a, b) {
101         if (b.sname == a.sname) return 0;
102         return (a.sname > b.sname) ? 1 : -1;
103 }
104 function sortsnameDESC(a, b) {
105         if (b.sname == a.sname) return 0;
106         return (b.sname > a.sname) ? 1 : -1;
107 }
108 function sortsdescASC(a, b) {
109         if (b.sdesc == a.sdesc) return 0;
110         return (a.sdesc > b.sdesc) ? 1 : -1;
111 }
112 function sortsdescDESC(a, b) {
113         if (b.sdesc == a.sdesc) return 0;
114         return (b.sdesc > a.sdesc) ? 1 : -1;
115 }
116 //</sato(na)0.402j>