www: fix tooltip met apostrof

This commit is contained in:
Peter Kleiweg
2026-04-14 19:16:15 +02:00
parent e49bdf82dd
commit 23c1881227
2 changed files with 141 additions and 115 deletions

View File

@@ -1,113 +1,136 @@
var tooltip=function(){ var tooltip = (function () {
var id = 'tt'; var id = 'tt'
var top = 3; var top = 3
var left = 3; var left = 3
var maxw = 500; var maxw = 500
var speed = 10; var speed = 10
var timer = 20; var timer = 20
var endalpha = 95; var endalpha = 95
var alpha = 0; var alpha = 0
var tt,t,c,b,h; var tt, t, c, b, h
var ie = document.all ? true : false; var ie = document.all ? true : false
return{ return {
show:function(v,w,below){ show: function (v, w, below) {
if (v.search("<table") == 0) { if (tt == null) {
v = v.replace(/&lt;/g, "<") tt = document.createElement('div')
.replace(/&gt;/g, ">") tt.setAttribute('id', id)
.replace(/&quot;/g, "\"") t = document.createElement('div')
.replace(/&apos;/g, "'") t.setAttribute('id', id + 'top')
.replace(/&amp;/g, "&"); c = document.createElement('div')
} c.setAttribute('id', id + 'cont')
if(tt == null){ b = document.createElement('div')
tt = document.createElement('div'); b.setAttribute('id', id + 'bot')
tt.setAttribute('id',id); tt.appendChild(t)
t = document.createElement('div'); tt.appendChild(c)
t.setAttribute('id',id + 'top'); tt.appendChild(b)
c = document.createElement('div'); document.body.appendChild(tt)
c.setAttribute('id',id + 'cont'); tt.style.opacity = 0
b = document.createElement('div'); tt.style.filter = 'alpha(opacity=0)'
b.setAttribute('id',id + 'bot'); }
tt.appendChild(t); document.onmousemove = below ? this.pos2 : this.pos
tt.appendChild(c); tt.style.display = 'block'
tt.appendChild(b); c.innerHTML = v
document.body.appendChild(tt); tt.style.width = w ? w + 'px' : 'auto'
tt.style.opacity = 0; if (!w && ie) {
tt.style.filter = 'alpha(opacity=0)'; t.style.display = 'none'
} b.style.display = 'none'
document.onmousemove = below ? this.pos2 : this.pos; tt.style.width = tt.offsetWidth
tt.style.display = 'block'; t.style.display = 'block'
c.innerHTML = v; b.style.display = 'block'
tt.style.width = w ? w + 'px' : 'auto'; }
if(!w && ie){ if (tt.offsetWidth > maxw) {
t.style.display = 'none'; tt.style.width = maxw + 'px'
b.style.display = 'none'; }
tt.style.width = tt.offsetWidth; h = parseInt(tt.offsetHeight) + top
t.style.display = 'block'; clearInterval(tt.timer)
b.style.display = 'block'; tt.timer = setInterval(function () {
} tooltip.fade(1)
if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'} }, timer)
h = parseInt(tt.offsetHeight) + top; },
clearInterval(tt.timer); pos: function (e) {
tt.timer = setInterval(function(){tooltip.fade(1)},timer); var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY
}, var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX
pos:function(e){ var w =
var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY; window.innerWidth ||
var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX; document.documentElement.clientWidth ||
var w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; document.body.clientWidth
var o = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0; var o =
var scroll = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; window.pageXOffset ||
var top = u - h; document.documentElement.scrollLeft ||
if (top < scroll + 10) { document.body.scrollLeft ||
top = scroll + 10; 0
} var scroll =
tt.style.top = top + 'px'; window.pageYOffset ||
if (w > maxw && l + maxw > w + o) { document.documentElement.scrollTop ||
tt.style.right = (w - l - left + 10) + 'px'; document.body.scrollTop ||
tt.style.left = 'auto'; 0
} else { var top = u - h
tt.style.left = (l + left + 10) + 'px'; if (top < scroll + 10) {
tt.style.right = 'auto'; top = scroll + 10
} }
}, tt.style.top = top + 'px'
pos2:function(e){ if (w > maxw && l + maxw > w + o) {
var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY; tt.style.right = w - l - left + 10 + 'px'
var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX; tt.style.left = 'auto'
var w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; } else {
var o = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0; tt.style.left = l + left + 10 + 'px'
var scroll = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; tt.style.right = 'auto'
var top = u + 24; }
if (top < scroll + 10) { },
top = scroll + 10; pos2: function (e) {
} var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY
tt.style.top = top + 'px'; var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX
if (w > maxw && l + maxw > w + o) { var w =
tt.style.right = (w - l - left + 10) + 'px'; window.innerWidth ||
tt.style.left = 'auto'; document.documentElement.clientWidth ||
} else { document.body.clientWidth
tt.style.left = (l + left + 10) + 'px'; var o =
tt.style.right = 'auto'; window.pageXOffset ||
} document.documentElement.scrollLeft ||
}, document.body.scrollLeft ||
fade:function(d){ 0
var a = alpha; var scroll =
if((a != endalpha && d == 1) || (a != 0 && d == -1)){ window.pageYOffset ||
var i = speed; document.documentElement.scrollTop ||
if(endalpha - a < speed && d == 1){ document.body.scrollTop ||
i = endalpha - a; 0
}else if(alpha < speed && d == -1){ var top = u + 24
i = a; if (top < scroll + 10) {
} top = scroll + 10
alpha = a + (i * d); }
tt.style.opacity = alpha * .01; tt.style.top = top + 'px'
tt.style.filter = 'alpha(opacity=' + alpha + ')'; if (w > maxw && l + maxw > w + o) {
}else{ tt.style.right = w - l - left + 10 + 'px'
clearInterval(tt.timer); tt.style.left = 'auto'
if(d == -1){tt.style.display = 'none'} } else {
} tt.style.left = l + left + 10 + 'px'
}, tt.style.right = 'auto'
hide:function(){ }
clearInterval(tt.timer); },
tt.timer = setInterval(function(){tooltip.fade(-1)},timer); fade: function (d) {
} var a = alpha
}; if ((a != endalpha && d == 1) || (a != 0 && d == -1)) {
}(); var i = speed
if (endalpha - a < speed && d == 1) {
i = endalpha - a
} else if (alpha < speed && d == -1) {
i = a
}
alpha = a + i * d
tt.style.opacity = alpha * 0.01
tt.style.filter = 'alpha(opacity=' + alpha + ')'
} else {
clearInterval(tt.timer)
if (d == -1) {
tt.style.display = 'none'
}
}
},
hide: function () {
clearInterval(tt.timer)
tt.timer = setInterval(function () {
tooltip.fade(-1)
}, timer)
},
}
})()

View File

@@ -14,6 +14,9 @@ titles = {
'tag.txt': 'tags' 'tag.txt': 'tags'
} }
def e(s):
return s.replace('&#x27;', '&amp;#x27;')
omt0 = ''' onmouseover="tooltip.show('{} &nbsp; {}')" onmouseout="tooltip.hide()"''' omt0 = ''' onmouseover="tooltip.show('{} &nbsp; {}')" onmouseout="tooltip.hide()"'''
omt1 = ''' onmouseover="tooltip.show('{} &nbsp; {}&lt;br&gt;&lt;small&gt;{}&lt;/small&gt;')" onmouseout="tooltip.hide()" class="tags"''' omt1 = ''' onmouseover="tooltip.show('{} &nbsp; {}&lt;br&gt;&lt;small&gt;{}&lt;/small&gt;')" onmouseout="tooltip.hide()" class="tags"'''
@@ -47,9 +50,9 @@ with open(sys.argv[1], 'rt', encoding='utf-8') as fp:
cols=len(aa) cols=len(aa)
p = 100 / mx * v p = 100 / mx * v
if len(aa) > 2: if len(aa) > 2:
mo = omt1.format(aa[0], aa[1], aa[2]) mo = omt1.format(e(aa[0]), e(aa[1]), e(aa[2]))
else: else:
mo = omt0.format(aa[0], aa[1]) mo = omt0.format(e(aa[0]), e(aa[1]))
sys.stdout.buffer.write('<tr{}><td><div style="width:{:.0f}%"></div><td>{}</tr>\n'.format(mo, p, aa[1]).encode('utf-8')) sys.stdout.buffer.write('<tr{}><td><div style="width:{:.0f}%"></div><td>{}</tr>\n'.format(mo, p, aa[1]).encode('utf-8'))
lineno += 1 lineno += 1
if lineno == 20: if lineno == 20: