4chan-x/src/General/lib/clone.class
ccd0 6ad0064f41 Suppress post thumbnails from loading until they are actually inserted into the index.
Hopefully a temporary way of doing this until we get filtering working on JSON
so we don't have to build the posts at all.
2015-03-28 18:27:09 -07:00

90 lines
2.8 KiB
Plaintext
Executable File

class Clone extends Post
constructor: (@origin, @context, contractThumb) ->
for key in ['ID', 'fullID', 'board', 'thread', 'info', 'quotes', 'isReply']
# Copy or point to the origin's key value.
@[key] = @origin[key]
{nodes} = @origin
root = if contractThumb
@cloneWithoutVideo nodes.root
else
nodes.root.cloneNode true
post = $ '.post', root
info = $ '.postInfo', post
@nodes =
root: root
post: post
info: info
nameBlock: $ '.nameBlock', info
quote: $ '.postNum > a:nth-of-type(2)', info
comment: $ '.postMessage', post
quotelinks: []
backlinks: info.getElementsByClassName 'backlink'
# Remove inlined posts inside of this post.
for inline in $$ '.inline', post
$.rm inline
for inlined in $$ '.inlined', post
$.rmClass inlined, 'inlined'
root.hidden = false # post hiding
$.rmClass root, 'forwarded' # quote inlining
$.rmClass post, 'highlight' # keybind navigation, ID highlighting
if nodes.subject
@nodes.subject = $ '.subject', info
if nodes.name
@nodes.name = $ '.name', info
if nodes.email
@nodes.email = $ '.useremail', info
if nodes.tripcode
@nodes.tripcode = $ '.postertrip', info
if nodes.uniqueID
@nodes.uniqueID = $ '.posteruid', info
if nodes.capcode
@nodes.capcode = $ '.capcode.hand', info
if nodes.flag
@nodes.flag = $ '.flag, .countryFlag', info
if nodes.date
@nodes.date = $ '.dateTime', info
@parseQuotes()
if @origin.file
# Copy values, point to relevant elements.
# See comments in Post's constructor.
@file = {}
for key, val of @origin.file
@file[key] = val
file = $ '.file', post
@file.text = file.firstElementChild
@file.link = $ '.fileText > a, .fileText-original', file
@file.thumb = $ '.fileThumb > [data-md5]', file
@file.fullImage = $ '.full-image', file
@file.videoControls = $ '.video-controls', @file.text
@file.thumb.muted = true if @file.videoThumb
if @file.thumb?.dataset.src
@file.thumb.src = @file.thumb.dataset.src
# XXX https://bugzilla.mozilla.org/show_bug.cgi?id=1021289
@file.thumb.removeAttribute 'data-src'
# Contract thumbnails in quote preview
ImageExpand.contract @ if @file.thumb and contractThumb
@isDead = true if @origin.isDead
@isClone = true
root.dataset.clone = @origin.clones.push(@) - 1
cloneWithoutVideo: (node) ->
if node.tagName is 'VIDEO' and !node.dataset.md5 # (exception for WebM thumbnails)
[]
else if node.nodeType is Node.ELEMENT_NODE and $ 'video', node
clone = node.cloneNode false
$.add clone, @cloneWithoutVideo child for child in node.childNodes
clone
else
node.cloneNode true