Suppress post thumbnails from loading until they are actually inserted into the index.

Hopefully a temporary way of doing this until we get filtering working on JSON
so we don't have to build the posts at all.
This commit is contained in:
ccd0 2015-03-28 18:14:44 -07:00
parent 897bdac327
commit 6ad0064f41
6 changed files with 25 additions and 10 deletions

View File

@ -26,7 +26,7 @@ Build =
"#p#{postID}" "#p#{postID}"
else else
"/#{boardID}/thread/#{threadID}#p#{postID}" "/#{boardID}/thread/#{threadID}#p#{postID}"
postFromObject: (data, boardID) -> postFromObject: (data, boardID, suppressThumb) ->
o = o =
# id # id
postID: data.no postID: data.no
@ -70,8 +70,8 @@ Build =
isSpoiler: !!data.spoiler isSpoiler: !!data.spoiler
isDeleted: false isDeleted: false
tag: data.tag tag: data.tag
Build.post o Build.post o, suppressThumb
post: (o) -> post: (o, suppressThumb) ->
### ###
This function contains code from 4chan-JS (https://github.com/4chan/4chan-JS). This function contains code from 4chan-JS (https://github.com/4chan/4chan-JS).
@license: https://github.com/4chan/4chan-JS/blob/master/LICENSE @license: https://github.com/4chan/4chan-JS/blob/master/LICENSE
@ -115,6 +115,7 @@ Build =
shortFilename = Build.shortFilename file.name shortFilename = Build.shortFilename file.name
fileSize = $.bytesToString file.size fileSize = $.bytesToString file.size
fileDims = if file.url[-4..] is '.pdf' then 'PDF' else "#{file.width}x#{file.height}" fileDims = if file.url[-4..] is '.pdf' then 'PDF' else "#{file.width}x#{file.height}"
fileThumb = if file.isSpoiler then Build.spoilerThumb boardID else file.turl
fileBlock = <%= importHTML('Build/File') %> fileBlock = <%= importHTML('Build/File') %>
@ -166,7 +167,7 @@ Build =
root root
excerptThread: (board, data, OP) -> excerptThread: (board, data, OP) ->
nodes = [if OP then OP.nodes.root else Build.postFromObject data, board.ID] nodes = [if OP then OP.nodes.root else Build.postFromObject data, board.ID, true]
if data.omitted_posts or !Conf['Show Replies'] and data.replies if data.omitted_posts or !Conf['Show Replies'] and data.replies
[posts, files] = if Conf['Show Replies'] [posts, files] = if Conf['Show Replies']
# XXX data.omitted_images is not accurate. # XXX data.omitted_images is not accurate.

View File

@ -647,6 +647,10 @@ Index =
buildStructure: (nodes) -> buildStructure: (nodes) ->
for node in nodes for node in nodes
if thumb = $ 'img[data-src]', node
thumb.src = thumb.dataset.src
# XXX https://bugzilla.mozilla.org/show_bug.cgi?id=1021289
thumb.removeAttribute 'data-src'
$.add Index.root, [node, $.el 'hr'] $.add Index.root, [node, $.el 'hr']
$.event 'PostsInserted' if doc.contains Index.root $.event 'PostsInserted' if doc.contains Index.root
ThreadHiding.onIndexBuild nodes ThreadHiding.onIndexBuild nodes
@ -661,7 +665,7 @@ Index =
if Index.search if Index.search
Index.searchInput.dataset.searching = 1 Index.searchInput.dataset.searching = 1
else else
# XXX https://github.com/greasemonkey/greasemonkey/issues/1571 # XXX https://bugzilla.mozilla.org/show_bug.cgi?id=1021289
Index.searchInput.removeAttribute 'data-searching' Index.searchInput.removeAttribute 'data-searching'
onSearchInput: -> onSearchInput: ->

View File

@ -18,8 +18,8 @@
(${fileSize}, ${fileDims}) (${fileSize}, ${fileDims})
</div> </div>
<a class="fileThumb?{file.isSpoiler}{ imgspoiler}{}" href="${file.url}" target="_blank"> <a class="fileThumb?{file.isSpoiler}{ imgspoiler}{}" href="${file.url}" target="_blank">
<img <img
src="${file.isSpoiler ? Build.spoilerThumb(boardID) : file.turl}" ?{suppressThumb}{ data-src="${fileThumb}"}{ src="${fileThumb}"}
alt="${fileSize}" alt="${fileSize}"
data-md5="${file.MD5}" data-md5="${file.MD5}"
style="height: ${file.isSpoiler ? 100 : file.theight}px; width: ${file.isSpoiler ? 100 : file.twidth}px;" style="height: ${file.isSpoiler ? 100 : file.theight}px; width: ${file.isSpoiler ? 100 : file.twidth}px;"

View File

@ -65,6 +65,11 @@ class Clone extends Post
@file.thumb.muted = true if @file.videoThumb @file.thumb.muted = true if @file.videoThumb
if @file.thumb?.dataset.src
@file.thumb.src = @file.thumb.dataset.src
# XXX https://bugzilla.mozilla.org/show_bug.cgi?id=1021289
@file.thumb.removeAttribute 'data-src'
# Contract thumbnails in quote preview # Contract thumbnails in quote preview
ImageExpand.contract @ if @file.thumb and contractThumb ImageExpand.contract @ if @file.thumb and contractThumb

View File

@ -38,7 +38,7 @@ ImageLoader =
preload: 'none' preload: 'none'
loop: true loop: true
muted: true muted: true
poster: thumb.src poster: thumb.src or thumb.dataset.src
textContent: thumb.alt textContent: thumb.alt
className: thumb.className className: thumb.className
video.setAttribute 'muted', 'muted' video.setAttribute 'muted', 'muted'
@ -55,7 +55,7 @@ ImageLoader =
{isImage, isVideo, thumb, URL} = file {isImage, isVideo, thumb, URL} = file
return if file.isPrefetched or !(isImage or isVideo) or post.isHidden or post.thread.isHidden return if file.isPrefetched or !(isImage or isVideo) or post.isHidden or post.thread.isHidden
type = if (match = URL.match(/\.([^.]+)$/)[1].toUpperCase()) is 'JPEG' then 'JPG' else match type = if (match = URL.match(/\.([^.]+)$/)[1].toUpperCase()) is 'JPEG' then 'JPG' else match
replace = Conf["Replace #{type}"] and !/spoiler/.test thumb.src replace = Conf["Replace #{type}"] and !/spoiler/.test(thumb.src or thumb.dataset.src)
return unless replace or Conf['prefetch'] return unless replace or Conf['prefetch']
return unless [post, post.clones...].some (clone) -> doc.contains clone.nodes.root return unless [post, post.clones...].some (clone) -> doc.contains clone.nodes.root
file.isPrefetched = true file.isPrefetched = true
@ -72,6 +72,8 @@ ImageLoader =
$.on el, 'load', -> $.on el, 'load', ->
clone.file.thumb.src = URL for clone in post.clones clone.file.thumb.src = URL for clone in post.clones
thumb.src = URL thumb.src = URL
# XXX https://bugzilla.mozilla.org/show_bug.cgi?id=1021289
thumb.removeAttribute 'data-src'
el.src = URL el.src = URL
toggle: -> toggle: ->

View File

@ -13,4 +13,7 @@ RevealSpoilers =
thumb.removeAttribute 'style' thumb.removeAttribute 'style'
# Enforce thumbnail size if thumbnail is replaced. # Enforce thumbnail size if thumbnail is replaced.
thumb.style.maxHeight = thumb.style.maxWidth = if @isReply then '125px' else '250px' thumb.style.maxHeight = thumb.style.maxWidth = if @isReply then '125px' else '250px'
thumb.src = @file.thumbURL if thumb.src
thumb.src = @file.thumbURL
else
thumb.dataset.src = @file.thumbURL