reorganize Build.post
This commit is contained in:
parent
dac0a18558
commit
79ef398b32
@ -1,6 +1,5 @@
|
||||
Build =
|
||||
h_staticPath: '//s.4cdn.org/image/'
|
||||
h_gifIcon: if window.devicePixelRatio >= 2 then '@2x.gif' else '.gif'
|
||||
initPixelRatio: window.devicePixelRatio
|
||||
spoilerRange: {}
|
||||
h_escape: (text) ->
|
||||
(text+'').replace /[&"'<>]/g, (c) ->
|
||||
@ -80,55 +79,33 @@ Build =
|
||||
postID, threadID, boardID
|
||||
name, capcode, tripcode, uniqueID, email, subject, flagCode, flagName, date, dateUTC
|
||||
isSticky, isClosed
|
||||
h_comment
|
||||
file
|
||||
} = o
|
||||
name or= ''
|
||||
subject or= ''
|
||||
h_comment = o.h_comment
|
||||
isOP = postID is threadID
|
||||
{h_staticPath, h_gifIcon} = Build
|
||||
|
||||
if isOP
|
||||
h_sideArrows = ''
|
||||
if Build.initPixelRatio >= 2
|
||||
h_retina = '@2x'
|
||||
else
|
||||
h_sideArrows = "<div class='sideArrows' id='sa#{+postID}'>>></div>"
|
||||
h_retina = ''
|
||||
|
||||
if isOP or boardID is 'f'
|
||||
h_subject = "<span class='subject'>#{E subject}</span> "
|
||||
else
|
||||
h_subject = ''
|
||||
|
||||
h_postClass = "post #{if isOP then 'op' else 'reply'}#{if capcode is 'admin_highlight' then ' highlightPost' else ''}"
|
||||
|
||||
if tripcode
|
||||
h_tripcode = " <span class='postertrip'>#{E tripcode}</span>"
|
||||
else
|
||||
h_tripcode = ''
|
||||
|
||||
if email
|
||||
emailProcessed = encodeURIComponent(email).replace(/%40/g, '@')
|
||||
h_emailStart = "<a href='mailto:#{E emailProcessed}' class='useremail'>"
|
||||
h_emailEnd = '</a>'
|
||||
else
|
||||
h_emailStart = ''
|
||||
h_emailEnd = ''
|
||||
|
||||
unless isOP and boardID is 'f'
|
||||
h_emailEnd += ' '
|
||||
### Name Block ###
|
||||
|
||||
switch capcode
|
||||
when 'admin', 'admin_highlight'
|
||||
h_capcodeClass = ' capcodeAdmin'
|
||||
h_capcodeStart = ' <strong class="capcode hand id_admin" title="Highlight posts by the Administrator">## Admin</strong>'
|
||||
h_capcodeIcon = "<img src='#{h_staticPath}adminicon#{h_gifIcon}' alt='Admin Icon' title='This user is the 4chan Administrator.' class='identityIcon retina'>"
|
||||
h_capcodeIcon = "<img src='//s.4cdn.org/image/adminicon#{h_retina}.gif' alt='Admin Icon' title='This user is the 4chan Administrator.' class='identityIcon retina'>"
|
||||
when 'mod'
|
||||
h_capcodeClass = ' capcodeMod'
|
||||
h_capcodeStart = ' <strong class="capcode hand id_mod" title="Highlight posts by Moderators">## Mod</strong>'
|
||||
h_capcodeIcon = "<img src='#{h_staticPath}modicon#{h_gifIcon}' alt='Mod Icon' title='This user is a 4chan Moderator.' class='identityIcon retina'>"
|
||||
h_capcodeIcon = "<img src='//s.4cdn.org/image/modicon#{h_retina}.gif' alt='Mod Icon' title='This user is a 4chan Moderator.' class='identityIcon retina'>"
|
||||
when 'developer'
|
||||
h_capcodeClass = ' capcodeDeveloper'
|
||||
h_capcodeStart = ' <strong class="capcode hand id_developer" title="Highlight posts by Developers">## Developer</strong>'
|
||||
h_capcodeIcon = "<img src='#{h_staticPath}developericon#{h_gifIcon}' alt='Developer Icon' title='This user is a 4chan Developer.' class='identityIcon retina'>"
|
||||
h_capcodeIcon = "<img src='//s.4cdn.org/image/developericon#{h_retina}.gif' alt='Developer Icon' title='This user is a 4chan Developer.' class='identityIcon retina'>"
|
||||
else
|
||||
h_capcodeClass = ''
|
||||
h_capcodeStart = ''
|
||||
@ -139,6 +116,20 @@ Build =
|
||||
else
|
||||
h_nameClass = ''
|
||||
|
||||
if tripcode
|
||||
h_tripcode = " <span class='postertrip'>#{E tripcode}</span>"
|
||||
else
|
||||
h_tripcode = ''
|
||||
|
||||
h_emailCont = "<span class='name#{h_nameClass}'>#{E name}</span>#{h_tripcode}#{h_capcodeStart}"
|
||||
if email
|
||||
emailProcessed = encodeURIComponent(email).replace /%40/g, '@'
|
||||
h_email = "<a href='mailto:#{E emailProcessed}' class='useremail'>#{h_emailCont}</a>"
|
||||
else
|
||||
h_email = h_emailCont
|
||||
unless isOP and boardID is 'f'
|
||||
h_email += ' '
|
||||
|
||||
if !capcode and uniqueID
|
||||
h_userID = " <span class='posteruid id_#{E uniqueID}'>(ID: <span class='hand' title='Highlight posts by this ID'>#{E uniqueID}</span>)</span>"
|
||||
else
|
||||
@ -146,59 +137,28 @@ Build =
|
||||
|
||||
unless flagCode
|
||||
h_flag = ''
|
||||
else if boardID is 'pol'
|
||||
h_flag = "<img src='#{h_staticPath}country/troll/#{E flagCode.toLowerCase()}.gif' alt='#{E flagCode}' title='#{E flagName}' class='countryFlag'>"
|
||||
else
|
||||
h_flag = "<span title='#{E flagName}' class='flag flag-#{E flagCode.toLowerCase()}'></span>"
|
||||
|
||||
if file?.isDeleted
|
||||
h_file = "<div class='file' id='f#{+postID}'><span class='fileThumb'>"
|
||||
h_file += "<img src='#{h_staticPath}filedeleted-res#{h_gifIcon}' alt='File deleted.' class='fileDeletedRes retina'>"
|
||||
h_file += '</span></div>'
|
||||
else if file
|
||||
fileSize = $.bytesToString file.size
|
||||
fileThumb = file.turl
|
||||
if file.isSpoiler
|
||||
unless isArchived
|
||||
fileThumb = "#{h_staticPath}spoiler"
|
||||
if spoilerRange = Build.spoilerRange[boardID]
|
||||
# Randomize the spoiler image.
|
||||
fileThumb += "-#{boardID}" + Math.floor 1 + spoilerRange * Math.random()
|
||||
fileThumb += '.png'
|
||||
file.twidth = file.theight = 100
|
||||
shortFilename = 'Spoiler Image'
|
||||
flagCodeLC = flagCode.toLowerCase()
|
||||
if boardID is 'pol'
|
||||
h_flag = "<img src='//s.4cdn.org/image/country/troll/#{E flagCodeLC}.gif' alt='#{E flagCode}' title='#{E flagName}' class='countryFlag'>"
|
||||
else
|
||||
shortFilename = Build.shortFilename file.name, !isOP
|
||||
h_flag = "<span title='#{E flagName}' class='flag flag-#{E flagCodeLC}'></span>"
|
||||
|
||||
if file.url[-4..] is '.pdf'
|
||||
h_fileDims = 'PDF'
|
||||
else
|
||||
h_fileDims = "#{+file.width}x#{+file.height}"
|
||||
h_nameBlock = "<span class='nameBlock#{h_capcodeClass}'>"
|
||||
h_nameBlock += "#{h_email}#{h_capcodeIcon}#{h_userID}#{h_flag}"
|
||||
h_nameBlock += '</span> '
|
||||
|
||||
if boardID is 'f'
|
||||
h_imgSrc = ''
|
||||
h_fileInfo = "<div class='fileInfo'><span class='fileText' id='fT#{+postID}'>"
|
||||
h_fileInfo += "File: <a data-width='#{+file.width}' data-height='#{+file.height}' href='#{E file.url}' target='_blank'>#{E file.name}</a>-(#{E fileSize}, #{h_fileDims}, #{E file.tag})"
|
||||
h_fileInfo += '</span></div>'
|
||||
else
|
||||
h_imgSrc = "<a class='fileThumb#{if file.isSpoiler then ' imgspoiler' else ''}' href='#{E file.url}' target='_blank'>"
|
||||
h_imgSrc += "<img src='#{E fileThumb}' alt='#{E fileSize}' data-md5='#{E file.MD5}' style='height: #{+file.theight}px; width: #{+file.twidth}px;'>"
|
||||
h_imgSrc += '</a>'
|
||||
### Post Info ###
|
||||
|
||||
h_fileTitle1 = ''
|
||||
h_fileTitle2 = ''
|
||||
if file.isSpoiler
|
||||
h_fileTitle1 = " title='#{E file.name}'"
|
||||
else if file.name isnt shortFilename
|
||||
h_fileTitle2 = " title='#{E file.name}'"
|
||||
|
||||
h_fileInfo = "<div class='fileText' id='fT#{+postID}' #{h_fileTitle1}>"
|
||||
h_fileInfo += "File: <a #{h_fileTitle2} href='#{E file.url}' target='_blank'>#{E shortFilename}</a> (#{E fileSize}, #{h_fileDims})"
|
||||
h_fileInfo += '</div>'
|
||||
|
||||
h_file = "<div class='file' id='f#{+postID}'>#{h_fileInfo}#{h_imgSrc}</div>"
|
||||
if isOP or boardID is 'f'
|
||||
h_subject = "<span class='subject'>#{E subject}</span> "
|
||||
else
|
||||
h_file = ''
|
||||
h_subject = ''
|
||||
|
||||
if isOP and boardID is 'f'
|
||||
h_desktop2 = ''
|
||||
else
|
||||
h_desktop2 = ' desktop'
|
||||
|
||||
postLink = Build.postURL boardID, threadID, postID
|
||||
quoteLink = if Build.sameThread boardID, threadID
|
||||
@ -206,34 +166,118 @@ Build =
|
||||
else
|
||||
"/#{boardID}/thread/#{threadID}\#q#{postID}"
|
||||
|
||||
if isSticky
|
||||
h_sticky = " <img src='#{h_staticPath}sticky#{h_gifIcon}' alt='Sticky' title='Sticky' class='stickyIcon retina'>"
|
||||
else
|
||||
h_sticky = ''
|
||||
|
||||
if isClosed
|
||||
h_closed = " <img src='#{h_staticPath}closed#{h_gifIcon}' alt='Closed' title='Closed' class='closedIcon retina'>"
|
||||
else
|
||||
h_closed = ''
|
||||
|
||||
if isOP and g.VIEW is 'index' and Conf['JSON Navigation']
|
||||
pageNum = Math.floor(Index.liveThreadIDs.indexOf(postID) / Index.threadsNumPerPage) + 1
|
||||
h_pageIcon = " <span class='page-num' title='This thread is on page #{+pageNum} in the original index.'>[#{+pageNum}]</span>"
|
||||
else
|
||||
h_pageIcon = ''
|
||||
|
||||
if isSticky
|
||||
h_sticky = " <img src='//s.4cdn.org/image/sticky#{h_retina}.gif' alt='Sticky' title='Sticky' class='stickyIcon retina'>"
|
||||
else
|
||||
h_sticky = ''
|
||||
|
||||
if isClosed
|
||||
h_closed = " <img src='//s.4cdn.org/image/closed#{h_retina}.gif' alt='Closed' title='Closed' class='closedIcon retina'>"
|
||||
else
|
||||
h_closed = ''
|
||||
|
||||
if isOP and g.VIEW is 'index'
|
||||
h_replyLink = " <span>[<a href='/#{E boardID}/thread/#{+threadID}' class='replylink'>Reply</a>]</span>"
|
||||
else
|
||||
h_replyLink = ''
|
||||
|
||||
h_postInfo = "<div class='postInfo desktop' id='pi#{+postID}'>"
|
||||
h_postInfo += "<input type='checkbox' name='#{+postID}' value='delete'> "
|
||||
h_postInfo += h_subject
|
||||
h_postInfo += h_nameBlock
|
||||
h_postInfo += "<span class='dateTime' data-utc='#{+dateUTC}'>#{E date}</span> "
|
||||
h_postInfo += "<span class='postNum#{h_desktop2}'>"
|
||||
h_postInfo += "<a href='#{E postLink}' title='Link to this post'>No.</a>"
|
||||
h_postInfo += "<a href='#{E quoteLink}' title='Reply to this post'>#{+postID}</a>"
|
||||
h_postInfo += "#{h_pageIcon}#{h_sticky}#{h_closed}#{h_replyLink}"
|
||||
h_postInfo += '</span>'
|
||||
h_postInfo += '</div>'
|
||||
|
||||
### File Info ###
|
||||
|
||||
if file?.isDeleted
|
||||
h_fileCont = '<span class="fileThumb">'
|
||||
h_fileCont += "<img src='//s.4cdn.org/image/filedeleted-res#{h_retina}.gif' alt='File deleted.' class='fileDeletedRes retina'>"
|
||||
h_fileCont += '</span>'
|
||||
else if file and boardID is 'f'
|
||||
fileSize = $.bytesToString file.size
|
||||
h_fileCont = "<div class='fileInfo'><span class='fileText' id='fT#{+postID}'>"
|
||||
h_fileCont += "File: <a data-width='#{+file.width}' data-height='#{+file.height}' href='#{E file.url}' target='_blank'>#{E file.name}</a>"
|
||||
h_fileCont += "-(#{E fileSize}, #{+file.width}x#{+file.height}, #{E file.tag})"
|
||||
h_fileCont += '</span></div>'
|
||||
else if file
|
||||
if file.isSpoiler
|
||||
h_fileTitle1 = "title='#{E file.name}'"
|
||||
shortFilename = 'Spoiler Image'
|
||||
h_spoilerClass = ' imgspoiler'
|
||||
else
|
||||
h_fileTitle1 = ''
|
||||
shortFilename = Build.shortFilename file.name, !isOP
|
||||
h_spoilerClass = ''
|
||||
|
||||
if file.isSpoiler or file.name is shortFilename
|
||||
h_fileTitle2 = ''
|
||||
else
|
||||
h_fileTitle2 = "title='#{E file.name}'"
|
||||
|
||||
fileSize = $.bytesToString file.size
|
||||
|
||||
if file.url[-4..] is '.pdf'
|
||||
h_fileDims = 'PDF'
|
||||
else
|
||||
h_fileDims = "#{+file.width}x#{+file.height}"
|
||||
|
||||
if file.isSpoiler and !isArchived
|
||||
if spoilerRange = Build.spoilerRange[boardID]
|
||||
# Randomize the spoiler image.
|
||||
fileThumb = "//s.4cdn.org/image/spoiler-#{boardID}#{Math.floor 1 + spoilerRange * Math.random()}.png"
|
||||
else
|
||||
fileThumb = '//s.4cdn.org/image/spoiler.png'
|
||||
file.twidth = file.theight = 100
|
||||
else
|
||||
fileThumb = file.turl
|
||||
|
||||
h_fileCont = "<div class='fileText' id='fT#{+postID}' #{h_fileTitle1}>"
|
||||
h_fileCont += "File: <a #{h_fileTitle2} href='#{E file.url}' target='_blank'>#{E shortFilename}</a> (#{E fileSize}, #{h_fileDims})"
|
||||
h_fileCont += '</div>'
|
||||
h_fileCont += "<a class='fileThumb#{h_spoilerClass}' href='#{E file.url}' target='_blank'>"
|
||||
h_fileCont += "<img src='#{E fileThumb}' alt='#{E fileSize}' data-md5='#{E file.MD5}' style='height: #{+file.theight}px; width: #{+file.twidth}px;'>"
|
||||
h_fileCont += '</a>'
|
||||
|
||||
if file
|
||||
h_file = "<div class='file' id='f#{+postID}'>#{h_fileCont}</div>"
|
||||
else
|
||||
h_file = ''
|
||||
|
||||
### Whole Post ###
|
||||
|
||||
if capcode is 'admin_highlight'
|
||||
h_highlightPost = ' highlightPost'
|
||||
else
|
||||
h_highlightPost = ''
|
||||
|
||||
h_message = "<blockquote class='postMessage' id='m#{+postID}'>#{h_comment}</blockquote>"
|
||||
|
||||
if isOP
|
||||
h_post = "<div id='p#{+postID}' class='post op#{h_highlightPost}'>"
|
||||
h_post += "#{h_file}#{h_postInfo}#{h_message}"
|
||||
h_post += '</div>'
|
||||
else
|
||||
h_post = "<div class='sideArrows' id='sa#{+postID}'>>></div>"
|
||||
h_post += "<div id='p#{+postID}' class='post reply#{h_highlightPost}'>"
|
||||
h_post += "#{h_postInfo}#{h_file}#{h_message}"
|
||||
h_post += '</div>'
|
||||
|
||||
container = $.el 'div',
|
||||
className: "postContainer #{if isOP then 'op' else 'reply'}Container"
|
||||
id: "pc#{postID}"
|
||||
innerHTML: <%= grunt.file.read('src/General/html/Build/post.html').replace(/\r?\n\s*/g, '') %>
|
||||
|
||||
if isOP and boardID is 'f'
|
||||
$.rmClass $('.postNum', container), 'desktop'
|
||||
id: "pc#{postID}"
|
||||
innerHTML: h_post
|
||||
|
||||
# Fix pathnames
|
||||
for quote in $$ '.quotelink', container
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
"""#{h_sideArrows}
|
||||
<div id='p#{+postID}' class='#{h_postClass}'>
|
||||
|
||||
#{if isOP then h_file else ''}
|
||||
|
||||
<div class='postInfo desktop' id='pi#{+postID}'>
|
||||
<input type='checkbox' name='#{+postID}' value='delete'>#{' '}
|
||||
#{h_subject}
|
||||
<span class='nameBlock#{h_capcodeClass}'>
|
||||
#{h_emailStart}
|
||||
<span class='name#{h_nameClass}'>#{E name}</span>
|
||||
#{h_tripcode}#{h_capcodeStart}#{h_emailEnd}#{h_capcodeIcon}#{h_userID}#{h_flag}
|
||||
</span>#{' '}
|
||||
<span class='dateTime' data-utc='#{+dateUTC}'>#{E date}</span>#{' '}
|
||||
<span class='postNum desktop'>
|
||||
<a href='#{E postLink}' title='Link to this post'>No.</a>
|
||||
<a href='#{E quoteLink}' title='Reply to this post'>#{+postID}</a>
|
||||
#{h_pageIcon}#{h_sticky}#{h_closed}#{h_replyLink}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
#{if isOP then '' else h_file}
|
||||
|
||||
<blockquote class='postMessage' id='m#{+postID}'>#{h_comment}</blockquote>
|
||||
|
||||
</div>"""
|
||||
Loading…
x
Reference in New Issue
Block a user