diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index ad576af6f..b61806181 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -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 diff --git a/src/Posting/QR.oekaki.coffee b/src/Posting/QR.oekaki.coffee new file mode 100644 index 000000000..c26f23c4b --- /dev/null +++ b/src/Posting/QR.oekaki.coffee @@ -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}