QuoteBacklink = # Backlinks appending need to work for: # - previous, same, and following posts. # - existing and yet-to-exist posts. # - newly fetched posts. # - in copies. # XXX what about order for fetched posts? # # First callback creates backlinks and add them to relevant containers. # Second callback adds relevant containers into posts. # This is is so that fetched posts can get their backlinks, # and that as much backlinks are appended in the background as possible. init: -> return if g.VIEW is 'catalog' or !Conf['Quote Backlinks'] format = Conf['backlink'].replace /%id/g, "' + id + '" @funk = Function 'id', "return '#{format}'" @containers = {} Post.callbacks.push name: 'Quote Backlinking Part 1' cb: @firstNode Post.callbacks.push name: 'Quote Backlinking Part 2' cb: @secondNode firstNode: -> return if @isClone or !@quotes.length a = $.el 'a', href: "/#{@board}/res/#{@thread}#p#{@}" className: if @isHidden then 'filtered backlink' else 'backlink' textContent: (QuoteBacklink.funk @ID) + (if Conf['Mark Quotes of You'] and @info.yours then '\u00A0(You)' else '') for quote in @quotes containers = [QuoteBacklink.getContainer quote] if (post = g.posts[quote]) and post.nodes.backlinkContainer # Don't add OP clones when OP Backlinks is disabled, # as the clones won't have the backlink containers. $.addClass post.nodes.post, 'quoted' for clone in post.clones containers.push clone.nodes.backlinkContainer for container in containers nodes = [$.tn(' '), link = a.cloneNode true] if Conf['Quote Previewing'] $.on link, 'mouseover', QuotePreview.mouseover if Conf['Quote Inlining'] $.on link, 'click', QuoteInline.toggle nodes.push.apply nodes, QuoteInline.qiQuote link, $.hasClass link, 'filtered' if Conf['Quote Hash Navigation'] $.add container, nodes return secondNode: -> if @isClone and (@origin.isReply or Conf['OP Backlinks']) @nodes.backlinkContainer = $ '.container', @nodes.info return # Don't backlink the OP. return unless @isReply or Conf['OP Backlinks'] container = QuoteBacklink.getContainer @fullID @nodes.backlinkContainer = container $.add @nodes.info, container if container.children.length > 0 $.addClass @nodes.post, 'quoted' getContainer: (id) -> @containers[id] or= $.el 'span', className: 'container'