2018-06-15 23:03:24 +08:00
|
|
|
import { on } from "ember-addons/ember-computed-decorators";
|
2015-11-24 05:45:05 +08:00
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
2018-06-15 23:03:24 +08:00
|
|
|
classNames: ["site-text"],
|
|
|
|
classNameBindings: ["siteText.overridden"],
|
2015-11-24 05:45:05 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
@on("didInsertElement")
|
2015-11-24 05:45:05 +08:00
|
|
|
highlightTerm() {
|
2018-11-10 08:17:07 +08:00
|
|
|
const term = this._searchTerm();
|
|
|
|
|
2015-11-24 05:45:05 +08:00
|
|
|
if (term) {
|
2019-07-16 18:45:15 +08:00
|
|
|
$(
|
|
|
|
this.element.querySelector(".site-text-id, .site-text-value")
|
|
|
|
).highlight(term, {
|
2018-06-15 23:03:24 +08:00
|
|
|
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"));
|
|
|
|
if (matches) return matches[0];
|
|
|
|
}
|
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
return this.term;
|
2015-11-24 05:45:05 +08:00
|
|
|
}
|
|
|
|
});
|