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:
Marius Balteanu
2025-07-04 05:45:29 +00:00
parent c1115fea4a
commit a531b4fe80
12 changed files with 188 additions and 84 deletions

View File

@@ -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'
});
}
}

File diff suppressed because one or more lines are too long