leftypol_vichan/js/inline.js

73 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-09-24 02:52:06 +00:00
;(function() {
2014-09-24 19:49:18 +00:00
var cache = {}
2014-09-24 04:25:34 +00:00
var inline = function(e) {
e.preventDefault()
2014-09-25 17:11:33 +00:00
var $root = $(this).closest('.post')
2014-09-24 04:25:34 +00:00
var postNum = this.textContent.slice(2)
2014-09-25 17:11:33 +00:00
var $clone = $root.find('#inline_' + postNum)
2014-09-24 04:25:34 +00:00
if ($clone.length)
return $clone.remove()
2014-09-24 19:17:30 +00:00
var postOP = this.pathname.match(/(\d+).html/)[1]
var selector = postNum === postOP
2014-09-24 04:25:34 +00:00
? '.op .body'
: '#reply_' + postNum + ' .body'
2014-09-25 17:11:33 +00:00
var node = this.className
2014-10-03 16:17:19 +00:00
// XXX post hover element is added to the quoting post
? $root.find('> .body, > .inline').first()
2014-09-25 17:11:33 +00:00
: this.nextSibling
2014-09-24 04:25:34 +00:00
var link = {
2014-09-25 17:11:33 +00:00
node: node,
postNum: postNum
2014-09-24 04:25:34 +00:00
}
2014-09-24 19:17:30 +00:00
var OP = $('input[name="thread"]').val()
if (OP === postOP) {
2014-10-03 16:17:19 +00:00
// XXX post hover adds fetched threads to the DOM
2014-09-24 19:37:25 +00:00
selector = '#thread_' + OP + ' ' + selector
2014-09-24 19:17:30 +00:00
var $target = $(selector)
2014-09-24 19:49:18 +00:00
return add(link, $target)
}
var url = this.pathname
var data = cache[url]
if (data) {
var $target = $(data).find(selector)
return add(link, $target)
2014-09-24 19:17:30 +00:00
}
2014-09-24 19:49:18 +00:00
$.get(url, function(data) {
cache[url] = data
var $target = $(data).find(selector)
add(link, $target)
})
2014-09-24 04:25:34 +00:00
}
var add = function(link, $target) {
var $clone = $target.clone(true)
$clone.attr({
"class": 'inline',
id: 'inline_' + link.postNum
})
2014-09-25 17:11:33 +00:00
$clone.insertBefore(link.node)
2014-09-24 04:25:34 +00:00
}
2014-09-24 02:52:06 +00:00
$('head').append(
'<style>' +
'.inline {' +
' border: 1px dashed black;' +
' margin-left: 1em;' +
' padding: 1em;' +
'}' +
'</style>')
2014-09-25 17:11:33 +00:00
$('.body a, .mentioned a')
2014-10-03 16:17:19 +00:00
.attr('onclick', null)// XXX disable highlightReply
2014-09-25 16:58:44 +00:00
.click(inline)
2014-09-24 04:25:34 +00:00
})()