|
43 | 43 | class: { value: classToggleBind, writable: true, configurable: false, enumerable: false }, |
44 | 44 | attribute: { value: attributeBind, writable: true, configurable: false, enumerable: false }, |
45 | 45 | property: { value: propertyBind, writable: true, configurable: false, enumerable: false }, |
| 46 | + language: { value: languageBind, writable: true, configurable: false, enumerable: false }, |
46 | 47 |
|
47 | 48 | input: { value: valueBind, writable: true, configurable: false, enumerable: false }, |
48 | 49 | input_checkbox: { value: checkBind, writable: true, configurable: false, enumerable: false }, |
|
1353 | 1354 | // I am alive! |
1354 | 1355 | return this.contextValue() === undefined ? false : true; |
1355 | 1356 | } |
| 1357 | + function languageBind(event) { |
| 1358 | + |
| 1359 | + if (event?.eventName === "unbind") { |
| 1360 | + |
| 1361 | + this.innerHTML = ''; |
| 1362 | + // I am dead! |
| 1363 | + return false; |
| 1364 | + } |
| 1365 | + |
| 1366 | + var val = this.contextValue(); |
| 1367 | + |
| 1368 | + if (typeof val === 'object' && val !== null) { |
| 1369 | + |
| 1370 | + // If the value is an object, we will try to find the language key in it. |
| 1371 | + var lang = navigator.language || navigator.userLanguage || 'en'; |
| 1372 | + lang = lang.toLowerCase().split('-')[0]; // Get the language code without region |
| 1373 | + |
| 1374 | + if (val[lang] !== undefined) { val = val[lang]; } |
| 1375 | + |
| 1376 | + else { |
| 1377 | + |
| 1378 | + val = val['en']; |
| 1379 | + |
| 1380 | + if (val[lang] !== undefined) { |
| 1381 | + |
| 1382 | + val = Object.values(val).find(function (v) { return typeof v === 'string'; }) || ''; |
| 1383 | + } |
| 1384 | + } |
| 1385 | + } |
| 1386 | + |
| 1387 | + this.innerHTML = val; |
| 1388 | + |
| 1389 | + // I am alive! |
| 1390 | + return val === undefined ? false : true; |
| 1391 | + } |
1356 | 1392 |
|
1357 | 1393 |
|
1358 | 1394 | function updateAttributeBinding(isEnabled, attributeName, attributeValue = '') { |
|
1389 | 1425 | } |
1390 | 1426 | function resolveTemplateLiterals(templateValue, isValueInverted) { |
1391 | 1427 |
|
1392 | | - if (templateValue.indexOf('${')) { |
| 1428 | + if (templateValue.indexOf('${') > -1) { |
| 1429 | + |
| 1430 | + var isEmpty = false; |
1393 | 1431 |
|
1394 | 1432 | templateValue = templateValue.replace(/\$\{([^\}]+)\}/g, function (match, propertyPath) { |
1395 | 1433 |
|
1396 | | - var value = this.contextValue(), |
1397 | | - propertyParts = propertyPath.split('.'); |
| 1434 | + var value = this.contextValue(); |
1398 | 1435 |
|
1399 | | - if (value === undefined) { return ''; } |
| 1436 | + if (value === undefined) { |
| 1437 | + |
| 1438 | + if (isValueInverted) { isEmpty = true; } |
| 1439 | + |
| 1440 | + return ''; |
| 1441 | + } |
| 1442 | + |
| 1443 | + var propertyParts = propertyPath.split('.'); |
1400 | 1444 |
|
1401 | 1445 | while (propertyParts.length) { |
1402 | 1446 |
|
1403 | 1447 | value = value[propertyParts.shift()]; |
1404 | 1448 |
|
1405 | | - if (value === undefined) { return ''; } |
1406 | | - } |
| 1449 | + if (value === undefined) { |
1407 | 1450 |
|
1408 | | - if (isValueInverted) { value = !value; } |
| 1451 | + if (isValueInverted) { isEmpty = true; } |
| 1452 | + |
| 1453 | + return ''; |
| 1454 | + } |
| 1455 | + } |
1409 | 1456 |
|
1410 | 1457 | return value; |
1411 | 1458 |
|
1412 | 1459 | }.bind(this)); |
1413 | 1460 | } |
1414 | 1461 |
|
| 1462 | + if (isValueInverted && isEmpty) { return ''; } |
| 1463 | + |
1415 | 1464 | return templateValue; |
1416 | 1465 | } |
1417 | 1466 |
|
|
0 commit comments