Skip to content

Commit 870475c

Browse files
authored
Merge pull request #393 from iLib-js/fixSafari
Get ilib to work on Opera and Safari properly
2 parents 9097b2d + c220f49 commit 870475c

File tree

5 files changed

+53
-23
lines changed

5 files changed

+53
-23
lines changed

js/lib/ilib.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,33 +169,33 @@ ilib._getBrowser = function () {
169169
if (ilib._getPlatform() === "browser") {
170170
if (navigator && navigator.userAgent) {
171171
if (navigator.userAgent.indexOf("Firefox") > -1) {
172-
browser = "firefox";
172+
return "firefox";
173173
}
174174
if (navigator.userAgent.search(/Opera|OPR/) > -1 ) {
175-
browser = "opera";
175+
return "opera";
176176
}
177177
if (navigator.userAgent.indexOf("Chrome") > -1) {
178-
browser = "chrome";
178+
return "chrome";
179179
}
180180
if (navigator.userAgent.indexOf(" .NET") > -1) {
181-
browser = "ie";
181+
return "ie";
182182
}
183183
if (navigator.userAgent.indexOf("Safari") > -1) {
184184
// chrome also has the string Safari in its userAgent, but the chrome case is
185185
// already taken care of above
186-
browser = "safari";
186+
return "safari";
187187
}
188188
if (navigator.userAgent.indexOf("Edge") > -1) {
189-
browser = "Edge";
189+
return "Edge";
190190
}
191191
if (navigator.userAgent.search(/iPad|iPhone|iPod/) > -1) {
192192
// Due to constraints of the iOS platform,
193193
// all browser must be built on top of the WebKit rendering engine
194-
browser = "iOS";
194+
return "iOS";
195195
}
196196
}
197197
}
198-
return browser;
198+
return "unknown";
199199
};
200200

201201
/**

js/test/date/testdatefmt_az_Latn_AZ.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,28 @@ module.exports.testdatefmt_az_Latn_AZ = {
104104
millisecond: 0
105105
});
106106

107-
if(ilib._getPlatform() === "nodejs"){
108-
test.equal(fmt.format(date), "29 sentyabr 2011");
109-
} else {
110-
var browser = ilib._getBrowser();
111-
if(browser === "firefox"){
112-
test.equal(fmt.format(date), "29 sentyabr 2011");
113-
} else {
114-
test.equal(fmt.format(date), "2011 M09 29");
115-
}
107+
var expected;
108+
switch (ilib._getPlatform()) {
109+
case "nodejs":
110+
expected = "29 sentyabr 2011";
111+
break;
112+
case "browser":
113+
var browser = ilib._getBrowser();
114+
switch (browser) {
115+
case "firefox":
116+
case 'safari':
117+
expected = "29 sentyabr 2011";
118+
break;
119+
default:
120+
expected = "2011 M09 29";
121+
break;
122+
}
123+
break;
124+
default:
125+
expected = "2011 M09 29";
126+
break;
116127
}
128+
test.equal(fmt.format(date), expected);
117129
test.done();
118130
},
119131

js/test/date/testdatefmt_ko_KR.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ module.exports.testdatefmt_ko_KR = {
8888
millisecond: 0,
8989
timezone: "local"
9090
});
91-
test.equal(fmt.format(date), "11. 9. 29.");
91+
var expected = (ilib._getPlatform() === "browser" && ilib._getBrowser() === "safari") ? "2011. 9. 29." : "11. 9. 29.";
92+
test.equal(fmt.format(date), expected);
9293
test.done();
9394
},
9495

js/test/date/testdatefmtasync.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ module.exports.testdatefmtasync = {
343343
return;
344344
}
345345
test.expect(2);
346+
var expected = (ilib._getPlatform() === "browser" && ilib._getBrowser() === "safari") ? "2022. 5. 29." : "22. 5. 29.";
346347
new DateFmt({
347348
length: "short",
348349
locale: "ko-KR",
@@ -351,7 +352,7 @@ module.exports.testdatefmtasync = {
351352
onLoad: function(fmt) {
352353
test.ok(fmt !== null);
353354
var date = new Date(2022, 4, 29);
354-
test.equal(fmt.format(date), "22. 5. 29.");
355+
test.equal(fmt.format(date), expected);
355356
test.done();
356357
}
357358
});

js/test/root/teststrings.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3289,7 +3289,11 @@ module.exports.teststrings = {
32893289
test.equal(str.formatChoice(1000000), "The items are many");
32903290
}
32913291
} else {
3292-
test.equal(str.formatChoice(1000000), "The items are many");
3292+
if (ilib._getPlatform() === "browser" && ilib._getBrowser() === "opera") {
3293+
test.equal(str.formatChoice(1000000), "Default items");
3294+
} else {
3295+
test.equal(str.formatChoice(1000000), "The items are many");
3296+
}
32933297
}
32943298
test.done();
32953299
},
@@ -3945,7 +3949,11 @@ module.exports.teststrings = {
39453949
test.equal(str.formatChoice(1000000), "The items are many");
39463950
}
39473951
} else {
3948-
test.equal(str.formatChoice(1000000), "The items are many");
3952+
if (ilib._getPlatform() === "browser" && ilib._getBrowser() === "opera") {
3953+
test.equal(str.formatChoice(1000000), "Default items");
3954+
} else {
3955+
test.equal(str.formatChoice(1000000), "The items are many");
3956+
}
39493957
}
39503958
test.done();
39513959
},
@@ -3966,7 +3974,11 @@ module.exports.teststrings = {
39663974
test.equal(str.formatChoice(3e6), "The items are many");
39673975
}
39683976
} else {
3969-
test.equal(str.formatChoice(3e6), "The items are many");
3977+
if (ilib._getPlatform() === "browser" && ilib._getBrowser() === "opera") {
3978+
test.equal(str.formatChoice(3e6), "Default items");
3979+
} else {
3980+
test.equal(str.formatChoice(3e6), "The items are many");
3981+
}
39703982
}
39713983
test.done();
39723984
},
@@ -3986,7 +3998,11 @@ module.exports.teststrings = {
39863998
test.equal(str.formatChoice(1000000), "The items are many");
39873999
}
39884000
} else {
3989-
test.equal(str.formatChoice(1000000), "The items are many");
4001+
if (ilib._getPlatform() === "browser" && ilib._getBrowser() === "opera") {
4002+
test.equal(str.formatChoice(1000000), "Default items");
4003+
} else {
4004+
test.equal(str.formatChoice(1000000), "The items are many");
4005+
}
39904006
}
39914007
test.done();
39924008
},

0 commit comments

Comments
 (0)