Rework QuoteThreading slightly
This commit is contained in:
parent
b1c86eabf7
commit
630db39831
@ -8471,13 +8471,9 @@
|
||||
$.extend(this.threadNewLink, {
|
||||
innerHTML: "<a href=\"javascript:;\">Thread New Posts</a>"
|
||||
});
|
||||
$.on($('input', this.controls), 'change', function() {
|
||||
return QuoteThreading.rethread(this.checked);
|
||||
});
|
||||
$.on(this.threadNewLink.firstElementChild, 'click', function() {
|
||||
QuoteThreading.threadNewLink.hidden = true;
|
||||
return QuoteThreading.rethread(true);
|
||||
});
|
||||
$.on($('input', this.controls), 'change', this.cb.thread);
|
||||
$.on(this.threadNewLink.firstElementChild, 'click', this.cb.click);
|
||||
$.on(d, '4chanXInitFinished', this.cb.thread);
|
||||
Header.menu.addEntry(this.entry = {
|
||||
el: this.controls,
|
||||
order: 98
|
||||
@ -8505,6 +8501,9 @@
|
||||
this.parent = {};
|
||||
this.children = {};
|
||||
this.inserted = {};
|
||||
$.off($('input', this.controls), 'change', this.cb.thread);
|
||||
$.off(this.threadNewLink.firstElementChild, 'click', this.cb.click);
|
||||
$.off(d, '4chanXInitFinished', this.cb.thread);
|
||||
Thread.callbacks.disconnect('Quote Threading');
|
||||
return Post.callbacks.disconnect('Quote Threading');
|
||||
},
|
||||
@ -8528,11 +8527,9 @@
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
quote = _ref[_i];
|
||||
parent = g.posts[quote];
|
||||
if (!parent || parent.isFetchedQuote || !parent.isReply || parent.ID >= this.ID) {
|
||||
continue;
|
||||
if ((parent = g.posts[quote]) && !parent.isFetchedQuote && parent.isReply && parent.ID <= this.ID) {
|
||||
_results.push(parent);
|
||||
}
|
||||
_results.push(parent);
|
||||
}
|
||||
return _results;
|
||||
}).call(this);
|
||||
@ -8552,16 +8549,24 @@
|
||||
return posts;
|
||||
},
|
||||
insert: function(post) {
|
||||
var child, children, descendants, i, next, nodes, order, parent, prev, prev2, threadContainer, x, _base, _i, _j, _k, _len, _name;
|
||||
var child, children, descendants, i, next, nodes, order, parent, prev, prev2, threadContainer, x, _base, _i, _j, _len, _name;
|
||||
if (!(QuoteThreading.enabled && (parent = QuoteThreading.parent[post.fullID]) && !QuoteThreading.inserted[post.fullID])) {
|
||||
return false;
|
||||
}
|
||||
descendants = QuoteThreading.descendants(post);
|
||||
if (!Unread.posts.has(parent.ID) && descendants.some(function(x) {
|
||||
return Unread.posts.has(x.ID);
|
||||
})) {
|
||||
QuoteThreading.threadNewLink.hidden = false;
|
||||
return false;
|
||||
if (!Unread.posts.has(parent.ID)) {
|
||||
if ((function() {
|
||||
var x, _i, _len;
|
||||
for (_i = 0, _len = descendants.length; _i < _len; _i++) {
|
||||
x = descendants[_i];
|
||||
if (Unread.posts.has(x.ID)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
})()) {
|
||||
QuoteThreading.threadNewLink.hidden = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
order = Unread.order;
|
||||
children = ((_base = QuoteThreading.children)[_name = parent.fullID] || (_base[_name] = []));
|
||||
@ -8573,16 +8578,13 @@
|
||||
nodes.push(post.nodes.threadContainer);
|
||||
}
|
||||
i = children.length;
|
||||
for (_i = children.length - 1; _i >= 0; _i += -1) {
|
||||
child = children[_i];
|
||||
if (child.ID >= post.ID) {
|
||||
i--;
|
||||
}
|
||||
while ((child = children[i]) && child.ID >= post.ID) {
|
||||
i--;
|
||||
}
|
||||
if (i !== children.length) {
|
||||
next = children[i];
|
||||
for (_j = 0, _len = descendants.length; _j < _len; _j++) {
|
||||
x = descendants[_j];
|
||||
for (_i = 0, _len = descendants.length; _i < _len; _i++) {
|
||||
x = descendants[_i];
|
||||
order.before(order[next.ID], order[x.ID]);
|
||||
}
|
||||
children.splice(i, 0, post);
|
||||
@ -8592,8 +8594,8 @@
|
||||
while ((prev2 = QuoteThreading.children[prev.fullID]) && prev2.length) {
|
||||
prev = prev2[prev2.length - 1];
|
||||
}
|
||||
for (_k = descendants.length - 1; _k >= 0; _k += -1) {
|
||||
x = descendants[_k];
|
||||
for (_j = descendants.length - 1; _j >= 0; _j += -1) {
|
||||
x = descendants[_j];
|
||||
order.after(order[prev.ID], order[x.ID]);
|
||||
}
|
||||
children.push(post);
|
||||
@ -8609,6 +8611,9 @@
|
||||
},
|
||||
rethread: function(enabled) {
|
||||
var nodes, posts, thread;
|
||||
if (enabled == null) {
|
||||
enabled = true;
|
||||
}
|
||||
thread = QuoteThreading.thread;
|
||||
posts = thread.posts;
|
||||
if (QuoteThreading.enabled = enabled) {
|
||||
@ -8639,6 +8644,15 @@
|
||||
Unread.setLine(true);
|
||||
Unread.read();
|
||||
return Unread.update();
|
||||
},
|
||||
cb: {
|
||||
thread: function() {
|
||||
return QuoteThreading.rethread(QuoteThreading.checked);
|
||||
},
|
||||
click: function() {
|
||||
QuoteThreading.threadNewLink.hidden = true;
|
||||
return QuoteThreading.cb.thread();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -8513,13 +8513,9 @@
|
||||
$.extend(this.threadNewLink, {
|
||||
innerHTML: "<a href=\"javascript:;\">Thread New Posts</a>"
|
||||
});
|
||||
$.on($('input', this.controls), 'change', function() {
|
||||
return QuoteThreading.rethread(this.checked);
|
||||
});
|
||||
$.on(this.threadNewLink.firstElementChild, 'click', function() {
|
||||
QuoteThreading.threadNewLink.hidden = true;
|
||||
return QuoteThreading.rethread(true);
|
||||
});
|
||||
$.on($('input', this.controls), 'change', this.cb.thread);
|
||||
$.on(this.threadNewLink.firstElementChild, 'click', this.cb.click);
|
||||
$.on(d, '4chanXInitFinished', this.cb.thread);
|
||||
Header.menu.addEntry(this.entry = {
|
||||
el: this.controls,
|
||||
order: 98
|
||||
@ -8547,6 +8543,9 @@
|
||||
this.parent = {};
|
||||
this.children = {};
|
||||
this.inserted = {};
|
||||
$.off($('input', this.controls), 'change', this.cb.thread);
|
||||
$.off(this.threadNewLink.firstElementChild, 'click', this.cb.click);
|
||||
$.off(d, '4chanXInitFinished', this.cb.thread);
|
||||
Thread.callbacks.disconnect('Quote Threading');
|
||||
return Post.callbacks.disconnect('Quote Threading');
|
||||
},
|
||||
@ -8570,11 +8569,9 @@
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
quote = _ref[_i];
|
||||
parent = g.posts[quote];
|
||||
if (!parent || parent.isFetchedQuote || !parent.isReply || parent.ID >= this.ID) {
|
||||
continue;
|
||||
if ((parent = g.posts[quote]) && !parent.isFetchedQuote && parent.isReply && parent.ID <= this.ID) {
|
||||
_results.push(parent);
|
||||
}
|
||||
_results.push(parent);
|
||||
}
|
||||
return _results;
|
||||
}).call(this);
|
||||
@ -8594,16 +8591,24 @@
|
||||
return posts;
|
||||
},
|
||||
insert: function(post) {
|
||||
var child, children, descendants, i, next, nodes, order, parent, prev, prev2, threadContainer, x, _base, _i, _j, _k, _len, _name;
|
||||
var child, children, descendants, i, next, nodes, order, parent, prev, prev2, threadContainer, x, _base, _i, _j, _len, _name;
|
||||
if (!(QuoteThreading.enabled && (parent = QuoteThreading.parent[post.fullID]) && !QuoteThreading.inserted[post.fullID])) {
|
||||
return false;
|
||||
}
|
||||
descendants = QuoteThreading.descendants(post);
|
||||
if (!Unread.posts.has(parent.ID) && descendants.some(function(x) {
|
||||
return Unread.posts.has(x.ID);
|
||||
})) {
|
||||
QuoteThreading.threadNewLink.hidden = false;
|
||||
return false;
|
||||
if (!Unread.posts.has(parent.ID)) {
|
||||
if ((function() {
|
||||
var x, _i, _len;
|
||||
for (_i = 0, _len = descendants.length; _i < _len; _i++) {
|
||||
x = descendants[_i];
|
||||
if (Unread.posts.has(x.ID)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
})()) {
|
||||
QuoteThreading.threadNewLink.hidden = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
order = Unread.order;
|
||||
children = ((_base = QuoteThreading.children)[_name = parent.fullID] || (_base[_name] = []));
|
||||
@ -8615,16 +8620,13 @@
|
||||
nodes.push(post.nodes.threadContainer);
|
||||
}
|
||||
i = children.length;
|
||||
for (_i = children.length - 1; _i >= 0; _i += -1) {
|
||||
child = children[_i];
|
||||
if (child.ID >= post.ID) {
|
||||
i--;
|
||||
}
|
||||
while ((child = children[i]) && child.ID >= post.ID) {
|
||||
i--;
|
||||
}
|
||||
if (i !== children.length) {
|
||||
next = children[i];
|
||||
for (_j = 0, _len = descendants.length; _j < _len; _j++) {
|
||||
x = descendants[_j];
|
||||
for (_i = 0, _len = descendants.length; _i < _len; _i++) {
|
||||
x = descendants[_i];
|
||||
order.before(order[next.ID], order[x.ID]);
|
||||
}
|
||||
children.splice(i, 0, post);
|
||||
@ -8634,8 +8636,8 @@
|
||||
while ((prev2 = QuoteThreading.children[prev.fullID]) && prev2.length) {
|
||||
prev = prev2[prev2.length - 1];
|
||||
}
|
||||
for (_k = descendants.length - 1; _k >= 0; _k += -1) {
|
||||
x = descendants[_k];
|
||||
for (_j = descendants.length - 1; _j >= 0; _j += -1) {
|
||||
x = descendants[_j];
|
||||
order.after(order[prev.ID], order[x.ID]);
|
||||
}
|
||||
children.push(post);
|
||||
@ -8651,6 +8653,9 @@
|
||||
},
|
||||
rethread: function(enabled) {
|
||||
var nodes, posts, thread;
|
||||
if (enabled == null) {
|
||||
enabled = true;
|
||||
}
|
||||
thread = QuoteThreading.thread;
|
||||
posts = thread.posts;
|
||||
if (QuoteThreading.enabled = enabled) {
|
||||
@ -8681,6 +8686,15 @@
|
||||
Unread.setLine(true);
|
||||
Unread.read();
|
||||
return Unread.update();
|
||||
},
|
||||
cb: {
|
||||
thread: function() {
|
||||
return QuoteThreading.rethread(QuoteThreading.checked);
|
||||
},
|
||||
click: function() {
|
||||
QuoteThreading.threadNewLink.hidden = true;
|
||||
return QuoteThreading.cb.thread();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -9,16 +9,15 @@ QuoteThreading =
|
||||
@enabled = true
|
||||
@controls = $.el 'span',
|
||||
<%= html('<label><input id="threadingControl" type="checkbox" checked> Threading</label>') %>
|
||||
|
||||
@threadNewLink = $.el 'span',
|
||||
className: 'brackets-wrap threadnewlink'
|
||||
hidden: true
|
||||
$.extend @threadNewLink, <%= html('<a href="javascript:;">Thread New Posts</a>') %>
|
||||
|
||||
$.on $('input', @controls), 'change', ->
|
||||
QuoteThreading.rethread @checked
|
||||
$.on @threadNewLink.firstElementChild, 'click', ->
|
||||
QuoteThreading.threadNewLink.hidden = true
|
||||
QuoteThreading.rethread true
|
||||
$.on $('input', @controls), 'change', @cb.thread
|
||||
$.on @threadNewLink.firstElementChild, 'click', @cb.click
|
||||
$.on d, '4chanXInitFinished', @cb.thread
|
||||
|
||||
Header.menu.addEntry @entry =
|
||||
el: @controls
|
||||
@ -49,6 +48,10 @@ QuoteThreading =
|
||||
@children = {}
|
||||
@inserted = {}
|
||||
|
||||
$.off $('input', @controls), 'change', @cb.thread
|
||||
$.off @threadNewLink.firstElementChild, 'click', @cb.click
|
||||
$.off d, '4chanXInitFinished', @cb.thread
|
||||
|
||||
Thread.callbacks.disconnect 'Quote Threading'
|
||||
Post.callbacks.disconnect 'Quote Threading'
|
||||
|
||||
@ -60,10 +63,10 @@ QuoteThreading =
|
||||
node: ->
|
||||
return if @isFetchedQuote or @isClone or !@isReply
|
||||
{thread} = QuoteThreading
|
||||
parents = for quote in @quotes
|
||||
parent = g.posts[quote]
|
||||
continue if !parent or parent.isFetchedQuote or !parent.isReply or parent.ID >= @ID
|
||||
parent
|
||||
parents = (parent for quote in @quotes when (parent = g.posts[quote]) and
|
||||
not parent.isFetchedQuote and parent.isReply and parent.ID <= @ID
|
||||
)
|
||||
|
||||
if parents.length is 1
|
||||
QuoteThreading.parent[@fullID] = parents[0]
|
||||
|
||||
@ -80,9 +83,10 @@ QuoteThreading =
|
||||
!QuoteThreading.inserted[post.fullID]
|
||||
|
||||
descendants = QuoteThreading.descendants post
|
||||
if !Unread.posts.has(parent.ID) and descendants.some((x) -> Unread.posts.has(x.ID))
|
||||
QuoteThreading.threadNewLink.hidden = false
|
||||
return false
|
||||
if !Unread.posts.has(parent.ID)
|
||||
if (do -> return true for x in descendants when Unread.posts.has x.ID)
|
||||
QuoteThreading.threadNewLink.hidden = false
|
||||
return false
|
||||
|
||||
{order} = Unread
|
||||
children = (QuoteThreading.children[parent.fullID] or= [])
|
||||
@ -91,7 +95,7 @@ QuoteThreading =
|
||||
nodes.push post.nodes.threadContainer if post.nodes.threadContainer
|
||||
|
||||
i = children.length
|
||||
i-- for child in children by -1 when child.ID >= post.ID
|
||||
i-- while (child = children[i]) and child.ID >= post.ID
|
||||
if i isnt children.length
|
||||
next = children[i]
|
||||
order.before order[next.ID], order[x.ID] for x in descendants
|
||||
@ -114,7 +118,7 @@ QuoteThreading =
|
||||
|
||||
return true
|
||||
|
||||
rethread: (enabled) ->
|
||||
rethread: (enabled = true) ->
|
||||
{thread} = QuoteThreading
|
||||
{posts} = thread
|
||||
|
||||
@ -140,3 +144,9 @@ QuoteThreading =
|
||||
Unread.setLine true
|
||||
Unread.read()
|
||||
Unread.update()
|
||||
|
||||
cb:
|
||||
thread: -> QuoteThreading.rethread QuoteThreading.checked
|
||||
click: ->
|
||||
QuoteThreading.threadNewLink.hidden = true
|
||||
QuoteThreading.cb.thread()
|
||||
Loading…
x
Reference in New Issue
Block a user