Fix delete cooldown "jumps", only start the cooldown on our posts. #968

This commit is contained in:
Nicolas Stepien 2013-03-30 19:06:40 +01:00
parent e88e3e4707
commit d4a0af9e21

View File

@ -1548,20 +1548,15 @@ DeleteLink =
open: (post) -> open: (post) ->
return false if post.isDead return false if post.isDead
DeleteLink.post = post DeleteLink.post = post
DeleteLink.cooldown.start post
node = div.firstChild node = div.firstChild
if seconds = DeleteLink.cooldown[post.fullID] node.textContent = 'Delete'
node.textContent = "Delete (#{seconds})" DeleteLink.cooldown.start post, node
DeleteLink.cooldown.el = node
else
node.textContent = 'Delete'
delete DeleteLink.cooldown.el
true true
subEntries: [postEntry, fileEntry] subEntries: [postEntry, fileEntry]
delete: -> delete: ->
{post} = DeleteLink {post} = DeleteLink
return if DeleteLink.cooldown[post.fullID] return if DeleteLink.cooldown.counting is post
$.off @, 'click', DeleteLink.delete $.off @, 'click', DeleteLink.delete
@textContent = "Deleting #{@textContent}..." @textContent = "Deleting #{@textContent}..."
@ -1601,25 +1596,29 @@ DeleteLink =
$.on link, 'click', DeleteLink.delete $.on link, 'click', DeleteLink.delete
cooldown: cooldown:
start: (post) -> start: (post, node) ->
return if post.fullID of DeleteLink.cooldown unless (thread = QR.yourPosts?.threads?[post.thread]) and post.ID in thread
# Only start counting on our posts.
delete DeleteLink.cooldown.counting
return
DeleteLink.cooldown.counting = post
length = if post.board.ID is 'q' length = if post.board.ID is 'q'
600 600
else else
30 30
seconds = Math.ceil (length * $.SECOND - (Date.now() - post.info.date)) / $.SECOND seconds = Math.ceil (length * $.SECOND - (Date.now() - post.info.date)) / $.SECOND
DeleteLink.cooldown.count post.fullID, seconds, length DeleteLink.cooldown.count post, seconds, length, node
count: (fullID, seconds, length) -> count: (post, seconds, length, node) ->
return unless 0 <= seconds <= length return if DeleteLink.cooldown.counting isnt post
setTimeout DeleteLink.cooldown.count, 1000, fullID, seconds-1, length unless 0 <= seconds <= length
{el} = DeleteLink.cooldown if DeleteLink.cooldown.counting is post
if seconds is 0 delete DeleteLink.cooldown.counting
el?.textContent = 'Delete'
delete DeleteLink.cooldown[fullID]
delete DeleteLink.cooldown.el
return return
el?.textContent = "Delete (#{seconds})" setTimeout DeleteLink.cooldown.count, 1000, post, seconds - 1, length, node
DeleteLink.cooldown[fullID] = seconds if seconds is 0
node.textContent = 'Delete'
return
node.textContent = "Delete (#{seconds})"
DownloadLink = DownloadLink =
init: -> init: ->