-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxmlunstyled.html
More file actions
97 lines (85 loc) · 2.84 KB
/
Copy pathxmlunstyled.html
File metadata and controls
97 lines (85 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>xml unstyled</title>
</head>
<body>
<p id='info'></p>
<p>xslt: <span id='xslterror'></span> <bdo dir='ltr'><span id='xslthash'></span></bdo></p>
<p><button type="button" onclick="measure()">measure</button> <span id='results'><span></p>
<!-- we need to force a really narrow width as some scripts have narrow single char words
- and in order to see the numbmer of lines (scrollbars get in the way), we will use a large height
-->
<iframe id='test' width='20px' height='30px' src='xmlunstyled.xml'></iframe><br>
<iframe id='view' width='20px' height='1500px' src='xmlunstyled.xml'></iframe>
<iframe id='visual' width='200px' height='1500px' src='xmlunstyled.xml'></iframe>
<iframe id='xslt' width='200px' height='1500px' src='xslterror1.xml'></iframe>
</div>
<script>
'use strict';
// https://searchfox.org/firefox-main/source/dom/locales/en-US/dom = XMLPrettyPrint
function mini(str) {
// https://stackoverflow.com/a/22429679
const json = `${JSON.stringify(str)}`
let len = json.length, hash = 0x811c9dc5
for (let i=0; i < len; i++) {
hash = Math.imul(31, hash) + json.charCodeAt(i) | 0
}
return ('0000000' + (hash >>> 0).toString(16)).slice(-8)
}
function set_info() {
let isLocale, isLanguage
try {
isLocale = Intl.DateTimeFormat().resolvedOptions().locale
} catch(e) {
isLocale = 'error'; console.log(e)
}
try {
isLanguage = navigator.language
} catch(e) {
isLanguage = 'error'; console.log(e)
}
document.getElementById('info').innerHTML = 'language: '+ isLanguage +' | locale: '+ isLocale
}
set_info()
let target = document.getElementById('test'),
view = document.getElementById('view'),
visual = document.getElementById('visual'),
xslt = document.getElementById('xslt')
// we need to wait for the xml file to load
// just stick it behind a button for now
function measure() {
let testheight, viewheight, visualheight, xsltresult, xslthash =''
try {
testheight = target.contentDocument.firstChild.getBoundingClientRect().height
} catch(e) {
console.log('testheight',e)
testheight = 'error'
}
try {
viewheight = view.contentDocument.firstChild.getBoundingClientRect().height
} catch(e) {
console.log('viewheight',e)
viewheight = 'error'
}
try {
visualheight = visual.contentDocument.firstChild.getBoundingClientRect().height
} catch(e) {
console.log('visualheight',e)
visualheight = 'error'
}
document.getElementById('results').innerHTML = 'short: '+ testheight
+' | tall: '+ viewheight +' | visual: '+ visualheight
// get xslt style error
try {
xsltresult = xslt.contentDocument.children[0].textContent
xslthash = mini(xsltresult)
} catch(e) {
xsltresult = e
}
document.getElementById('xslterror').innerHTML = xsltresult
document.getElementById('xslthash').innerHTML = xslthash
}
</script>
</body>
</html>