mirror of
https://github.com/redmine/redmine.git
synced 2026-07-01 00:30:14 +02:00
Reimplement partial quote feature using Stimulus JS (#42515).
Patch by Katsuya HIDAKA (user:hidakatsuya). git-svn-id: https://svn.redmine.org/redmine/trunk@23854 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -1,21 +1,6 @@
|
||||
function quoteReply(path, selectorForContentElement, textFormatting) {
|
||||
const contentElement = $(selectorForContentElement).get(0);
|
||||
const selectedRange = QuoteExtractor.extract(contentElement);
|
||||
|
||||
let formatter;
|
||||
|
||||
if (textFormatting === 'common_mark') {
|
||||
formatter = new QuoteCommonMarkFormatter();
|
||||
} else {
|
||||
formatter = new QuoteTextFormatter();
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: path,
|
||||
type: 'post',
|
||||
data: { quote: formatter.format(selectedRange) }
|
||||
});
|
||||
}
|
||||
import { Controller } from '@hotwired/stimulus'
|
||||
import TurndownService from 'turndown'
|
||||
import { post } from '@rails/request.js'
|
||||
|
||||
class QuoteExtractor {
|
||||
static extract(targetElement) {
|
||||
@@ -214,3 +199,26 @@ class QuoteCommonMarkFormatter {
|
||||
return htmlFragment.innerHTML;
|
||||
}
|
||||
}
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = [ 'content' ];
|
||||
|
||||
quote(event) {
|
||||
const { url, textFormatting } = event.params;
|
||||
const selectedRange = QuoteExtractor.extract(this.contentTarget);
|
||||
|
||||
let formatter;
|
||||
|
||||
if (textFormatting === 'common_mark') {
|
||||
formatter = new QuoteCommonMarkFormatter();
|
||||
} else {
|
||||
formatter = new QuoteTextFormatter();
|
||||
}
|
||||
|
||||
post(url, {
|
||||
body: JSON.stringify({ quote: formatter.format(selectedRange) }),
|
||||
contentType: 'application/json',
|
||||
responseKind: 'script'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
8
app/assets/javascripts/turndown-7.2.0.min.js
vendored
8
app/assets/javascripts/turndown-7.2.0.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user