diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 1e19b7e32..3ada33895 100755 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -57,7 +57,9 @@ Main = Redirect.navigate URL else if Conf['Loop in New Tab'] and video = $ 'video' video.loop = true - Video.start video + video.controls = false + video.play() + ImageCommon.addControls video return if Conf['Normalize URL'] and g.VIEW is 'thread' diff --git a/src/Images/Gallery.coffee b/src/Images/Gallery.coffee index 716fc3d24..9c069be2b 100644 --- a/src/Images/Gallery.coffee +++ b/src/Images/Gallery.coffee @@ -160,8 +160,8 @@ Gallery = $.replace nodes.current, file if elType is 'video' file.loop = true - file.controls = Conf['Show Controls'] - Video.start file if Conf['Autoplay'] + file.play() if Conf['Autoplay'] + ImageCommon.addControls file if Conf['Show Controls'] nodes.count.textContent = +@dataset.id + 1 nodes.current = file nodes.frame.scrollTop = 0 @@ -216,7 +216,7 @@ Gallery = Gallery.cb.cleanupTimer() {current} = Gallery.nodes isVideo = current.nodeName is 'VIDEO' - Video.start current if isVideo + current.play() if isVideo if (if isVideo then current.readyState > 4 else current.complete) or current.nodeName is 'IFRAME' Gallery.cb.startTimer() else diff --git a/src/Images/ImageCommon.coffee b/src/Images/ImageCommon.coffee index ef9737735..542fcfa41 100644 --- a/src/Images/ImageCommon.coffee +++ b/src/Images/ImageCommon.coffee @@ -42,3 +42,11 @@ ImageCommon = filename: post.file.URL if URL and (/^https:\/\//.test(URL) or location.protocol is 'http:') return cb URL + + addControls: (video) -> + handler = -> + $.off video, 'mouseover', handler + # Hacky workaround for Firefox forever-loading bug for very short videos + $.asap (-> (video.readyState >= 3 and video.currentTime <= Math.max 0.1, (video.duration - 0.5)) or !d.contains video), -> + video.controls = true + $.on video, 'mouseover', handler diff --git a/src/Images/ImageExpand.coffee b/src/Images/ImageExpand.coffee index 18e4682f3..6a8114eb5 100755 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -171,9 +171,9 @@ ImageExpand = video = file.fullImage video.loop = true - video.controls = Conf['Show Controls'] ImageExpand.setupVideoCB post ImageExpand.play post if Conf['Autoplay'] + ImageCommon.addControls video if Conf['Show Controls'] # Scroll to keep our place in the thread when images are expanded above us. if oldBottom? and oldBottom <= 0 @@ -181,7 +181,7 @@ ImageExpand = play: (post) -> if !d.hidden and Header.isNodeVisible post.file.fullImage - Video.start post.file.fullImage + post.file.fullImage.play() else post.file.wasPlaying = true diff --git a/src/Images/Video.coffee b/src/Images/Video.coffee deleted file mode 100644 index 3215c5f0c..000000000 --- a/src/Images/Video.coffee +++ /dev/null @@ -1,12 +0,0 @@ -Video = - start: (video) -> - return unless video.paused - {controls} = video - video.controls = false - video.play() - # Hacky workaround for Firefox forever-loading bug for very short videos - if controls - $.asap (-> (video.readyState >= 3 and video.currentTime <= Math.max 0.1, (video.duration - 0.5)) or !d.contains video), -> - video.controls = true - , 500 -