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