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";
|
2020-12-02 02:31:26 +08:00
|
|
|
import { on } from "discourse-common/utils/decorators";
|
2015-11-24 05:45:05 +08:00
|
|
|
|
2019-10-24 00:30:52 +08:00
|
|
|
export default Component.extend({
|
2015-11-24 05:45:05 +08:00
|
|
|
classNames: ["site-text"],
|
2015-12-01 04:22:58 +08:00
|
|
|
classNameBindings: ["siteText.overridden"],
|
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
|
|
|
}
|
2019-07-16 18:45:15 +08:00
|
|
|
$(this.element.querySelector(".site-text-value")).ellipsis();
|
2015-11-24 05:45:05 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
click() {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.editAction(this.siteText);
|
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;
|
2015-11-24 05:45:05 +08:00
|
|
|
},
|
|
|
|
});
|