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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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