diff options
Diffstat (limited to 'misc/upload.js')
-rw-r--r-- | misc/upload.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/misc/upload.js b/misc/upload.js new file mode 100644 index 000000000..48f403448 --- /dev/null +++ b/misc/upload.js @@ -0,0 +1,59 @@ +// Global killswitch +if (isJsEnabled()) { + addLoadEvent(uploadAutoAttach); +} + +/** + * Attaches the upload behaviour to the upload form. + */ +function uploadAutoAttach() { + var acdb = []; + var inputs = document.getElementsByTagName('input'); + for (i = 0; input = inputs[i]; i++) { + if (input && hasClass(input, 'upload')) { + var uri = input.value; + var button = input.id.substr(5); + var wrapper = button + '-wrapper'; + var hide = button + '-hide'; + var upload = new jsUpload(uri, button, wrapper, hide); + } + } +} + +/** + * JS upload object. + */ +function jsUpload(uri, button, wrapper, hide) { + var upload = this; + this.button = button; + this.wrapper = wrapper; + this.hide = hide; + redirectFormButton(uri, $(button), this); +} + +/** + * Handler for the form redirection submission. + */ +jsUpload.prototype.onsubmit = function () { + var hide = $(this.hide); + // Insert progressbar and stretch to take the same space. + this.progress = new progressBar('uploadprogress'); + this.progress.setProgress(-1, 'Uploading file...'); + this.progress.element.style.width = '28em'; + this.progress.element.style.height = hide.offsetHeight +'px'; + hide.parentNode.insertBefore(this.progress.element, hide); + // Hide file form + hide.style.display = 'none'; +} + +/** + * Handler for the form redirection completion. + */ +jsUpload.prototype.oncomplete = function (data) { + // Remove progressbar + removeNode(this.progress); + this.progress = null; + // Replace form and re-attach behaviour + $(this.wrapper).innerHTML = data; + uploadAutoAttach(); +}
\ No newline at end of file |