MediaWiki:Gadget-Tooltip.js: Difference between revisions
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 4: | Line 4: | ||
}); | }); | ||
// Auto-positioning of floating tooltips, | // Auto-positioning of floating tooltips, on desktop/hoverable only (maybe need to refine by skin so that it matches the css?) | ||
mw.loader.using('oojs-ui-widgets').then(() => { // make sure the PopupWidget library is loaded | mw.loader.using('oojs-ui-widgets').then(() => { // make sure the PopupWidget library is loaded | ||
const supportsHover = window.matchMedia('(hover: hover)').matches; | |||
mw.hook('wikipage.content').add((contents)=>{ // hydrate any content inserted | mw.hook('wikipage.content').add((contents)=>{ // hydrate any content inserted | ||
if (contents instanceof Element || contents instanceof NodeList) {contents = $(contents);} | if (contents instanceof Element || contents instanceof NodeList) {contents = $(contents);} | ||
| Line 33: | Line 35: | ||
// [[T:Tt]]'s toggle effect | // [[T:Tt]]'s toggle effect | ||
$wrapper.append(popup.$element); | $wrapper.append(popup.$element); | ||
// T:Extra Effect's hover effect | // T:Extra Effect's hover effect | ||
let time; | |||
$toggle.add(popup.$element).on('mouseover mouseout', (e) => { | |||
if (time) { clearTimeout(time); } | |||
time = setTimeout(()=>{ | |||
popup.toggle(e.type==='mouseout' ? false : true); | |||
}, e.type==='mouseout' ? 250 : 0); | |||
}); | |||
}); | }); | ||
}); | }); | ||
}); | }); | ||