Merge branch 'mayhem' into delete

This commit is contained in:
James Campos 2012-06-13 06:16:22 -07:00
commit e718579e04
2 changed files with 30 additions and 24 deletions

View File

@ -311,6 +311,19 @@
id: function(id) { id: function(id) {
return d.getElementById(id); return d.getElementById(id);
}, },
formData: function(arg) {
var fd, key, val;
if (arg instanceof HTMLFormElement) {
fd = new FormData(arg);
} else {
fd = new FormData();
for (key in arg) {
val = arg[key];
fd.append(key, val);
}
}
return fd;
},
ajax: function(url, callbacks, opts) { ajax: function(url, callbacks, opts) {
var form, headers, key, r, type, upCallbacks, val; var form, headers, key, r, type, upCallbacks, val;
if (opts == null) { if (opts == null) {
@ -318,18 +331,15 @@
} }
type = opts.type, headers = opts.headers, upCallbacks = opts.upCallbacks, form = opts.form; type = opts.type, headers = opts.headers, upCallbacks = opts.upCallbacks, form = opts.form;
r = new XMLHttpRequest(); r = new XMLHttpRequest();
r.open(type || 'get', url, true); type || (type = form && 'post' || 'get');
r.open(type, url, true);
for (key in headers) { for (key in headers) {
val = headers[key]; val = headers[key];
r.setRequestHeader(key, val); r.setRequestHeader(key, val);
} }
$.extend(r, callbacks); $.extend(r, callbacks);
$.extend(r.upload, upCallbacks); $.extend(r.upload, upCallbacks);
if (typeof form === 'string') { r.send(form);
r.sendAsBinary(form);
} else {
r.send(form);
}
return r; return r;
}, },
cache: function(url, cb) { cache: function(url, cb) {
@ -1976,7 +1986,7 @@
return QR.el.dispatchEvent(e); return QR.el.dispatchEvent(e);
}, },
submit: function(e) { submit: function(e) {
var callbacks, captcha, captchas, challenge, err, form, m, name, opts, post, reply, response, threadID, val; var callbacks, captcha, captchas, challenge, err, m, opts, post, reply, response, threadID;
if (e != null) { if (e != null) {
e.preventDefault(); e.preventDefault();
} }
@ -2043,13 +2053,6 @@
recaptcha_challenge_field: challenge, recaptcha_challenge_field: challenge,
recaptcha_response_field: response + ' ' recaptcha_response_field: response + ' '
}; };
form = new FormData();
for (name in post) {
val = post[name];
if (val) {
form.append(name, val);
}
}
callbacks = { callbacks = {
onload: function() { onload: function() {
return QR.response(this.response); return QR.response(this.response);
@ -2064,8 +2067,7 @@
} }
}; };
opts = { opts = {
form: form, form: $.formData(post),
type: 'POST',
upCallbacks: { upCallbacks: {
onload: function() { onload: function() {
return QR.status({ return QR.status({

View File

@ -266,15 +266,24 @@ $.extend $,
cb JSON.parse e.newValue if e.key is "#{Main.namespace}#{key}" cb JSON.parse e.newValue if e.key is "#{Main.namespace}#{key}"
id: (id) -> id: (id) ->
d.getElementById id d.getElementById id
formData: (arg) ->
if arg instanceof HTMLFormElement
fd = new FormData arg
else
fd = new FormData()
for key, val of arg
fd.append key, val
fd
ajax: (url, callbacks, opts={}) -> ajax: (url, callbacks, opts={}) ->
{type, headers, upCallbacks, form} = opts {type, headers, upCallbacks, form} = opts
r = new XMLHttpRequest() r = new XMLHttpRequest()
r.open type or 'get', url, true type or= form and 'post' or 'get'
r.open type, url, true
for key, val of headers for key, val of headers
r.setRequestHeader key, val r.setRequestHeader key, val
$.extend r, callbacks $.extend r, callbacks
$.extend r.upload, upCallbacks $.extend r.upload, upCallbacks
if typeof form is 'string' then r.sendAsBinary form else r.send form r.send form
r r
cache: (url, cb) -> cache: (url, cb) ->
if req = $.cache.requests[url] if req = $.cache.requests[url]
@ -1547,10 +1556,6 @@ QR =
recaptcha_challenge_field: challenge recaptcha_challenge_field: challenge
recaptcha_response_field: response + ' ' recaptcha_response_field: response + ' '
form = new FormData()
for name, val of post
form.append name, val if val
callbacks = callbacks =
onload: -> onload: ->
QR.response @response QR.response @response
@ -1563,8 +1568,7 @@ QR =
target: '_blank' target: '_blank'
textContent: 'Connection error, or you are banned.' textContent: 'Connection error, or you are banned.'
opts = opts =
form: form form: $.formData post
type: 'POST'
upCallbacks: upCallbacks:
onload: -> onload: ->
# Upload done, waiting for response. # Upload done, waiting for response.