This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/select-box/select-box-row.js.es6

45 lines
1.1 KiB
JavaScript

import { on, observes } from 'ember-addons/ember-computed-decorators';
export default Ember.Component.extend({
classNames: "select-box-row",
tagName: "li",
classNameBindings: ["isHighlighted"],
attributeBindings: ["text:title"],
lastHoveredId: null,
@on("init")
@observes("content", "lastHoveredId", "selectedId", "selectBoxRowTemplate")
_updateTemplate: function() {
this.set("isHighlighted", this._isHighlighted());
this.set("text", this.get("content.text"));
this.set("template", this.get("selectBoxRowTemplate")(this));
},
mouseEnter() {
this.sendAction("onHover", this.get("content.id"));
},
click() {
this.sendAction("onSelect", this.get("content.id"));
},
didReceiveAttrs() {
this._super();
this.set("isHighlighted", this._isHighlighted());
this.set("text", this.get("content.text"));
},
_isHighlighted() {
if(_.isUndefined(this.get("lastHoveredId"))) {
return this.get("content.id") === this.get("selectedId");
} else {
return this.get("content.id") === this.get("lastHoveredId");
}
},
});