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