Proper fix for getDirection() problems

Hopefully the last fix for my edits to 181afb9 (#4534)

Follow-up to the previous two commits
This commit is contained in:
Dan Stillman 2024-08-14 03:55:33 -04:00
parent 531e8697be
commit f5af1898fd
2 changed files with 11 additions and 12 deletions

View file

@ -433,13 +433,11 @@ Zotero.ItemFields = new function() {
}
var fieldName = this.getName(fieldName);
if (!fieldName) {
return 'auto';
}
var baseField = this.getBaseIDFromTypeAndField(itemTypeID, fieldName);
if (baseField) {
fieldName = this.getName(baseField);
if (fieldName) {
let baseField = this.getBaseIDFromTypeAndField(itemTypeID, fieldName);
if (baseField) {
fieldName = this.getName(baseField);
}
}
switch (fieldName) {
// Certain fields containing IDs, numbers, and data: always LTR
@ -466,7 +464,8 @@ Zotero.ItemFields = new function() {
case 'extra':
return 'ltr';
// Everything else: guess based on the language if we have one; otherwise auto
// Everything else (including false): guess based on the language if we have one;
// otherwise auto
default:
if (itemLanguage) {
let languageCode = Zotero.Utilities.Item.languageToISO6391(itemLanguage);

View file

@ -46,12 +46,12 @@ describe("Zotero.ItemFields", function () {
});
describe("#getDirection()", function () {
it("should return 'auto' for non-field", function () {
assert.equal(Zotero.ItemFields.getDirection('book', 'creator-0-lastName', ''), 'auto');
});
it("should follow app locale for primary field", function () {
assert.equal(Zotero.ItemFields.getDirection('book', 'dateAdded', ''), Zotero.dir)
});
it("should use item language for non-field", function () {
assert.equal(Zotero.ItemFields.getDirection('book', 'creator-0-lastName', 'ar'), 'rtl');
});
});
})