mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
This reverts commit20780a1eee
. * SECURITY: re-adds accidentally reverted commit:03d26cd6
: ensure embed_url contains valid http(s) uri * when the merge commite62a85cf
was reverted, git chose the2660c2e2
parent to land on instead of the03d26cd6
parent (which contains security fixes)
63 lines
1.7 KiB
JavaScript
63 lines
1.7 KiB
JavaScript
import { computed, get, action } from "@ember/object";
|
|
import Component from "@ember/component";
|
|
import { makeArray } from "discourse-common/lib/helpers";
|
|
import UtilsMixin from "select-kit/mixins/utils";
|
|
|
|
export default Component.extend(UtilsMixin, {
|
|
tagName: "",
|
|
layoutName: "select-kit/templates/components/selected-name",
|
|
name: null,
|
|
value: null,
|
|
|
|
@action
|
|
onSelectedNameClick() {
|
|
if (this.selectKit.options.clearOnClick) {
|
|
this.selectKit.deselect(this.item);
|
|
return false;
|
|
}
|
|
},
|
|
|
|
didReceiveAttrs() {
|
|
this._super(...arguments);
|
|
|
|
// we can't listen on `item.nameProperty` given it's variable
|
|
this.setProperties({
|
|
name: this.getName(this.item),
|
|
value:
|
|
this.item === this.selectKit.noneItem ? null : this.getValue(this.item)
|
|
});
|
|
},
|
|
|
|
ariaLabel: computed("item", "sanitizedTitle", function() {
|
|
return this._safeProperty("ariaLabel", this.item) || this.sanitizedTitle;
|
|
}),
|
|
|
|
// this might need a more advanced solution
|
|
// but atm it's the only case we have to handle
|
|
sanitizedTitle: computed("title", function() {
|
|
return String(this.title).replace("…", "");
|
|
}),
|
|
|
|
title: computed("item", function() {
|
|
return this._safeProperty("title", this.item) || this.name || "";
|
|
}),
|
|
|
|
label: computed("title", "name", function() {
|
|
return this._safeProperty("label", this.item) || this.title || this.name;
|
|
}),
|
|
|
|
icons: computed("item.{icon,icons}", function() {
|
|
const icon = makeArray(this._safeProperty("icon", this.item));
|
|
const icons = makeArray(this._safeProperty("icons", this.item));
|
|
return icon.concat(icons).filter(Boolean);
|
|
}),
|
|
|
|
_safeProperty(name, content) {
|
|
if (!content) {
|
|
return null;
|
|
}
|
|
|
|
return get(content, name);
|
|
}
|
|
});
|