Add the context post from which a clone comes from.

This commit is contained in:
Nicolas Stepien 2012-09-11 04:24:03 +02:00
parent 60f6f6571f
commit 37f399bf48
2 changed files with 41 additions and 36 deletions

View File

@ -750,8 +750,8 @@
g.posts["" + board + "." + this] = thread.posts[this] = board.posts[this] = this; g.posts["" + board + "." + this] = thread.posts[this] = board.posts[this] = this;
} }
Post.prototype.addClone = function() { Post.prototype.addClone = function(context) {
return new Clone(this); return new Clone(this, context);
}; };
Post.prototype.rmClone = function(index) { Post.prototype.rmClone = function(index) {
@ -770,9 +770,10 @@
__extends(Clone, _super); __extends(Clone, _super);
function Clone(origin) { function Clone(origin, context) {
var file, index, info, inline, inlined, key, nodes, post, quotelink, root, val, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3, _ref4; var file, index, info, inline, inlined, key, nodes, post, quotelink, root, val, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3, _ref4;
this.origin = origin; this.origin = origin;
this.context = context;
_ref = ['ID', 'board', 'thread', 'info', 'quotes', 'isReply']; _ref = ['ID', 'board', 'thread', 'info', 'quotes', 'isReply'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
key = _ref[_i]; key = _ref[_i];
@ -1374,29 +1375,29 @@
postID: postID postID: postID
}; };
}, },
postClone: function(board, threadID, postID, root) { postClone: function(board, threadID, postID, root, context) {
var post, url; var post, url;
if (post = g.posts["" + board + "." + postID]) { if (post = g.posts["" + board + "." + postID]) {
Get.insert(post, root); Get.insert(post, root, context);
return; return;
} }
root.textContent = "Loading post No." + postID + "..."; root.textContent = "Loading post No." + postID + "...";
if (threadID) { if (threadID) {
return $.cache("/" + board + "/res/" + threadID, function() { return $.cache("/" + board + "/res/" + threadID, function() {
return Get.fetchedPost(this, board, threadID, postID, root); return Get.fetchedPost(this, board, threadID, postID, root, context);
}); });
} else if (url = Redirect.post(board, postID)) { } else if (url = Redirect.post(board, postID)) {
return $.cache(url, function() { return $.cache(url, function() {
return Get.archivedPost(this, board, postID, root); return Get.archivedPost(this, board, postID, root, context);
}); });
} }
}, },
insert: function(post, root) { insert: function(post, root, context) {
var clone, nodes; var clone, nodes;
if (!root.parentNode) { if (!root.parentNode) {
return; return;
} }
clone = post.addClone(); clone = post.addClone(context);
Main.callbackNodes(Post, [clone]); Main.callbackNodes(Post, [clone]);
nodes = clone.nodes; nodes = clone.nodes;
nodes.root.innerHTML = null; nodes.root.innerHTML = null;
@ -1404,10 +1405,10 @@
root.innerHTML = null; root.innerHTML = null;
return $.add(root, nodes.root); return $.add(root, nodes.root);
}, },
fetchedPost: function(req, board, threadID, postID, root) { fetchedPost: function(req, board, threadID, postID, root, context) {
var doc, href, link, pc, post, quote, status, thread, url, _i, _len, _ref; var doc, href, link, pc, post, quote, status, thread, url, _i, _len, _ref;
if (post = g.posts["" + board + "." + postID]) { if (post = g.posts["" + board + "." + postID]) {
Get.insert(post, root); Get.insert(post, root, context);
return; return;
} }
status = req.status; status = req.status;
@ -1452,12 +1453,12 @@
thread = g.threads["" + board + "." + threadID] || new Thread(threadID, inBoard); thread = g.threads["" + board + "." + threadID] || new Thread(threadID, inBoard);
post = new Post(pc, thread, board); post = new Post(pc, thread, board);
Main.callbackNodes(Post, [post]); Main.callbackNodes(Post, [post]);
return Get.insert(post, root); return Get.insert(post, root, context);
}, },
archivedPost: function(req, board, postID, root) { archivedPost: function(req, board, postID, root, context) {
var bq, comment, data, post, postContainer, thread, threadID; var bq, comment, data, post, postContainer, thread, threadID;
if (post = g.posts["" + board + "." + postID]) { if (post = g.posts["" + board + "." + postID]) {
Get.insert(post, root); Get.insert(post, root, context);
return; return;
} }
data = JSON.parse(req.response); data = JSON.parse(req.response);
@ -1531,7 +1532,7 @@
isArchived: true isArchived: true
}); });
Main.callbackNodes(Post, [post]); Main.callbackNodes(Post, [post]);
return Get.insert(post, root); return Get.insert(post, root, context);
} }
}; };
@ -1645,14 +1646,15 @@
return this.classList.toggle('inlined'); return this.classList.toggle('inlined');
}, },
add: function(quotelink, board, threadID, postID) { add: function(quotelink, board, threadID, postID) {
var inline, isBacklink, post, root; var context, inline, isBacklink, post, root;
inline = $.el('div', { inline = $.el('div', {
id: "i" + postID, id: "i" + postID,
className: 'inline' className: 'inline'
}); });
root = (isBacklink = $.hasClass(quotelink, 'backlink')) ? quotelink.parentNode.parentNode : $.x('ancestor-or-self::*[parent::blockquote][1]', quotelink); root = (isBacklink = $.hasClass(quotelink, 'backlink')) ? quotelink.parentNode.parentNode : $.x('ancestor-or-self::*[parent::blockquote][1]', quotelink);
context = Get.postFromRoot($.x('ancestor::div[contains(@class,"postContainer")][1]', this));
$.after(root, inline); $.after(root, inline);
Get.postClone(board, threadID, postID, inline); Get.postClone(board, threadID, postID, inline, context);
if (!(board === g.BOARD.ID && $.x("ancestor::div[@id='t" + threadID + "']", quotelink))) { if (!(board === g.BOARD.ID && $.x("ancestor::div[@id='t" + threadID + "']", quotelink))) {
return; return;
} }
@ -1721,7 +1723,7 @@
} }
}, },
mouseover: function(e) { mouseover: function(e) {
var board, clone, origin, post, postID, posts, qp, quote, quoterID, threadID, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2; var board, clone, context, origin, post, postID, posts, qp, quote, quoterID, threadID, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
if ($.hasClass(this, 'inlined')) { if ($.hasClass(this, 'inlined')) {
return; return;
} }
@ -1734,8 +1736,9 @@
className: 'reply dialog' className: 'reply dialog'
}); });
UI.hover(e); UI.hover(e);
context = Get.postFromRoot($.x('ancestor::div[contains(@class,"postContainer")][1]', this));
$.add(d.body, qp); $.add(d.body, qp);
Get.postClone(board, threadID, postID, qp); Get.postClone(board, threadID, postID, qp, context);
$.on(this, 'mousemove', UI.hover); $.on(this, 'mousemove', UI.hover);
$.on(this, 'mouseout click', QuotePreview.mouseout); $.on(this, 'mouseout click', QuotePreview.mouseout);
if (!(origin = g.posts["" + board + "." + postID])) { if (!(origin = g.posts["" + board + "." + postID])) {

View File

@ -600,8 +600,8 @@ class Post
@clones = [] @clones = []
g.posts["#{board}.#{@}"] = thread.posts[@] = board.posts[@] = @ g.posts["#{board}.#{@}"] = thread.posts[@] = board.posts[@] = @
addClone: -> addClone: (context) ->
new Clone @ new Clone @, context
rmClone: (index) -> rmClone: (index) ->
@clones.splice index, 1 @clones.splice index, 1
for i in [index...@clones.length] for i in [index...@clones.length]
@ -609,7 +609,7 @@ class Post
return return
class Clone extends Post class Clone extends Post
constructor: (@origin) -> constructor: (@origin, @context) ->
for key in ['ID', 'board', 'thread', 'info', 'quotes', 'isReply'] for key in ['ID', 'board', 'thread', 'info', 'quotes', 'isReply']
# Copy or point to the origin's key value. # Copy or point to the origin's key value.
@[key] = origin[key] @[key] = origin[key]
@ -1192,22 +1192,22 @@ Get =
threadID: threadID threadID: threadID
postID: postID postID: postID
} }
postClone: (board, threadID, postID, root) -> postClone: (board, threadID, postID, root, context) ->
if post = g.posts["#{board}.#{postID}"] if post = g.posts["#{board}.#{postID}"]
Get.insert post, root Get.insert post, root, context
return return
root.textContent = "Loading post No.#{postID}..." root.textContent = "Loading post No.#{postID}..."
if threadID if threadID
$.cache "/#{board}/res/#{threadID}", -> $.cache "/#{board}/res/#{threadID}", ->
Get.fetchedPost @, board, threadID, postID, root Get.fetchedPost @, board, threadID, postID, root, context
else if url = Redirect.post board, postID else if url = Redirect.post board, postID
$.cache url, -> $.cache url, ->
Get.archivedPost @, board, postID, root Get.archivedPost @, board, postID, root, context
insert: (post, root) -> insert: (post, root, context) ->
# Stop here if the container has been removed while loading. # Stop here if the container has been removed while loading.
return unless root.parentNode return unless root.parentNode
clone = post.addClone() clone = post.addClone context
Main.callbackNodes Post, [clone] Main.callbackNodes Post, [clone]
# Get rid of the side arrows. # Get rid of the side arrows.
@ -1217,11 +1217,11 @@ Get =
root.innerHTML = null root.innerHTML = null
$.add root, nodes.root $.add root, nodes.root
fetchedPost: (req, board, threadID, postID, root) -> fetchedPost: (req, board, threadID, postID, root, context) ->
# In case of multiple callbacks for the same request, # In case of multiple callbacks for the same request,
# don't parse the same original post more than once. # don't parse the same original post more than once.
if post = g.posts["#{board}.#{postID}"] if post = g.posts["#{board}.#{postID}"]
Get.insert post, root Get.insert post, root, context
return return
{status} = req {status} = req
if status isnt 200 if status isnt 200
@ -1266,12 +1266,12 @@ Get =
new Thread threadID, inBoard new Thread threadID, inBoard
post = new Post pc, thread, board post = new Post pc, thread, board
Main.callbackNodes Post, [post] Main.callbackNodes Post, [post]
Get.insert post, root Get.insert post, root, context
archivedPost: (req, board, postID, root) -> archivedPost: (req, board, postID, root, context) ->
# In case of multiple callbacks for the same request, # In case of multiple callbacks for the same request,
# don't parse the same original post more than once. # don't parse the same original post more than once.
if post = g.posts["#{board}.#{postID}"] if post = g.posts["#{board}.#{postID}"]
Get.insert post, root Get.insert post, root, context
return return
data = JSON.parse req.response data = JSON.parse req.response
if data.error if data.error
@ -1356,7 +1356,7 @@ Get =
post = new Post postContainer, thread, board, post = new Post postContainer, thread, board,
isArchived: true isArchived: true
Main.callbackNodes Post, [post] Main.callbackNodes Post, [post]
Get.insert post, root Get.insert post, root, context
Quotify = Quotify =
init: -> init: ->
@ -1467,8 +1467,9 @@ QuoteInline =
quotelink.parentNode.parentNode quotelink.parentNode.parentNode
else else
$.x 'ancestor-or-self::*[parent::blockquote][1]', quotelink $.x 'ancestor-or-self::*[parent::blockquote][1]', quotelink
context = Get.postFromRoot $.x 'ancestor::div[contains(@class,"postContainer")][1]', @
$.after root, inline $.after root, inline
Get.postClone board, threadID, postID, inline Get.postClone board, threadID, postID, inline, context
return unless board is g.BOARD.ID and $.x "ancestor::div[@id='t#{threadID}']", quotelink return unless board is g.BOARD.ID and $.x "ancestor::div[@id='t#{threadID}']", quotelink
post = g.posts["#{board}.#{postID}"] post = g.posts["#{board}.#{postID}"]
@ -1559,8 +1560,9 @@ QuotePreview =
id: 'qp' id: 'qp'
className: 'reply dialog' className: 'reply dialog'
UI.hover e UI.hover e
context = Get.postFromRoot $.x 'ancestor::div[contains(@class,"postContainer")][1]', @
$.add d.body, qp $.add d.body, qp
Get.postClone board, threadID, postID, qp Get.postClone board, threadID, postID, qp, context
$.on @, 'mousemove', UI.hover $.on @, 'mousemove', UI.hover
$.on @, 'mouseout click', QuotePreview.mouseout $.on @, 'mouseout click', QuotePreview.mouseout