This commit is contained in:
Mayhem 2014-04-05 00:32:44 +02:00
parent 92ac7893d3
commit 0bc93400c1
10 changed files with 48 additions and 35 deletions

View File

@ -1,3 +1,5 @@
- Add support for .webm files.
### 3.19.5 - *2014-04-03*
- Fix captcha submission:<br>

View File

@ -146,7 +146,8 @@ Filter =
return post.file.name
false
dimensions: (post) ->
if post.file and post.file.isImage
{file} = post
if file and (file.isImage or file.isVideo)
return post.file.dimensions
false
filesize: (post) ->

View File

@ -7,8 +7,9 @@ Build =
# OPs have a +10 characters threshold.
# The file extension is not taken into account.
threshold = if isReply then 30 else 40
if filename.length - 4 > threshold
"#{filename[...threshold - 5]}(...).#{filename[-3..]}"
ext = filename.match(/\.[^.]+$/)[0]
if filename.length - ext.length > threshold
"#{filename[...threshold - 5]}(...)#{ext}"
else
filename
thumbRotate: do ->

View File

@ -113,7 +113,7 @@ class Post
parseFile: (that) ->
return unless (fileEl = $ '.file', @nodes.post) and thumb = $ 'img[data-md5]', fileEl
# Supports JPG/PNG/GIF/PDF.
# Supports JPG/PNG/GIF/WEBM/PDF.
# Flash files are not supported.
anchor = thumb.parentNode
fileText = fileEl.firstElementChild
@ -144,7 +144,9 @@ class Post
# http://www.whatwg.org/specs/web-apps/current-work/#multipart-form-data
@file.name = @file.name.replace /%22/g, '"'
<% } %>
if @file.isImage = /(jpg|png|gif)$/i.test @file.name
@file.isImage = /(jpg|png|gif)$/i.test @file.name
@file.isVideo = /webm$/i.test @file.name
if @file.isImage or @file.isVideo
@file.dimensions = fileText.textContent.match(/\d+x\d+/)[0]
cleanup: (root, post) ->

View File

@ -304,6 +304,7 @@ Settings =
sizeInBytes: 276 * 1024
dimensions: '1280x720'
isImage: true
isVideo: false
isSpoiler: true
funk = FileInfo.createFunc @value
@nextElementSibling.innerHTML = funk FileInfo, data

View File

@ -32,4 +32,3 @@ AutoGIF =
else
thumb.src = URL
gif.src = URL

View File

@ -13,7 +13,7 @@ ImageExpand =
name: 'Image Expansion'
cb: @node
node: ->
return unless @file?.isImage
return unless @file and (@file.isImage or @file.isVideo)
{thumb} = @file
$.on thumb.parentNode, 'click', ImageExpand.cb.toggle
if @isClone and $.hasClass thumb, 'expanding'
@ -42,7 +42,7 @@ ImageExpand =
for ID, post of g.posts
for post in [post].concat post.clones
{file} = post
continue unless file and file.isImage and doc.contains post.nodes.root
continue unless file and (file.isImage or file.isVideo) and doc.contains post.nodes.root
if ImageExpand.on and !post.isHidden and
(!Conf['Expand spoilers'] and file.isSpoiler or
Conf['Expand from here'] and Header.getTopOf(file.thumb) < 0)
@ -72,6 +72,7 @@ ImageExpand =
$.rmClass post.nodes.root, 'expanded-image'
$.rmClass post.file.thumb, 'expanding'
post.file.isExpanded = false
post.file.fullImage.pause() if post.file.isVideo
expand: (post, src) ->
# Do not expand images of hidden/filtered replies, or already expanded pictures.
@ -80,21 +81,29 @@ ImageExpand =
$.addClass thumb, 'expanding'
if post.file.fullImage
# Expand already-loaded/ing picture.
$.asap (-> post.file.fullImage.naturalHeight), ->
$.asap (-> post.file.isVideo or post.file.fullImage.naturalHeight), ->
ImageExpand.completeExpand post
return
post.file.fullImage = img = $.el 'img',
className: 'full-image'
src: src or post.file.URL
$.on img, 'error', ImageExpand.error
$.asap (-> post.file.fullImage.naturalHeight), ->
file = if post.file.isImage
$.el 'img',
className: 'full-image'
src: src or post.file.URL
else
$.el 'video',
className: 'full-image'
src: src or post.file.URL
loop: true
post.file.fullImage = file
$.on file, 'error', ImageExpand.error
$.asap (-> post.file.isVideo or post.file.fullImage.naturalHeight), ->
ImageExpand.completeExpand post
$.after thumb, img
$.after thumb, file
completeExpand: (post) ->
{thumb} = post.file
return unless $.hasClass thumb, 'expanding' # contracted before the image loaded
post.file.isExpanded = true
post.file.fullImage.play() if post.file.isVideo
unless post.nodes.root.parentNode
# Image might start/finish loading before the post is inserted.
# Don't scroll when it's expanded in a QP for example.

