2020-03-21 18:30:11 +01:00
|
|
|
import computed from "discourse-common/utils/decorators";
|
2021-04-12 08:26:22 +02:00
|
|
|
import { isLTR, isRTL, siteDir } from "discourse/lib/text-direction";
|
2022-07-26 16:18:09 +02:00
|
|
|
import I18n from "I18n";
|
2022-03-16 14:09:23 +01:00
|
|
|
import TextField from "@ember/component/text-field";
|
2018-02-08 05:30:55 +01:00
|
|
|
|
2022-03-16 14:09:23 +01:00
|
|
|
export default TextField.extend({
|
2021-03-28 11:06:49 +02:00
|
|
|
attributeBindings: [
|
|
|
|
"autocorrect",
|
|
|
|
"autocapitalize",
|
|
|
|
"autofocus",
|
|
|
|
"maxLength",
|
|
|
|
"dir",
|
|
|
|
],
|
2018-02-08 05:30:55 +01:00
|
|
|
|
|
|
|
@computed
|
|
|
|
dir() {
|
2022-03-16 12:33:34 +01:00
|
|
|
if (this.siteSettings.support_mixed_text_direction) {
|
2018-02-08 05:30:55 +01:00
|
|
|
let val = this.value;
|
|
|
|
if (val) {
|
2021-03-28 11:06:49 +02:00
|
|
|
return isRTL(val) ? "rtl" : "ltr";
|
2018-02-08 05:30:55 +01:00
|
|
|
} else {
|
|
|
|
return siteDir();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
keyUp() {
|
2022-03-16 12:33:34 +01:00
|
|
|
if (this.siteSettings.support_mixed_text_direction) {
|
2018-02-08 05:30:55 +01:00
|
|
|
let val = this.value;
|
|
|
|
if (isRTL(val)) {
|
2021-03-28 11:06:49 +02:00
|
|
|
this.set("dir", "rtl");
|
2018-02-08 05:30:55 +01:00
|
|
|
} else if (isLTR(val)) {
|
2021-03-28 11:06:49 +02:00
|
|
|
this.set("dir", "ltr");
|
2018-02-08 05:30:55 +01:00
|
|
|
} else {
|
2021-03-28 11:06:49 +02:00
|
|
|
this.set("dir", siteDir());
|
2018-02-08 05:30:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed("placeholderKey")
|
|
|
|
placeholder(placeholderKey) {
|
2022-07-26 16:18:09 +02:00
|
|
|
return placeholderKey ? I18n.t(placeholderKey) : "";
|
2021-03-28 11:06:49 +02:00
|
|
|
},
|
2018-02-08 05:30:55 +01:00
|
|
|
});
|