Expand OP comments when expanding a thread. Close #764.

This commit is contained in:
Nicolas Stepien 2013-02-17 18:47:41 +01:00
parent 67c66a2d4c
commit 149ea4ccc2
2 changed files with 61 additions and 25 deletions

View File

@ -3912,21 +3912,42 @@
node: function() { node: function() {
var a; var a;
if (a = $('.abbr > a', this.nodes.comment)) { if (a = $('.abbr > a', this.nodes.comment)) {
return $.on(a, 'click', ExpandComment.expand); return $.on(a, 'click', ExpandComment.cb);
} }
}, },
expand: function(e) { cb: function(e) {
var a, post; var post;
e.preventDefault(); e.preventDefault();
post = Get.postFromNode(this); post = Get.postFromNode(this);
this.textContent = "Post No." + post + " Loading..."; return ExpandComment.expand(post);
a = this; },
return $.cache("//api.4chan.org" + this.pathname + ".json", function() { expand: function(post) {
var a;
if (post.nodes.longComment) {
$.replace(post.nodes.shortComment, post.nodes.longComment);
post.nodes.comment = post.nodes.longComment;
return;
}
if (!(a = $('.abbr > a', post.nodes.comment))) {
return;
}
a.textContent = "Post No." + post + " Loading...";
return $.cache("//api.4chan.org" + a.pathname + ".json", function() {
return ExpandComment.parse(this, a, post); return ExpandComment.parse(this, a, post);
}); });
}, },
contract: function(post) {
var a;
if (!post.nodes.shortComment) {
return;
}
a = a = $('.abbr > a', post.nodes.shortComment);
a.textContent = 'here';
$.replace(post.nodes.longComment, post.nodes.shortComment);
return post.nodes.comment = post.nodes.shortComment;
},
parse: function(req, a, post) { parse: function(req, a, post) {
var comment, href, postObj, posts, prev, quote, spoilerRange, _i, _j, _len, _len1, _ref; var clone, href, postObj, posts, quote, spoilerRange, _i, _j, _len, _len1, _ref;
if (req.status !== 200) { if (req.status !== 200) {
a.textContent = "Error " + req.statusText + " (" + req.status + ")"; a.textContent = "Error " + req.statusText + " (" + req.status + ")";
return; return;
@ -3945,9 +3966,9 @@
a.textContent = "Post No." + post + " not found."; a.textContent = "Post No." + post + " not found.";
return; return;
} }
comment = post.nodes.comment; clone = post.nodes.comment.cloneNode(false);
comment.innerHTML = postObj.com; clone.innerHTML = postObj.com;
_ref = $$('.quotelink', comment); _ref = $$('.quotelink', clone);
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
quote = _ref[_j]; quote = _ref[_j];
href = quote.getAttribute('href'); href = quote.getAttribute('href');
@ -3973,9 +3994,9 @@
if (Conf['Mark Cross-thread Quotes']) { if (Conf['Mark Cross-thread Quotes']) {
QuoteCT.node.call(post); QuoteCT.node.call(post);
} }
prev = comment.previousSibling; post.nodes.shortComment = post.nodes.comment;
$.rm(comment); $.replace(post.nodes.comment, clone);
return $.after(prev, comment); return post.nodes.comment = post.nodes.longComment = clone;
} }
}; };
@ -4020,12 +4041,14 @@
$.cache(url, function() { $.cache(url, function() {
return ExpandThread.parse(this, thread, a); return ExpandThread.parse(this, thread, a);
}); });
ExpandComment.expand(thread.posts[thread]);
break; break;
case '×': case '×':
a.textContent = text.replace('× Loading...', '+'); a.textContent = text.replace('× Loading...', '+');
break; break;
case '-': case '-':
a.textContent = text.replace('-', '+'); a.textContent = text.replace('-', '+');
ExpandComment.contract(thread.posts[thread]);
num = (function() { num = (function() {
switch (g.BOARD) { switch (g.BOARD) {
case 'b': case 'b':

View File

@ -2428,13 +2428,25 @@ ExpandComment =
cb: @node cb: @node
node: -> node: ->
if a = $ '.abbr > a', @nodes.comment if a = $ '.abbr > a', @nodes.comment
$.on a, 'click', ExpandComment.expand $.on a, 'click', ExpandComment.cb
expand: (e) -> cb: (e) ->
e.preventDefault() e.preventDefault()
post = Get.postFromNode @ post = Get.postFromNode @
@textContent = "Post No.#{post} Loading..." ExpandComment.expand post
a = @ expand: (post) ->
$.cache "//api.4chan.org#{@pathname}.json", -> ExpandComment.parse @, a, post if post.nodes.longComment
$.replace post.nodes.shortComment, post.nodes.longComment
post.nodes.comment = post.nodes.longComment
return
return unless a = $ '.abbr > a', post.nodes.comment
a.textContent = "Post No.#{post} Loading..."
$.cache "//api.4chan.org#{a.pathname}.json", -> ExpandComment.parse @, a, post
contract: (post) ->
return unless post.nodes.shortComment
a = a = $ '.abbr > a', post.nodes.shortComment
a.textContent = 'here'
$.replace post.nodes.longComment, post.nodes.shortComment
post.nodes.comment = post.nodes.shortComment
parse: (req, a, post) -> parse: (req, a, post) ->
if req.status isnt 200 if req.status isnt 200
a.textContent = "Error #{req.statusText} (#{req.status})" a.textContent = "Error #{req.statusText} (#{req.status})"
@ -2450,9 +2462,9 @@ ExpandComment =
a.textContent = "Post No.#{post} not found." a.textContent = "Post No.#{post} not found."
return return
{comment} = post.nodes clone = post.nodes.comment.cloneNode false
comment.innerHTML = postObj.com clone.innerHTML = postObj.com
for quote in $$ '.quotelink', comment for quote in $$ '.quotelink', clone
href = quote.getAttribute 'href' href = quote.getAttribute 'href'
continue if href[0] is '/' # Cross-board quote, or board link continue if href[0] is '/' # Cross-board quote, or board link
quote.href = "/#{post.board}/res/#{href}" # Fix pathnames quote.href = "/#{post.board}/res/#{href}" # Fix pathnames
@ -2470,10 +2482,9 @@ ExpandComment =
QuoteCT.node.call post QuoteCT.node.call post
# XXX g code # XXX g code
# XXX sci math # XXX sci math
# Fix linkifiers: post.nodes.shortComment = post.nodes.comment
prev = comment.previousSibling $.replace post.nodes.comment, clone
$.rm comment post.nodes.comment = post.nodes.longComment = clone
$.after prev, comment
ExpandThread = ExpandThread =
init: -> init: ->
@ -2506,12 +2517,14 @@ ExpandThread =
when '+' when '+'
a.textContent = text.replace '+', '× Loading...' a.textContent = text.replace '+', '× Loading...'
$.cache url, -> ExpandThread.parse @, thread, a $.cache url, -> ExpandThread.parse @, thread, a
ExpandComment.expand thread.posts[thread]
when '×' when '×'
a.textContent = text.replace '× Loading...', '+' a.textContent = text.replace '× Loading...', '+'
when '-' when '-'
a.textContent = text.replace '-', '+' a.textContent = text.replace '-', '+'
ExpandComment.contract thread.posts[thread]
#goddamit moot #goddamit moot
num = switch g.BOARD num = switch g.BOARD
# XXX boards config # XXX boards config