More robust/Less shitty QR status.
This commit is contained in:
parent
5711a85c8c
commit
28a472adec
@ -5684,6 +5684,8 @@
|
||||
$.on(d, 'ThreadUpdate', function() {
|
||||
if (g.DEAD) {
|
||||
return QR.abort();
|
||||
} else {
|
||||
return QR.status();
|
||||
}
|
||||
});
|
||||
if (Conf['Persistent QR']) {
|
||||
@ -5786,11 +5788,8 @@
|
||||
}
|
||||
return QR.notifications = [];
|
||||
},
|
||||
status: function(data) {
|
||||
status: function() {
|
||||
var disabled, status, value;
|
||||
if (data == null) {
|
||||
data = {};
|
||||
}
|
||||
if (!QR.nodes) {
|
||||
return;
|
||||
}
|
||||
@ -5799,9 +5798,9 @@
|
||||
disabled = true;
|
||||
QR.cooldown.auto = false;
|
||||
}
|
||||
value = data.progress || QR.cooldown.seconds || value;
|
||||
value = QR.req ? QR.req.progress : QR.cooldown.seconds || value;
|
||||
status = QR.nodes.status;
|
||||
status.value = QR.cooldown.auto ? value ? "Auto " + value : 'Auto' : value || 'Submit';
|
||||
status.value = !value ? 'Submit' : QR.cooldown.auto ? "Auto " + value : value;
|
||||
return status.disabled = disabled || false;
|
||||
},
|
||||
cooldown: {
|
||||
@ -6519,15 +6518,15 @@
|
||||
if (e != null) {
|
||||
e.preventDefault();
|
||||
}
|
||||
if (QR.req) {
|
||||
QR.abort();
|
||||
return;
|
||||
}
|
||||
if (QR.cooldown.seconds) {
|
||||
QR.cooldown.auto = !QR.cooldown.auto;
|
||||
QR.status();
|
||||
return;
|
||||
}
|
||||
if (QR.ajax) {
|
||||
QR.abort();
|
||||
return;
|
||||
}
|
||||
reply = QR.replies[0];
|
||||
if (reply === QR.selected) {
|
||||
reply.forceSave();
|
||||
@ -6576,9 +6575,6 @@
|
||||
if (!QR.cooldown.auto && $.x('ancestor::div[@id="qr"]', d.activeElement)) {
|
||||
d.activeElement.blur();
|
||||
}
|
||||
QR.status({
|
||||
progress: '...'
|
||||
});
|
||||
post = {
|
||||
resto: threadID,
|
||||
name: reply.name,
|
||||
@ -6595,11 +6591,9 @@
|
||||
recaptcha_response_field: response
|
||||
};
|
||||
callbacks = {
|
||||
onload: function() {
|
||||
return QR.response(this);
|
||||
},
|
||||
onload: QR.response,
|
||||
onerror: function() {
|
||||
delete QR.ajax;
|
||||
delete QR.req;
|
||||
QR.cooldown.auto = false;
|
||||
QR.status();
|
||||
return QR.error($.el('a', {
|
||||
@ -6613,22 +6607,23 @@
|
||||
form: $.formData(post),
|
||||
upCallbacks: {
|
||||
onload: function() {
|
||||
return QR.status({
|
||||
progress: '...'
|
||||
});
|
||||
QR.req.progress = '...';
|
||||
return QR.status();
|
||||
},
|
||||
onprogress: function(e) {
|
||||
return QR.status({
|
||||
progress: "" + (Math.round(e.loaded / e.total * 100)) + "%"
|
||||
});
|
||||
QR.req.progress = "" + (Math.round(e.loaded / e.total * 100)) + "%";
|
||||
return QR.status();
|
||||
}
|
||||
}
|
||||
};
|
||||
return QR.ajax = $.ajax($.id('postForm').parentNode.action, callbacks, opts);
|
||||
QR.req = $.ajax($.id('postForm').parentNode.action, callbacks, opts);
|
||||
QR.req.progress = '...';
|
||||
return QR.status();
|
||||
},
|
||||
response: function(req) {
|
||||
var ban, board, err, h1, persona, postID, reply, threadID, tmpDoc, _, _base, _ref, _ref1;
|
||||
delete QR.ajax;
|
||||
response: function() {
|
||||
var ban, board, err, h1, persona, postID, reply, req, threadID, tmpDoc, _, _base, _ref, _ref1;
|
||||
req = QR.req;
|
||||
delete QR.req;
|
||||
tmpDoc = d.implementation.createHTMLDocument('');
|
||||
tmpDoc.documentElement.innerHTML = req.response;
|
||||
if (ban = $('.banType', tmpDoc)) {
|
||||
@ -6700,9 +6695,9 @@
|
||||
return QR.status();
|
||||
},
|
||||
abort: function() {
|
||||
if (QR.ajax) {
|
||||
QR.ajax.abort();
|
||||
delete QR.ajax;
|
||||
if (QR.req) {
|
||||
QR.req.abort();
|
||||
delete QR.req;
|
||||
QR.notifications.push(new Notification('info', 'QR upload aborted.', 5));
|
||||
}
|
||||
return QR.status();
|
||||
|
||||
@ -36,7 +36,10 @@ QR =
|
||||
$.on d, 'drop', QR.dropFile
|
||||
$.on d, 'dragstart dragend', QR.drag
|
||||
$.on d, 'ThreadUpdate', ->
|
||||
QR.abort() if g.DEAD
|
||||
if g.DEAD
|
||||
QR.abort()
|
||||
else
|
||||
QR.status()
|
||||
|
||||
QR.persist() if Conf['Persistent QR']
|
||||
|
||||
@ -108,19 +111,25 @@ QR =
|
||||
notification.close()
|
||||
QR.notifications = []
|
||||
|
||||
status: (data={}) ->
|
||||
status: ->
|
||||
return unless QR.nodes
|
||||
if g.DEAD
|
||||
value = 404
|
||||
disabled = true
|
||||
QR.cooldown.auto = false
|
||||
value = data.progress or QR.cooldown.seconds or value
|
||||
|
||||
value = if QR.req
|
||||
QR.req.progress
|
||||
else
|
||||
QR.cooldown.seconds or value
|
||||
|
||||
{status} = QR.nodes
|
||||
status.value =
|
||||
if QR.cooldown.auto
|
||||
if value then "Auto #{value}" else 'Auto'
|
||||
else
|
||||
value or 'Submit'
|
||||
status.value = unless value
|
||||
'Submit'
|
||||
else if QR.cooldown.auto
|
||||
"Auto #{value}"
|
||||
else
|
||||
value
|
||||
status.disabled = disabled or false
|
||||
|
||||
cooldown:
|
||||
@ -727,15 +736,16 @@ QR =
|
||||
|
||||
submit: (e) ->
|
||||
e?.preventDefault()
|
||||
|
||||
if QR.req
|
||||
QR.abort()
|
||||
return
|
||||
|
||||
if QR.cooldown.seconds
|
||||
QR.cooldown.auto = !QR.cooldown.auto
|
||||
QR.status()
|
||||
return
|
||||
|
||||
if QR.ajax
|
||||
QR.abort()
|
||||
return
|
||||
|
||||
reply = QR.replies[0]
|
||||
reply.forceSave() if reply is QR.selected
|
||||
if g.BOARD.ID is 'f'
|
||||
@ -781,10 +791,6 @@ QR =
|
||||
# Unfocus the focused element if it is one within the QR and we're not auto-posting.
|
||||
d.activeElement.blur()
|
||||
|
||||
# Starting to upload might take some time.
|
||||
# Provide some feedback that we're starting to submit.
|
||||
QR.status progress: '...'
|
||||
|
||||
post =
|
||||
resto: threadID
|
||||
name: reply.name
|
||||
@ -801,10 +807,9 @@ QR =
|
||||
recaptcha_response_field: response
|
||||
|
||||
callbacks =
|
||||
onload: ->
|
||||
QR.response @
|
||||
onload: QR.response
|
||||
onerror: ->
|
||||
delete QR.ajax
|
||||
delete QR.req
|
||||
# Connection error, or
|
||||
# CORS disabled error on www.4chan.org/banned
|
||||
QR.cooldown.auto = false
|
||||
@ -817,16 +822,23 @@ QR =
|
||||
form: $.formData post
|
||||
upCallbacks:
|
||||
onload: ->
|
||||
# Upload done, waiting for response.
|
||||
QR.status progress: '...'
|
||||
# Upload done, waiting for server response.
|
||||
QR.req.progress = '...'
|
||||
QR.status()
|
||||
onprogress: (e) ->
|
||||
# Uploading...
|
||||
QR.status progress: "#{Math.round e.loaded / e.total * 100}%"
|
||||
QR.req.progress = "#{Math.round e.loaded / e.total * 100}%"
|
||||
QR.status()
|
||||
|
||||
QR.ajax = $.ajax $.id('postForm').parentNode.action, callbacks, opts
|
||||
QR.req = $.ajax $.id('postForm').parentNode.action, callbacks, opts
|
||||
# Starting to upload might take some time.
|
||||
# Provide some feedback that we're starting to submit.
|
||||
QR.req.progress = '...'
|
||||
QR.status()
|
||||
|
||||
response: (req) ->
|
||||
delete QR.ajax
|
||||
response: ->
|
||||
{req} = QR
|
||||
delete QR.req
|
||||
|
||||
tmpDoc = d.implementation.createHTMLDocument ''
|
||||
tmpDoc.documentElement.innerHTML = req.response
|
||||
@ -916,8 +928,8 @@ QR =
|
||||
QR.status()
|
||||
|
||||
abort: ->
|
||||
if QR.ajax
|
||||
QR.ajax.abort()
|
||||
delete QR.ajax
|
||||
if QR.req
|
||||
QR.req.abort()
|
||||
delete QR.req
|
||||
QR.notifications.push new Notification 'info', 'QR upload aborted.', 5
|
||||
QR.status()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user