From 50e3e6deadc04c35d6f799523b348eef3bf5aef8 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Mon, 26 Oct 2015 11:20:20 -0700 Subject: [PATCH] Support editing first frame of video from QR. Because why not? --- src/Posting/QR.oekaki.coffee | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Posting/QR.oekaki.coffee b/src/Posting/QR.oekaki.coffee index 848385e76..749121446 100644 --- a/src/Posting/QR.oekaki.coffee +++ b/src/Posting/QR.oekaki.coffee @@ -104,20 +104,22 @@ QR.oekaki = cb = (e) -> document.removeEventListener 'QRFile', cb, false return error 'No file to edit.' unless e.detail - return error 'Not an image.' unless /^image\//.test e.detail.type - img = new Image() - img.onerror = -> error 'Could not open image.' - img.onload = -> + return error 'Not an image.' unless /^(image|video)\//.test e.detail.type + isVideo = /^video\//.test e.detail.type + file = document.createElement(if isVideo then 'video' else 'img') + file.addEventListener 'error', -> error 'Could not open file.', false + file.addEventListener (if isVideo then 'loadeddata' else 'load'), -> Tegaki.destroy() if Tegaki.bg FCX.oekakiName = name Tegaki.open onDone: FCX.oekakiCB onCancel: -> - width: img.naturalWidth - height: img.naturalHeight + width: file.naturalWidth or file.videoWidth + height: file.naturalHeight or file.videoHeight bgColor: 'transparent' - Tegaki.activeCtx.drawImage img, 0, 0 - img.src = URL.createObjectURL e.detail + Tegaki.activeCtx.drawImage file, 0, 0 + , false + file.src = URL.createObjectURL e.detail if Tegaki.bg and Tegaki.onDoneCb is FCX.oekakiCB and source is FCX.oekakiLatest FCX.oekakiName = name Tegaki.resume()