Gallery stuff.

This commit is contained in:
Zixaphir 2013-08-23 14:37:20 -07:00
parent fafc46952f
commit 8c1ac1710a
6 changed files with 323 additions and 121 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -397,6 +397,12 @@ Config =
'Advance to next post when contracting an expanded image.' 'Advance to next post when contracting an expanded image.'
] ]
gallery:
# Gallery mostly gets its config from imageExpansion
'Hide thumbnails': [
false
]
threadWatcher: threadWatcher:
'Current Board': [ 'Current Board': [
false false

View File

@ -1097,7 +1097,6 @@ a:only-of-type > .remove {
<%= align %>-items: stretch; <%= align %>-items: stretch;
<%= flex %>-direction: row; <%= flex %>-direction: row;
<%= flex %>: 1 1 auto; <%= flex %>: 1 1 auto;
position: relative;
} }
.gal-thumbnails { .gal-thumbnails {
<%= flex %>: 0 0 150px; <%= flex %>: 0 0 150px;
@ -1107,24 +1106,29 @@ a:only-of-type > .remove {
<%= align %>-items: stretch; <%= align %>-items: stretch;
text-align: center; text-align: center;
} }
.gal-thumbnails img { .hide-thumbnails .gal-thumbnails {
display: none;
}
.gal-thumb img {
max-width: 125px; max-width: 125px;
max-height: 125px; max-height: 125px;
height: auto; height: auto;
width: auto; width: auto;
} }
.gal-thumbnails a { .gal-thumb {
<%= flex %>: 0 0 auto; <%= flex %>: 0 0 auto;
padding: 3px; padding: 3px;
line-height: 0; line-height: 0;
transition: background .3s linear; transition: background .3s linear;
background: rgba(0,0,0,.5); background: rgba(0,0,0,.5);
border-left: 1px solid #222;
} }
.gal-highlight { .gal-highlight {
background: rgb(190, 190, 255); background: rgb(190, 190, 255);
} }
.gal-prev { .gal-prev {
order: 0; order: 0;
border-right: 1px solid #222;
} }
.gal-next { .gal-next {
order: 2; order: 2;
@ -1135,7 +1139,6 @@ a:only-of-type > .remove {
<%= flex %>: 0 0 20px; <%= flex %>: 0 0 20px;
position: relative; position: relative;
cursor: pointer; cursor: pointer;
border-right: 1px solid #222;
opacity: 0.7; opacity: 0.7;
background-color: rgba(0, 0, 0, 0.3); background-color: rgba(0, 0, 0, 0.3);
} }
@ -1167,30 +1170,46 @@ a:only-of-type > .remove {
display: <%= flex %>; display: <%= flex %>;
<%= align %>-items: flex-start; <%= align %>-items: flex-start;
<%= justify %>: space-around; <%= justify %>: space-around;
overflow: hidden; overflow: auto;
/* Flex > Non-Flex child max-width and overflow fix (Firefox only?) */ /* Flex > Non-Flex child max-width and overflow fix (Firefox only?) */
width: 1%; width: 1%;
} }
.gal-image a { .gal-image a {
margin: auto; margin: auto;
line-height: 0;
} }
.gal-image img { .fit-width .gal-image img {
max-width: 100%; max-width: 100%;
max-height: 100vh;
} }
.gal-close { .fit-height .gal-image img {
max-height: calc(100vh - 25px);
}
.gal-buttons {
font-size: 2em; font-size: 2em;
padding-right: 8px; margin-right: 10px;
position: fixed;
top: 5px; top: 5px;
right: 180px;
color: #ffffff; color: #ffffff;
text-shadow: 0px 0px 1px #000000; text-shadow: 0px 0px 1px #000000;
} }
.gal-name { .gal-buttons i {
vertical-align: baseline;
border-top-width: .5em;
border-right-width: .3em;
border-left-width: .3em;
}
.gal-buttons,
.gal-name,
.gal-count {
position: fixed; position: fixed;
bottom: 5px;
right: 178px; right: 178px;
}
.hide-thumbnails .gal-buttons,
.hide-thumbnails .gal-count,
.hide-thumbnails .gal-name {
right: 28px;
}
.gal-name {
bottom: 5px;
background: rgba(0,0,0,0.6) !important; background: rgba(0,0,0,0.6) !important;
border-radius: 3px; border-radius: 3px;
padding: 1px 5px 2px 5px; padding: 1px 5px 2px 5px;
@ -1202,9 +1221,7 @@ a:only-of-type > .remove {
color: rgb(95, 95, 101) !important; color: rgb(95, 95, 101) !important;
} }
.gal-count { .gal-count {
position: fixed;
bottom: 26px; bottom: 26px;
right: 178px;
background: rgba(0,0,0,0.6) !important; background: rgba(0,0,0,0.6) !important;
border-radius: 3px; border-radius: 3px;
padding: 1px 5px 2px 5px; padding: 1px 5px 2px 5px;

View File

@ -19,19 +19,25 @@ Gallery =
node: -> node: ->
return unless @file?.isImage return unless @file?.isImage
if Gallery.el if Gallery.nodes
Gallery.generateThumb $ '.file', @nodes.root Gallery.generateThumb $ '.file', @nodes.root
Gallery.total.textContent = Gallery.images.length Gallery.nodes.total.textContent = Gallery.images.length
unless Conf['Image Expansion'] unless Conf['Image Expansion']
$.on @file.thumb.parentNode, 'click', Gallery.cb.image $.on @file.thumb.parentNode, 'click', Gallery.cb.image
build: (image) -> build: (image) ->
Gallery.el = dialog = $.el 'div', Gallery.images = []
nodes = Gallery.nodes = {}
nodes.el = dialog = $.el 'div',
id: 'a-gallery' id: 'a-gallery'
innerHTML: """ innerHTML: """
<div class=gal-viewport> <div class=gal-viewport>
<span class=gal-buttons>
<a class="menu-button" href="javascript:;"><i></i></a>
<a href=javascript:; class=gal-close>×</a> <a href=javascript:; class=gal-close>×</a>
</span>
<a class=gal-name target="_blank"></a> <a class=gal-name target="_blank"></a>
<span class=gal-count><span class='count'></span> / <span class='total'></span></a></span> <span class=gal-count><span class='count'></span> / <span class='total'></span></a></span>
<div class=gal-prev></div> <div class=gal-prev></div>
@ -42,7 +48,8 @@ Gallery =
</div> </div>
<div class=gal-thumbnails></div> <div class=gal-thumbnails></div>
""" """
Gallery[key] = $ value, dialog for key, value of {
nodes[key] = $ value, dialog for key, value of {
frame: '.gal-image' frame: '.gal-image'
name: '.gal-name' name: '.gal-name'
count: '.count' count: '.count'
@ -52,26 +59,41 @@ Gallery =
current: '.gal-image img' current: '.gal-image img'
} }
Gallery.images = [] menuButton = $ '.menu-button', dialog
nodes.menu = new UI.Menu 'gallery'
$.on Gallery.frame, 'click', Gallery.cb.blank {cb} = Gallery
$.on Gallery.current, 'click', Gallery.cb.download $.on nodes.frame, 'click', cb.blank
$.on Gallery.next, 'click', Gallery.cb.next $.on nodes.current, 'click', cb.download
$.on ($ '.gal-prev', dialog), 'click', Gallery.cb.prev $.on nodes.next, 'click', cb.next
$.on ($ '.gal-next', dialog), 'click', Gallery.cb.next $.on ($ '.gal-prev', dialog), 'click', cb.prev
$.on ($ '.gal-close', dialog), 'click', Gallery.cb.close $.on ($ '.gal-next', dialog), 'click', cb.next
$.on ($ '.gal-close', dialog), 'click', cb.close
$.on d, 'keydown', Gallery.cb.keybinds $.on menuButton, 'click', (e) ->
nodes.menu.toggle e, @, g
{createSubEntry} = Gallery.menu
for name in ['Fit width', 'Fit height', 'Hide thumbnails']
{el} = createSubEntry name
$.event 'AddMenuEntry',
type: 'gallery'
el: el
order: 0
$.on d, 'keydown', cb.keybinds
$.off d, 'keydown', Keybinds.keydown $.off d, 'keydown', Keybinds.keydown
i = 0 i = 0
files = $$ '.post .file' files = $$ '.post .file'
while file = files[i++] while file = files[i++]
continue if $ '.fileDeletedRes, .fileDeleted', file
Gallery.generateThumb file Gallery.generateThumb file
$.add d.body, dialog $.add d.body, dialog
Gallery.thumbs.scrollTop = 0 nodes.thumbs.scrollTop = 0
Gallery.current.parentElement.scrollTop = 0 nodes.current.parentElement.scrollTop = 0
Gallery.cb.open.call if image Gallery.cb.open.call if image
$ "[href='#{image.href.replace /https?:/, ''}']", Gallery.thumbs $ "[href='#{image.href.replace /https?:/, ''}']", Gallery.thumbs
@ -79,7 +101,7 @@ Gallery =
Gallery.images[0] Gallery.images[0]
d.body.style.overflow = 'hidden' d.body.style.overflow = 'hidden'
Gallery.total.textContent = --i nodes.total.textContent = --i
generateThumb: (file) -> generateThumb: (file) ->
title = ($ '.fileText a', file).textContent title = ($ '.fileText a', file).textContent
@ -87,7 +109,7 @@ Gallery =
if double = $ 'img + img', thumb if double = $ 'img + img', thumb
$.rm double $.rm double
thumb.className = 'a-thumb' thumb.className = 'gal-thumb'
thumb.title = title thumb.title = title
thumb.dataset.id = Gallery.images.length thumb.dataset.id = Gallery.images.length
thumb.firstElementChild.style.cssText = '' thumb.firstElementChild.style.cssText = ''
@ -95,7 +117,7 @@ Gallery =
$.on thumb, 'click', Gallery.cb.open $.on thumb, 'click', Gallery.cb.open
Gallery.images.push thumb Gallery.images.push thumb
$.add Gallery.thumbs, thumb $.add Gallery.nodes.thumbs, thumb
cb: cb:
keybinds: (e) -> keybinds: (e) ->
@ -116,35 +138,67 @@ Gallery =
open: (e) -> open: (e) ->
e.preventDefault() if e e.preventDefault() if e
{nodes} = Gallery
{name} = nodes
$.rmClass el, 'gal-highlight' if el = $ '.gal-highlight', Gallery.thumbs $.rmClass el, 'gal-highlight' if el = $ '.gal-highlight', Gallery.thumbs
$.addClass @, 'gal-highlight' $.addClass @, 'gal-highlight'
img = $.el 'img', img = $.el 'img',
src: Gallery.name.href = @href src: name.href = @href
title: Gallery.name.download = Gallery.name.textContent = @title title: name.download = name.textContent = @title
img.dataset.id = @dataset.id img.dataset.id = @dataset.id
$.replace Gallery.current, img $.replace nodes.current, img
Gallery.count.textContent = +@dataset.id + 1 nodes.count.textContent = +@dataset.id + 1
Gallery.current = img nodes.current = img
Gallery.frame.scrollTop = 0 nodes.frame.scrollTop = 0
Gallery.current.focus() nodes.current.focus()
image: (e) -> image: (e) ->
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
Gallery.build @ Gallery.build @
prev: -> Gallery.cb.open.call Gallery.images[+Gallery.current.dataset.id - 1] prev: -> Gallery.cb.open.call Gallery.images[+Gallery.nodes.current.dataset.id - 1]
next: -> Gallery.cb.open.call Gallery.images[+Gallery.current.dataset.id + 1] next: -> Gallery.cb.open.call Gallery.images[+Gallery.nodes.current.dataset.id + 1]
toggle: -> (if Gallery.el then Gallery.cb.close else Gallery.build)() toggle: -> (if Gallery.nodes then Gallery.cb.close else Gallery.build)()
blank: (e) -> Gallery.cb.close() if e.target is @ blank: (e) -> Gallery.cb.close() if e.target is @
close: -> close: ->
$.rm Gallery.el $.rm Gallery.nodes.el
delete Gallery.el delete Gallery.nodes
d.body.style.overflow = '' d.body.style.overflow = ''
$.off d, 'keydown', Gallery.cb.keybinds $.off d, 'keydown', Gallery.cb.keybinds
$.on d, 'keydown', Keybinds.keydown $.on d, 'keydown', Keybinds.keydown
menu:
init: ->
return if g.VIEW is 'catalog' or !Conf['Gallery'] or Conf['Image Expansion']
el = $.el 'span',
textContent: 'Gallery'
className: 'gallery-link'
{createSubEntry} = Gallery.menu
subEntries = []
for name in ['Fit width', 'Fit height', 'Hide thumbnails']
subEntries.push createSubEntry name
$.event 'AddMenuEntry',
type: 'header'
el: el
order: 105
subEntries: subEntries
createSubEntry: (name) ->
label = $.el 'label',
innerHTML: "<input type=checkbox name='#{name}'> #{name}"
input = label.firstElementChild
# Reusing ImageExpand here because this code doesn't need any auditing to work for what we need
$.on input, 'change', ImageExpand.cb.setFitness
input.checked = Conf[name]
$.event 'change', null, input
$.on input, 'change', $.cb.checked
el: label

View File

@ -189,6 +189,3 @@ ImageExpand =
$.event 'change', null, input $.event 'change', null, input
$.on input, 'change', $.cb.checked $.on input, 'change', $.cb.checked
el: label el: label
menuToggle: (e) ->
ImageExpand.opmenu.toggle e, @, g