Skip to content

Commit 3ef4b51

Browse files
tweak (#356)
1 parent a96af57 commit 3ef4b51

File tree

2 files changed

+166
-161
lines changed

2 files changed

+166
-161
lines changed

js/generic.js

+29-17
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ function get_isVer(METRIC) {
578578
}
579579
}
580580

581-
const get_isXML = (METRIC) => new Promise(resolve => {
581+
const get_isXML = () => new Promise(resolve => {
582582
if (!isGecko) {isXML = zNA; return resolve()}
583583
// get once ASAP +clear console: not going to change between tests
584584
// e.g. change app lang and it requires closing and a new tab
@@ -599,22 +599,34 @@ const get_isXML = (METRIC) => new Promise(resolve => {
599599
//split into parts: works back to FF52 and works with LTR
600600
let parts = str.split('\n')
601601
if ('n02' == k) {
602-
// programatically determine delimiter
603-
// usually = ":" (charCode 58) but zh-Hans-CN = ":" (charCode 65306) and my = "-"
604-
let strLoc = parts[1]
605-
let schema = isFile ? 'file://' : 'https://'
606-
let index = strLoc.indexOf(schema) - 2
607-
if (strLoc.charAt(index + 1) !== ' ') {index++} // zh-Hans-CN has no space: e.g. "位置:http://"
608-
if (strLoc.charAt(index) == ' ') {index = index -1} // jfc: ms has a double space: "Lokasi: http"
609-
delimiter = strLoc.charAt(index)
610-
strLoc = ': '+ strLoc.slice(0, index)
611-
let strName = parts[0].split(delimiter)[0]
612-
let strLine = parts[2] == undefined ? '' : ': '+ parts[2] // eg hebrew is only 2 lines
613-
isXML['n00'] = strName + strLoc + strLine
614-
isXML['n01'] = delimiter +' (' + delimiter.charCodeAt(0) +')'
602+
// ensure 3 parts: e.g. hebrew only has 2 lines
603+
let tmpStr = parts[1]
604+
let loc = window.location+'', locLen = loc.length, locStart = tmpStr.indexOf(loc)
605+
if (undefined == parts[2]) {
606+
let position = locLen+ locStart
607+
parts[1] = (tmpStr.slice(0, position)).trim()
608+
parts.push((tmpStr.slice(-(tmpStr.length - position))).trim())
609+
}
610+
// set delimiter: should aways be the last item in parts[1] after we strip location
611+
// usually = ":" (charCode 58) but zh-Hans-CN = ":" (charCode 65306) and my = " -"
612+
let strLoc = (parts[1].slice(0, locStart)).trim() // trim
613+
delimiter = strLoc.slice(-1) // last char
614+
// concat some bits
615+
// don't trim strName prior to +delimiter (which is length 1)
616+
// e.g. 'fr','my' have a preceeding space, so capture that
617+
let strName = parts[0].split(delimiter)[0] + delimiter
618+
// use an object as joining for a string can get weird with RTL
619+
let oData = {
620+
'delimiter': delimiter +' (' + delimiter.charCodeAt(0) +')', // redundant but record it for debugging
621+
'error': strName,
622+
'line': parts[2].trim(),
623+
'location': strLoc,
624+
}
625+
isXML['n00'] = oData
615626
}
616-
// this is always the error message
617-
isXML[k] = parts[0].split(delimiter)[1].trim()
627+
// parts[0] is always the error message
628+
let value = parts[0], trimLen = parts[0].split(delimiter)[0].length + 1
629+
isXML[k] = value.slice(trimLen).trim()
618630
}
619631
} catch(e) {
620632
isXML = e+''
@@ -1902,7 +1914,7 @@ function run_immediate() {
19021914
let warmNFcompact = new Intl.NumberFormat(undefined, {notation: 'compact'}).format(1)
19031915
let warmNFunit = new Intl.NumberFormat(undefined, {style: 'unit', unit: 'hectare'}).format(1)
19041916
} catch(e) {}
1905-
get_isXML('xml_messages')
1917+
get_isXML()
19061918
get_isArch('isArch')
19071919
})
19081920
}

js/region.js

+137-144
Original file line numberDiff line numberDiff line change
@@ -142,54 +142,47 @@ function set_isLanguageSmart() {
142142
// last checked 13.5.1
143143
localesSupported = {
144144
// v hashes are with localized NumberRangeOver/Underflow
145-
'ar': {m: '1f9a06e3', v: '1dfb5b8c', x: 'ebfbdc43'},
146-
'be': {m: '076d68e6', v: '4edeafab', x: 'b74b3840'},
147-
'bg': {m: '2da6c02e', v: 'ce892c88', x: '914590a4'},
148-
'ca': {m: 'd856d812', v: '6b3bb3d8', x: '81f31519'},
149-
'cs': {m: 'c92accb0', v: 'de3ab0ad', x: '45f277f7'},
150-
'da': {m: '39169214', v: '479797a1', x: '44535972'},
151-
'de': {m: '298d11c6', v: 'f9e2eae6', x: 'f4b2a56f'},
152-
// el: xml n30 = english but is would-be-n39 'reserved prefix (xmlns) must not be declared or undeclared'
153-
// changing to spoof english returns n30.. phew!
154-
'el': {m: '7053311d', v: 'b1a88a13', x: 'da8c80af'},
155-
'en-US': {m: '05c30936', v: '41310558', x: '945f8952'},
156-
'es-ES': {m: '96b78cbd', v: '97c3f5a9', x: '3eeba3bc'},
157-
'fa': {m: '6648d919', v: '8ef57409', x: '113d0a7e'},
158-
'fi': {m: '82d079c7', v: '3e29e6e7', x: '71abeeec'},
159-
'fr': {m: '024d0fce', v: '34e28fa2', x: '74f5df3d'},
160-
'ga-IE': {m: '97fca229', v: '2bf1321d', x: 'd9761e70'},
161-
// he: xml n27 n28 n30 = english
162-
'he': {m: 'cdde832b', v: 'e47dbb82', x: '786876d5'},
163-
'hu': {m: 'db7366e6', v: 'dad6d689', x: '9f537fe6'},
164-
'id': {m: '1e275882', v: '71224946', x: '79f3851e'},
165-
'is': {m: '204c8f73', v: '6bbe7a8f', x: '7f3e38b8'},
166-
'it': {m: '716e7242', v: '3b781f09', x: '469cb2af'},
167-
'ja': {m: 'ab56d7cb', v: '48645d06', x: '46faea8b'},
168-
'ka': {m: '6961b7e4', v: '40feb44f', x: '4e712712'},
169-
'ko': {m: 'c758b027', v: 'd3b54047', x: 'fc4c50ed'},
170-
'lt': {m: 'c36fbafb', v: 'd5f9b95d', x: 'f50f2b50'},
171-
// mk: v = english but not number format, and xml n30 = english but is would-be-n39 (same as el)
172-
// and n27 n28 = english
173-
'mk': {m: '78274f1b', v: '333aae58', x: '3b22df8b'},
174-
'ms': {m: '3e26c6be', v: '9dadbc64', x: 'f23d0969'},
175-
// my: two items in english: date+over/under
176-
'my': {m: '939f2013', v: '43cc3aa3', x: '11d4d458'},
177-
// nb-NO: xml most is english
178-
'nb-NO': {m: '1d496fea', v: '84ce54eb', x: '50426960'},
179-
'nl': {m: 'e1d3b281', v: '326cbfd2', x: 'b03574e4'},
180-
'pl': {m: '0bd88e98', v: '95ad4851', x: 'c1295e2b'},
181-
'pt-BR': {m: '39835e93', v: 'de2c3569', x: '96f79e68'},
182-
'pt-PT': {m: '6ae9a13a', v: 'b21f3984', x: 'b42389f7'},
183-
'ro': {m: '3e321768', v: 'd72a350b', x: 'cf85bb64'},
184-
'ru': {m: '8e9b7945', v: '2391fbec', x: '2178a2b6'},
185-
'sq': {m: '91943e67', v: 'e0259277', x: 'a732eca1'},
186-
'sv-SE': {m: 'bc792ce2', v: 'd9d7828b', x: '80f52165'},
187-
'th': {m: 'a32d70a7', v: '07358a87', x: 'e29567ce'},
188-
'tr': {m: '4217ef80', v: '5048d312', x: 'e16dd3c7'},
189-
'uk': {m: '3e2b3e39', v: '0163f51d', x: 'cc85d2f5'},
190-
'vi': {m: 'bba6c980', v: 'b8137d59', x: '7cf3c6f9'},
191-
'zh-Hans-CN': {m: '550ea53e', v:'0e58f82a', x: '328cc79b'},
192-
'zh-Hant-TW': {m: '66b515a4', v: '8e4cfa0e', x: '87abb9fa'},
145+
'ar': {m: '1f9a06e3', v: '1dfb5b8c', x: '71982b47'},
146+
'be': {m: '076d68e6', v: '4edeafab', x: '42583d22'},
147+
'bg': {m: '2da6c02e', v: 'ce892c88', x: 'c4f06f98'},
148+
'ca': {m: 'd856d812', v: '6b3bb3d8', x: '77a62a49'},
149+
'cs': {m: 'c92accb0', v: 'de3ab0ad', x: '81c91d49'},
150+
'da': {m: '39169214', v: '479797a1', x: 'a30818e8'},
151+
'de': {m: '298d11c6', v: 'f9e2eae6', x: 'c1ce6571'},
152+
'el': {m: '7053311d', v: 'b1a88a13', x: '493f7225'},
153+
'en-US': {m: '05c30936', v: '41310558', x: '544e1ae8'},
154+
'es-ES': {m: '96b78cbd', v: '97c3f5a9', x: 'ed807f70'},
155+
'fa': {m: '6648d919', v: '8ef57409', x: '1ed34bca'},
156+
'fi': {m: '82d079c7', v: '3e29e6e7', x: '859efc32'},
157+
'fr': {m: '024d0fce', v: '34e28fa2', x: '1d2050d3'},
158+
'ga-IE': {m: '97fca229', v: '2bf1321d', x: 'd3af2cd8'},
159+
'he': {m: 'cdde832b', v: 'e47dbb82', x: 'c7274a3e'},
160+
'hu': {m: 'db7366e6', v: 'dad6d689', x: 'e4f85168'},
161+
'id': {m: '1e275882', v: '71224946', x: 'a70cd23c'},
162+
'is': {m: '204c8f73', v: '6bbe7a8f', x: 'edb8b212'},
163+
'it': {m: '716e7242', v: '3b781f09', x: 'c567f479'},
164+
'ja': {m: 'ab56d7cb', v: '48645d06', x: 'a58f6165'},
165+
'ka': {m: '6961b7e4', v: '40feb44f', x: 'bfbc28c2'},
166+
'ko': {m: 'c758b027', v: 'd3b54047', x: '1235e26d'},
167+
'lt': {m: 'c36fbafb', v: 'd5f9b95d', x: 'b0e8a3bc'},
168+
'mk': {m: '78274f1b', v: '333aae58', x: 'b6020ec1'},
169+
'ms': {m: '3e26c6be', v: '9dadbc64', x: '15e6148f'},
170+
'my': {m: '939f2013', v: '43cc3aa3', x: 'a6571ec7'},
171+
'nb-NO': {m: '1d496fea', v: '84ce54eb', x: 'e0d34e04'},
172+
'nl': {m: 'e1d3b281', v: '326cbfd2', x: 'caef95fc'},
173+
'pl': {m: '0bd88e98', v: '95ad4851', x: '2a45177d'},
174+
'pt-BR': {m: '39835e93', v: 'de2c3569', x: '68f80c66'},
175+
'pt-PT': {m: '6ae9a13a', v: 'b21f3984', x: '0aa2a309'},
176+
'ro': {m: '3e321768', v: 'd72a350b', x: 'a9da3416'},
177+
'ru': {m: '8e9b7945', v: '2391fbec', x: '26f663da'},
178+
'sq': {m: '91943e67', v: 'e0259277', x: '4e0bbdcd'},
179+
'sv-SE': {m: 'bc792ce2', v: 'd9d7828b', x: '4af3452f'},
180+
'th': {m: 'a32d70a7', v: '07358a87', x: '2a04071a'},
181+
'tr': {m: '4217ef80', v: '5048d312', x: '55daef93'},
182+
'uk': {m: '3e2b3e39', v: '0163f51d', x: '4f817ea3'},
183+
'vi': {m: 'bba6c980', v: 'b8137d59', x: '80da1efb'},
184+
'zh-Hans-CN': {m: '550ea53e', v:'0e58f82a', x: '536abb21'},
185+
'zh-Hant-TW': {m: '66b515a4', v: '8e4cfa0e', x: '9ad3338c'},
193186
}
194187
// mac: japanese languages are the same but the locale is 'ja-JP' not 'ja'
195188
if ('mac' == isOS) {
@@ -809,6 +802,99 @@ function get_locale_resolvedoptions(METRIC) {
809802
return
810803
}
811804

805+
const get_messages_media = (METRIC) => new Promise(resolve => {
806+
let hash, btn='', data = {}, notation = isLanguageSmart ? locale_red : ""
807+
try {
808+
let aList = ['Invalid','Scaled']
809+
for (const k of aList) {
810+
let name = k +'Image'
811+
let target = dom[name], title = ''
812+
if ('Scaled' == k) {
813+
title = target.contentWindow.document.title
814+
title = title.replace(name +'.png', '') // strip image name to reduce noise
815+
} else {
816+
const image = target.contentWindow.document.querySelector('img')
817+
title = image.alt
818+
title = title.replace(target.src, '') // remove noise
819+
}
820+
data[name] = title.trim()
821+
}
822+
hash = mini(data); btn = addButton(4, METRIC)
823+
if (isLanguageSmart) {
824+
if (isLocaleValid && localesSupported[isLocaleAlt] !== undefined) {
825+
if (hash === localesSupported[isLocaleAlt].m) {notation = locale_green}
826+
}
827+
}
828+
} catch(e) {
829+
hash = e; data = zErrLog
830+
}
831+
addBoth(4, METRIC, hash, btn, notation, data)
832+
return resolve()
833+
})
834+
835+
function get_messages_validation(METRIC) {
836+
const aNames = ['BadInputNumber','CheckboxMissing','DateTimeRangeOverflow','DateTimeRangeUnderflow',
837+
'FileMissing','InvalidEmail','InvalidURL','NumberRangeOverflow','NumberRangeUnderflow',
838+
'PatternMismatch','RadioMissing','SelectMissing','StepMismatch','ValueMissing',]
839+
const input = "<input type='number' required>"
840+
+ "<input type='checkbox' required>"
841+
+ "<input type='date' value='2024-01-01' max='2023-12-31'>"
842+
+ "<input type='date' value='2022-01-01' min='2023-12-31'>"
843+
+ "<input type='file' required>"
844+
+ "<input type='email' value='a'>"
845+
+ "<input type='url' value='a'>"
846+
+ "<input type='number' max='1974.3' value='2000'>"
847+
+ "<input type='number' min='8026.5' value='1'>"
848+
+ "<input type='tel' pattern='[0-9]{1}' value='a'>"
849+
+ "<input type='radio' required name='radiogroup'>"
850+
+ "<select required><option></option></select>"
851+
+ "<input type='number' min='1.2345' step='1005.5545' value='2'>"
852+
+ "<input type='text' required>"
853+
854+
let hash, btn ='', data = {}, notation = isLanguageSmart ? locale_red : ''
855+
try {
856+
let collection = ((new DOMParser).parseFromString(input, 'text/html')).body.children
857+
let cType = typeFn(collection)
858+
if ('object' !== cType) {throw zErrType + cType}
859+
for (const k of Object.keys(collection)) {
860+
let msg = collection[k].validationMessage
861+
if (runST) {msg = undefined}
862+
let typeCheck = typeFn(msg)
863+
if ('string' !== typeCheck) {throw zErrType + typeCheck}
864+
data[aNames[k]] = msg
865+
}
866+
hash = mini(data)
867+
let count = Object.keys(data).length
868+
let details = count === aNames.length ? 'details' : count +'/' + aNames.length
869+
btn = addButton(4, METRIC, details)
870+
if (isLanguageSmart) {
871+
if (isLocaleValid && localesSupported[isLocaleAlt] !== undefined) {
872+
if (hash === localesSupported[isLocaleAlt].v) {notation = locale_green}
873+
}
874+
}
875+
} catch(e) {
876+
hash = e; data = zErrLog
877+
}
878+
addBoth(4, METRIC, hash ,btn, notation, data)
879+
return
880+
}
881+
882+
function get_messages_xml(METRIC) {
883+
let hash, btn ='', data = isXML, notation = isLanguageSmart ? locale_red : ""
884+
if ('string' == typeof isXML) {
885+
hash = isXML; data = isXML == zNA ? '' : zErrLog
886+
} else {
887+
hash = mini(isXML); btn = addButton(4, METRIC)
888+
if (isLanguageSmart) {
889+
if (isLocaleValid && localesSupported[isLocaleAlt] !== undefined) {
890+
if (hash === localesSupported[isLocaleAlt].x) {notation = locale_green}
891+
}
892+
}
893+
}
894+
addBoth(4, METRIC, hash, btn, notation, data)
895+
return
896+
}
897+
812898
function get_timezone(METRIC) {
813899
let t0 = nowFn()
814900
const METRICtz = 'timezone'
@@ -1158,99 +1244,6 @@ function get_timezone_offset(METRIC) {
11581244
return
11591245
}
11601246

1161-
const get_media_messages = (METRIC) => new Promise(resolve => {
1162-
let hash, btn='', data = {}, notation = isLanguageSmart ? locale_red : ""
1163-
try {
1164-
let aList = ['Invalid','Scaled']
1165-
for (const k of aList) {
1166-
let name = k +'Image'
1167-
let target = dom[name], title = ''
1168-
if ('Scaled' == k) {
1169-
title = target.contentWindow.document.title
1170-
title = title.replace(name +'.png', '') // strip image name to reduce noise
1171-
} else {
1172-
const image = target.contentWindow.document.querySelector('img')
1173-
title = image.alt
1174-
title = title.replace(target.src, '') // remove noise
1175-
}
1176-
data[name] = title.trim()
1177-
}
1178-
hash = mini(data); btn = addButton(4, METRIC)
1179-
if (isLanguageSmart) {
1180-
if (isLocaleValid && localesSupported[isLocaleAlt] !== undefined) {
1181-
if (hash === localesSupported[isLocaleAlt].m) {notation = locale_green}
1182-
}
1183-
}
1184-
} catch(e) {
1185-
hash = e; data = zErrLog
1186-
}
1187-
addBoth(4, METRIC, hash, btn, notation, data)
1188-
return resolve()
1189-
})
1190-
1191-
function get_validation_messages(METRIC) {
1192-
const aNames = ['BadInputNumber','CheckboxMissing','DateTimeRangeOverflow','DateTimeRangeUnderflow',
1193-
'FileMissing','InvalidEmail','InvalidURL','NumberRangeOverflow','NumberRangeUnderflow',
1194-
'PatternMismatch','RadioMissing','SelectMissing','StepMismatch','ValueMissing',]
1195-
const input = "<input type='number' required>"
1196-
+ "<input type='checkbox' required>"
1197-
+ "<input type='date' value='2024-01-01' max='2023-12-31'>"
1198-
+ "<input type='date' value='2022-01-01' min='2023-12-31'>"
1199-
+ "<input type='file' required>"
1200-
+ "<input type='email' value='a'>"
1201-
+ "<input type='url' value='a'>"
1202-
+ "<input type='number' max='1974.3' value='2000'>"
1203-
+ "<input type='number' min='8026.5' value='1'>"
1204-
+ "<input type='tel' pattern='[0-9]{1}' value='a'>"
1205-
+ "<input type='radio' required name='radiogroup'>"
1206-
+ "<select required><option></option></select>"
1207-
+ "<input type='number' min='1.2345' step='1005.5545' value='2'>"
1208-
+ "<input type='text' required>"
1209-
1210-
let hash, btn ='', data = {}, notation = isLanguageSmart ? locale_red : ''
1211-
try {
1212-
let collection = ((new DOMParser).parseFromString(input, 'text/html')).body.children
1213-
let cType = typeFn(collection)
1214-
if ('object' !== cType) {throw zErrType + cType}
1215-
for (const k of Object.keys(collection)) {
1216-
let msg = collection[k].validationMessage
1217-
if (runST) {msg = undefined}
1218-
let typeCheck = typeFn(msg)
1219-
if ('string' !== typeCheck) {throw zErrType + typeCheck}
1220-
data[aNames[k]] = msg
1221-
}
1222-
hash = mini(data)
1223-
let count = Object.keys(data).length
1224-
let details = count === aNames.length ? 'details' : count +'/' + aNames.length
1225-
btn = addButton(4, METRIC, details)
1226-
if (isLanguageSmart) {
1227-
if (isLocaleValid && localesSupported[isLocaleAlt] !== undefined) {
1228-
if (hash === localesSupported[isLocaleAlt].v) {notation = locale_green}
1229-
}
1230-
}
1231-
} catch(e) {
1232-
hash = e; data = zErrLog
1233-
}
1234-
addBoth(4, METRIC, hash ,btn, notation, data)
1235-
return
1236-
}
1237-
1238-
function get_xml_messages(METRIC) {
1239-
let hash, btn ='', data = isXML, notation = isLanguageSmart ? locale_red : ""
1240-
if ('string' == typeof isXML) {
1241-
hash = isXML; data = isXML == zNA ? '' : zErrLog
1242-
} else {
1243-
hash = mini(isXML); btn = addButton(4, METRIC)
1244-
if (isLanguageSmart) {
1245-
if (isLocaleValid && localesSupported[isLocaleAlt] !== undefined) {
1246-
if (hash === localesSupported[isLocaleAlt].x) {notation = locale_green}
1247-
}
1248-
}
1249-
}
1250-
addBoth(4, METRIC, hash, btn, notation, data)
1251-
return
1252-
}
1253-
12541247
const get_dates = () => new Promise(resolve => {
12551248
let d = new Date(Date.UTC(2023, 0, 1, 0, 0, 1)) //
12561249
let o = {weekday: "long", month: "long", day: "numeric", year: "numeric", hour: "numeric",
@@ -1358,13 +1351,13 @@ const outputRegion = () => new Promise(resolve => {
13581351
get_locale_resolvedoptions('locale_resolvedoptions'),
13591352
get_locale_intl(),
13601353
get_timezone('timezone_offsets'), // sets isTimeZoneValid/Value
1361-
get_validation_messages('messages_validation'),
1362-
get_xml_messages('messages_xml'),
1354+
get_messages_validation('messages_validation'),
1355+
get_messages_xml('messages_xml'),
13631356
]).then(function(){
13641357
Promise.all([
13651358
get_timezone_offset('timezone_offset'), // might use isTimeZoneValid/Value
13661359
get_dates(), // will use isTimeZoneValid/Value + isLocaleValid/Value
1367-
get_media_messages('messages_media'),
1360+
get_messages_media('messages_media'),
13681361
]).then(function(){
13691362
return resolve()
13701363
})

0 commit comments

Comments
 (0)