From 3de119e41750c065cebffefc216e56d339bbbc1c Mon Sep 17 00:00:00 2001 From: James Campos Date: Tue, 23 Sep 2014 21:25:34 -0700 Subject: [PATCH] maybe support cross thread inlining --- js/inline.js | 62 ++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/js/inline.js b/js/inline.js index 1130c68b..6b373dce 100644 --- a/js/inline.js +++ b/js/inline.js @@ -1,5 +1,40 @@ ;(function() { - $('.body a').click(inline) + var inline = function(e) { + e.preventDefault() + + var postNum = this.textContent.slice(2) + + var $clone = $('#inline_' + postNum) + if ($clone.length) + return $clone.remove() + + var OP = location.pathname.match(/(\d+).html/)[1] + var selector = postNum === OP + ? '.op .body' + : '#reply_' + postNum + ' .body' + + var link = { + postNum: postNum, + node: this + } + var $target = $(selector) + if ($target.length) + add(link, $target) + else + $.get(this.pathname, function(data) { + var $target = $(data).find(selector) + add(link, $target) + }) + } + + var add = function(link, $target) { + var $clone = $target.clone(true) + $clone.attr({ + "class": 'inline', + id: 'inline_' + link.postNum + }) + $clone.insertAfter(link.node) + } $('head').append( '') + + $('.body a').click(inline) + })() - -function inline(e) { - e.preventDefault() - var postNum = parseInt(this.textContent.slice(2)) - - var cloneID = 'inline_' + postNum - var $clone = $('#' + cloneID) - if ($clone.length) - return $clone.remove() - - var OP = location.pathname.match(/(\d+).html/)[1] - var selector = postNum === OP - ? '.op .body' - : '#reply_' + postNum + ' .body' - - $clone = $(selector).clone(true) - $clone.attr({ - className: 'inline', - id: cloneID - }) - $clone.insertAfter(this) -}