2023-02-23 23:32:53 +08:00
|
|
|
import { classNameBindings, classNames } from "@ember-decorators/component";
|
2019-10-24 00:30:52 +08:00
|
|
|
import Component from "@ember/component";
|
2020-04-15 13:41:00 +08:00
|
|
|
import highlightHTML from "discourse/lib/highlight-html";
|
2023-02-24 17:50:52 +08:00
|
|
|
import { on } from "@ember-decorators/object";
|
2015-11-24 05:45:05 +08:00
|
|
|
|
2023-02-23 23:32:53 +08:00
|
|
|
@classNames("site-text")
|
|
|
|
@classNameBindings("siteText.overridden")
|
|
|
|
export default class SiteTextSummary extends Component {
|
2015-11-24 05:45:05 +08:00
|
|
|
@on("didInsertElement")
|
|
|
|
highlightTerm() {
|
2018-11-10 08:17:07 +08:00
|
|
|
const term = this._searchTerm();
|
|
|
|
|
2015-11-24 05:45:05 +08:00
|
|
|
if (term) {
|
2020-04-15 13:41:00 +08:00
|
|
|
highlightHTML(
|
|
|
|
this.element.querySelector(".site-text-id, .site-text-value"),
|
|
|
|
term,
|
|
|
|
{
|
|
|
|
className: "text-highlight",
|
|
|
|
}
|
|
|
|
);
|
2015-11-24 05:45:05 +08:00
|
|
|
}
|
2023-02-23 23:32:53 +08:00
|
|
|
}
|
2015-11-24 05:45:05 +08:00
|
|
|
|
|
|
|
click() {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.editAction(this.siteText);
|
2023-02-23 23:32:53 +08:00
|
|
|
}
|
2015-11-24 05:45:05 +08:00
|
|
|
|
2018-11-10 08:17:07 +08:00
|
|
|
_searchTerm() {
|
2019-05-27 16:15:39 +08:00
|
|
|
const regex = this.searchRegex;
|
|
|
|
const siteText = this.siteText;
|
2018-11-10 08:17:07 +08:00
|
|
|
|
|
|
|
if (regex && siteText) {
|
|
|
|
const matches = siteText.value.match(new RegExp(regex, "i"));
|
2020-09-22 22:28:28 +08:00
|
|
|
if (matches) {
|
|
|
|
return matches[0];
|
|
|
|
}
|
2018-11-10 08:17:07 +08:00
|
|
|
}
|
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
return this.term;
|
2023-02-23 23:32:53 +08:00
|
|
|
}
|
|
|
|
}
|