มีเดียวิกิ:Common.js

จาก วิกิพจนานุกรม พจนานุกรมเสรี

หมายเหตุ: หลังเผยแพร่ คุณอาจต้องล้างแคชเว็บเบราว์เซอร์ของคุณเพื่อดูการเปลี่ยนแปลง

  • ไฟร์ฟอกซ์ / ซาฟารี: กด Shift ค้างขณะคลิก Reload หรือกด Ctrl-F5 หรือ Ctrl-R (⌘-R บนแมค)
  • กูเกิล โครม: กด Ctrl-Shift-R (⌘-Shift-R บนแมค)
  • อินเทอร์เน็ตเอกซ์พลอเรอร์ และ Edge: กด Ctrl ค้างขณะคลิก Refresh หรือกด Ctrl-F5
  • โอเปร่า: กด Ctrl-F5
/**
 * Keep code in MediaWiki:Common.js to a minimum as it is unconditionally
 * loaded for all users on every wiki page. If possible create a gadget that is
 * enabled by default instead of adding it here (since gadgets are fully
 * optimized ResourceLoader modules with possibility to add dependencies etc.)
 *
 * Since Common.js isn't a gadget, there is no place to declare its
 * dependencies, so we have to lazy load them with mw.loader.using on demand and
 * then execute the rest in the callback. In most cases these dependencies will
 * be loaded (or loading) already and the callback will not be delayed. In case a
 * dependency hasn't arrived yet it'll make sure those are loaded before this.
 */
'use strict';
// [[หมวดหมู่:สคริปต์วิกิพจนานุกรม]] <nowiki>
/*jshint shadow:true, undef:true, latedef:true, unused:true, es3:true */
/*global jQuery, mw, importScript, importStylesheet, $ */



// == Unsupported titles == 
// [[Special:PrefixIndex/Unsupported titles]]
// [[MediaWiki:UnsupportedTitles.js]]
if ((mw.config.get('wgAction') === 'view' && /^(?:พูดคุย:)?ชื่อไม่รองรับ\//.test(mw.config.get('wgPageName')))
		|| mw.config.get('wgCanonicalSpecialPageName') == 'Badtitle')
	mw.loader.using('mediawiki.util', function(){importScript("MediaWiki:UnsupportedTitles.js");});


if (mw.config.get("wgTitle").indexOf("แบ่งตามภาษา") != -1)
$("a.CategoryTreeLabelCategory").text(
	function(index, content) {
		return content.replace(
			/^Requests for (?:verification|deletion|cleanup) in (.+) entries$/,
			"$1"
		);
	}
);

// removes "0 c" for categories that do not have subcategories
$(".CategoryTreeEmptyBullet + a + span")
	.html(
		function(index, content) {
			return content.replace(
				"0 ม, ",
				""
			);
		}
	);


// Various fixes for the trees generated by [[Module:family tree]].
$(function () {
	// Show the top toggle.
	$('.familytree-toptoggle').css('display', '');
	
	// Initialize the text of the toggles.
	$('.familytree').get().forEach(function (tree) {
		var isCollapsed = tree.classList.contains('mw-collapsed');
		var toggles = $(tree).find('.familytree-toggle');
		if (toggles[0]) {
			var customToggleClass = Array.from(toggles[0].classList).filter(function (className) {
				return className.indexOf('mw-customtoggle-familytree') === 0;
			})[0];
			if (customToggleClass) {
				var toggledElement = $('#' + customToggleClass.replace('mw-customtoggle', 'mw-customcollapsible'));
				if (toggledElement) {
					toggles.html(toggledElement.data(isCollapsed ? 'expandtext' : 'collapsetext'));
				}
			}
		}
	});
	
	// Change the text in the custom toggles generated by [[Module:family tree]]
	// when they are clicked.
	$('.mw-collapsible').on('beforeExpand.mw-collapsible beforeCollapse.mw-collapsible',
    function (event) {
        if (this.id.indexOf('mw-customcollapsible-familytree') === 0) {
            var toggle = $('.' + this.id.replace('mw-customcollapsible', 'mw-customtoggle'));
            if (event.type === 'beforeExpand') {
                toggle.html(this.dataset.collapsetext);
            } else { // beforeCollapse
                toggle.html(this.dataset.expandtext);
            }
            event.stopPropagation();
        }
    });
});


// </nowiki>
// The rest of the scripts are at [[MediaWiki:Gadget-legacy.js]].
// Most of them should be converted into gadgets as time and resources allow.