discourse/app/assets/javascripts/admin/addon/components/site-text-summary.js
David Taylor a433b30650
DEV: Convert admin component definitions to native class syntax (#20311)
This conversion was achieved using the ember-native-class-codemod, plus a handful of manual fixes/tweaks
2023-02-23 15:32:53 +00:00

42 lines
975 B
JavaScript

import { classNameBindings, classNames } from "@ember-decorators/component";
import Component from "@ember/component";
import highlightHTML from "discourse/lib/highlight-html";
import { on } from "discourse-common/utils/decorators";
@classNames("site-text")
@classNameBindings("siteText.overridden")
export default class SiteTextSummary extends Component {
@on("didInsertElement")
highlightTerm() {
const term = this._searchTerm();
if (term) {
highlightHTML(
this.element.querySelector(".site-text-id, .site-text-value"),
term,
{
className: "text-highlight",
}
);
}
}
click() {
this.editAction(this.siteText);
}
_searchTerm() {
const regex = this.searchRegex;
const siteText = this.siteText;
if (regex && siteText) {
const matches = siteText.value.match(new RegExp(regex, "i"));
if (matches) {
return matches[0];
}
}
return this.term;
}
}