move escape function to Build
This commit is contained in:
parent
17ef291fde
commit
e74fc2765a
@ -2,6 +2,9 @@ Build =
|
|||||||
staticPath: '//s.4cdn.org/image/'
|
staticPath: '//s.4cdn.org/image/'
|
||||||
gifIcon: if window.devicePixelRatio >= 2 then '@2x.gif' else '.gif'
|
gifIcon: if window.devicePixelRatio >= 2 then '@2x.gif' else '.gif'
|
||||||
spoilerRange: {}
|
spoilerRange: {}
|
||||||
|
escape: (name) ->
|
||||||
|
name.replace /[&"'<>]/g, (c) ->
|
||||||
|
{'&': '&', "'": ''', '"': '"', '<': '<', '>': '>'}[c]
|
||||||
shortFilename: (filename, isReply) ->
|
shortFilename: (filename, isReply) ->
|
||||||
# FILENAME SHORTENING SCIENCE:
|
# FILENAME SHORTENING SCIENCE:
|
||||||
# OPs have a +10 characters threshold.
|
# OPs have a +10 characters threshold.
|
||||||
|
|||||||
@ -13,7 +13,7 @@ FileInfo =
|
|||||||
if c of FileInfo.formatters
|
if c of FileInfo.formatters
|
||||||
FileInfo.formatters[c].call(post)
|
FileInfo.formatters[c].call(post)
|
||||||
else
|
else
|
||||||
FileInfo.escape s
|
Build.escape s
|
||||||
convertUnit: (size, unit) ->
|
convertUnit: (size, unit) ->
|
||||||
if unit is 'B'
|
if unit is 'B'
|
||||||
return "#{size.toFixed()} Bytes"
|
return "#{size.toFixed()} Bytes"
|
||||||
@ -24,25 +24,22 @@ FileInfo =
|
|||||||
else
|
else
|
||||||
size.toFixed()
|
size.toFixed()
|
||||||
"#{size} #{unit}"
|
"#{size} #{unit}"
|
||||||
escape: (name) ->
|
|
||||||
name.replace /[&"'<>]/g, (c) ->
|
|
||||||
{'&': '&', "'": ''', '"': '"', '<': '<', '>': '>'}[c]
|
|
||||||
formatters:
|
formatters:
|
||||||
t: -> FileInfo.escape @file.URL.match(/\d+\..+$/)[0]
|
t: -> Build.escape @file.URL.match(/\d+\..+$/)[0]
|
||||||
T: -> "<a href=#{FileInfo.escape @file.URL} target=_blank>#{FileInfo.formatters.t.call @}</a>"
|
T: -> "<a href=#{Build.escape @file.URL} target=_blank>#{FileInfo.formatters.t.call @}</a>"
|
||||||
l: -> "<a href=#{FileInfo.escape @file.URL} target=_blank>#{FileInfo.formatters.n.call @}</a>"
|
l: -> "<a href=#{Build.escape @file.URL} target=_blank>#{FileInfo.formatters.n.call @}</a>"
|
||||||
L: -> "<a href=#{FileInfo.escape @file.URL} target=_blank>#{FileInfo.formatters.N.call @}</a>"
|
L: -> "<a href=#{Build.escape @file.URL} target=_blank>#{FileInfo.formatters.N.call @}</a>"
|
||||||
n: ->
|
n: ->
|
||||||
fullname = @file.name
|
fullname = @file.name
|
||||||
shortname = Build.shortFilename @file.name, @isReply
|
shortname = Build.shortFilename @file.name, @isReply
|
||||||
if fullname is shortname
|
if fullname is shortname
|
||||||
FileInfo.escape fullname
|
Build.escape fullname
|
||||||
else
|
else
|
||||||
"<span class=fntrunc>#{FileInfo.escape shortname}</span><span class=fnfull>#{FileInfo.escape fullname}</span>"
|
"<span class=fntrunc>#{Build.escape shortname}</span><span class=fnfull>#{Build.escape fullname}</span>"
|
||||||
N: -> FileInfo.escape @file.name
|
N: -> Build.escape @file.name
|
||||||
p: -> if @file.isSpoiler then 'Spoiler, ' else ''
|
p: -> if @file.isSpoiler then 'Spoiler, ' else ''
|
||||||
s: -> FileInfo.escape @file.size
|
s: -> Build.escape @file.size
|
||||||
B: -> FileInfo.convertUnit @file.sizeInBytes, 'B'
|
B: -> FileInfo.convertUnit @file.sizeInBytes, 'B'
|
||||||
K: -> FileInfo.convertUnit @file.sizeInBytes, 'KB'
|
K: -> FileInfo.convertUnit @file.sizeInBytes, 'KB'
|
||||||
M: -> FileInfo.convertUnit @file.sizeInBytes, 'MB'
|
M: -> FileInfo.convertUnit @file.sizeInBytes, 'MB'
|
||||||
r: -> FileInfo.escape (@file.dimensions or 'PDF')
|
r: -> Build.escape (@file.dimensions or 'PDF')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user