FIX: Tolerate quotes with no username and no title

This commit is contained in:
Kane York 2020-03-06 11:05:46 -08:00 committed by Kane York
parent f7ea2fdea5
commit 26da99a2d2
1 changed files with 7 additions and 6 deletions

View File

@ -3,6 +3,12 @@ import Component from "@ember/component";
import discourseDebounce from "discourse/lib/debounce"; import discourseDebounce from "discourse/lib/debounce";
import { selectedText, selectedElement } from "discourse/lib/utilities"; import { selectedText, selectedElement } from "discourse/lib/utilities";
function getQuoteTitle(element) {
const titleEl = element.querySelector(".title");
if (!titleEl) return;
return titleEl.textContent.trim().replace(/:$/, "");
}
export default Component.extend({ export default Component.extend({
classNames: ["quote-button"], classNames: ["quote-button"],
classNameBindings: ["visible"], classNameBindings: ["visible"],
@ -55,12 +61,7 @@ export default Component.extend({
element = element.parentElement element = element.parentElement
) { ) {
if (element.tagName === "ASIDE" && element.classList.contains("quote")) { if (element.tagName === "ASIDE" && element.classList.contains("quote")) {
opts.username = opts.username = element.dataset.username || getQuoteTitle(element);
element.dataset.username ||
element
.querySelector(".title")
.textContent.trim()
.replace(/:$/, "");
opts.post = element.dataset.post; opts.post = element.dataset.post;
opts.topic = element.dataset.topic; opts.topic = element.dataset.topic;
} }