diff options
| author | James Campos <james.r.campos@gmail.com> | 2014-09-23 21:25:34 -0700 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2014-10-07 03:27:33 +0200 |
| commit | 3de119e41750c065cebffefc216e56d339bbbc1c (patch) | |
| tree | 4e4f9d2d39aed228195264f1ffe6c14efdefabd6 | |
| parent | cb92ee048303a6d9065c2e7b9dd4f9532152db34 (diff) | |
maybe support cross thread inlining
| -rw-r--r-- | js/inline.js | 60 |
1 files changed, 38 insertions, 22 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( '<style>' + @@ -9,26 +44,7 @@ ' padding: 1em;' + '}' + '</style>') -})() - -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' + $('.body a').click(inline) - $clone = $(selector).clone(true) - $clone.attr({ - className: 'inline', - id: cloneID - }) - $clone.insertAfter(this) -} +})() |
