Merge branch 'perf' into v3

This commit is contained in:
Mayhem 2013-12-20 04:39:46 +01:00
commit 05f6fb7385
8 changed files with 54 additions and 77 deletions

View File

@ -111,10 +111,12 @@ PostHiding =
$.event 'CloseMenu'
makeButton: (post, type) ->
span = $.el 'span',
textContent: "[\u00A0#{if type is 'hide' then '-' else '+'}\u00A0]"
a = $.el 'a',
className: "#{type}-reply-button"
innerHTML: "<span>[&nbsp;#{if type is 'hide' then '-' else '+'}&nbsp;]</span>"
href: 'javascript:;'
$.add a, span
$.on a, 'click', PostHiding.toggle
a
@ -166,7 +168,7 @@ PostHiding =
className: 'stub'
$.add post.nodes.stub, a
if Conf['Menu']
$.add post.nodes.stub, [$.tn(' '), Menu.makeButton()]
$.add post.nodes.stub, Menu.makeButton()
$.prepend post.nodes.root, post.nodes.stub
show: (post, showRecursively=Conf['Recursive Hiding']) ->

View File

@ -124,7 +124,7 @@ ThreadHiding =
thread.stub = $.el 'div',
className: 'stub'
if Conf['Menu']
$.add thread.stub, [a, $.tn(' '), Menu.makeButton()]
$.add thread.stub, [a, Menu.makeButton()]
else
$.add thread.stub, a
$.prepend root, thread.stub

View File

@ -1,4 +1,6 @@
Build =
staticPath: '//s.4cdn.org/image/'
gifIcon: if window.devicePixelRatio >= 2 then '@2x.gif' else '.gif'
spoilerRange: {}
shortFilename: (filename, isReply) ->
# FILENAME SHORTENING SCIENCE:
@ -61,12 +63,12 @@ Build =
file
} = o
isOP = postID is threadID
{staticPath, gifIcon} = Build
staticPath = '//s.4cdn.org/image/'
gifIcon = if window.devicePixelRatio >= 2
'@2x.gif'
tripcode = if tripcode
" <span class=postertrip>#{tripcode}</span>"
else
'.gif'
''
if email
emailStart = '<a href="mailto:' + email + '" class="useremail">'
@ -75,41 +77,35 @@ Build =
emailStart = ''
emailEnd = ''
subject = "<span class=subject>#{subject or ''}</span>"
userID =
if !capcode and uniqueID
" <span class='posteruid id_#{uniqueID}'>(ID: " +
"<span class=hand title='Highlight posts by this ID'>#{uniqueID}</span>)</span> "
else
''
switch capcode
when 'admin', 'admin_highlight'
capcodeClass = " capcodeAdmin"
capcodeStart = " <strong class='capcode hand id_admin'" +
"title='Highlight posts by the Administrator'>## Admin</strong>"
capcode = " <img src='#{staticPath}adminicon#{gifIcon}' " +
"alt='This user is the 4chan Administrator.' " +
capcodeIcon = " <img src='#{staticPath}adminicon#{gifIcon}' " +
"title='This user is the 4chan Administrator.' class=identityIcon>"
when 'mod'
capcodeClass = " capcodeMod"
capcodeStart = " <strong class='capcode hand id_mod' " +
"title='Highlight posts by Moderators'>## Mod</strong>"
capcode = " <img src='#{staticPath}modicon#{gifIcon}' " +
"alt='This user is a 4chan Moderator.' " +
capcodeIcon = " <img src='#{staticPath}modicon#{gifIcon}' " +
"title='This user is a 4chan Moderator.' class=identityIcon>"
when 'developer'
capcodeClass = " capcodeDeveloper"
capcodeStart = " <strong class='capcode hand id_developer' " +
"title='Highlight posts by Developers'>## Developer</strong>"
capcode = " <img src='#{staticPath}developericon#{gifIcon}' " +
"alt='This user is a 4chan Developer.' " +
capcodeIcon = " <img src='#{staticPath}developericon#{gifIcon}' " +
"title='This user is a 4chan Developer.' class=identityIcon>"
else
capcodeClass = ''
capcodeStart = ''
capcode = ''
capcodeIcon = ''
userID = if uniqueID and !capcode
" <span class='posteruid id_#{uniqueID}'>(ID: " +
"<span class=hand title='Highlight posts by this ID'>#{uniqueID}</span>)</span>"
else
''
flag = unless flagCode
''
@ -128,13 +124,7 @@ Build =
"<img src='#{staticPath}filedeleted-res#{gifIcon}' alt='File deleted.' class=fileDeletedRes>" +
"</span></div>"
else if file
ext = file.name[-3..]
if !file.twidth and !file.theight and ext is 'gif' # wtf ?
file.twidth = file.width
file.theight = file.height
fileSize = $.bytesToString file.size
fileSize = $.bytesToString file.size
fileThumb = file.turl
if file.isSpoiler
fileSize = "Spoiler Image, #{fileSize}"
@ -153,20 +143,17 @@ Build =
"<img src='#{fileThumb}' alt='#{fileSize}' data-md5=#{file.MD5} style='height: #{file.theight}px; width: #{file.twidth}px;'>" +
"</a>"
# Ha ha, filenames!
# html -> text, translate WebKit's %22s into "s
a = $.el 'a', innerHTML: file.name
filename = a.textContent.replace /%22/g, '"'
# shorten filename, get html
a.textContent = Build.shortFilename filename
shortFilename = a.innerHTML
# get html
a.textContent = filename
filename = a.innerHTML.replace /'/g, '&apos;'
fileDims = if ext is 'pdf' then 'PDF' else "#{file.width}x#{file.height}"
fileDims = if file.name[-3..] is 'pdf' then 'PDF' else "#{file.width}x#{file.height}"
fileInfo = "<div class=fileText id=fT#{postID}#{if file.isSpoiler then " title='#{filename}'" else ''}>File: <a href='#{file.url}' target=_blank>#{file.timestamp}</a>" +
"-(#{fileSize}, #{fileDims}#{
if file.isSpoiler
@ -179,11 +166,6 @@ Build =
else
fileHTML = ''
tripcode = if tripcode
" <span class=postertrip>#{tripcode}</span>"
else
''
sticky = if isSticky
" <img src=#{staticPath}sticky#{gifIcon} alt=Sticky title=Sticky class=stickyIcon>"
else
@ -212,37 +194,21 @@ Build =
''
}'>" +
"<div class='postInfoM mobile' id=pim#{postID}>" +
"<span class='nameBlock#{capcodeClass}'>" +
"<span class=name>#{name or ''}</span>" + tripcode +
capcodeStart + capcode + userID + flag + sticky + closed +
"<br>#{subject}" +
"</span><span class='dateTime postNum' data-utc=#{dateUTC}>#{date}" +
"<a href=#{"/#{boardID}/res/#{threadID}#p#{postID}"}>No.</a>" +
"<a href='#{
if g.VIEW is 'thread' and g.THREADID is +threadID
"javascript:quote(#{postID})"
else
"/#{boardID}/res/#{threadID}#q#{postID}"
}'>#{postID}</a>" +
'</span>' +
'</div>' +
(if isOP then fileHTML else '') +
"<div class='postInfo desktop' id=pi#{postID}>" +
"<div class='postInfo' id=pi#{postID}>" +
"<input type=checkbox name=#{postID} value=delete> " +
"#{subject} " +
"<span class=subject>#{subject or ''}</span> " +
"<span class='nameBlock#{capcodeClass}'>" +
emailStart +
"<span class=name>#{name or ''}</span>" + tripcode +
capcodeStart + emailEnd + capcode + userID + flag +
capcodeStart + emailEnd + capcodeIcon + userID + flag +
' </span> ' +
"<span class=dateTime data-utc=#{dateUTC}>#{date}</span> " +
"<span class='postNum desktop'>" +
"<span class='postNum'>" +
"<a href=#{"/#{boardID}/res/#{threadID}#p#{postID}"} title='Highlight this post'>No.</a>" +
"<a href='#{
if g.VIEW is 'thread' and g.THREADID is +threadID
if g.VIEW is 'thread' and g.THREADID is threadID
"javascript:quote(#{postID})"
else
"/#{boardID}/res/#{threadID}#q#{postID}"

