From bed88c3324bccfb05379772bd9f421e9b59ffd03 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 25 Jan 2015 09:41:48 -0800 Subject: [PATCH] Remove contract button; work around controls by estimating their position. --- src/General/Config.coffee | 2 +- src/General/lib/clone.class | 1 - src/Images/Gallery.coffee | 9 +++++--- src/Images/ImageCommon.coffee | 4 ++++ src/Images/ImageExpand.coffee | 39 ++++++----------------------------- 5 files changed, 17 insertions(+), 38 deletions(-) diff --git a/src/General/Config.coffee b/src/General/Config.coffee index dcc8d3f73..0153016a9 100755 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -242,7 +242,7 @@ Config = ] 'Show Controls': [ true - 'Show controls on videos expanded inline. Turn this off if you want to contract videos by clicking on them.' + 'Show controls on videos expanded inline.' ] 'Loop in New Tab': [ true diff --git a/src/General/lib/clone.class b/src/General/lib/clone.class index d40c4dcea..dc81d1433 100755 --- a/src/General/lib/clone.class +++ b/src/General/lib/clone.class @@ -60,7 +60,6 @@ class Clone extends Post @file.text = file.firstElementChild @file.thumb = $ '.fileThumb > [data-md5]', file @file.fullImage = $ '.full-image', file - @file.videoControls = $ '.video-controls', @file.text # Contract thumbnails in quote preview ImageExpand.contract @ if contractThumb diff --git a/src/Images/Gallery.coffee b/src/Images/Gallery.coffee index 6b25855db..3538af6f0 100644 --- a/src/Images/Gallery.coffee +++ b/src/Images/Gallery.coffee @@ -209,7 +209,7 @@ Gallery = when 'Right' Gallery.cb.next when 'Enter' - Gallery.cb.enterKey + Gallery.cb.advance when 'Left', '' Gallery.cb.prev when Conf['Pause'] @@ -239,8 +239,11 @@ Gallery = Gallery.cb.open.call( Gallery.images[+Gallery.nodes.current.dataset.id + 1] or Gallery.images[0] ) - enterKey: -> if Gallery.nodes.current.paused then Gallery.nodes.current.play() else Gallery.cb.next() - click: -> Gallery.cb[if Gallery.nodes.current.controls then 'stop' else 'enterKey']() + click: (e) -> + return if ImageCommon.onControls e + e.preventDefault() + Gallery.cb.advance() + advance: -> if Gallery.nodes.current.paused then Gallery.nodes.current.play() else Gallery.cb.next() toggle: -> (if Gallery.nodes then Gallery.cb.close else Gallery.build)() blank: (e) -> Gallery.cb.close() if e.target is @ toggleSlideshow: -> Gallery.cb[if Gallery.slideshow then 'stop' else 'start']() diff --git a/src/Images/ImageCommon.coffee b/src/Images/ImageCommon.coffee index 2c55fbbbf..3ee657eea 100644 --- a/src/Images/ImageCommon.coffee +++ b/src/Images/ImageCommon.coffee @@ -79,3 +79,7 @@ ImageCommon = $.asap (-> chrome? or (video.readyState >= 3 and video.currentTime <= Math.max 0.1, (video.duration - 0.5)) or new Date().getTime() >= t + 1000), -> video.controls = true $.on video, 'mouseover', handler + + # XXX Estimate whether clicks are on the video controls and should be ignored. + onControls: (e) -> + e.target.controls and e.target.getBoundingClientRect().bottom - e.clientY < 35 diff --git a/src/Images/ImageExpand.coffee b/src/Images/ImageExpand.coffee index fe393f1ed..e903cbd6e 100755 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -10,8 +10,6 @@ ImageExpand = $.on @EAI, 'click', @cb.toggleAll Header.addShortcut @EAI, 3 $.on d, 'scroll visibilitychange', @cb.playVideos - @videoControls = $.el 'span', className: 'video-controls' - $.extend @videoControls, <%= html('\u00A0contract') %> Post.callbacks.push name: 'Image Expansion' @@ -27,7 +25,6 @@ ImageExpand = ImageExpand.contract @ ImageExpand.expand @ else if @file.isExpanded and @file.isVideo - ImageExpand.setupVideoCB @ ImageExpand.setupVideo @, !@origin.file.fullImage?.paused or @origin.file.wasPlaying, @file.fullImage.controls else if ImageExpand.on and !@isHidden and !@isFetchedQuote and (Conf['Expand spoilers'] or !@file.isSpoiler) and @@ -39,9 +36,12 @@ ImageExpand = return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0 post = Get.postFromNode @ {file} = post - return if file.isExpanded and file.isVideo and file.fullImage.controls + return if file.isExpanded and ImageCommon.onControls e e.preventDefault() - ImageExpand.toggle post + if file.fullImage?.paused + file.fullImage.play() + else + ImageExpand.toggle post toggleAll: -> $.event 'CloseMenu' @@ -110,10 +110,9 @@ ImageExpand = $.rmClass post.nodes.root, 'expanded-image' $.rmClass file.thumb, 'expanding' - $.rm file.videoControls if file.videoControls file.thumb.parentNode.href = file.URL file.thumb.parentNode.target = '_blank' - for x in ['isExpanding', 'isExpanded', 'videoControls', 'wasPlaying', 'scrollIntoView'] + for x in ['isExpanding', 'isExpanded', 'wasPlaying', 'scrollIntoView'] delete file[x] return unless el @@ -133,8 +132,6 @@ ImageExpand = ImageCommon.pushCache el if file.isVideo el.pause() - for eventName, cb of ImageExpand.videoCB - $.off el, eventName, cb ImageCommon.rewind file.thumb if Conf['Restart when Opened'] delete file.fullImage $.queueTask -> @@ -170,17 +167,11 @@ ImageExpand = $.after thumb, el if isVideo - # add contract link to file info - if Conf['Show Controls'] and !file.videoControls - file.videoControls = ImageExpand.videoControls.cloneNode true - $.add file.text, file.videoControls - # disable link to file so native controls can work thumb.parentNode.removeAttribute 'href' thumb.parentNode.removeAttribute 'target' el.loop = true - ImageExpand.setupVideoCB post if !isVideo $.asap (-> el.naturalHeight), -> ImageExpand.completeExpand post @@ -230,24 +221,6 @@ ImageExpand = if controls ImageCommon.addControls fullImage - videoCB: do -> - # dragging to the left contracts the video - mousedown = false - mouseover: -> mousedown = false - mousedown: (e) -> mousedown = true if e.button is 0 - mouseup: (e) -> mousedown = false if e.button is 0 - mouseout: (e) -> ImageExpand.toggle(Get.postFromNode @) if mousedown and e.clientX <= @getBoundingClientRect().left - click: (e) -> - if @paused and not @controls - @play() - e.stopPropagation() - - setupVideoCB: (post) -> - for eventName, cb of ImageExpand.videoCB - $.on post.file.fullImage, eventName, cb - if post.file.videoControls - $.on post.file.videoControls.firstElementChild, 'click', -> ImageExpand.toggle post - error: -> post = Get.postFromNode @ $.rm @