Canapin
(Coin-coin le Canapin)
17 سبتمبر 2020، 1:46م
1
Hi!
I’d like to try to modify the buildQuote function so it adds a new line before the opening [quote] tag.
Basically, modifying this:
return `[quote="${params.join(", ")}"]\n${contents.trim()}\n[/quote]\n\n`;
to this:
return `\n[quote="${params.join(", ")}"]\n${contents.trim()}\n[/quote]\n\n`;
Is it possible to do such a thing with a theme component? How do I override this function?
Canapin
(Coin-coin le Canapin)
17 سبتمبر 2020، 4:03م
2
I’ve managed to achieve it, but is there a prettier solution?
<script type="text/discourse-plugin" version="0.8.23">
function buildQuote(post, contents, opts = {}) {
if (!post || !contents) {
return "";
}
const params = [
opts.username || post.username,
`post:${opts.post || post.post_number}`,
`topic:${opts.topic || post.topic_id}`
];
if (opts.full) params.push("full:true");
return `\n[quote="${params.join(", ")}"]\n${contents.trim()}\n[/quote]\n\n`;
}
api.modifyClass('controller:composer', {
actions: {
importQuote(toolbarEvent) {
const postStream = this.get("topic.postStream");
let postId = this.get("model.post.id");
// If there is no current post, use the first post id from the stream
if (!postId && postStream) {
postId = postStream.get("stream.firstObject");
}
// If we're editing a post, fetch the reply when importing a quote
if (this.get("model.editingPost")) {
const replyToPostNumber = this.get("model.post.reply_to_post_number");
if (replyToPostNumber) {
const replyPost = postStream.posts.findBy(
"post_number",
replyToPostNumber
);
if (replyPost) {
postId = replyPost.id;
}
}
}
if (postId) {
this.set("model.loading", true);
return this.store.find("post", postId).then(post => {
const quote = buildQuote(post, post.raw, {
full: true
});
toolbarEvent.addText(quote);
this.set("model.loading", false);
});
}
}
}
});
</script>
إعجابَين (2)
asc
27 فبراير 2023، 11:10م
3
عذرًا على إحياء موضوع قديم، ولكن هل لا يزال هذا يعمل لديك/هل اضطررت إلى تحديثه على الإطلاق؟ لقد كنت أحاول جعل هذا يعمل ولا يمكنني جعله يعمل على الإطلاق، ولكنني كنت أواجه وقتًا عصيبًا مع أي شيء يتعلق بـ modifyClass.
Canapin
(Coin-coin le Canapin)
28 فبراير 2023، 8:05ص
4
asc:
هل ما زال هذا يعمل لديك؟
لقد جربته للتو، وما زال يعمل
لقد قمت بنسخه ولصقه حرفياً في القالب الخاص بي، وعمل دون أي تعديل.
إعجاب واحد (1)
asc
28 فبراير 2023، 2:10م
6
شكراً @merefield و @Canapin . لقد كنت أحاول تعلم واجهة برمجة تطبيقات إضافات Discourse وأعبث بما أشعر أنه يجب أن تكون أشياء بسيطة مثل هذه ولكن modifyClass غير متسق عندما يعمل/لا يعمل. لدي مكون سمة صغير (الذي ذكرته @merefield ) حيث تعمل استدعاءات modifyClass مرتين ولكن الثالثة لا تعمل، وهو أمر محبط للغاية لمحاولة معرفة ما إذا كنت قد ارتكبت خطأً أم أن المشكلة فقط في modifyClass.
عذرًا على الخروج عن الموضوع في موضوعك وشكرًا على الرد السريع @Canapin
تحديث:
إعجاب واحد (1)
Canapin
(Coin-coin le Canapin)
28 فبراير 2023، 2:16م
7
لا تقلق، لا أعرف ما الذي يعنيه الخروج عن الموضوع ولكننا هنا للمساعدة!
إعجاب واحد (1)
Canapin
(Coin-coin le Canapin)
تم إغلاقه في
30 مارس 2023، 2:16م
8
تم إغلاق هذا الموضوع تلقائيًا بعد 30 يومًا من آخر رد. لم تعد الردود الجديدة مسموح بها.