MediaWiki:Gadget-ExplainTooltips.js

From Rhythm Heaven Wiki
Revision as of 20:05, 18 July 2023 by PanchamBro (talk | contribs) (Creating gadget for mobile use)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Make it so users can click on "tooltip" spans to toggle their content
   Useful for mobile users, since there's no mouse-over */

function toggleExplain(e) {
	var old = e.getAttribute('oldContent');
	if (old && old.length > 0) {
		e.innerHTML = old;
		e.setAttribute('oldContent', '');
		e.style.borderBottom = '1px dotted';
	} else {
		e.setAttribute('oldContent', e.innerHTML);
		e.innerHTML = e.getAttribute('title');
		e.style.borderBottom = '1px dashed';
	}
}

$(function() {
	if ('ontouchstart' in window || navigator.MaxTouchPoints > 0 || navigator.msMaxTouchPoints > 0) {
		var explain_spans = document.getElementsByClassName('tooltip');
		for (var e = 0; e < explain_spans.length; e++) {
			explain_spans[e].onclick = function(){ toggleExplain(this) };
		}
	}
});