Move oekaki onDone callback to FCX.oekakiCB.

This commit is contained in:
ccd0 2015-10-25 16:52:59 -07:00
parent fddfd68405
commit 8d0d9492c8
3 changed files with 19 additions and 13 deletions

View File

@ -95,7 +95,9 @@ Main =
initFeatures: -> initFeatures: ->
if location.hostname in ['boards.4chan.org', 'sys.4chan.org', 'www.4chan.org'] if location.hostname in ['boards.4chan.org', 'sys.4chan.org', 'www.4chan.org']
$.globalEval 'document.documentElement.classList.add("js-enabled");' $.global ->
document.documentElement.classList.add 'js-enabled'
window.FCX = {}
switch location.hostname switch location.hostname
when 'www.4chan.org' when 'www.4chan.org'

View File

@ -584,6 +584,7 @@ QR =
new QR.post true new QR.post true
QR.status() QR.status()
QR.cooldown.setup() QR.cooldown.setup()
QR.oekaki.setup()
QR.captcha.init() QR.captcha.init()
$.add d.body, dialog $.add d.body, dialog

View File

@ -32,6 +32,15 @@ QR.oekaki =
else else
QR.error "Can't load image." QR.error "Can't load image."
setup: ->
$.global ->
{FCX} = window
FCX.oekakiCB = ->
window.Tegaki.flatten().toBlob (file) ->
document.dispatchEvent new CustomEvent 'QRSetFile',
bubbles: true
detail: {file, name: FCX.oekakiName}
load: (cb) -> load: (cb) ->
if $ 'script[src^="//s.4cdn.org/js/painter"]', d.head if $ 'script[src^="//s.4cdn.org/js/painter"]', d.head
cb() cb()
@ -50,21 +59,18 @@ QR.oekaki =
draw: -> draw: ->
$.global -> $.global ->
{Tegaki} = window {Tegaki, FCX} = window
Tegaki.destroy() if Tegaki.bg Tegaki.destroy() if Tegaki.bg
FCX.oekakiName = 'tegaki.png'
Tegaki.open Tegaki.open
onDone: -> onDone: FCX.oekakiCB
Tegaki.flatten().toBlob (file) ->
document.dispatchEvent new CustomEvent 'QRSetFile',
bubbles: true
detail: {file, name: 'tegaki.png'}
onCancel: -> onCancel: ->
width: +document.querySelector('#qr [name=oekaki-width]').value width: +document.querySelector('#qr [name=oekaki-width]').value
height: +document.querySelector('#qr [name=oekaki-height]').value height: +document.querySelector('#qr [name=oekaki-height]').value
edit: -> edit: ->
QR.oekaki.load -> $.global -> QR.oekaki.load -> $.global ->
{Tegaki} = window {Tegaki, FCX} = window
name = document.getElementById('qr-filename').value.replace(/\.\w+$/, '') + '.png' name = document.getElementById('qr-filename').value.replace(/\.\w+$/, '') + '.png'
error = (content) -> error = (content) ->
document.dispatchEvent new CustomEvent 'CreateNotification', document.dispatchEvent new CustomEvent 'CreateNotification',
@ -78,12 +84,9 @@ QR.oekaki =
img.onerror = -> error 'Could not open image.' img.onerror = -> error 'Could not open image.'
img.onload = -> img.onload = ->
Tegaki.destroy() if Tegaki.bg Tegaki.destroy() if Tegaki.bg
FCX.oekakiName = name
Tegaki.open Tegaki.open
onDone: -> onDone: FCX.oekakiCB
Tegaki.flatten().toBlob (file) ->
document.dispatchEvent new CustomEvent 'QRSetFile',
bubbles: true
detail: {file, name}
onCancel: -> onCancel: ->
width: img.naturalWidth width: img.naturalWidth
height: img.naturalHeight height: img.naturalHeight