Move oekaki stuff to separate file.

This commit is contained in:
ccd0 2015-10-24 23:46:34 -07:00
parent 23b223f2e2
commit 29785d59b1
2 changed files with 48 additions and 48 deletions

View File

@ -214,52 +214,6 @@ QR =
QR.setCustomCooldown enabled
$.set 'customCooldownEnabled', enabled
oekakiDraw: ->
$.globalEval '''
Tegaki.open({
onDone: function() {
Tegaki.flatten().toBlob(function (blob) {
var detail = {file: blob, name: 'tegaki.png'};
var event = new CustomEvent('QRSetFile', {bubbles: true, detail: detail});
document.dispatchEvent(event);
});
},
onCancel: function() {},
width: +document.querySelector('#qr [name=oekaki-width]').value,
height: +document.querySelector('#qr [name=oekaki-height]').value
});
'''
oekakiEdit: ->
$.global ->
{Tegaki} = window
name = document.getElementById('qr-filename').value.replace(/\.\w+$/, '') + '.png'
error = (content) ->
document.dispatchEvent new CustomEvent 'CreateNotification',
bubbles: true
detail: {type: 'warning', content, lifetime: 20}
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 = ->
Tegaki.destroy() if Tegaki.bg
Tegaki.open
onDone: ->
Tegaki.flatten().toBlob (file) ->
document.dispatchEvent new CustomEvent 'QRSetFile',
bubbles: true
detail: {file, name}
onCancel: ->
width: img.naturalWidth
height: img.naturalHeight
Tegaki.activeCtx.drawImage img, 0, 0
img.src = URL.createObjectURL e.detail
document.addEventListener 'QRFile', cb, false
document.dispatchEvent new CustomEvent 'QRGetFile', {bubbles: true}
error: (err, focusOverride) ->
QR.open()
if typeof err is 'string'
@ -594,8 +548,8 @@ QR =
$.on nodes.texButton, 'mousedown', QR.texPreviewShow
$.on nodes.texButton, 'mouseup', QR.texPreviewHide
$.on nodes.customCooldown, 'click', QR.toggleCustomCooldown
$.on nodes.drawButton, 'click', QR.oekakiDraw
$.on nodes.editButton, 'click', QR.oekakiEdit
$.on nodes.drawButton, 'click', QR.oekaki.draw
$.on nodes.editButton, 'click', QR.oekaki.edit
window.addEventListener 'focus', QR.focus, true
window.addEventListener 'blur', QR.focus, true

View File

@ -0,0 +1,46 @@
QR.oekaki =
draw: ->
$.globalEval '''
Tegaki.open({
onDone: function() {
Tegaki.flatten().toBlob(function (blob) {
var detail = {file: blob, name: 'tegaki.png'};
var event = new CustomEvent('QRSetFile', {bubbles: true, detail: detail});
document.dispatchEvent(event);
});
},
onCancel: function() {},
width: +document.querySelector('#qr [name=oekaki-width]').value,
height: +document.querySelector('#qr [name=oekaki-height]').value
});
'''
edit: ->
$.global ->
{Tegaki} = window
name = document.getElementById('qr-filename').value.replace(/\.\w+$/, '') + '.png'
error = (content) ->
document.dispatchEvent new CustomEvent 'CreateNotification',
bubbles: true
detail: {type: 'warning', content, lifetime: 20}
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 = ->
Tegaki.destroy() if Tegaki.bg
Tegaki.open
onDone: ->
Tegaki.flatten().toBlob (file) ->
document.dispatchEvent new CustomEvent 'QRSetFile',
bubbles: true
detail: {file, name}
onCancel: ->
width: img.naturalWidth
height: img.naturalHeight
Tegaki.activeCtx.drawImage img, 0, 0
img.src = URL.createObjectURL e.detail
document.addEventListener 'QRFile', cb, false
document.dispatchEvent new CustomEvent 'QRGetFile', {bubbles: true}