diff --git a/src/General/css/style.css b/src/General/css/style.css index c576009f6..8ff31cf5f 100755 --- a/src/General/css/style.css +++ b/src/General/css/style.css @@ -1449,6 +1449,8 @@ input#qr-filename { } #qr:not(.has-spoiler) #qr-spoiler-label, #file-n-submit:not(.has-file) #qr-spoiler-label, +#file-n-submit:not(.has-file) #qr-edit-button, +body:not(.board_i) #qr-edit-button, .has-file #paste-area, .has-file #url-button, #file-n-submit:not(.custom-cooldown) #custom-cooldown-button { diff --git a/src/General/html/Features/QuickReply.html b/src/General/html/Features/QuickReply.html index f55d8f1d5..ff75a9e74 100755 --- a/src/General/html/Features/QuickReply.html +++ b/src/General/html/Features/QuickReply.html @@ -39,6 +39,7 @@ S + diff --git a/src/General/lib/$.coffee b/src/General/lib/$.coffee index 2dcc822e9..5cb9205a0 100755 --- a/src/General/lib/$.coffee +++ b/src/General/lib/$.coffee @@ -299,6 +299,9 @@ $.globalEval = (code) -> $.add (d.head or doc), script $.rm script +$.global = (fn) -> + $.globalEval "(#{fn})();" + $.bytesToString = (size) -> unit = 0 # Bytes while size >= 1024 diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 1351eefc3..ad576af6f 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -230,6 +230,36 @@ QR = }); ''' + 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' @@ -503,6 +533,7 @@ QR = setNode 'customCooldown', '#custom-cooldown-button' setNode 'flashTag', '[name=filetag]' setNode 'drawButton', '#qr-draw-button' + setNode 'editButton', '#qr-edit-button' rules = $('ul.rules').textContent.trim() match_min = rules.match(/.+smaller than (\d+)x(\d+).+/) @@ -564,6 +595,7 @@ QR = $.on nodes.texButton, 'mouseup', QR.texPreviewHide $.on nodes.customCooldown, 'click', QR.toggleCustomCooldown $.on nodes.drawButton, 'click', QR.oekakiDraw + $.on nodes.editButton, 'click', QR.oekakiEdit window.addEventListener 'focus', QR.focus, true window.addEventListener 'blur', QR.focus, true