View File

@ -9,19 +9,26 @@ ImageHover =
name: 'Image Hover'
cb: @catalogNode
node: ->
return unless @file?.isImage
return unless @file and (@file.isImage or @file.isVideo)
$.on @file.thumb, 'mouseover', ImageHover.mouseover
catalogNode: ->
return unless @thread.OP.file?.isImage
return unless @thread.OP.file and (@thread.OP.file.isImage @thread.OP.file.isVideo)
$.on @nodes.thumb, 'mouseover', ImageHover.mouseover
mouseover: (e) ->
post = if $.hasClass @, 'thumb'
g.posts[@parentNode.dataset.fullID]
else
Get.postFromNode @
el = $.el 'img',
id: 'ihover'
src: post.file.URL
el = if post.file.isImage
$.el 'img',
id: 'ihover'
src: post.file.URL
else
$.el 'video',
id: 'ihover'
src: post.file.URL
autoplay: true
loop: true
el.dataset.fullID = post.fullID
$.add d.body, el
UI.hover
@ -29,7 +36,7 @@ ImageHover =
el: el
latestEvent: e
endEvents: 'mouseout click'
asapTest: -> el.naturalHeight
asapTest: -> post.file.isVideo or el.naturalHeight
$.on el, 'error', ImageHover.error
error: ->
return unless doc.contains @

View File

@ -47,4 +47,4 @@ FileInfo =
B: -> FileInfo.convertUnit @file.sizeInBytes, 'B'
K: -> FileInfo.convertUnit @file.sizeInBytes, 'KB'
M: -> FileInfo.convertUnit @file.sizeInBytes, 'MB'
r: -> if @file.isImage then @file.dimensions else 'PDF'
r: -> @file.dimensions or 'PDF'

View File

@ -1,6 +1,4 @@
QR =
# Add empty mimeType to avoid errors with URLs selected in Window's file dialog.
mimeTypes: ['image/jpeg', 'image/png', 'image/gif', 'application/pdf', 'application/x-shockwave-flash', '']
init: ->
return if !Conf['Quick Reply']
@ -258,21 +256,14 @@ QR =
if file.size > max
QR.error "#{file.name}: File too large (file: #{$.bytesToString file.size}, max: #{$.bytesToString max})."
return
unless file.type in QR.mimeTypes
unless /^text/.test file.type
QR.error "#{file.name}: Unsupported file type."
return
if isSingle
post = QR.selected
else if (post = QR.posts[QR.posts.length - 1]).com
post = new QR.post()
post.pasteText file
return
if isSingle
post = QR.selected
else if (post = QR.posts[QR.posts.length - 1]).file
post = new QR.post()
post.setFile file
if /^text/.test file.type
post.pasteText file
else
post.setFile file
openFileInput: ->
QR.nodes.fileInput.click()