| 1 | function getxy(){ |
| 2 | var x,y; |
| 3 | if (self.innerHeight) // all except Explorer |
| 4 | { |
| 5 | x = self.innerWidth; |
| 6 | y = self.innerHeight; |
| 7 | } |
| 8 | else if (document.documentElement && document.documentElement.clientHeight) |
| 9 | // Explorer 6 Strict Mode |
| 10 | { |
| 11 | x = document.documentElement.clientWidth; |
| 12 | y = document.documentElement.clientHeight; |
| 13 | } |
| 14 | else if (document.body) // other Explorers |
| 15 | { |
| 16 | x = document.body.clientWidth; |
| 17 | y = document.body.clientHeight; |
| 18 | } |
| 19 | return {'x':x,'y':y} |
| 20 | } |
| 21 | |
| 22 | var humanvalue = ['B','KB','MB','GB'] |
| 23 | function humanize(bytes) { |
| 24 | curbytes = bytes |
| 25 | iterations = 0 |
| 26 | while (curbytes>1024) { |
| 27 | iterations++ |
| 28 | curbytes=curbytes/1024 |
| 29 | } |
| 30 | return curbytes.toFixed(1) + ' ' + humanvalue[iterations] |
| 31 | } |
| 32 | |
| 33 | interval = null; |
| 34 | function fetch(uuid) { |
| 35 | req = xmlhttp |
| 36 | req.open("GET", "/admin/upload_progress/", 1); |
| 37 | req.setRequestHeader("X-Progress-Id", uuid); |
| 38 | req.onreadystatechange = function () { |
| 39 | if (req.readyState == 4) { |
| 40 | if (req.status == 200) { |
| 41 | |
| 42 | var upload = eval( '(' + req.responseText + ')' ); |
| 43 | |
| 44 | if (upload.state == 'done' || upload.state == 'uploading') |
| 45 | bar = document.getElementById('progress_bar'); |
| 46 | progress_wrap = document.getElementById('progress_wrap'); |
| 47 | if (upload.state == 'done') { |
| 48 | window.clearTimeout(interval); |
| 49 | progress_wrap.style.visibility = 'hidden'; |
| 50 | return; |
| 51 | } |
| 52 | bar_txt = document.getElementById('progress_text') |
| 53 | bar_txt.innerHTML = ((upload.received / upload.size) * 100).toFixed(1) + '% - ' + |
| 54 | humanize(upload.received) + ' of ' + humanize(upload.size) |
| 55 | w = 400 * upload.received / upload.size; |
| 56 | bar.style.width = w + 'px'; |
| 57 | |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | req.send(null); |
| 62 | |
| 63 | } |
| 64 | |
| 65 | function closeprogress() { |
| 66 | |
| 67 | |
| 68 | |
| 69 | } |
| 70 | |
| 71 | function openprogress(e) { |
| 72 | |
| 73 | uuid = ""; |
| 74 | for (i = 0; i < 32; i++) { |
| 75 | uuid += Math.floor(Math.random() * 16).toString(16); |
| 76 | } |
| 77 | frm = e.target||e.srcElement; |
| 78 | |
| 79 | if (frm.action.indexOf('?') == -1) { |
| 80 | frm.action=frm.action+"?progress_id=" + uuid; |
| 81 | } else { |
| 82 | frm.action=frm.action+"&progress_id=" + uuid; |
| 83 | } |
| 84 | |
| 85 | if (document.getElementById('progress_wrap')) { |
| 86 | document.getElementById('progress_wrap').style.visibility = 'visible'; |
| 87 | document.getElementById('progress_bar').style.width = '0'; |
| 88 | document.getElementById('progress_text').innerHTML = '0%'; |
| 89 | |
| 90 | interval = window.setInterval( |
| 91 | function () { |
| 92 | fetch(uuid); |
| 93 | }, |
| 94 | 1000 |
| 95 | ); |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | pos = getxy() |
| 100 | posx = parseInt((pos.x/2)-(420/2), 10) |
| 101 | posy = parseInt((pos.y/2)-(50/2), 10) |
| 102 | |
| 103 | progress_wrap = quickElement('div', document.body, '', 'style', |
| 104 | 'position: absolute; top: '+posy+'px; left: '+posx+'px; height: 50px; ' + |
| 105 | 'padding: 10px; width: 420px; background: #ffffff; ' + |
| 106 | 'border: solid 1px #dddddd;', 'id', 'progress_wrap') |
| 107 | |
| 108 | progress_label = quickElement('h1', progress_wrap, 'Upload progress') |
| 109 | |
| 110 | progress = quickElement('div', progress_wrap, '', 'style', |
| 111 | 'top: 0; left: 0; width: 0px; ', 'id', 'progress_bar', 'class', 'submit-row') |
| 112 | |
| 113 | progress_text = quickElement('div', progress_wrap, '0%', 'style', |
| 114 | 'color: #000000; ', 'id', 'progress_text') |
| 115 | |
| 116 | interval = window.setInterval( |
| 117 | function () { |
| 118 | fetch(uuid); |
| 119 | }, |
| 120 | 1000 |
| 121 | ); |
| 122 | } |
| 123 | |
| 124 | addEvent(window, 'load', function() { |
| 125 | frms = document.getElementsByTagName('form'); |
| 126 | for (var i=0; i<frms.length; i++) { |
| 127 | if (frms[i].encoding.toLowerCase() == 'multipart/form-data') { |
| 128 | addEvent(frms[i], 'submit', openprogress); |
| 129 | return; |
| 130 | } |
| 131 | } |
| 132 | }); |
| 133 | function getxy(){ |
| 134 | var x,y; |
| 135 | if (self.innerHeight) // all except Explorer |
| 136 | { |
| 137 | x = self.innerWidth; |
| 138 | y = self.innerHeight; |
| 139 | } |
| 140 | else if (document.documentElement && document.documentElement.clientHeight) |
| 141 | // Explorer 6 Strict Mode |
| 142 | { |
| 143 | x = document.documentElement.clientWidth; |
| 144 | y = document.documentElement.clientHeight; |
| 145 | } |
| 146 | else if (document.body) // other Explorers |
| 147 | { |
| 148 | x = document.body.clientWidth; |
| 149 | y = document.body.clientHeight; |
| 150 | } |
| 151 | return {'x':x,'y':y} |
| 152 | } |
| 153 | |
| 154 | var humanvalue = ['B','KB','MB','GB'] |
| 155 | function humanize(bytes) { |
| 156 | curbytes = bytes |
| 157 | iterations = 0 |
| 158 | while (curbytes>1024) { |
| 159 | iterations++ |
| 160 | curbytes=curbytes/1024 |
| 161 | } |
| 162 | return curbytes.toFixed(1) + ' ' + humanvalue[iterations] |
| 163 | } |
| 164 | |
| 165 | interval = null; |
| 166 | function fetch(uuid) { |
| 167 | req = xmlhttp |
| 168 | req.open("GET", "/admin/upload_progress/", 1); |
| 169 | req.setRequestHeader("X-Progress-Id", uuid); |
| 170 | req.onreadystatechange = function () { |
| 171 | if (req.readyState == 4) { |
| 172 | if (req.status == 200) { |
| 173 | |
| 174 | var upload = eval( '(' + req.responseText + ')' ); |
| 175 | |
| 176 | if (upload.state == 'done' || upload.state == 'uploading') |
| 177 | bar = document.getElementById('progress_bar'); |
| 178 | progress_wrap = document.getElementById('progress_wrap'); |
| 179 | if (upload.state == 'done') { |
| 180 | window.clearTimeout(interval); |
| 181 | progress_wrap.style.visibility = 'hidden'; |
| 182 | return; |
| 183 | } |
| 184 | bar_txt = document.getElementById('progress_text') |
| 185 | bar_txt.innerHTML = ((upload.received / upload.size) * 100).toFixed(1) + '% - ' + |
| 186 | humanize(upload.received) + ' of ' + humanize(upload.size) |
| 187 | w = 400 * upload.received / upload.size; |
| 188 | bar.style.width = w + 'px'; |
| 189 | |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | req.send(null); |
| 194 | |
| 195 | } |
| 196 | |
| 197 | function closeprogress() { |
| 198 | |
| 199 | |
| 200 | |
| 201 | } |
| 202 | |
| 203 | function openprogress(e) { |
| 204 | |
| 205 | uuid = ""; |
| 206 | for (i = 0; i < 32; i++) { |
| 207 | uuid += Math.floor(Math.random() * 16).toString(16); |
| 208 | } |
| 209 | frm = e.target||e.srcElement; |
| 210 | |
| 211 | if (frm.action.indexOf('?') == -1) { |
| 212 | frm.action=frm.action+"?progress_id=" + uuid; |
| 213 | } else { |
| 214 | frm.action=frm.action+"&progress_id=" + uuid; |
| 215 | } |
| 216 | |
| 217 | if (document.getElementById('progress_wrap')) { |
| 218 | document.getElementById('progress_wrap').style.visibility = 'visible'; |
| 219 | document.getElementById('progress_bar').style.width = '0'; |
| 220 | document.getElementById('progress_text').innerHTML = '0%'; |
| 221 | |
| 222 | interval = window.setInterval( |
| 223 | function () { |
| 224 | fetch(uuid); |
| 225 | }, |
| 226 | 1000 |
| 227 | ); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | pos = getxy() |
| 232 | posx = parseInt((pos.x/2)-(420/2), 10) |
| 233 | posy = parseInt((pos.y/2)-(50/2), 10) |
| 234 | |
| 235 | progress_wrap = quickElement('div', document.body, '', 'style', |
| 236 | 'position: absolute; top: '+posy+'px; left: '+posx+'px; height: 50px; ' + |
| 237 | 'padding: 10px; width: 420px; background: #ffffff; ' + |
| 238 | 'border: solid 1px #dddddd;', 'id', 'progress_wrap') |
| 239 | |
| 240 | progress_label = quickElement('h1', progress_wrap, 'Upload progress') |
| 241 | |
| 242 | progress = quickElement('div', progress_wrap, '', 'style', |
| 243 | 'top: 0; left: 0; width: 0px; ', 'id', 'progress_bar', 'class', 'submit-row') |
| 244 | |
| 245 | progress_text = quickElement('div', progress_wrap, '0%', 'style', |
| 246 | 'color: #000000; ', 'id', 'progress_text') |
| 247 | |
| 248 | interval = window.setInterval( |
| 249 | function () { |
| 250 | fetch(uuid); |
| 251 | }, |
| 252 | 1000 |
| 253 | ); |
| 254 | } |
| 255 | |
| 256 | addEvent(window, 'load', function() { |
| 257 | frms = document.getElementsByTagName('form'); |
| 258 | for (var i=0; i<frms.length; i++) { |
| 259 | if (frms[i].encoding.toLowerCase() == 'multipart/form-data') { |
| 260 | addEvent(frms[i], 'submit', openprogress); |
| 261 | return; |
| 262 | } |
| 263 | } |
| 264 | }); |
| 265 | function getxy(){ |
| 266 | var x,y; |
| 267 | if (self.innerHeight) // all except Explorer |
| 268 | { |
| 269 | x = self.innerWidth; |
| 270 | y = self.innerHeight; |
| 271 | } |
| 272 | else if (document.documentElement && document.documentElement.clientHeight) |
| 273 | // Explorer 6 Strict Mode |
| 274 | { |
| 275 | x = document.documentElement.clientWidth; |
| 276 | y = document.documentElement.clientHeight; |
| 277 | } |
| 278 | else if (document.body) // other Explorers |
| 279 | { |
| 280 | x = document.body.clientWidth; |
| 281 | y = document.body.clientHeight; |
| 282 | } |
| 283 | return {'x':x,'y':y} |
| 284 | } |
| 285 | |
| 286 | var humanvalue = ['B','KB','MB','GB'] |
| 287 | function humanize(bytes) { |
| 288 | curbytes = bytes |
| 289 | iterations = 0 |
| 290 | while (curbytes>1024) { |
| 291 | iterations++ |
| 292 | curbytes=curbytes/1024 |
| 293 | } |
| 294 | return curbytes.toFixed(1) + ' ' + humanvalue[iterations] |
| 295 | } |
| 296 | |
| 297 | interval = null; |
| 298 | function fetch(uuid) { |
| 299 | req = xmlhttp |
| 300 | req.open("GET", "/admin/upload_progress/", 1); |
| 301 | req.setRequestHeader("X-Progress-Id", uuid); |
| 302 | req.onreadystatechange = function () { |
| 303 | if (req.readyState == 4) { |
| 304 | if (req.status == 200) { |
| 305 | |
| 306 | var upload = eval( '(' + req.responseText + ')' ); |
| 307 | |
| 308 | if (upload.state == 'done' || upload.state == 'uploading') |
| 309 | bar = document.getElementById('progress_bar'); |
| 310 | progress_wrap = document.getElementById('progress_wrap'); |
| 311 | if (upload.state == 'done') { |
| 312 | window.clearTimeout(interval); |
| 313 | progress_wrap.style.visibility = 'hidden'; |
| 314 | return; |
| 315 | } |
| 316 | bar_txt = document.getElementById('progress_text') |
| 317 | bar_txt.innerHTML = ((upload.received / upload.size) * 100).toFixed(1) + '% - ' + |
| 318 | humanize(upload.received) + ' of ' + humanize(upload.size) |
| 319 | w = 400 * upload.received / upload.size; |
| 320 | bar.style.width = w + 'px'; |
| 321 | |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | req.send(null); |
| 326 | |
| 327 | } |
| 328 | |
| 329 | function closeprogress() { |
| 330 | |
| 331 | |
| 332 | |
| 333 | } |
| 334 | |
| 335 | function openprogress(e) { |
| 336 | |
| 337 | uuid = ""; |
| 338 | for (i = 0; i < 32; i++) { |
| 339 | uuid += Math.floor(Math.random() * 16).toString(16); |
| 340 | } |
| 341 | frm = e.target||e.srcElement; |
| 342 | |
| 343 | if (frm.action.indexOf('?') == -1) { |
| 344 | frm.action=frm.action+"?progress_id=" + uuid; |
| 345 | } else { |
| 346 | frm.action=frm.action+"&progress_id=" + uuid; |
| 347 | } |
| 348 | |
| 349 | if (document.getElementById('progress_wrap')) { |
| 350 | document.getElementById('progress_wrap').style.visibility = 'visible'; |
| 351 | document.getElementById('progress_bar').style.width = '0'; |
| 352 | document.getElementById('progress_text').innerHTML = '0%'; |
| 353 | |
| 354 | interval = window.setInterval( |
| 355 | function () { |
| 356 | fetch(uuid); |
| 357 | }, |
| 358 | 1000 |
| 359 | ); |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | pos = getxy() |
| 364 | posx = parseInt((pos.x/2)-(420/2), 10) |
| 365 | posy = parseInt((pos.y/2)-(50/2), 10) |
| 366 | |
| 367 | progress_wrap = quickElement('div', document.body, '', 'style', |
| 368 | 'position: absolute; top: '+posy+'px; left: '+posx+'px; height: 50px; ' + |
| 369 | 'padding: 10px; width: 420px; background: #ffffff; ' + |
| 370 | 'border: solid 1px #dddddd;', 'id', 'progress_wrap') |
| 371 | |
| 372 | progress_label = quickElement('h1', progress_wrap, 'Upload progress') |
| 373 | |
| 374 | progress = quickElement('div', progress_wrap, '', 'style', |
| 375 | 'top: 0; left: 0; width: 0px; ', 'id', 'progress_bar', 'class', 'submit-row') |
| 376 | |
| 377 | progress_text = quickElement('div', progress_wrap, '0%', 'style', |
| 378 | 'color: #000000; ', 'id', 'progress_text') |
| 379 | |
| 380 | interval = window.setInterval( |
| 381 | function () { |
| 382 | fetch(uuid); |
| 383 | }, |
| 384 | 1000 |
| 385 | ); |
| 386 | } |
| 387 | |
| 388 | addEvent(window, 'load', function() { |
| 389 | frms = document.getElementsByTagName('form'); |
| 390 | for (var i=0; i<frms.length; i++) { |
| 391 | if (frms[i].encoding.toLowerCase() == 'multipart/form-data') { |
| 392 | addEvent(frms[i], 'submit', openprogress); |
| 393 | return; |
| 394 | } |
| 395 | } |
| 396 | }); |
| 397 | function getxy(){ |
| 398 | var x,y; |
| 399 | if (self.innerHeight) // all except Explorer |
| 400 | { |
| 401 | x = self.innerWidth; |
| 402 | y = self.innerHeight; |
| 403 | } |
| 404 | else if (document.documentElement && document.documentElement.clientHeight) |
| 405 | // Explorer 6 Strict Mode |
| 406 | { |
| 407 | x = document.documentElement.clientWidth; |
| 408 | y = document.documentElement.clientHeight; |
| 409 | } |
| 410 | else if (document.body) // other Explorers |
| 411 | { |
| 412 | x = document.body.clientWidth; |
| 413 | y = document.body.clientHeight; |
| 414 | } |
| 415 | return {'x':x,'y':y} |
| 416 | } |
| 417 | |
| 418 | var humanvalue = ['B','KB','MB','GB'] |
| 419 | function humanize(bytes) { |
| 420 | curbytes = bytes |
| 421 | iterations = 0 |
| 422 | while (curbytes>1024) { |
| 423 | iterations++ |
| 424 | curbytes=curbytes/1024 |
| 425 | } |
| 426 | return curbytes.toFixed(1) + ' ' + humanvalue[iterations] |
| 427 | } |
| 428 | |
| 429 | interval = null; |
| 430 | function fetch(uuid) { |
| 431 | req = xmlhttp |
| 432 | req.open("GET", "/admin/upload_progress/", 1); |
| 433 | req.setRequestHeader("X-Progress-Id", uuid); |
| 434 | req.onreadystatechange = function () { |
| 435 | if (req.readyState == 4) { |
| 436 | if (req.status == 200) { |
| 437 | |
| 438 | var upload = eval( '(' + req.responseText + ')' ); |
| 439 | |
| 440 | if (upload.state == 'done' || upload.state == 'uploading') |
| 441 | bar = document.getElementById('progress_bar'); |
| 442 | progress_wrap = document.getElementById('progress_wrap'); |
| 443 | if (upload.state == 'done') { |
| 444 | window.clearTimeout(interval); |
| 445 | progress_wrap.style.visibility = 'hidden'; |
| 446 | return; |
| 447 | } |
| 448 | bar_txt = document.getElementById('progress_text') |
| 449 | bar_txt.innerHTML = ((upload.received / upload.size) * 100).toFixed(1) + '% - ' + |
| 450 | humanize(upload.received) + ' of ' + humanize(upload.size) |
| 451 | w = 400 * upload.received / upload.size; |
| 452 | bar.style.width = w + 'px'; |
| 453 | |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | req.send(null); |
| 458 | |
| 459 | } |
| 460 | |
| 461 | function closeprogress() { |
| 462 | |
| 463 | |
| 464 | |
| 465 | } |
| 466 | |
| 467 | function openprogress(e) { |
| 468 | |
| 469 | uuid = ""; |
| 470 | for (i = 0; i < 32; i++) { |
| 471 | uuid += Math.floor(Math.random() * 16).toString(16); |
| 472 | } |
| 473 | frm = e.target||e.srcElement; |
| 474 | |
| 475 | if (frm.action.indexOf('?') == -1) { |
| 476 | frm.action=frm.action+"?progress_id=" + uuid; |
| 477 | } else { |
| 478 | frm.action=frm.action+"&progress_id=" + uuid; |
| 479 | } |
| 480 | |
| 481 | if (document.getElementById('progress_wrap')) { |
| 482 | document.getElementById('progress_wrap').style.visibility = 'visible'; |
| 483 | document.getElementById('progress_bar').style.width = '0'; |
| 484 | document.getElementById('progress_text').innerHTML = '0%'; |
| 485 | |
| 486 | interval = window.setInterval( |
| 487 | function () { |
| 488 | fetch(uuid); |
| 489 | }, |
| 490 | 1000 |
| 491 | ); |
| 492 | return; |
| 493 | } |
| 494 | |
| 495 | pos = getxy() |
| 496 | posx = parseInt((pos.x/2)-(420/2), 10) |
| 497 | posy = parseInt((pos.y/2)-(50/2), 10) |
| 498 | |
| 499 | progress_wrap = quickElement('div', document.body, '', 'style', |
| 500 | 'position: absolute; top: '+posy+'px; left: '+posx+'px; height: 50px; ' + |
| 501 | 'padding: 10px; width: 420px; background: #ffffff; ' + |
| 502 | 'border: solid 1px #dddddd;', 'id', 'progress_wrap') |
| 503 | |
| 504 | progress_label = quickElement('h1', progress_wrap, 'Upload progress') |
| 505 | |
| 506 | progress = quickElement('div', progress_wrap, '', 'style', |
| 507 | 'top: 0; left: 0; width: 0px; ', 'id', 'progress_bar', 'class', 'submit-row') |
| 508 | |
| 509 | progress_text = quickElement('div', progress_wrap, '0%', 'style', |
| 510 | 'color: #000000; ', 'id', 'progress_text') |
| 511 | |
| 512 | interval = window.setInterval( |
| 513 | function () { |
| 514 | fetch(uuid); |
| 515 | }, |
| 516 | 1000 |
| 517 | ); |
| 518 | } |
| 519 | |
| 520 | addEvent(window, 'load', function() { |
| 521 | frms = document.getElementsByTagName('form'); |
| 522 | for (var i=0; i<frms.length; i++) { |
| 523 | if (frms[i].encoding.toLowerCase() == 'multipart/form-data') { |
| 524 | addEvent(frms[i], 'submit', openprogress); |
| 525 | return; |
| 526 | } |
| 527 | } |
| 528 | }); |
| 529 | No newline at end of file |