summaryrefslogtreecommitdiff
path: root/js/inline.js
blob: 863aefbb47940edf2e81f1bf8fff4938f74aaf26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
;(function() {
  var inline = function(e) {
    e.preventDefault()

    var postNum = this.textContent.slice(2)

    var $clone = $('#inline_' + postNum)
    if ($clone.length)
      return $clone.remove()

    var OP = $('input[name="thread"]').val()
    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>' +
      '.inline {' +
      '  border: 1px dashed black;' +
      '  margin-left: 1em;' +
      '  padding: 1em;' +
      '}' +
    '</style>')

  $('.body a').click(inline)

})()