View File

@ -194,8 +194,8 @@ Get =
threadID = +data.thread_num
o =
# id
postID: "#{postID}"
threadID: "#{threadID}"
postID: postID
threadID: threadID
boardID: boardID
# info
name: data.name_processed
@ -231,7 +231,6 @@ Get =
new Board boardID
thread = g.threads["#{boardID}.#{threadID}"] or
new Thread threadID, board
post = new Post Build.post(o, true), thread, board,
isArchived: true
post = new Post Build.post(o, true), thread, board, {isArchived: true}
Main.callbackNodes Post, [post]
Get.insert post, root, context

View File

@ -174,7 +174,7 @@ Main =
posts = []
for postRoot in $$ '.thread > .postContainer', threadRoot
try
posts.push new Post postRoot, thread, g.BOARD
posts.push post = new Post postRoot, thread, g.BOARD, {isOriginalMarkup: true}
catch err
# Skip posts that we failed to parse.
errors = [] unless errors

View File

@ -6,6 +6,7 @@ class Post
@ID = +root.id[2..]
@fullID = "#{@board}.#{@ID}"
@cleanup root if that.isOriginalMarkup
post = $ '.post', root
info = $ '.postInfo', post
@nodes =
@ -141,6 +142,13 @@ class Post
if @file.isImage = /(jpg|png|gif)$/i.test @file.name
@file.dimensions = fileText.textContent.match(/\d+x\d+/)[0]
cleanup: (root) ->
for node in $$ '.mobile', root
$.rm node
for node in $$ '.desktop', root
$.rmClass node, 'desktop'
return
kill: (file, now) ->
now or= new Date()
if file

View File

@ -33,6 +33,8 @@ class Thread
className: "#{typeLC}Icon"
root = if type is 'Closed' and @isSticky
$ '.stickyIcon', @OP.nodes.info
else if g.VIEW is 'index'
$ '.page-num', @OP.nodes.info
else
$ '[title="Quote this post"]', @OP.nodes.info
$.after root, [$.tn(' '), icon]

View File

@ -9,22 +9,22 @@ Menu =
node: ->
if @isClone
button = $ '.menu-button', @nodes.info
$.on button, 'click', Menu.toggle
$.on $('.menu-button', @nodes.info), 'click', Menu.toggle
return
button = Menu.makeButton()
$.add @nodes.info, [$.tn('\u00A0'), button]
$.add @nodes.info, Menu.makeButton()
makeButton: do ->
a = null
frag = null
->
a or= $.el 'a',
className: 'menu-button'
innerHTML: '[<i></i>]'
href: 'javascript:;'
button = a.cloneNode true
$.on button, 'click', Menu.toggle
button
unless frag
a = $.el 'a',
className: 'menu-button'
innerHTML: '[<i></i>]'
href: 'javascript:;'
frag = $.nodes [$.tn(' '), a]
clone = frag.cloneNode true
$.on clone.lastElementChild, 'click', Menu.toggle
clone
toggle: (e) ->
try