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() @parseQuotes()
@quotes = [@origin.quotes...] @quotes = [@origin.quotes...]
if @origin.file @files = []
fileRoots = @fileRoots() if @origin.files.length
for originFile in @origin.files
# Copy values, point to relevant elements. # Copy values, point to relevant elements.
# See comments in Post's constructor. file = {}
@file = {} for key, val of originFile
for key, val of @origin.file file[key] = val
@file[key] = val fileRoot = fileRoots[file.index]
for key, selector of g.SITE.selectors.file for key, selector of g.SITE.selectors.file
@file[key] = $ selector, @nodes.root file[key] = $ selector, fileRoot
@file.thumbLink = @file.thumb?.parentNode file.thumbLink = file.thumb?.parentNode
@file.fullImage = $ '.full-image', @file.thumbLink if @file.thumbLink file.fullImage = $ '.full-image', file.thumbLink if file.thumbLink
@file.videoControls = $ '.video-controls', @file.text 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 # Contract thumbnails in quote preview
ImageExpand.contract @ if @file.thumb and contractThumb ImageExpand.contract @ if @file.thumb and contractThumb

View File

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

View File

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