fix resize-compensating scrolling
This commit is contained in:
parent
adda6e19de
commit
cf2f7d3a2f
@ -114,11 +114,20 @@ ImageExpand =
|
|||||||
|
|
||||||
contract: (post) ->
|
contract: (post) ->
|
||||||
{file} = post
|
{file} = post
|
||||||
|
|
||||||
|
{bottom} = post.nodes.root.getBoundingClientRect()
|
||||||
|
oldHeight = d.body.clientHeight
|
||||||
|
|
||||||
$.rmClass post.nodes.root, 'expanded-image'
|
$.rmClass post.nodes.root, 'expanded-image'
|
||||||
$.rmClass file.thumb, 'expanding'
|
$.rmClass file.thumb, 'expanding'
|
||||||
$.rm file.videoControls if file.videoControls
|
$.rm file.videoControls if file.videoControls
|
||||||
for x in ['isExpanding', 'isExpanded', 'videoControls', 'wasPlaying', 'scrollIntoView']
|
for x in ['isExpanding', 'isExpanded', 'videoControls', 'wasPlaying', 'scrollIntoView']
|
||||||
delete file[x]
|
delete file[x]
|
||||||
|
|
||||||
|
# Scroll to keep our place in the thread when images are contracted above us.
|
||||||
|
if doc.contains(post.nodes.root) and bottom <= 0
|
||||||
|
window.scrollBy 0, d.body.clientHeight - oldHeight
|
||||||
|
|
||||||
if el = file.fullImage
|
if el = file.fullImage
|
||||||
$.off el, 'error', ImageExpand.error
|
$.off el, 'error', ImageExpand.error
|
||||||
if file.isVideo
|
if file.isVideo
|
||||||
@ -161,32 +170,30 @@ ImageExpand =
|
|||||||
ImageExpand.setupVideoCB post
|
ImageExpand.setupVideoCB post
|
||||||
|
|
||||||
$.asap (-> if isVideo then el.readyState >= el.HAVE_CURRENT_DATA else el.naturalHeight), ->
|
$.asap (-> if isVideo then el.readyState >= el.HAVE_CURRENT_DATA else el.naturalHeight), ->
|
||||||
if post.nodes.root.parentNode
|
ImageExpand.completeExpand post
|
||||||
{bottom} = post.nodes.root.getBoundingClientRect()
|
|
||||||
$.queueTask -> ImageExpand.completeExpand post, bottom
|
|
||||||
else
|
|
||||||
# Image might start/finish loading before the post is inserted; don't scroll.
|
|
||||||
ImageExpand.completeExpand post
|
|
||||||
|
|
||||||
completeExpand: (post, oldBottom) ->
|
completeExpand: (post) ->
|
||||||
{file} = post
|
{file} = post
|
||||||
return unless file.isExpanding # contracted before the image loaded
|
return unless file.isExpanding # contracted before the image loaded
|
||||||
|
|
||||||
|
{bottom} = post.nodes.root.getBoundingClientRect()
|
||||||
|
oldHeight = d.body.clientHeight
|
||||||
|
|
||||||
$.addClass post.nodes.root, 'expanded-image'
|
$.addClass post.nodes.root, 'expanded-image'
|
||||||
$.rmClass file.thumb, 'expanding'
|
$.rmClass file.thumb, 'expanding'
|
||||||
file.isExpanded = true
|
file.isExpanded = true
|
||||||
delete file.isExpanding
|
delete file.isExpanding
|
||||||
|
|
||||||
# Scroll to keep our place in the thread when images are expanded above us.
|
# Scroll to keep our place in the thread when images are expanded above us.
|
||||||
if oldBottom? and oldBottom <= 0
|
if doc.contains(post.nodes.root) and bottom <= 0
|
||||||
window.scrollBy 0, post.nodes.root.getBoundingClientRect().bottom - oldBottom
|
window.scrollBy 0, d.body.clientHeight - oldHeight
|
||||||
|
|
||||||
# Scroll to display full image.
|
# Scroll to display full image.
|
||||||
if file.scrollIntoView
|
if file.scrollIntoView
|
||||||
delete file.scrollIntoView
|
delete file.scrollIntoView
|
||||||
imageBottom = Header.getBottomOf file.fullImage
|
imageBottom = Header.getBottomOf file.fullImage
|
||||||
{height} = file.fullImage.getBoundingClientRect()
|
imageHeight = file.fullImage.getBoundingClientRect().height
|
||||||
if imageBottom + height >= 0 and imageBottom < 0
|
if imageBottom + imageHeight >= 0 and imageBottom < 0
|
||||||
window.scrollBy 0, Math.min(-imageBottom, Header.getTopOf file.fullImage)
|
window.scrollBy 0, Math.min(-imageBottom, Header.getTopOf file.fullImage)
|
||||||
|
|
||||||
if file.isVideo
|
if file.isVideo
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user