PageSourceSearch

https://sendfile.jp/vcheck.js

js sendfile.jp collected 2026-10-04 21:08:06 UTC 5,541 bytes, 238 lines download raw bytes

1// vim:set ts=2 sts=2 sw=2 bs=2 ai si et nu ft=javascript fdm=marker commentstring=\ //%s:
2// $Id$
3// Last Change: 2006/05/19. 
4
5function vCheckInit(){ //{{{
6  if(document.getElementById("errors")){
7    var obj = document.getElementById("errors");
8    obj.innerHTML = "";
9    obj.style.display = 'none';
10  }
11}
12 //}}}
13function changeBgColor(el,color){ //{{{
14  if(BGCOLOR){
15    if(!(el[0])){
16      el.style.backgroundColor = color;
17    }else{
18      for(var i=0;i<el.length;i++){
19        el[i].style.backgroundColor = color;
20      }
21    }
22  }
23}
24 //}}}
25function errorCheck(el,key,val){ //{{{
26
27  if(el.length == 0){
28    errors.push(val["empty_error"]);
29    indexs.push(key);
30    return false;
31  }
32
33  if(val["maxlength"] && el.length > val["maxlength"]){
34    errors.push(val["maxlength_error"]);
35    indexs.push(key);
36    return false;
37  }
38
39  if(val["regexp"] && !(el.match(val["regexp"]))){
40    errors.push(val["regexp_error"]);
41    indexs.push(key);
42    return false;
43  }
44
45  return true;
46
47}
48 //}}}
49function makeError(errors){ //{{{
50  
51  var res = "";
52
53  if(errors.length > 0){
54
55    res += ERROR_TITLE;
56
57    if(ERROR_MODE==1){
58      res += ERROR_LIST_S + "<li>";
59      res += errors.join("</li><li>");
60      res += "</li>" + ERROR_LIST_E;
61    }else if(ERROR_MODE==2){
62      for(var i=0;i<names.length;i++){
63        var obj = document.getElementById(ERROR_ID_PREFIX+names[i]);
64        if(obj) obj.style.display = "none";
65      }
66      for(var i=0;i<indexs.length;i++){
67        var obj = document.getElementById(ERROR_ID_PREFIX+String(indexs[i]));
68        if(obj){
69          obj.innerHTML = ERROR_PREFIX + errors[i];
70          obj.style.display = "block";
71        }
72      }
73    }
74
75  }
76
77  return res;
78
79}
80 //}}}
81function vCheck(form){ //{{{
82  if(DEBUG){
83    var debug_values = new Array();
84  }
85
86  var elsize = names.length;
87  indexs = new Array();
88  errors = new Array();
89
90
91  for(var i=0;i<elsize;i++){
92
93    var key=names[i];
94    var val=values[key];
95    var el=form.elements[key];
96    var elvalue=new Array();
97    var errflag=true;
98
99    if(val["plural"]){
100
101      if(!(val["empty"]) && el.length == 0){
102        changeBgColor(el, FALSE_BGCOLOR);
103        errors.push(val["empty_error"]);
104        indexs.push(key);
105        continue;
106      }
107
108      if(el.type != "select-one"){
109        for(var j=0;j<el.length;j++){
110          if(el[j].type == "text" || el[j].type == "textarea"){
111            elvalue.push(el[j].value);
112          }else if(el[j].type == "checkbox" || el[j].type == "radio"){
113            if(el[j].checked){
114              elvalue.push(el[j].value);
115            }
116          }
117        }
118      }else{
119        for(var k=0;k<el.options.length;k++){
120          if(el.options[k].selected){
121            elvalue.push(el.options[k].text);
122          }
123        }
124      }
125
126      if(DEBUG){
127        debug_values.push(elvalue.toSource());
128      }
129
130      if(val["empty"] && elvalue.length == 0){
131        continue;
132      }else{
133
134        if(!(val["empty"]) && elvalue.length == 0){
135          changeBgColor(el, FALSE_BGCOLOR);
136          errors.push(val["empty_error"]);
137          indexs.push(key);
138          continue;
139        }
140
141        if(val["plural_min"] && (elvalue.length < Number(val["plural_min"]))){
142          changeBgColor(el, FALSE_BGCOLOR);
143          errors.push(val["plural_min_error"]);
144          indexs.push(key);
145          continue;
146        }
147
148        if(val["plural_max"] && (elvalue.length > Number(val["plural_max"]))){
149          changeBgColor(el, FALSE_BGCOLOR);
150          errors.push(val["plural_max_error"]);
151          indexs.push(key);
152          continue;
153        }
154
155        for(var k=0;k<elvalue.length;k++){
156
157          if(val["empty"] && elvalue[k].length == 0){
158            continue;
159          }
160
161          errflag = errorCheck(elvalue[k],key,val);
162        }
163      }
164        
165    }else{
166
167      if(el.type == "text" || el.type == "textarea"){
168        elvalue.push(el.value);
169      }else if(el.type == "checkbox" || el.type == "radio"){
170        if(el.checked){
171          elvalue.push(el.value);
172        }
173      }else if(el.type == "select-one"){
174        elvalue.push(el.options[el.selectedIndex].value);
175      }
176
177      if(DEBUG){
178        debug_values.push(elvalue.toSource());
179      }
180
181      if(!(val["empty"]) && elvalue.length == 0){
182        changeBgColor(el, FALSE_BGCOLOR);
183        errors.push(val["empty_error"]);
184        indexs.push(key);
185        continue;
186      }else if(val["empty"] && elvalue[0].length == 0){
187        continue;
188      }else if(elvalue[0].length == 0){
189        changeBgColor(el, FALSE_BGCOLOR);
190        errors.push(val["empty_error"]);
191        indexs.push(key);
192        continue;
193      }else{
194
195        errflag = errorCheck(elvalue[0],key,val);
196        if(errflag){
197          if(val["confirm"]){
198            if(elvalue[0] != form.elements[val["confirm"]].value){
199              errors.push(val["confirm_error"]);
200              indexs.push(key);
201              errflag=false;
202            }
203          }
204        }
205      }
206
207    }
208
209    if(!errflag){
210      changeBgColor(el, FALSE_BGCOLOR);
211      errflag=true;
212    }else{
213      changeBgColor(el, TRUE_BGCOLOR);
214    }
215
216  }
217
218  var obj = document.getElementById("errors");
219  obj.style.display = 'block';
220  location.hash = '#';
221
222  if(errors.length > 0){
223    if(DEBUG){
224      obj.innerHTML = makeError(errors) + "<pre>" + debug_values.toSource() + "</pre>";
225    }else{
226      obj.innerHTML = makeError(errors);
227    }
228    return false;
229  }else{
230//    obj.innerHTML = SUCCESS_TITLE;
231//    return confirm(CONFIRM_COMMENT);
232    obj.style.display = 'none';
233    return;
234  }
235
236}
237 //}}}
238

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.