Merge from Appchan X: src/Images
This commit is contained in:
parent
8df52a0b24
commit
c0f4a85a28
@ -46,13 +46,13 @@ Gallery =
|
||||
|
||||
nodes[key] = $ value, dialog for key, value of {
|
||||
buttons: '.gal-buttons'
|
||||
frame: '.gal-image'
|
||||
name: '.gal-name'
|
||||
count: '.count'
|
||||
total: '.total'
|
||||
frame: '.gal-image'
|
||||
thumbs: '.gal-thumbnails'
|
||||
next: '.gal-image a'
|
||||
current: '.gal-image img'
|
||||
thumbs: '.gal-thumbnails'
|
||||
}
|
||||
|
||||
menuButton = $ '.menu-button', dialog
|
||||
@ -79,8 +79,9 @@ Gallery =
|
||||
$.on d, 'keydown', cb.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
|
||||
continue if !post.file or post.file.isDead
|
||||
Gallery.generateThumb post
|
||||
# If no image to open is given, pick image we have scrolled to.
|
||||
if !image and Gallery.fullIDs[post.fullID]
|
||||
@ -136,9 +137,12 @@ Gallery =
|
||||
$.rmClass el, 'gal-highlight' if el = $ '.gal-highlight', nodes.thumbs
|
||||
$.addClass thumb, 'gal-highlight'
|
||||
|
||||
elType = 'img'
|
||||
elType = 'video' if /\.webm$/.test(thumb.href)
|
||||
elType = 'iframe' if /\.pdf$/.test(thumb.href)
|
||||
elType = if /\.webm$/.test(thumb.href)
|
||||
'video'
|
||||
else if /\.pdf$/.test(thumb.href)
|
||||
'iframe'
|
||||
else
|
||||
'img'
|
||||
|
||||
$[if elType is 'iframe' then 'addClass' else 'rmClass'] doc, 'gal-pdf'
|
||||
file = $.el elType,
|
||||
@ -313,13 +317,14 @@ Gallery =
|
||||
createSubEntry: (name) ->
|
||||
label = UI.checkbox name, " #{name}"
|
||||
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
|
||||
$.on input, 'change', $.cb.checked
|
||||
el: label
|
||||
|
||||
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">') %>
|
||||
delayInput = delayLabel.firstElementChild
|
||||
|
||||
@ -62,7 +62,7 @@ ImageExpand =
|
||||
if ImageExpand.on = $.hasClass ImageExpand.EAI, 'expand-all-shortcut'
|
||||
ImageExpand.EAI.className = 'contract-all-shortcut fa fa-compress'
|
||||
ImageExpand.EAI.title = 'Contract All Images'
|
||||
func = (post) -> ImageExpand.expand post
|
||||
func = ImageExpand.expand
|
||||
else
|
||||
ImageExpand.EAI.className = 'expand-all-shortcut fa fa-expand'
|
||||
ImageExpand.EAI.title = 'Expand All Images'
|
||||
@ -74,19 +74,22 @@ ImageExpand =
|
||||
|
||||
playVideos: (e) ->
|
||||
g.posts.forEach (post) ->
|
||||
for post in [post, post.clones...] when post.file and post.file.isVideo and post.file.isExpanded
|
||||
video = post.file.fullImage
|
||||
for post in [post, post.clones...]
|
||||
{file} = post
|
||||
continue unless file and file.isVideo and file.isExpanded
|
||||
|
||||
video = file.fullImage
|
||||
visible = Header.isNodeVisible video
|
||||
if visible and post.file.wasPlaying
|
||||
delete post.file.wasPlaying
|
||||
if visible and file.wasPlaying
|
||||
delete file.wasPlaying
|
||||
video.play()
|
||||
else if !visible and !video.paused
|
||||
post.file.wasPlaying = true
|
||||
file.wasPlaying = true
|
||||
video.pause()
|
||||
return
|
||||
|
||||
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) ->
|
||||
unless post.file.isExpanding or post.file.isExpanded
|
||||
@ -218,7 +221,7 @@ ImageExpand =
|
||||
fullImage.controls = controls
|
||||
return
|
||||
fullImage.controls = false
|
||||
$.asap (=> doc.contains fullImage), =>
|
||||
$.asap (-> doc.contains fullImage), ->
|
||||
if !d.hidden and Header.isNodeVisible fullImage
|
||||
fullImage.play()
|
||||
else
|
||||
|
||||
@ -7,7 +7,7 @@ ImageHover =
|
||||
cb: @node
|
||||
if Conf['Image Hover in Catalog']
|
||||
CatalogThread.callbacks.push
|
||||
name: 'Catalog Image Hover'
|
||||
name: 'Image Hover'
|
||||
cb: @catalogNode
|
||||
|
||||
node: ->
|
||||
@ -44,7 +44,7 @@ ImageHover =
|
||||
el.controls = false
|
||||
el.muted = !Conf['Allow Sound']
|
||||
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()
|
||||
padding = 16
|
||||
maxWidth = Math.max left, doc.clientWidth - right
|
||||
|
||||
@ -12,14 +12,7 @@ ImageLoader =
|
||||
g.posts.forEach ImageLoader.prefetch
|
||||
|
||||
if Conf['Replace WEBM']
|
||||
$.on d, 'scroll visibilitychange 4chanXInitFinished PostsInserted', ->
|
||||
# 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
|
||||
$.on d, 'scroll visibilitychange 4chanXInitFinished PostsInserted', @playVideos
|
||||
|
||||
return unless Conf['Image Prefetching']
|
||||
|
||||
@ -27,9 +20,7 @@ ImageLoader =
|
||||
<%= html('<input type="checkbox" name="prefetch"> Prefetch Images') %>
|
||||
|
||||
@el = prefetch.firstElementChild
|
||||
$.on @el, 'change', ->
|
||||
if Conf['prefetch'] = @checked
|
||||
g.posts.forEach ImageLoader.prefetch
|
||||
$.on @el, 'change', @toggle
|
||||
|
||||
Header.menu.addEntry
|
||||
el: prefetch
|
||||
@ -82,3 +73,17 @@ ImageLoader =
|
||||
clone.file.thumb.src = URL for clone in post.clones
|
||||
thumb.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
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
RevealSpoilers =
|
||||
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
|
||||
name: 'Reveal Spoiler Thumbnails'
|
||||
cb: @node
|
||||
|
||||
node: ->
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
Sauce =
|
||||
init: ->
|
||||
return if g.VIEW not in ['index', 'thread'] or !Conf['Sauce']
|
||||
return unless g.VIEW in ['index', 'thread'] and Conf['Sauce']
|
||||
|
||||
links = []
|
||||
for link in Conf['sauces'].split '\n'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user