1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-28 17:31:00 +01:00
vichan/js/inline.js

68 lines
1.5 KiB
JavaScript
Raw Normal View History

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