rm as many id attributes in posts as possible.

Add root.dataset.fullID, simplify Get.postFromRoot().
Also figured Menu.toggle() could be simplified since stub of threads do not exist anymore.
This commit is contained in:
Mayhem 2014-02-27 19:02:32 +01:00
parent a853bd5e8e
commit 59f2ca6a51
8 changed files with 21 additions and 31 deletions

View File

@ -116,11 +116,11 @@ Build =
if file?.isDeleted
fileHTML = if isOP
"<div class=file id=f#{postID}><span class=fileThumb>" +
"<div class=file><span class=fileThumb>" +
"<img src='#{staticPath}filedeleted#{gifIcon}' class=fileDeleted>" +
"</span></div>"
else
"<div class=file id=f#{postID}><span class=fileThumb>" +
"<div class=file><span class=fileThumb>" +
"<img src='#{staticPath}filedeleted-res#{gifIcon}' class=fileDeletedRes>" +
"</span></div>"
else if file
@ -154,7 +154,7 @@ Build =
filename = a.innerHTML.replace /'/g, '&apos;'
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#{if file.isSpoiler then " title='#{filename}'" else ''}>File: <a href='#{file.url}' target=_blank>#{file.timestamp}</a>" +
"-(#{fileSize}, #{fileDims}#{
if file.isSpoiler
''
@ -162,7 +162,7 @@ Build =
", <span#{if filename isnt shortFilename then " title='#{filename}'" else ''}>#{shortFilename}</span>"
}" + ")</div>"
fileHTML = "<div class=file id=f#{postID}>#{fileInfo}#{imgSrc}</div>"
fileHTML = "<div class=file>#{fileInfo}#{imgSrc}</div>"
else
fileHTML = ''
@ -186,7 +186,7 @@ Build =
id: "pc#{postID}"
className: "postContainer #{if isOP then 'op' else 'reply'}Container"
innerHTML: \
(if isOP then '' else "<div class=sideArrows id=sa#{postID}>&gt;&gt;</div>") +
(if isOP then '' else "<div class=sideArrows>&gt;&gt;</div>") +
"<div id=p#{postID} class='post #{if isOP then 'op' else 'reply'}#{
if capcode is 'admin_highlight'
' highlightPost'
@ -196,7 +196,7 @@ Build =
(if isOP then fileHTML else '') +
"<div class='postInfo' id=pi#{postID}>" +
"<div class=postInfo>" +
"<input type=checkbox name=#{postID} value=delete> " +
"<span class=subject>#{subject or ''}</span> " +
"<span class='nameBlock#{capcodeClass}'>" +
@ -219,7 +219,7 @@ Build =
(if isOP then '' else fileHTML) +
"<blockquote class=postMessage id=m#{postID}>#{comment or ''}</blockquote> " +
"<blockquote class=postMessage>#{comment or ''}</blockquote> " +
'</div>'

View File

@ -12,12 +12,8 @@ Get =
threadFromNode: (node) ->
Get.threadFromRoot $.x 'ancestor::div[@class="thread"]', node
postFromRoot: (root) ->
link = $ 'a[title="Highlight this post"]', root
boardID = link.pathname.split('/')[1]
postID = link.hash[2..]
index = root.dataset.clone
post = g.posts["#{boardID}.#{postID}"]
if index then post.clones[index] else post
post = g.posts[root.dataset.fullID]
if index = root.dataset.clone then post.clones[index] else post
postFromNode: (node) ->
Get.postFromRoot $.x 'ancestor::div[contains(@class,"postContainer")][1]', node
contextFromNode: (node) ->

View File

@ -266,7 +266,7 @@ Header =
hashScroll: ->
hash = @location.hash[1..]
return unless /^p\d+$/.test(hash) and post = $.id hash
return if (Get.postFromRoot post).isHidden
return if (Get.postFromNode post).isHidden
Header.scrollTo post
scrollTo: (root, down, needed) ->
if down

View File

@ -6,9 +6,10 @@ class Post
@ID = +root.id[2..]
@fullID = "#{@board}.#{@ID}"
@cleanup root if that.isOriginalMarkup
post = $ '.post', root
info = $ '.postInfo', post
@cleanup root, post if that.isOriginalMarkup
root.dataset.fullID = @fullID
@nodes =
root: root
post: post
@ -146,9 +147,11 @@ class Post
if @file.isImage = /(jpg|png|gif)$/i.test @file.name
@file.dimensions = fileText.textContent.match(/\d+x\d+/)[0]
cleanup: (root) ->
cleanup: (root, post) ->
for node in $$ '.mobile', root
$.rm node
for node in $$ '[id]', post
node.removeAttribute 'id'
for node in $$ '.desktop', root
$.rmClass node, 'desktop'
return

View File

@ -30,13 +30,4 @@ Menu =
clone
toggle: (e) ->
try
# Posts, inlined posts, hidden replies.
post = Get.postFromNode @
catch
post = if fullID = @parentNode.parentNode.dataset.fullID
g.threads[fullID].OP
else
# Hidden threads.
Get.threadFromNode(@).OP
Menu.menu.toggle e, @, post
Menu.menu.toggle e, @, Get.postFromNode @

View File

@ -26,9 +26,9 @@ ThreadUpdater =
cb: @node
node: ->
ThreadUpdater.thread = @
ThreadUpdater.root = @OP.nodes.root.parentNode
ThreadUpdater.lastPost = +ThreadUpdater.root.lastElementChild.id.match(/\d+/)[0]
ThreadUpdater.thread = @
ThreadUpdater.root = @OP.nodes.root.parentNode
ThreadUpdater.lastPost = +Object.keys(@posts).sort()[-1..][0]
for input in $$ 'input', ThreadUpdater.dialog
if input.type is 'checkbox'

View File

@ -60,7 +60,7 @@ ThreadWatcher =
ThreadWatcher.refresh()
$.event 'CloseMenu'
toggle: ->
ThreadWatcher.toggle Get.postFromNode(@).thread
ThreadWatcher.toggle Get.threadFromNode @
rm: ->
[boardID, threadID] = @parentNode.dataset.fullID.split '.'
ThreadWatcher.rm boardID, +threadID

View File

@ -17,7 +17,7 @@ QuoteInline =
if $.hasClass @, 'inlined'
QuoteInline.rm @, boardID, threadID, postID, context
else
return if $.x "ancestor::div[@id='p#{postID}']", @
return if $.x "ancestor::div[@id='pc#{postID}']", @
QuoteInline.add @, boardID, threadID, postID, context
@classList.toggle 'inlined'