From 1845c6b033b5ef25a4ab3462ccbe155bbf4223b7 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 25 Oct 2015 03:56:10 -0700 Subject: [PATCH] Add links to images to open them in the oekaki painter. --- src/General/Config.coffee | 4 ++++ src/General/Main.coffee | 1 + src/Posting/QR.coffee | 15 +++++++++------ src/Posting/QR.oekaki.coffee | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 38b95fb12..4f832776a 100755 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -210,6 +210,10 @@ Config = 'Show PDF files in gallery.' 1 ] + 'Oekaki Links': [ + true + 'Add links to edit images in oekaki painter.' + ] 'Sauce': [ true 'Add sauce links to images.' diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 3b7acd4d6..a6a33eb77 100755 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -387,6 +387,7 @@ Main = ['Strike-through Quotes', QuoteStrikeThrough] ['Quick Reply', QR] ['Cooldown', QR.cooldown] + ['Oekaki Links', QR.oekaki] ['Menu', Menu] ['Index Generator (Menu)', Index.menu] ['Report Link', ReportLink] diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index b61806181..2ac3c8249 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -273,6 +273,14 @@ QR = value status.disabled = disabled or false + openPost: -> + QR.open() + if QR.selected.isLocked + index = QR.posts.indexOf QR.selected + (QR.posts[index+1] or new QR.post()).select() + $.addClass QR.nodes.el, 'dump' + QR.cooldown.auto = true + quote: (e) -> e?.preventDefault() return unless QR.postingIsEnabled @@ -306,12 +314,7 @@ QR = $.rm node text += ">#{frag.textContent.trim()}\n" - QR.open() - if QR.selected.isLocked - index = QR.posts.indexOf QR.selected - (QR.posts[index+1] or new QR.post()).select() - $.addClass QR.nodes.el, 'dump' - QR.cooldown.auto = true + QR.openPost() {com, thread} = QR.nodes thread.value = Get.threadFromNode @ unless com.value diff --git a/src/Posting/QR.oekaki.coffee b/src/Posting/QR.oekaki.coffee index 76090ed16..5dd39038f 100644 --- a/src/Posting/QR.oekaki.coffee +++ b/src/Posting/QR.oekaki.coffee @@ -1,4 +1,37 @@ QR.oekaki = + init: -> + return unless Conf['Quick Reply'] and Conf['Oekaki Links'] + Post.callbacks.push + name: 'Oekaki Links' + cb: @node + + node: -> + return unless @file?.isImage + if @isClone + link = $ '.file-edit', @file.text + else + link = $.el 'a', + className: 'file-edit' + href: 'javascript:;' + title: 'Edit image' + $.extend link, <%= html('') %> + $.add @file.text, [$.tn('\u00A0'), link] + $.on link, 'click', QR.oekaki.editFile + + editFile: -> + post = Get.postFromNode @ + CrossOrigin.file post.file.url, (blob) -> + QR.openPost() + {com, thread} = QR.nodes + thread.value = (post.context or post).thread.ID unless com.value + QR.selected.save thread + if blob + blob.name = post.file.name + QR.handleFiles [blob] + QR.oekaki.edit() + else + QR.error "Can't load image." + load: (cb) -> if $ 'script[src^="//s.4cdn.org/js/painter"]', d.head cb()