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) {
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) {
var form, headers, key, r, type, upCallbacks, val;
if (opts == null) {
@ -318,18 +331,15 @@
}
type = opts.type, headers = opts.headers, upCallbacks = opts.upCallbacks, form = opts.form;
r = new XMLHttpRequest();
r.open(type || 'get', url, true);
type || (type = form && 'post' || 'get');
r.open(type, url, true);
for (key in headers) {
val = headers[key];
r.setRequestHeader(key, val);
}
$.extend(r, callbacks);
$.extend(r.upload, upCallbacks);
if (typeof form === 'string') {
r.sendAsBinary(form);
} else {
r.send(form);
}
r.send(form);
return r;
},
cache: function(url, cb) {
@ -1976,7 +1986,7 @@
return QR.el.dispatchEvent(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) {
e.preventDefault();
}
@ -2043,13 +2053,6 @@
recaptcha_challenge_field: challenge,
recaptcha_response_field: response + ' '
};
form = new FormData();
for (name in post) {
val = post[name];
if (val) {
form.append(name, val);
}
}
callbacks = {
onload: function() {
return QR.response(this.response);
@ -2064,8 +2067,7 @@
}
};
opts = {
form: form,
type: 'POST',
form: $.formData(post),
upCallbacks: {
onload: function() {
return QR.status({

View File

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