User:Saftzie/global.js

// __NOINDEX__

(function (mw, $) {	'use strict';

var wgCanonicalSpecialPageName = mw.config.get('wgCanonicalSpecialPageName'), wgNamespaceNumber = mw.config.get('wgNamespaceNumber'), wgSkin = mw.config.get('skin');

// redirect Specal:Chat to Oasis (function 	{		var			query, t;

if ((wgCanonicalSpecialPageName === 'Chat') &&	(wgSkin !== 'oasis')) {			query = location.search.slice(1).split('&'); if ((query.length === 1) && (query[0].length === 0)) {			 query = []; }			t = query.filter(function (v)			{	 		return (v.search(/^useskin=/) === 0);			}); if ((t.length === 1) && (t[0] === 'useskin=oasis')) {		 	return; // error, prevent infinite loop }			query = query.filter(function (v)			{		 	return (v.search(/^useskin=/) !== 0);			}); query.push('useskin=oasis'); location.search = '?' + query.join('&'); }	});

// add classes to closed and highlighted thread items if (wgNamespaceNumber === 2000) {		$(function 		{			$('.ThreadList > .thread').each(function {				var li = $(this);

$.post(mw.util.wikiScript('wikia'),				{					controller: 'Forum',					method: 'brickHeader',					id: li.data('id'),					format: 'json'				}, function (data)				{					if (data.isClosed)					{						li.addClass('g-closed');					}					if (data.isNotifyeveryone)					{						li.addClass('g-highlight');					}				}); });		});	}

/* dynamically generated textarea currently not supported edits to Wikia blog comments new replies to Wikia blog comments (#article-comm-reply-textfield- ) edits to replies to Wikia blog comments edits to Wikia threads edits to replies to Wikia threads // insert tab for tab key event in edit areas // however, because of Event.timeStamp, //  it's broken in IE 8 and earlier //  and might be broken in Chrome 49 and later $(function 	{		var			t = 0;

// insert a tab function tab(textarea) {			var s = textarea.selectionStart, t = textarea.scrollTop, v = textarea.value;

textarea.value = v.substr(0, s) + '\t' + v.substr(textarea.selectionEnd); textarea.scrollTop = t;			textarea.selectionStart = textarea.selectionEnd = s + 1; }

// attach keydown and keypress handlers to DOM elements function handle(select) {			$(select).keydown(function (e)			{				var					epoch = e.timeStamp;

if (e.keyCode === 9) {					e.preventDefault; if (typeof e.stopPropagation === 'function') { // required for replies to Wikia threads e.stopPropagation; }					if (epoch !== t)					{ tab(this); t = epoch; }				}			}).keypress(function (e) {				var epoch = e.timeStamp;

if (e.keyCode === 9) {					e.preventDefault; if (epoch !== t)					{ tab(this); t = epoch; }				}			});		}

// some things can take key handlers at document.ready handle(			'#wpTextbox1,'  + // articles, includes Wikia blogs			'#Wall .body,'   + // new Wikia threads			'#Wall .replyBody' // new replies to Wikia threads		);

// new comments on articles/blogs need to wait longer (function afterContentReady		{			if ($('#mw-data-after-content').length > 0)			{				if ($('#article-comm').length === 0)				{					setTimeout(afterContentReady, 100);				}				else				{					handle('#article-comm');				}			}		}); }); }(mediaWiki, jQuery));