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;
}
Post.prototype.addClone = function() {
return new Clone(this);
Post.prototype.addClone = function(context) {
return new Clone(this, context);
};
Post.prototype.rmClone = function(index) {
@ -770,9 +770,10 @@
__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;
this.origin = origin;
this.context = context;
_ref = ['ID', 'board', 'thread', 'info', 'quotes', 'isReply'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
key = _ref[_i];
@ -1374,29 +1375,29 @@
postID: postID
};
},
postClone: function(board, threadID, postID, root) {
postClone: function(board, threadID, postID, root, context) {
var post, url;
if (post = g.posts["" + board + "." + postID]) {
Get.insert(post, root);
Get.insert(post, root, context);
return;
}
root.textContent = "Loading post No." + postID + "...";
if (threadID) {
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)) {
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;
if (!root.parentNode) {
return;
}
clone = post.addClone();
clone = post.addClone(context);
Main.callbackNodes(Post, [clone]);
nodes = clone.nodes;
nodes.root.innerHTML = null;
@ -1404,10 +1405,10 @@
root.innerHTML = null;
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;
if (post = g.posts["" + board + "." + postID]) {
Get.insert(post, root);
Get.insert(post, root, context);
return;
}
status = req.status;
@ -1452,12 +1453,12 @@
thread = g.threads["" + board + "." + threadID] || new Thread(threadID, inBoard);
post = new Post(pc, thread, board);
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;
if (post = g.posts["" + board + "." + postID]) {
Get.insert(post, root);
Get.insert(post, root, context);
return;
}
data = JSON.parse(req.response);
@ -1531,7 +1532,7 @@
isArchived: true
});
Main.callbackNodes(Post, [post]);
return Get.insert(post, root);
return Get.insert(post, root, context);
}
};
@ -1645,14 +1646,15 @@
return this.classList.toggle('inlined');
},
add: function(quotelink, board, threadID, postID) {
var inline, isBacklink, post, root;
var context, inline, isBacklink, post, root;
inline = $.el('div', {
id: "i" + postID,
className: 'inline'
});
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);
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))) {
return;
}
@ -1721,7 +1723,7 @@
}
},
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')) {
return;
}
@ -1734,8 +1736,9 @@
className: 'reply dialog'
});
UI.hover(e);
context = Get.postFromRoot($.x('ancestor::div[contains(@class,"postContainer")][1]', this));
$.add(d.body, qp);
Get.postClone(board, threadID, postID, qp);
Get.postClone(board, threadID, postID, qp, context);
$.on(this, 'mousemove', UI.hover);
$.on(this, 'mouseout click', QuotePreview.mouseout);
if (!(origin = g.posts["" + board + "." + postID])) {

View File

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