From 0da7ead83d831fcb22f990b50de3cd253fce46d5 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 25 Jun 2013 15:54:24 -0400 Subject: [PATCH] Add FormData shim for IE (used in bot avatar uploads). (imported from commit 41cd090768c1299db3ca0d154ee5495802302a9f) --- humbug/settings.py | 1 + .../static/third/html5-formdata/formdata.js | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 zephyr/static/third/html5-formdata/formdata.js diff --git a/humbug/settings.py b/humbug/settings.py index b20dc822b6..b79e663229 100644 --- a/humbug/settings.py +++ b/humbug/settings.py @@ -311,6 +311,7 @@ PIPELINE_JS = { 'app': { 'source_filenames': [ 'third/bootstrap-notify/js/bootstrap-notify.js', + 'third/html5-formdata/formdata.js', 'third/jquery-validate/jquery.validate.js', 'third/jquery-form/jquery.form.js', 'third/jquery-highlight/jquery.highlight.js', diff --git a/zephyr/static/third/html5-formdata/formdata.js b/zephyr/static/third/html5-formdata/formdata.js new file mode 100644 index 0000000000..4eabc4815b --- /dev/null +++ b/zephyr/static/third/html5-formdata/formdata.js @@ -0,0 +1,37 @@ +/** + * Emulate FormData for some browsers + * MIT License + * (c) 2010 François de Metz + */ +(function(w) { + if (w.FormData) + return; + function FormData() { + this.fake = true; + this.boundary = "--------FormData" + Math.random(); + this._fields = []; + } + FormData.prototype.append = function(key, value) { + this._fields.push([key, value]); + } + FormData.prototype.toString = function() { + var boundary = this.boundary; + var body = ""; + this._fields.forEach(function(field) { + body += "--" + boundary + "\r\n"; + // file upload + if (field[1].name) { + var file = field[1]; + body += "Content-Disposition: form-data; name=\""+ field[0] +"\"; filename=\""+ file.name +"\"\r\n"; + body += "Content-Type: "+ file.type +"\r\n\r\n"; + body += file.getAsBinary() + "\r\n"; + } else { + body += "Content-Disposition: form-data; name=\""+ field[0] +"\";\r\n\r\n"; + body += field[1] + "\r\n"; + } + }); + body += "--" + boundary +"--"; + return body; + } + w.FormData = FormData; +})(window);