From 4ed1e1fe7a7317c0f2f67e459721240d7c75e1af Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Mon, 7 Apr 2014 10:33:52 -0700 Subject: [PATCH] Implement webm thumbnail replacement. Conflicts: LICENSE builds/4chan-X-beta.user.js builds/4chan-X.user.js src/General/css/style.css src/Images/AutoGIF.coffee src/Images/Gallery.coffee src/Images/ImageLoader.coffee --- src/General/Config.coffee | 16 +++++++----- src/General/css/style.css | 1 + src/Images/AutoGIF.coffee | 20 --------------- src/Images/ImageLoader.coffee | 48 ++++++++++++++++++++++++----------- 4 files changed, 44 insertions(+), 41 deletions(-) delete mode 100644 src/Images/AutoGIF.coffee diff --git a/src/General/Config.coffee b/src/General/Config.coffee index ef4a23063..7207d8dbf 100755 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -173,15 +173,19 @@ Config = ] 'Replace GIF': [ false - 'Replace thumbnail of gifs with its actual image.' - ] - 'Replace PNG': [ - false - 'Replace pngs.' + 'Replace gif thumbnails with the actual image.' ] 'Replace JPG': [ false - 'Replace jpgs.' + 'Replace jpg thumbnails with the actual image.' + ] + 'Replace PNG': [ + false + 'Replace png thumbnails with the actual image.' + ] + 'Replace WEBM': [ + false + 'Replace webm thumbnails with the actual webm video. Probably will degrade browser performance ;)' ] 'Image Prefetching': [ false diff --git a/src/General/css/style.css b/src/General/css/style.css index 187052c6e..9617f5a43 100755 --- a/src/General/css/style.css +++ b/src/General/css/style.css @@ -711,6 +711,7 @@ span.hide-announcement { /* File */ .fnswitch:hover > .fntrunc, .fnswitch:not(:hover) > .fnfull, +.expanded-image > .post > .file > .fileThumb > video[data-md5], .expanded-image > .post > .file > .fileThumb > img[data-md5] { display: none; } diff --git a/src/Images/AutoGIF.coffee b/src/Images/AutoGIF.coffee deleted file mode 100644 index 71ccc7d8e..000000000 --- a/src/Images/AutoGIF.coffee +++ /dev/null @@ -1,20 +0,0 @@ -AutoGIF = - init: -> - return if g.VIEW is 'catalog' or !Conf['Auto-GIF'] or g.BOARD.ID in ['gif', 'wsg'] - - Post.callbacks.push - name: 'Auto-GIF' - cb: @node - node: -> - return if @isClone or @isHidden or @thread.isHidden or !@file?.isImage - {thumb, URL} = @file - return unless /gif$/.test(URL) and !/spoiler/.test thumb.src - if @file.isSpoiler - # Revealed spoilers do not have height/width set, this fixes auto-gifs dimensions. - {style} = thumb - style.maxHeight = style.maxWidth = if @isReply then '125px' else '250px' - gif = $.el 'img' - $.on gif, 'load', -> - # Replace the thumbnail once the GIF has finished loading. - thumb.src = URL - gif.src = URL diff --git a/src/Images/ImageLoader.coffee b/src/Images/ImageLoader.coffee index 7fc8337c4..a7d71dac9 100755 --- a/src/Images/ImageLoader.coffee +++ b/src/Images/ImageLoader.coffee @@ -1,18 +1,16 @@ ImageLoader = init: -> return if g.VIEW is 'catalog' - return unless Conf["Image Prefetching"] or Conf["Replace JPG"] or Conf["Replace PNG"] or Conf["Replace GIF"] + return unless Conf["Image Prefetching"] or Conf["Replace JPG"] or Conf["Replace PNG"] or Conf["Replace GIF"] or Conf["Replace WEBM"] Post.callbacks.push name: 'Image Replace' cb: @node - + Thread.callbacks.push name: 'Image Replace' cb: @thread - - return unless Conf['Image Prefetching'] and g.VIEW is 'thread' - + prefetch = $.el 'label', <%= html(' Prefetch Images') %> @@ -22,27 +20,47 @@ ImageLoader = Header.menu.addEntry el: prefetch order: 104 - + thread: -> ImageLoader.thread = @ node: -> - return if @isClone or @isHidden or @thread.isHidden or !@file?.isImage + return unless @file + {isImage, isVideo} = @file + return if @isClone or @isHidden or @thread.isHidden or !(isImage or isVideo) {thumb, URL} = @file - return unless (Conf[string = "Replace #{if (type = (URL.match /\w{3}$/)[0].toUpperCase()) is 'PEG' then 'JPG' else type}"] and !/spoiler/.test thumb.src) or Conf['prefetch'] + {style} = thumb + type = if (match = URL.match(/\.([^.]+)$/)[1].toUpperCase()) is 'JPEG' then 'JPG' else match + replace = "Replace #{type}" + return unless (Conf[replace] and !/spoiler/.test thumb.src) or (Conf['prefetch'] and g.VIEW is 'thread') if @file.isSpoiler # Revealed spoilers do not have height/width set, this fixes the image's dimensions. - {style} = thumb style.maxHeight = style.maxWidth = if @isReply then '125px' else '250px' - img = $.el 'img' - if Conf[string] - $.on img, 'load', -> - # Replace the thumbnail once the GIF has finished loading. + file = $.el if isImage then 'img' else 'video' + if Conf[replace] + if isVideo + + file.alt = thumb.alt + file.dataset.md5 = thumb.dataset.md5 + file.style.height = style.height + file.style.width = style.width + file.style.maxHeight = style.maxHeight + file.style.maxWidth = style.maxWidth + file.loop = true + file.autoplay = Conf['Autoplay'] + if Conf['Image Hover'] + $.on file, 'mouseover', ImageHover.mouseover + $.on file, 'load loadedmetadata', => + # Replace the thumbnail once the file has finished loading. + if isVideo + $.replace thumb, file + @file.thumb = file # XXX expanding requires the post.file.thumb node. + return thumb.src = URL - img.src = URL + file.src = URL toggle: -> enabled = Conf['prefetch'] = @checked if enabled - ImageLoader.thread.posts.forEach (post) -> ImageLoader.node.call post + g.BOARD.posts.forEach (post) -> ImageLoader.node.call post return