Merge branch 'v3'

Conflicts:
	LICENSE
	builds/4chan-X.user.js
	builds/crx/script.js
	src/General/css/style.css
	src/Images/Gallery.coffee
This commit is contained in:
Zixaphir 2013-08-25 10:11:46 -07:00
commit 1450e61369
7 changed files with 12072 additions and 43 deletions

11818
builds/4chan-X.user.js Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -381,10 +381,16 @@ Config =
] ]
gallery: gallery:
# Gallery mostly gets its config from imageExpansion
'Hide thumbnails': [ 'Hide thumbnails': [
false false
] ]
# Fit Width =/= Fit width
'Fit Width': [
true
]
'Fit Height': [
true
]
style: style:

View File

@ -164,6 +164,7 @@ Main =
'File Info Formatting': FileInfo 'File Info Formatting': FileInfo
'Fappe Tyme': FappeTyme 'Fappe Tyme': FappeTyme
'Gallery': Gallery 'Gallery': Gallery
'Gallery (menu)': Gallery.menu
'Sauce': Sauce 'Sauce': Sauce
'Image Expansion': ImageExpand 'Image Expansion': ImageExpand
'Image Expansion (Menu)': ImageExpand.menu 'Image Expansion (Menu)': ImageExpand.menu

View File

@ -76,7 +76,7 @@ Gallery =
nodes.menu.toggle e, @, g nodes.menu.toggle e, @, g
{createSubEntry} = Gallery.menu {createSubEntry} = Gallery.menu
for name in ['Fit width', 'Fit height', 'Hide thumbnails'] for name of Config.gallery
{el} = createSubEntry name {el} = createSubEntry name
$.event 'AddMenuEntry', $.event 'AddMenuEntry',
@ -106,14 +106,16 @@ Gallery =
nodes.total.textContent = --i nodes.total.textContent = --i
generateThumb: (file) -> generateThumb: (file) ->
post = Get.postFromNode file
title = ($ '.fileText a', file).textContent title = ($ '.fileText a', file).textContent
thumb = ($ '.fileThumb', file).cloneNode true thumb = post.file.thumb.parentNode.cloneNode true
if double = $ 'img + img', thumb if double = $ 'img + img', thumb
$.rm double $.rm double
thumb.className = 'gal-thumb' thumb.className = 'gal-thumb'
thumb.title = title thumb.title = title
thumb.dataset.id = Gallery.images.length thumb.dataset.id = Gallery.images.length
thumb.dataset.post = $('a[title="Highlight this post"]', post.nodes.info).href
thumb.firstElementChild.style.cssText = '' thumb.firstElementChild.style.cssText = ''
$.on thumb, 'click', Gallery.cb.open $.on thumb, 'click', Gallery.cb.open
@ -140,6 +142,8 @@ Gallery =
open: (e) -> open: (e) ->
e.preventDefault() if e e.preventDefault() if e
return unless @
{nodes} = Gallery {nodes} = Gallery
{name} = nodes {name} = nodes
@ -150,18 +154,62 @@ Gallery =
src: name.href = @href src: name.href = @href
title: name.download = name.textContent = @title title: name.download = name.textContent = @title
img.dataset.id = @dataset.id $.extend img.dataset, @dataset
$.replace nodes.current, img $.replace nodes.current, img
nodes.count.textContent = +@dataset.id + 1 nodes.count.textContent = +@dataset.id + 1
nodes.current = img nodes.current = img
nodes.frame.scrollTop = 0 nodes.frame.scrollTop = 0
nodes.next.focus() nodes.next.focus()
# Scroll
rect = @getBoundingClientRect()
{top} = rect
if top > 0
top += rect.height - doc.clientHeight
return if top < 0
nodes.thumbs.scrollTop += top
$.on img, 'error', ->
Gallery.cb.error img, thumb
image: (e) -> image: (e) ->
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
Gallery.build @ Gallery.build @
error: (img, thumb) ->
post = Get.postFromLink $.el 'a', href: img.dataset.post
delete post.file.fullImage
src = @src.split '/'
if src[2] is 'images.4chan.org'
URL = Redirect.to 'file',
boardID: src[3]
filename: src[5]
if URL
thumb.href = URL
return unless Gallery.nodes.current is img
revived = $.el 'img',
src: URL
title: img.title
$.extend revived.dataset, img.dataset
$.replace img, revived
return
if g.DEAD or post.isDead or post.file.isDead
return
# XXX CORS for images.4chan.org WHEN?
$.ajax "//api.4chan.org/#{post.board}/res/#{post.thread}.json", onload: ->
return if @status isnt 200
i = 0
while postObj = JSON.parse(@response).posts[i++]
break if postObj.no is post.ID
unless postObj.no
return post.kill()
if postObj.filedeleted
post.kill true
prev: -> Gallery.cb.open.call Gallery.images[+Gallery.nodes.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.nodes.current.dataset.id + 1] next: -> Gallery.cb.open.call Gallery.images[+Gallery.nodes.current.dataset.id + 1]
toggle: -> (if Gallery.nodes then Gallery.cb.close else Gallery.build)() toggle: -> (if Gallery.nodes then Gallery.cb.close else Gallery.build)()
@ -175,9 +223,12 @@ Gallery =
$.off d, 'keydown', Gallery.cb.keybinds $.off d, 'keydown', Gallery.cb.keybinds
$.on d, 'keydown', Keybinds.keydown $.on d, 'keydown', Keybinds.keydown
setFitness: ->
(if @checked then $.addClass else $.rmClass) doc, "gal-#{@name.toLowerCase().replace /\s+/g, '-'}"
menu: menu:
init: -> init: ->
return if g.VIEW is 'catalog' or !Conf['Gallery'] or Conf['Image Expansion'] return if g.VIEW is 'catalog' or !Conf['Gallery']
el = $.el 'span', el = $.el 'span',
textContent: 'Gallery' textContent: 'Gallery'
@ -185,7 +236,7 @@ Gallery =
{createSubEntry} = Gallery.menu {createSubEntry} = Gallery.menu
subEntries = [] subEntries = []
for name in ['Fit width', 'Fit height', 'Hide thumbnails'] for name of Config.gallery
subEntries.push createSubEntry name subEntries.push createSubEntry name
$.event 'AddMenuEntry', $.event 'AddMenuEntry',
@ -198,8 +249,8 @@ Gallery =
label = $.el 'label', label = $.el 'label',
innerHTML: "<input type=checkbox name='#{name}'> #{name}" innerHTML: "<input type=checkbox name='#{name}'> #{name}"
input = label.firstElementChild input = label.firstElementChild
# Reusing ImageExpand here because this code doesn't need any auditing to work for what we need if ['Fit Width', 'Fit Height'].contains name
$.on input, 'change', ImageExpand.cb.setFitness $.on input, 'change', Gallery.cb.setFitness
input.checked = Conf[name] input.checked = Conf[name]
$.event 'change', null, input $.event 'change', null, input
$.on input, 'change', $.cb.checked $.on input, 'change', $.cb.checked

View File

@ -497,6 +497,7 @@ QR =
post.setFile file post.setFile file
openFileInput: (e) -> openFileInput: (e) ->
return if e.keyCode and not [32, 13].contains e.keyCode
e.stopPropagation() e.stopPropagation()
if e.shiftKey and e.type is 'click' if e.shiftKey and e.type is 'click'
return QR.selected.rmFile() return QR.selected.rmFile()