Post.Clone = class extends Post isClone: true 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.Clone.prefix or= 0 for node in [root, $$('[id]', root)...] node.id = Post.Clone.prefix + node.id Post.Clone.prefix++ 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: [] # XXX Edge invalidates HTMLCollections when an ancestor node is inserted into another node. # https://connect.microsoft.com/IE/feedback/details/1198967/ie11-appendchild-provoke-an-error-on-an-htmlcollection if $.engine is 'edge' Object.defineProperty @nodes, 'backlinks', configurable: true enumerable: true get: -> info.getElementsByClassName 'backlink' else @nodes.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() @quotes = [@origin.quotes...] 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 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