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