Merge from Appchan X: src/Images

This commit is contained in:
ccd0 2015-01-31 00:40:26 -08:00
parent 8df52a0b24
commit c0f4a85a28
6 changed files with 45 additions and 31 deletions

View File

@ -46,13 +46,13 @@ Gallery =
nodes[key] = $ value, dialog for key, value of { nodes[key] = $ value, dialog for key, value of {
buttons: '.gal-buttons' buttons: '.gal-buttons'
frame: '.gal-image'
name: '.gal-name' name: '.gal-name'
count: '.count' count: '.count'
total: '.total' total: '.total'
frame: '.gal-image' thumbs: '.gal-thumbnails'
next: '.gal-image a' next: '.gal-image a'
current: '.gal-image img' current: '.gal-image img'
thumbs: '.gal-thumbnails'
} }
menuButton = $ '.menu-button', dialog menuButton = $ '.menu-button', dialog
@ -79,8 +79,9 @@ Gallery =
$.on d, 'keydown', cb.keybinds $.on d, 'keydown', cb.keybinds
$.off d, 'keydown', Keybinds.keydown if Conf['Keybinds'] $.off d, 'keydown', Keybinds.keydown if Conf['Keybinds']
for file in $$ '.post .file' when !$ '.fileDeletedRes, .fileDeleted', file for file in $$ '.post .file'
post = Get.postFromNode file post = Get.postFromNode file
continue if !post.file or post.file.isDead
Gallery.generateThumb post Gallery.generateThumb post
# If no image to open is given, pick image we have scrolled to. # If no image to open is given, pick image we have scrolled to.
if !image and Gallery.fullIDs[post.fullID] if !image and Gallery.fullIDs[post.fullID]
@ -136,9 +137,12 @@ Gallery =
$.rmClass el, 'gal-highlight' if el = $ '.gal-highlight', nodes.thumbs $.rmClass el, 'gal-highlight' if el = $ '.gal-highlight', nodes.thumbs
$.addClass thumb, 'gal-highlight' $.addClass thumb, 'gal-highlight'
elType = 'img' elType = if /\.webm$/.test(thumb.href)
elType = 'video' if /\.webm$/.test(thumb.href) 'video'
elType = 'iframe' if /\.pdf$/.test(thumb.href) else if /\.pdf$/.test(thumb.href)
'iframe'
else
'img'
$[if elType is 'iframe' then 'addClass' else 'rmClass'] doc, 'gal-pdf' $[if elType is 'iframe' then 'addClass' else 'rmClass'] doc, 'gal-pdf'
file = $.el elType, file = $.el elType,
@ -313,13 +317,14 @@ Gallery =
createSubEntry: (name) -> createSubEntry: (name) ->
label = UI.checkbox name, " #{name}" label = UI.checkbox name, " #{name}"
input = label.firstElementChild input = label.firstElementChild
$.on input, 'change', Gallery.cb.setFitness if name in ['Fit Width', 'Fit Height', 'Hide Thumbnails']
$.on input, 'change', Gallery.cb.setFitness
$.event 'change', null, input $.event 'change', null, input
$.on input, 'change', $.cb.checked $.on input, 'change', $.cb.checked
el: label el: label
createSubEntries: -> createSubEntries: ->
subEntries = ['Hide Thumbnails', 'Fit Width', 'Fit Height', 'Scroll to Post'].map Gallery.menu.createSubEntry subEntries = (Gallery.menu.createSubEntry item for item in ['Hide Thumbnails', 'Fit Width', 'Fit Height', 'Scroll to Post'])
delayLabel = $.el 'label', <%= html('Slide Delay: <input type="number" name="Slide Delay" min="0" step="any" class="field">') %> delayLabel = $.el 'label', <%= html('Slide Delay: <input type="number" name="Slide Delay" min="0" step="any" class="field">') %>
delayInput = delayLabel.firstElementChild delayInput = delayLabel.firstElementChild

View File

