The version of vichan running on lainchan.org
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

155 lignes
3.5KB

  1. $(document).ready(function() {
  2. var App = {
  3. cache: {},
  4. get: function(url, cb) {
  5. var $page = App.cache[url]
  6. if ($page)
  7. return cb($page)
  8. $.get(url, function(data) {
  9. var $page = $(data)
  10. App.cache[url] = $page
  11. cb($page)
  12. })
  13. },
  14. options: {
  15. add: function(key, description, tab) {
  16. tab || (tab = 'general')
  17. var checked = App.options.get(key)
  18. var $el = $(
  19. '<div>' +
  20. '<label>' +
  21. '<input type="checkbox">' +
  22. description +
  23. '</label>' +
  24. '</div>')
  25. $el
  26. .find('input')
  27. .prop('checked', checked)
  28. .on('change', App.options.check(key))
  29. window.Options.extend_tab(tab, $el)
  30. },
  31. get: function(key) {
  32. if (localStorage[key])
  33. return JSON.parse(localStorage[key])
  34. },
  35. check: function(key) {
  36. return function(e) {
  37. var val = this.checked
  38. localStorage[key] = JSON.stringify(val)
  39. }
  40. }
  41. }
  42. }
  43. var inline = function(e) {
  44. e.preventDefault()
  45. var $root = $(this).closest('.post')
  46. var targetNum = this.textContent.slice(2)
  47. var srcOP = $root.closest('[id^=thread]').attr('id').match(/\d+/)[0]
  48. var node, targetOP
  49. var isBacklink = !!this.className
  50. if (isBacklink) {
  51. node = $root.find('> .intro')
  52. targetOP = srcOP
  53. } else {
  54. node = $(this)
  55. var to_search = inMod ? this.search : this.pathname;
  56. targetOP = to_search.match(/(\d+).html/)[1]
  57. }
  58. var link = {
  59. id: 'inline_' + targetNum,
  60. isBacklink: isBacklink,
  61. node: node
  62. }
  63. var selector = targetNum === targetOP
  64. ? '#op_' + srcOP
  65. : '#reply_' + targetNum
  66. var $clone = $root.find('#inline_' + targetNum)
  67. if ($clone.length) {
  68. $clone.remove()
  69. $(selector)
  70. .show()
  71. .next()
  72. .show()
  73. return
  74. }
  75. if (srcOP === targetOP) {
  76. if (targetNum === targetOP)
  77. link.node = link.node.next()// bypass `(OP)`
  78. var $target = $(selector)
  79. if ($target.length)
  80. return add(link, $target)
  81. }
  82. var $loading = $('<div class="inline post">loading...</div>')
  83. .attr('id', link.id)
  84. .insertAfter(link.node)
  85. App.get(this.pathname, function($page) {
  86. $loading.remove()
  87. var $target = $page.find(selector)
  88. add(link, $target)
  89. })
  90. }
  91. var add = function(link, $target) {
  92. var $clone = $target.clone(true)
  93. if (link.isBacklink && App.options.get('hidePost'))
  94. $target
  95. .hide()
  96. .next()
  97. .hide()
  98. $clone.find('.inline').remove()
  99. $clone.attr({
  100. "class": 'inline post',
  101. id: link.id,
  102. style: null// XXX remove post hover styling
  103. })
  104. $clone.insertAfter(link.node)
  105. }
  106. App.options.add('useInlining', _('Enable inlining'))
  107. App.options.add('hidePost', _('Hide inlined backlinked posts'))
  108. $('head').append(
  109. '<style>' +
  110. '.inline {' +
  111. 'border: 1px dashed black;' +
  112. 'white-space: normal;' +
  113. 'overflow: auto;' + // clearfix
  114. '}' +
  115. '</style>')
  116. // don't attach to outbound links
  117. if (App.options.get('useInlining')) {
  118. var assign_inline = function() {
  119. $('.body a[href*="'+location.pathname+'"]').not('[rel]').not('.toolong > a').add('.mentioned a')
  120. .attr('onclick', null)// XXX disable highlightReply
  121. .off('click')
  122. .click(inline)
  123. }
  124. assign_inline();
  125. $(document).on('new_post', function(e, post) {
  126. assign_inline();
  127. });
  128. }
  129. });