First step toward multifile support. #2171

This commit is contained in:
ccd0 2019-07-12 17:31:01 -07:00
parent a70648d8b1
commit 71187133c1
3 changed files with 36 additions and 14 deletions

View File

@ -38,19 +38,24 @@ Post.Clone = class extends Post
@parseQuotes()
@quotes = [@origin.quotes...]
if @origin.file
@files = []
fileRoots = @fileRoots() if @origin.files.length
for originFile in @origin.files
# Copy values, point to relevant elements.
# See comments in Post's constructor.
@file = {}
for key, val of @origin.file
@file[key] = val
file = {}
for key, val of originFile
file[key] = val
fileRoot = fileRoots[file.index]
for key, selector of g.SITE.selectors.file
@file[key] = $ selector, @nodes.root
@file.thumbLink = @file.thumb?.parentNode
@file.fullImage = $ '.full-image', @file.thumbLink if @file.thumbLink
@file.videoControls = $ '.video-controls', @file.text
file[key] = $ selector, fileRoot
file.thumbLink = file.thumb?.parentNode
file.fullImage = $ '.full-image', file.thumbLink if file.thumbLink
file.videoControls = $ '.video-controls', file.text
file.thumb.muted = true if file.videoThumb
@files.push file
@file.thumb.muted = true if @file.videoThumb
if @files.length
@file = @files[0]
# Contract thumbnails in quote preview
ImageExpand.contract @ if @file.thumb and contractThumb

View File

@ -49,7 +49,7 @@ class Post
@parseComment()
@parseQuotes()
@parseFile()
@parseFiles()
@isDead = false
@isHidden = false
@ -167,10 +167,26 @@ class Post
fullID = "#{match[1]}.#{match[3]}"
@quotes.push fullID unless fullID in @quotes
parseFile: ->
parseFiles: ->
@files = []
fileRoots = @fileRoots()
for fileRoot, index in fileRoots
if (file = @parseFile fileRoot)
file.index = index
@files.push file
if @files.length
@file = @files[0]
fileRoots: ->
if g.SITE.selectors.multifile
roots = $$(g.SITE.selectors.multifile, @nodes.root)
return roots if roots.length
[@nodes.root]
parseFile: (fileRoot) ->
file = {}
for key, selector of g.SITE.selectors.file
file[key] = $ selector, @nodes.root
file[key] = $ selector, fileRoot
file.thumbLink = file.thumb?.parentNode
return if not (file.text and file.link)
@ -185,7 +201,7 @@ class Post
size *= 1024 while unit-- > 0
file.sizeInBytes = size
@file = file
file
@deadMark =
# \u00A0 is nbsp

View File

@ -85,6 +85,7 @@ SW.tinyboard =
link: '.fileinfo > a'
thumb: 'a > .post-image'
thumbLink: '.file > a'
multifile: '.files > .file'
relative:
opHighlight: ' > .op'
replyPost: '.reply'