Move non-QR related code out of QR's code using the QRPostSuccessful CustomEvent. So pure~
This commit is contained in:
parent
b505dd34df
commit
19d4e1c777
@ -2396,9 +2396,6 @@
|
|||||||
if (Conf['Auto Hide QR'] && !QR.cooldown.auto) {
|
if (Conf['Auto Hide QR'] && !QR.cooldown.auto) {
|
||||||
QR.hide();
|
QR.hide();
|
||||||
}
|
}
|
||||||
if (Conf['Thread Watcher'] && Conf['Auto Watch Reply'] && threadID !== 'new') {
|
|
||||||
Watcher.watch(threadID);
|
|
||||||
}
|
|
||||||
if (!QR.cooldown.auto && $.x('ancestor::div[@id="qr"]', d.activeElement)) {
|
if (!QR.cooldown.auto && $.x('ancestor::div[@id="qr"]', d.activeElement)) {
|
||||||
d.activeElement.blur();
|
d.activeElement.blur();
|
||||||
}
|
}
|
||||||
@ -2487,15 +2484,13 @@
|
|||||||
$.set('QR.persona', persona);
|
$.set('QR.persona', persona);
|
||||||
_ref = msg.lastChild.textContent.match(/thread:(\d+),no:(\d+)/), _ = _ref[0], threadID = _ref[1], postID = _ref[2];
|
_ref = msg.lastChild.textContent.match(/thread:(\d+),no:(\d+)/), _ = _ref[0], threadID = _ref[1], postID = _ref[2];
|
||||||
$.event(QR.el, new CustomEvent('QRPostSuccessful', {
|
$.event(QR.el, new CustomEvent('QRPostSuccessful', {
|
||||||
|
bubbles: true,
|
||||||
detail: {
|
detail: {
|
||||||
threadID: threadID,
|
threadID: threadID,
|
||||||
postID: postID
|
postID: postID
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
if (threadID === '0') {
|
if (threadID === '0') {
|
||||||
if (Conf['Thread Watcher'] && Conf['Auto Watch']) {
|
|
||||||
$.set('autoWatch', postID);
|
|
||||||
}
|
|
||||||
location.pathname = "/" + g.BOARD + "/res/" + postID;
|
location.pathname = "/" + g.BOARD + "/res/" + postID;
|
||||||
} else {
|
} else {
|
||||||
QR.cooldown.auto = QR.replies.length > 1;
|
QR.cooldown.auto = QR.replies.length > 1;
|
||||||
@ -2509,13 +2504,6 @@
|
|||||||
} else {
|
} else {
|
||||||
QR.close();
|
QR.close();
|
||||||
}
|
}
|
||||||
if (g.REPLY && (Conf['Unread Count'] || Conf['Unread Favicon'])) {
|
|
||||||
Unread.foresee.push(postID);
|
|
||||||
}
|
|
||||||
if (g.REPLY && Conf['Thread Updater'] && Conf['Auto Update This']) {
|
|
||||||
Updater.unsuccessfulFetchCount = 0;
|
|
||||||
setTimeout(Updater.update, 500);
|
|
||||||
}
|
|
||||||
QR.status();
|
QR.status();
|
||||||
return QR.resetFileInput();
|
return QR.resetFileInput();
|
||||||
},
|
},
|
||||||
@ -2878,7 +2866,18 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$.add(d.body, dialog);
|
$.add(d.body, dialog);
|
||||||
return $.on(d, 'visibilitychange ovisibilitychange mozvisibilitychange webkitvisibilitychange', function() {
|
$.on(d, 'QRPostSuccessful', this.cb.post);
|
||||||
|
return $.on(d, 'visibilitychange ovisibilitychange mozvisibilitychange webkitvisibilitychange', this.cb.visibility);
|
||||||
|
},
|
||||||
|
cb: {
|
||||||
|
post: function() {
|
||||||
|
if (!Conf['Auto Update This']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Updater.unsuccessfulFetchCount = 0;
|
||||||
|
return setTimeout(Updater.update, 500);
|
||||||
|
},
|
||||||
|
visibility: function() {
|
||||||
var state;
|
var state;
|
||||||
state = d.visibilityState || d.oVisibilityState || d.mozVisibilityState || d.webkitVisibilityState;
|
state = d.visibilityState || d.oVisibilityState || d.mozVisibilityState || d.webkitVisibilityState;
|
||||||
if (state !== 'visible') {
|
if (state !== 'visible') {
|
||||||
@ -2888,9 +2887,7 @@
|
|||||||
if (Updater.timer.textContent < -Conf['Interval']) {
|
if (Updater.timer.textContent < -Conf['Interval']) {
|
||||||
return Updater.timer.textContent = -Updater.getInterval();
|
return Updater.timer.textContent = -Updater.getInterval();
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
},
|
|
||||||
cb: {
|
|
||||||
interval: function() {
|
interval: function() {
|
||||||
var val;
|
var val;
|
||||||
val = parseInt(this.value, 10);
|
val = parseInt(this.value, 10);
|
||||||
@ -3058,6 +3055,7 @@
|
|||||||
} else {
|
} else {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
$.on(d, 'QRPostSuccessful', this.cb.post);
|
||||||
return $.sync('watched', this.refresh);
|
return $.sync('watched', this.refresh);
|
||||||
},
|
},
|
||||||
refresh: function(watched) {
|
refresh: function(watched) {
|
||||||
@ -3106,6 +3104,17 @@
|
|||||||
var thread;
|
var thread;
|
||||||
thread = this.nextElementSibling.pathname.split('/');
|
thread = this.nextElementSibling.pathname.split('/');
|
||||||
return Watcher.unwatch(thread[3], thread[1]);
|
return Watcher.unwatch(thread[3], thread[1]);
|
||||||
|
},
|
||||||
|
post: function(e) {
|
||||||
|
var postID, threadID, _ref;
|
||||||
|
_ref = e.detail, postID = _ref.postID, threadID = _ref.threadID;
|
||||||
|
if (threadID === '0') {
|
||||||
|
if (Conf['Auto Watch']) {
|
||||||
|
return $.set('autoWatch', postID);
|
||||||
|
}
|
||||||
|
} else if (Conf['Auto Watch Reply']) {
|
||||||
|
return Watcher.watch(threadID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
toggle: function(thread) {
|
toggle: function(thread) {
|
||||||
@ -4274,12 +4283,16 @@
|
|||||||
Unread = {
|
Unread = {
|
||||||
init: function() {
|
init: function() {
|
||||||
this.title = d.title;
|
this.title = d.title;
|
||||||
|
$.on(d, 'QRPostSuccessful', this.post);
|
||||||
this.update();
|
this.update();
|
||||||
$.on(window, 'scroll', Unread.scroll);
|
$.on(window, 'scroll', Unread.scroll);
|
||||||
return Main.callbacks.push(this.node);
|
return Main.callbacks.push(this.node);
|
||||||
},
|
},
|
||||||
replies: [],
|
replies: [],
|
||||||
foresee: [],
|
foresee: [],
|
||||||
|
post: function(e) {
|
||||||
|
return Unread.foresee.push(e.detail.postID);
|
||||||
|
},
|
||||||
node: function(post) {
|
node: function(post) {
|
||||||
var count, el, index;
|
var count, el, index;
|
||||||
if ((index = Unread.foresee.indexOf(post.ID)) !== -1) {
|
if ((index = Unread.foresee.indexOf(post.ID)) !== -1) {
|
||||||
|
|||||||
@ -1860,8 +1860,6 @@ QR =
|
|||||||
QR.cooldown.auto = QR.replies.length > 1
|
QR.cooldown.auto = QR.replies.length > 1
|
||||||
if Conf['Auto Hide QR'] and not QR.cooldown.auto
|
if Conf['Auto Hide QR'] and not QR.cooldown.auto
|
||||||
QR.hide()
|
QR.hide()
|
||||||
if Conf['Thread Watcher'] and Conf['Auto Watch Reply'] and threadID isnt 'new'
|
|
||||||
Watcher.watch threadID
|
|
||||||
if not QR.cooldown.auto and $.x 'ancestor::div[@id="qr"]', d.activeElement
|
if not QR.cooldown.auto and $.x 'ancestor::div[@id="qr"]', d.activeElement
|
||||||
# Unfocus the focused element if it is one within the QR and we're not auto-posting.
|
# Unfocus the focused element if it is one within the QR and we're not auto-posting.
|
||||||
d.activeElement.blur()
|
d.activeElement.blur()
|
||||||
@ -1951,13 +1949,12 @@ QR =
|
|||||||
|
|
||||||
# Post/upload confirmed as successful.
|
# Post/upload confirmed as successful.
|
||||||
$.event QR.el, new CustomEvent 'QRPostSuccessful',
|
$.event QR.el, new CustomEvent 'QRPostSuccessful',
|
||||||
|
bubbles: true
|
||||||
detail:
|
detail:
|
||||||
threadID: threadID
|
threadID: threadID
|
||||||
postID: postID
|
postID: postID
|
||||||
|
|
||||||
if threadID is '0' # new thread
|
if threadID is '0' # new thread
|
||||||
if Conf['Thread Watcher'] and Conf['Auto Watch']
|
|
||||||
$.set 'autoWatch', postID
|
|
||||||
# auto-noko
|
# auto-noko
|
||||||
location.pathname = "/#{g.BOARD}/res/#{postID}"
|
location.pathname = "/#{g.BOARD}/res/#{postID}"
|
||||||
else
|
else
|
||||||
@ -1972,12 +1969,6 @@ QR =
|
|||||||
else
|
else
|
||||||
QR.close()
|
QR.close()
|
||||||
|
|
||||||
if g.REPLY and (Conf['Unread Count'] or Conf['Unread Favicon'])
|
|
||||||
Unread.foresee.push postID
|
|
||||||
if g.REPLY and Conf['Thread Updater'] and Conf['Auto Update This']
|
|
||||||
Updater.unsuccessfulFetchCount = 0
|
|
||||||
setTimeout Updater.update, 500
|
|
||||||
|
|
||||||
QR.status()
|
QR.status()
|
||||||
QR.resetFileInput()
|
QR.resetFileInput()
|
||||||
|
|
||||||
@ -2308,15 +2299,21 @@ Updater =
|
|||||||
|
|
||||||
$.add d.body, dialog
|
$.add d.body, dialog
|
||||||
|
|
||||||
$.on d, 'visibilitychange ovisibilitychange mozvisibilitychange webkitvisibilitychange', ->
|
$.on d, 'QRPostSuccessful', @cb.post
|
||||||
|
$.on d, 'visibilitychange ovisibilitychange mozvisibilitychange webkitvisibilitychange', @cb.visibility
|
||||||
|
|
||||||
|
cb:
|
||||||
|
post: ->
|
||||||
|
return unless Conf['Auto Update This']
|
||||||
|
Updater.unsuccessfulFetchCount = 0
|
||||||
|
setTimeout Updater.update, 500
|
||||||
|
visibility: ->
|
||||||
state = d.visibilityState or d.oVisibilityState or d.mozVisibilityState or d.webkitVisibilityState
|
state = d.visibilityState or d.oVisibilityState or d.mozVisibilityState or d.webkitVisibilityState
|
||||||
return if state isnt 'visible'
|
return if state isnt 'visible'
|
||||||
# Reset the counter when we focus this tab.
|
# Reset the counter when we focus this tab.
|
||||||
Updater.unsuccessfulFetchCount = 0
|
Updater.unsuccessfulFetchCount = 0
|
||||||
if Updater.timer.textContent < -Conf['Interval']
|
if Updater.timer.textContent < -Conf['Interval']
|
||||||
Updater.timer.textContent = -Updater.getInterval()
|
Updater.timer.textContent = -Updater.getInterval()
|
||||||
|
|
||||||
cb:
|
|
||||||
interval: ->
|
interval: ->
|
||||||
val = parseInt @value, 10
|
val = parseInt @value, 10
|
||||||
@value = if val > 5 then val else 5
|
@value = if val > 5 then val else 5
|
||||||
@ -2456,6 +2453,7 @@ Watcher =
|
|||||||
#populate watcher, display watch buttons
|
#populate watcher, display watch buttons
|
||||||
@refresh()
|
@refresh()
|
||||||
|
|
||||||
|
$.on d, 'QRPostSuccessful', @cb.post
|
||||||
$.sync 'watched', @refresh
|
$.sync 'watched', @refresh
|
||||||
|
|
||||||
refresh: (watched) ->
|
refresh: (watched) ->
|
||||||
@ -2493,6 +2491,13 @@ Watcher =
|
|||||||
x: ->
|
x: ->
|
||||||
thread = @nextElementSibling.pathname.split '/'
|
thread = @nextElementSibling.pathname.split '/'
|
||||||
Watcher.unwatch thread[3], thread[1]
|
Watcher.unwatch thread[3], thread[1]
|
||||||
|
post: (e) ->
|
||||||
|
{postID, threadID} = e.detail
|
||||||
|
if threadID is '0'
|
||||||
|
if Conf['Auto Watch']
|
||||||
|
$.set 'autoWatch', postID
|
||||||
|
else if Conf['Auto Watch Reply']
|
||||||
|
Watcher.watch threadID
|
||||||
|
|
||||||
toggle: (thread) ->
|
toggle: (thread) ->
|
||||||
id = $('.favicon + input', thread).name
|
id = $('.favicon + input', thread).name
|
||||||
@ -3390,6 +3395,7 @@ ThreadStats =
|
|||||||
Unread =
|
Unread =
|
||||||
init: ->
|
init: ->
|
||||||
@title = d.title
|
@title = d.title
|
||||||
|
$.on d, 'QRPostSuccessful', @post
|
||||||
@update()
|
@update()
|
||||||
$.on window, 'scroll', Unread.scroll
|
$.on window, 'scroll', Unread.scroll
|
||||||
Main.callbacks.push @node
|
Main.callbacks.push @node
|
||||||
@ -3397,6 +3403,9 @@ Unread =
|
|||||||
replies: []
|
replies: []
|
||||||
foresee: []
|
foresee: []
|
||||||
|
|
||||||
|
post: (e) ->
|
||||||
|
Unread.foresee.push e.detail.postID
|
||||||
|
|
||||||
node: (post) ->
|
node: (post) ->
|
||||||
if (index = Unread.foresee.indexOf post.ID) isnt -1
|
if (index = Unread.foresee.indexOf post.ID) isnt -1
|
||||||
Unread.foresee.splice index, 1
|
Unread.foresee.splice index, 1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user