A bit of clean up.

This commit is contained in:
Nicolas Stepien 2012-06-15 19:32:27 +02:00
parent 2ee04e6046
commit 9372c1dc32
2 changed files with 42 additions and 50 deletions

View File

@ -3099,35 +3099,30 @@
} }
}, },
parseArchivedPost: function(req, board, postID, root, cb) { parseArchivedPost: function(req, board, postID, root, cb) {
var bq, br, capcode, data, email, file, filesize, isOP, nameBlock, p, pc, pi, piM, span; var bq, br, capcode, data, email, file, filesize, isOP, name, nameBlock, pc, pi, piM, span, subject, threadID, trip;
data = JSON.parse(req.response); data = JSON.parse(req.response);
$.addClass(root, 'archivedPost');
if (data.error) { if (data.error) {
root.textContent = data.error; root.textContent = data.error;
return; return;
} }
isOP = postID === data.thread_num; threadID = data.thread_num;
pc = $.el('div', { isOP = postID === threadID;
id: "pc" + postID, name = data.name, trip = data.trip;
className: isOP ? 'postContainer opContainer' : 'postContainer replyContainer' subject = data.title;
});
p = $.el('div', {
id: "p" + postID,
className: isOP ? 'post op' : 'post reply'
});
$.add(pc, p);
piM = $.el('div', { piM = $.el('div', {
id: "pim" + postID, id: "pim" + postID,
className: 'postInfoM mobile', className: 'postInfoM mobile',
innerHTML: "<span class=nameBlock><span class=name></span><br><span class=subject></span></span><span class='dateTime postNum' data-utc=" + timestamp + ">" + data.fourchan_date + "<br><em></em><a href='/" + board + "/res/" + data.thread_num + "#p" + postID + "' title='Highlight this post'>No.</a><a href='/" + board + "/res/" + data.thread_num + "#q" + postID + "' title='Quote this post'>" + postID + "</a></span>" innerHTML: "<span class=nameBlock><span class=name></span><br><span class=subject></span></span><span class='dateTime postNum' data-utc=" + timestamp + ">" + data.fourchan_date + "<br><em></em><a href='/" + board + "/res/" + threadID + "#p" + postID + "' title='Highlight this post'>No.</a><a href='/" + board + "/res/" + threadID + "#q" + postID + "' title='Quote this post'>" + postID + "</a></span>"
}); });
$('.name', piM).textContent = data.name; $('.name', piM).textContent = name;
$('.subject', piM).textContent = data.title; $('.subject', piM).textContent = subject;
br = $('br', piM); br = $('br', piM);
if (data.trip) { if (trip) {
$.before(br, [ $.before(br, [
$.tn(' '), $.el('span', { $.tn(' '), $.el('span', {
className: 'postertrip', className: 'postertrip',
textContent: data.trip textContent: trip
}) })
]); ]);
} }
@ -3149,9 +3144,9 @@
pi = $.el('div', { pi = $.el('div', {
id: "pi" + postID, id: "pi" + postID,
className: 'postInfo desktop', className: 'postInfo desktop',
innerHTML: "<input type=checkbox name=" + postID + " value=delete> <span class=userInfo><span class=subject></span> <span class=nameBlock></span></span> <span class=dateTime data-utc=" + data.timestamp + ">data.fourchan_date</span> <span class='postNum desktop'><a href='/" + board + "/res/" + data.thread_num + "#p" + postID + "' title='Highlight this post'>No.</a><a href='/" + board + "/res/" + data.thread_num + "#q" + postID + "' title='Quote this post'>" + postID + "</a>" + (isOP ? ' &nbsp; ' : '') + "</span> " innerHTML: "<input type=checkbox name=" + postID + " value=delete> <span class=userInfo><span class=subject></span> <span class=nameBlock></span></span> <span class=dateTime data-utc=" + data.timestamp + ">data.fourchan_date</span> <span class='postNum desktop'><a href='/" + board + "/res/" + threadID + "#p" + postID + "' title='Highlight this post'>No.</a><a href='/" + board + "/res/" + threadID + "#q" + postID + "' title='Quote this post'>" + postID + "</a>" + (isOP ? ' &nbsp; ' : '') + "</span> "
}); });
$('.subject', pi).textContent = data.title; $('.subject', pi).textContent = subject;
nameBlock = $('.nameBlock', pi); nameBlock = $('.nameBlock', pi);
if (data.email) { if (data.email) {
email = $.el('a', { email = $.el('a', {
@ -3165,11 +3160,11 @@
className: 'name', className: 'name',
textContent: data.name textContent: data.name
})); }));
if (data.trip) { if (trip) {
$.add(nameBlock, [ $.add(nameBlock, [
$.tn(' '), $.el('span', { $.tn(' '), $.el('span', {
className: 'postertrip', className: 'postertrip',
textContent: data.trip textContent: trip
}) })
]); ]);
} }
@ -3223,7 +3218,12 @@
} }
}); });
bq.innerHTML = bq.innerHTML.replace(/(^|>)(&gt;[^<$]+)(<|$)/g, '$1<span class=quote>$2</span>$3'); bq.innerHTML = bq.innerHTML.replace(/(^|>)(&gt;[^<$]+)(<|$)/g, '$1<span class=quote>$2</span>$3');
$.add(p, [piM, pi, bq]); pc = $.el('div', {
id: "pc" + postID,
className: "postContainer " + (isOP ? 'op' : 'reply') + "Container",
innerHTML: "<div id=p" + postID + " class='postContainer " + (isOP ? 'op' : 'reply') + "'></div>"
});
$.add(pc.firstChild, [piM, pi, bq]);
if (data.media_filename) { if (data.media_filename) {
file = $.el('div', { file = $.el('div', {
id: "f" + postID, id: "f" + postID,
@ -3245,7 +3245,6 @@
})); }));
$.after((isOP ? piM : pi), file); $.after((isOP ? piM : pi), file);
} }
$.addClass(root, 'archivedPost');
$.replace(root.firstChild, pc); $.replace(root.firstChild, pc);
if (cb) { if (cb) {
return cb(); return cb();

View File

@ -2378,35 +2378,28 @@ Get =
cb() if cb cb() if cb
parseArchivedPost: (req, board, postID, root, cb) -> parseArchivedPost: (req, board, postID, root, cb) ->
data = JSON.parse req.response data = JSON.parse req.response
$.addClass root, 'archivedPost'
if data.error if data.error
root.textContent = data.error root.textContent = data.error
return return
isOP = postID is data.thread_num threadID = data.thread_num
isOP = postID is threadID
# post containers {name, trip} = data
pc = $.el 'div', subject = data.title
id: "pc#{postID}"
className: if isOP then 'postContainer opContainer' else 'postContainer replyContainer'
p = $.el 'div',
id: "p#{postID}"
className: if isOP then 'post op' else 'post reply'
$.add pc, p
# post info (mobile) # post info (mobile)
piM = $.el 'div', piM = $.el 'div',
id: "pim#{postID}" id: "pim#{postID}"
className: 'postInfoM mobile' className: 'postInfoM mobile'
innerHTML: "<span class=nameBlock><span class=name></span><br><span class=subject></span></span><span class='dateTime postNum' data-utc=#{timestamp}>#{data.fourchan_date}<br><em></em><a href='/#{board}/res/#{data.thread_num}#p#{postID}' title='Highlight this post'>No.</a><a href='/#{board}/res/#{data.thread_num}#q#{postID}' title='Quote this post'>#{postID}</a></span>" innerHTML: "<span class=nameBlock><span class=name></span><br><span class=subject></span></span><span class='dateTime postNum' data-utc=#{timestamp}>#{data.fourchan_date}<br><em></em><a href='/#{board}/res/#{threadID}#p#{postID}' title='Highlight this post'>No.</a><a href='/#{board}/res/#{threadID}#q#{postID}' title='Quote this post'>#{postID}</a></span>"
$('.name', piM).textContent = data.name $('.name', piM).textContent = name
$('.subject', piM).textContent = data.title $('.subject', piM).textContent = subject
br = $ 'br', piM br = $ 'br', piM
if data.trip if trip
$.before br, [$.tn(' '), $.el 'span', $.before br, [$.tn(' '), $.el 'span',
className: 'postertrip' className: 'postertrip'
textContent: data.trip textContent: trip
] ]
{capcode} = data {capcode} = data
if capcode isnt 'N' # 'A'dmin or 'M'od if capcode isnt 'N' # 'A'dmin or 'M'od
@ -2427,15 +2420,13 @@ Get =
) )
] ]
# post info # post info
pi = $.el 'div', pi = $.el 'div',
id: "pi#{postID}" id: "pi#{postID}"
className: 'postInfo desktop' className: 'postInfo desktop'
innerHTML: "<input type=checkbox name=#{postID} value=delete> <span class=userInfo><span class=subject></span> <span class=nameBlock></span></span> <span class=dateTime data-utc=#{data.timestamp}>data.fourchan_date</span> <span class='postNum desktop'><a href='/#{board}/res/#{data.thread_num}#p#{postID}' title='Highlight this post'>No.</a><a href='/#{board}/res/#{data.thread_num}#q#{postID}' title='Quote this post'>#{postID}</a>#{if isOP then ' &nbsp; ' else ''}</span> " innerHTML: "<input type=checkbox name=#{postID} value=delete> <span class=userInfo><span class=subject></span> <span class=nameBlock></span></span> <span class=dateTime data-utc=#{data.timestamp}>data.fourchan_date</span> <span class='postNum desktop'><a href='/#{board}/res/#{threadID}#p#{postID}' title='Highlight this post'>No.</a><a href='/#{board}/res/#{threadID}#q#{postID}' title='Quote this post'>#{postID}</a>#{if isOP then ' &nbsp; ' else ''}</span> "
# subject # subject
$('.subject', pi).textContent = data.title $('.subject', pi).textContent = subject
nameBlock = $ '.nameBlock', pi nameBlock = $ '.nameBlock', pi
if data.email if data.email
email = $.el 'a', email = $.el 'a',
@ -2446,8 +2437,8 @@ Get =
$.add nameBlock, $.el 'span', $.add nameBlock, $.el 'span',
className: 'name' className: 'name'
textContent: data.name textContent: data.name
if data.trip if trip
$.add nameBlock, [$.tn(' '), $.el('span', className: 'postertrip', textContent: data.trip)] $.add nameBlock, [$.tn(' '), $.el('span', className: 'postertrip', textContent: trip)]
if capcode isnt 'N' # 'A'dmin or 'M'od if capcode isnt 'N' # 'A'dmin or 'M'od
$.add nameBlock, [ $.add nameBlock, [
$.tn(' '), $.tn(' '),
@ -2468,7 +2459,6 @@ Get =
) )
] ]
# comment # comment
bq = $.el 'blockquote', bq = $.el 'blockquote',
id: "m#{postID}" id: "m#{postID}"
@ -2507,11 +2497,15 @@ Get =
'<b style="color: red;">' '<b style="color: red;">'
when '[/banned]' when '[/banned]'
'</b>' '</b>'
# greentext
bq.innerHTML = bq.innerHTML.replace /(^|>)(&gt;[^<$]+)(<|$)/g, '$1<span class=quote>$2</span>$3' bq.innerHTML = bq.innerHTML.replace /(^|>)(&gt;[^<$]+)(<|$)/g, '$1<span class=quote>$2</span>$3'
# post container
$.add p, [piM, pi, bq] pc = $.el 'div',
id: "pc#{postID}"
className: "postContainer #{if isOP then 'op' else 'reply'}Container"
innerHTML: "<div id=p#{postID} class='postContainer #{if isOP then 'op' else 'reply'}'></div>"
$.add pc.firstChild, [piM, pi, bq]
# file # file
if data.media_filename if data.media_filename
@ -2536,7 +2530,6 @@ Get =
innerHTML: "<img src=#{data.thumb_link} alt='#{if data.spoiler is '1' then 'Spoiler Image, ' else ''}#{filesize}' data-md5=#{data.media_hash} style='height: #{data.preview_h}px; width: #{data.preview_w}px;'>" innerHTML: "<img src=#{data.thumb_link} alt='#{if data.spoiler is '1' then 'Spoiler Image, ' else ''}#{filesize}' data-md5=#{data.media_hash} style='height: #{data.preview_h}px; width: #{data.preview_w}px;'>"
$.after (if isOP then piM else pi), file $.after (if isOP then piM else pi), file
$.addClass root, 'archivedPost'
$.replace root.firstChild, pc $.replace root.firstChild, pc
cb() if cb cb() if cb
cleanPost: (root) -> cleanPost: (root) ->