User:Nikki/LexemeToggleSections.js

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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* This adds expand/collapse toggles to the section headings on lexeme pages.

   To use it, add the following line to your common.js:
   mw.loader.load("https//www.wikidata.org/w/index.php?title=User:Nikki/LexemeToggleSections.js&action=raw&ctype=text/javascript");

   License: CC0
*/

(function () {
	mw.hook("wikibase.entityPage.entityView.rendered").add(function () {
	mw.hook("wikibase.entityPage.entityLoaded").add(function (e) {
		if (!e.language)
			return;

		var css = {
			"color": "#bbb",
			"cursor": "pointer",
			"display": "inline-block",
			"font-size": "medium",
			"padding": "3px",
			"user-select": "none",
			"vertical-align": "middle",
			"width": "1em",
		}
		var d = "▼";
		var r = "▶";

		$("<span/>").css(css).text(d).on("click", function () {
			$(".wikibase-entityview-main > .wikibase-statementgrouplistview").toggle();
			$(this).text( $(this).text() == r ? d : r );
		}).prependTo(".wikibase-statements");

		$("<span/>").css(css).text(d).on("click", function () {
			$(".wikibase-lexeme-forms").toggle();
			$(".wikibase-lexeme-forms-section > .wikibase-addtoolbar").toggle();
			$(this).text( $(this).text() == r ? d : r );
		}).prependTo(".wikibase-lexeme-forms-section > .wb-section-heading");

		$("<span/>").css(css).text(d).on("click", function () {
			$(".wikibase-lexeme-senses").toggle();
			$(".wikibase-lexeme-senses-section > .wikibase-addtoolbar").toggle();
			$(this).text( $(this).text() == r ? d : r );
		}).prependTo(".wikibase-lexeme-senses-section > .wb-section-heading");

	});
	});
})();
  NODES
Note 1