JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
enc_hhmm leaves a blank blank. remove extra whitespace from metaform templates
[wfpl.git] / uploader / progress.js
1 function tag(name) {
2     return document.getElementById(name);
3 }
4
5 var dbg_url;
6 function sendRequest(url,callback,postData) {
7         var req = createXMLHTTPObject();
8         if (!req) return;
9         var method = (postData) ? "POST" : "GET";
10         req.open(method,url,true);
11         req.setRequestHeader('User-Agent','XMLHTTP/1.0');
12         if (postData)
13                 req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
14         dbg_url = url;
15         req.onreadystatechange = function () {
16                 if(req.readyState != 4) {
17                         callback(req);
18                         return;
19                 }
20                 if (req.status != 200 && req.status != 304) {
21                         /* alert('url:' + dbg_url + '  HTTP error ' + req.status); */
22                         progress_start_delayed();
23                         return;
24                 }
25                 callback(req);
26         }
27         if (req.readyState == 4) return;
28         req.send(postData);
29 }
30
31 var XMLHttpFactories = [
32         function () {return new XMLHttpRequest()},
33         function () {return new ActiveXObject("Msxml2.XMLHTTP")},
34         function () {return new ActiveXObject("Msxml3.XMLHTTP")},
35         function () {return new ActiveXObject("Microsoft.XMLHTTP")}
36 ];
37
38 function createXMLHTTPObject() {
39         var xmlhttp = false;
40         for (var i=0;i<XMLHttpFactories.length;i++) {
41                 try {
42                         xmlhttp = XMLHttpFactories[i]();
43                 }
44                 catch (e) {
45                         continue;
46                 }
47                 break;
48         }
49         return xmlhttp;
50 }
51
52
53 function progress_start() {
54         sendRequest('~url~', progress_update_with);
55 }
56
57 function progress_start_delayed() {
58         setTimeout(progress_start, 1500);
59 }
60
61
62 function progress_finished() {
63         var appears;
64         tag('wfpl_progress_header').innerHTML = 'Upload Finished';
65         appears = tag('wfpl_upload_finished');
66         if(appears) {
67                 appears.style.position = 'static';
68         }
69         if(wfpl_upload_finished) {
70                 wfpl_upload_finished();
71         }
72 }
73
74 function progress_update_with(rec) {
75         length = rec.responseText.length;
76         bar = tag('wfpl_progress_bar');
77         bar.style.backgroundPosition = (Math.floor(length / 5) - 200) + 'px 0';
78
79         whole = Math.floor(length/10);
80         pct = '' + whole + '.' + (length - (whole * 10));
81         bar.innerHTML = pct + '%';
82
83         if(length == 1000) {
84                 progress_finished();
85         }
86 }
87
88 function submitting() {
89         if(wfpl_upload_starting) {
90                 wfpl_upload_starting();
91         }
92         tag('wfpl_progress_form').style.display = 'none';
93         tag('wfpl_progress_section').style.position = 'static';
94         progress_start_delayed();
95 }
96
97
98
99
100
101