@ -62,7 +62,7 @@ ImageExpand =
if ImageExpand.on = $.hasClass ImageExpand.EAI, 'expand-all-shortcut' if ImageExpand.on = $.hasClass ImageExpand.EAI, 'expand-all-shortcut'
ImageExpand.EAI.className = 'contract-all-shortcut fa fa-compress' ImageExpand.EAI.className = 'contract-all-shortcut fa fa-compress'
ImageExpand.EAI.title = 'Contract All Images' ImageExpand.EAI.title = 'Contract All Images'
func = (post) -> ImageExpand.expand post func = ImageExpand.expand
else else
ImageExpand.EAI.className = 'expand-all-shortcut fa fa-expand' ImageExpand.EAI.className = 'expand-all-shortcut fa fa-expand'
ImageExpand.EAI.title = 'Expand All Images' ImageExpand.EAI.title = 'Expand All Images'
@ -74,19 +74,22 @@ ImageExpand =
playVideos: (e) -> playVideos: (e) ->
g.posts.forEach (post) -> g.posts.forEach (post) ->
for post in [post, post.clones...] when post.file and post.file.isVideo and post.file.isExpanded for post in [post, post.clones...]
video = post.file.fullImage {file} = post
continue unless file and file.isVideo and file.isExpanded
video = file.fullImage
visible = Header.isNodeVisible video visible = Header.isNodeVisible video
if visible and post.file.wasPlaying if visible and file.wasPlaying
delete post.file.wasPlaying delete file.wasPlaying
video.play() video.play()
else if !visible and !video.paused else if !visible and !video.paused
post.file.wasPlaying = true file.wasPlaying = true
video.pause() video.pause()
return return
setFitness: -> setFitness: ->
(if @checked then $.addClass else $.rmClass) doc, @name.toLowerCase().replace /\s+/g, '-' $[if @checked then 'addClass' else 'rmClass'] doc, @name.toLowerCase().replace /\s+/g, '-'
toggle: (post) -> toggle: (post) ->
unless post.file.isExpanding or post.file.isExpanded unless post.file.isExpanding or post.file.isExpanded
@ -218,7 +221,7 @@ ImageExpand =
fullImage.controls = controls fullImage.controls = controls
return return
fullImage.controls = false fullImage.controls = false
$.asap (=> doc.contains fullImage), => $.asap (-> doc.contains fullImage), ->
if !d.hidden and Header.isNodeVisible fullImage if !d.hidden and Header.isNodeVisible fullImage
fullImage.play() fullImage.play()
else else

View File

@ -7,7 +7,7 @@ ImageHover =
cb: @node cb: @node
if Conf['Image Hover in Catalog'] if Conf['Image Hover in Catalog']
CatalogThread.callbacks.push CatalogThread.callbacks.push
name: 'Catalog Image Hover' name: 'Image Hover'
cb: @catalogNode cb: @catalogNode
node: -> node: ->
@ -44,7 +44,7 @@ ImageHover =
el.controls = false el.controls = false
el.muted = !Conf['Allow Sound'] el.muted = !Conf['Allow Sound']
el.play() if Conf['Autoplay'] el.play() if Conf['Autoplay']
[width, height] = file.dimensions.split('x').map (x) -> +x [width, height] = (+x for x in file.dimensions.split 'x')
{left, right} = @getBoundingClientRect() {left, right} = @getBoundingClientRect()
padding = 16 padding = 16
maxWidth = Math.max left, doc.clientWidth - right maxWidth = Math.max left, doc.clientWidth - right

View File

@ -12,14 +12,7 @@ ImageLoader =
g.posts.forEach ImageLoader.prefetch g.posts.forEach ImageLoader.prefetch
if Conf['Replace WEBM'] if Conf['Replace WEBM']
$.on d, 'scroll visibilitychange 4chanXInitFinished PostsInserted', -> $.on d, 'scroll visibilitychange 4chanXInitFinished PostsInserted', @playVideos
# Special case: Quote previews are off screen when inserted into document, but quickly moved on screen.
qpClone = $.id('qp')?.firstElementChild
g.posts.forEach (post) ->
for post in [post, post.clones...] when post.file?.videoThumb
{thumb} = post.file
if Header.isNodeVisible(thumb) or post.nodes.root is qpClone then thumb.play() else thumb.pause()
return
return unless Conf['Image Prefetching'] return unless Conf['Image Prefetching']
@ -27,9 +20,7 @@ ImageLoader =
<%= html('<input type="checkbox" name="prefetch"> Prefetch Images') %> <%= html('<input type="checkbox" name="prefetch"> Prefetch Images') %>
@el = prefetch.firstElementChild @el = prefetch.firstElementChild
$.on @el, 'change', -> $.on @el, 'change', @toggle
if Conf['prefetch'] = @checked
g.posts.forEach ImageLoader.prefetch
Header.menu.addEntry Header.menu.addEntry
el: prefetch el: prefetch
@ -82,3 +73,17 @@ ImageLoader =
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
el.src = URL el.src = URL
toggle: ->
if Conf['prefetch'] = @checked
g.posts.forEach ImageLoader.prefetch
return
playVideos: ->
# Special case: Quote previews are off screen when inserted into document, but quickly moved on screen.
qpClone = $.id('qp')?.firstElementChild
g.posts.forEach (post) ->
for post in [post, post.clones...] when post.file?.videoThumb
{thumb} = post.file
if Header.isNodeVisible(thumb) or post.nodes.root is qpClone then thumb.play() else thumb.pause()
return

View File

@ -1,8 +1,9 @@
RevealSpoilers = RevealSpoilers =
init: -> init: ->
return if g.VIEW not in ['index', 'thread'] or !Conf['Reveal Spoiler Thumbnails'] return unless g.VIEW in ['index', 'thread'] and Conf['Reveal Spoiler Thumbnails']
Post.callbacks.push Post.callbacks.push
name: 'Reveal Spoiler Thumbnails'
cb: @node cb: @node
node: -> node: ->

View File

@ -1,6 +1,6 @@
Sauce = Sauce =
init: -> init: ->
return if g.VIEW not in ['index', 'thread'] or !Conf['Sauce'] return unless g.VIEW in ['index', 'thread'] and Conf['Sauce']
links = [] links = []
for link in Conf['sauces'].split '\n' for link in Conf['sauces'].split '\n'