User:Mr. Kakarot/global.js

importScriptPage('SkinSwitchButton/code.js', 'dev'); var monoBookText = 'MB', oasisText = 'Oasis';

importScriptPage('FastDelete/code.js', 'dev'); importScriptPage( 'AjaxUndo/code.js', 'dev' ); importScriptPage('AjaxRC/code.js', 'dev');

importScriptPage('User:Monchoman45/ChatHacks.js', 'c'); /*pm button */ if(wgCanonicalSpecialPageName == 'Chat') { function createGroupPM { var users = prompt('Enter comma seperated list of users to start a PM with',''); var users = users.split(','); mainRoom.openPrivateChat(users); } $('form#Write').append('PM'); } importScriptPage('AjaxRC/code.js', 'dev');

importArticles({   type: 'script',    articles: [        'u:wikimarks:Client.js'    ] });

/*! * @fileOverview PortableCSSPad [ 7 December 2012 ] * * Testing / developer tool * * Creates a tiny pad in which you can write/paste CSS rules. *    Similar to Firebug, but better support for raw text and w/ some extra features such as *     Beautify, Minify, Adding/removing !important * * The main script provides a simple API: * * Pad.init(opt) *    the (optional) opt object contains properties left, top, width, height *    which are positive integers specifying where to create the pad and how large it should be * Pad.open * Pad.close * * A separate loader script is required to utilize the API. In this case, the loader script * is here in the same file (at the bottom of this page) for performance reasons. The loader script * must make sure that jQuery, jQuery UI Resizable and jQuery UI Draggable are installed before * attempting to load the main script. The loader should also provide an on/off button for the pad. * * @author Copyright (c) Jeff Bradford User:Mathmagician */

/*jshint forin:true, noempty:true, eqeqeq:true, bitwise:true, strict:true, undef:true, unused:true, curly:true, browser:true, jquery:true */ /*global mediaWiki */

(function ($, mw, window, console) {	"use strict";

// private properties var options, lastSetTimeout, $liveStyle, $textarea, Pad;

/**	 * Private helper function to insert \t into #PortableCSSPad-textarea on keydown * Inserts the given text into a textarea element where the mouse cursor / caret is	 * http://stackoverflow.com/questions/1064089/inserting-a-text-where-cursor-is-using-javascript-jquery * @param {HTMLTextAreaElement} element A textarea field to insert the text into * @param {String} text The text to be inserted */	function insertAtCaret(element, text) { if (document.selection) { // Internet Explorer element.focus; var sel = document.selection.createRange; sel.text = text; element.focus; } else if (element.selectionStart || element.selectionStart === 0) { // Firefox and WebKit-based browsers var startPos = element.selectionStart; var endPos = element.selectionEnd; var scrollTop = element.scrollTop; element.value = element.value.substring(0, startPos) + text + element.value.substring(endPos, element.value.length); element.focus; element.selectionStart = startPos + text.length; element.selectionEnd = startPos + text.length; element.scrollTop = scrollTop; }	}

// [private] updates the live style (pass in the css rules as a string parameter) function updateStyle(css) { if ('string' !== typeof css) { css = $textarea.val; }		$liveStyle.text(css); }

// [private] the keyup event of #PortableCSSPad-textarea function textareaKeyup { window.clearTimeout(lastSetTimeout); lastSetTimeout = window.setTimeout(updateStyle, 500); }

// [private] reveal the pad function open { var $container = $('#PortableCSSPad-container'), style = $container[0].style, left = window.parseInt(style.left), top = window.parseInt(style.top), $window = $(window), windowWidth = $window.width, windowHeight = $window.height;

$container.removeClass('PortableCSSPad-pad-disabled');

// spawn the pad in the upper-left corner if it's offscreen (necessary precaution) if (left > windowWidth || top > windowHeight) { $container.css({ left: 0, top: 0 }); }	}

// [private] hides the pad function close { $('#PortableCSSPad-container').addClass('PortableCSSPad-pad-disabled'); }

// [private] Initializes Portable CSS Pad when called function init(opt) { // setup default options options = $.extend({			width: 380,			height: 230,			left: 0,			top: 0,			stylesheetURL: 'http://dev.wikia.com/wiki/PortableCSSPad/stylesheet.css?action=raw&ctype=text/css',			prettyDiffURL: 'http://mathmagician.wikia.com/wiki/MediaWiki:Prettydiff.js?action=raw&ctype=text/javascript'		}, opt);

// insert prettydiff, stylesheet and live-style tag into the document $('#PortableCSSPad-pretty-diff-script, #PortableCSSPad-stylesheet, #PortableCSSPad-live-style').remove; $(document.head).append('  ');

// HTML base for the whole pad var padHTML = ' PortableCSSPad             ';

// insert HTML base into document $('#PortableCSSPad-container').remove; $(document.body).after(padHTML); // initialize private properties $liveStyle = $('#PortableCSSPad-live-style'); $textarea = $('#PortableCSSPad-textarea');

// set up draggable widget, resizable widget, default style for container // requires draggable and resizable from jQuery UI, will log error if not available var containerStyle, $container; try { $container = $('#PortableCSSPad-container');

$container .draggable({				containment: 'window',				scroll: false,				stop: function {					containerStyle = this.style;					containerStyle = {						left: containerStyle.left,						top: containerStyle.top					};				}			}) .resizable({				containment: 'parent',				minWidth: 380, // strongly desired this matches value in stylesheet				minHeight: 230, // strongly desired this matches value in stylesheet				handles: 'se',				alsoResize: '#PortableCSSPad-textarea',				stop: function  {					// Test page: http://tardis.wikia.com/wiki/Forum:Monobook_users:_please_install_this_code?useskin=monobook					// patch bug where pad randomly teleports after resizing (Monobook only?)					$(this).css({ left: containerStyle.left, top: containerStyle.top });

// Test page: http://tardis.wikia.com/wiki/Forum:Monobook_users:_please_install_this_code?useskin=oasis // if container is too small, make it fit around the textarea // this patches another weird bug where the container randomly shrinks // (but the textarea was resized properly) if ($container.width < 380) { $container.css('width', $textarea.width + 10 + 'px'); }					if ($container.height < 230) { $container.css('height', $textarea.height + 39 + 'px'); }

// if textarea is bigger than container, make it fit inside the container // patches a minor resize bug when trying to resize the container outside of the window if ($textarea.height + 39 > $container.height) { $textarea.css('height', $container.height - 39 + 'px'); }					if ($textarea.width + 10 > $container.width) { $textarea.css('width', $container.width - 10 + 'px'); }				}			})			.attr('style', 'position: fixed; left: ' + options.left + 'px; top: ' + options.top + 'px; width: ' + options.width + 'px; height: ' + options.height + 'px;');

containerStyle = $container[0].style; containerStyle = { left: containerStyle.left, top: containerStyle.top };		} catch (e) { if (typeof console.error === 'function') { console.error(e, ' -- please make sure jQuery UI resizable and draggable are installed'); }		}

// textarea keydown: insert \t character when pressing tab instead of switching focus // textarea keyup:  apply style changes when the textarea contents change $textarea .keydown(function (event) {			if (9 === event.which) {				insertAtCaret(this, '\t');				return false;			}		}) .on('keyup', textareaKeyup) .attr('style', 'width: ' + (options.width - 10) + 'px; height: ' + (options.height - 39) + 'px;');

// beautify event $('#PortableCSSPad-beautify-button').click(function {			var text = $textarea.val;

if (text.length !== 0) { var prettyDiffSettings = { comments: "indent", content: false, context: "", csvchar: ",", diff: "", difflabel: "base", diffview: "sidebyside", force_indent: false, html: false, inchar: "\t", indent: "", insize: 1, lang: "css", mode: "beautify", quote: false, semicolon: false, source: text, sourcelabel: "base", style: "indent", topcoms: false };

var css = window.prettydiff(prettyDiffSettings)[0];

// fix prettydiff's "opacity: 0px" bug css = css.replace(/ 0px/g, ' 0').replace(/:0px/g, ': 0');

$textarea.val(css); }		});

// minify event $('#PortableCSSPad-minify-button').click(function {			var text = $textarea.val;

if (text.length !== 0) { var prettyDiffSettings = { comments: "indent", content: false, context: "", csvchar: ",", diff: "", difflabel: "base", diffview: "sidebyside", force_indent: false, html: false, inchar: "\t", indent: "", insize: 1, lang: "css", mode: "minify", quote: false, semicolon: false, source: text, sourcelabel: "base", style: "indent", topcoms: false };

var css = window.prettydiff(prettyDiffSettings)[0];

$textarea.val(css); }		});

// important event $('#PortableCSSPad-important-button').click(function {			var text = $textarea.val;

if (text.length !== 0) { // remove all !importants text = text.replace(/[\s]*(!important)+/g, ''); // add !important to any word boundary which is followed by ; or } text = text.replace(/\b(?=[\s]*(|\}))/g, ' !important'); $textarea.val(text); updateStyle(text); }		});

// unimportant event $('#PortableCSSPad-unimportant-button').click(function {			var text = $textarea.val;

if (text.length !== 0) { // remove all !importants text = text.replace(/[\s]*(!important)+/g, ''); $textarea.val(text); updateStyle(text); }		});

// validate event $('#PortableCSSPad-validate-button').click(function {			window.open('http://jigsaw.w3.org/css-validator/#validate_by_input');		});

// on & off events $('#PortableCSSPad-onoff-button').click(function {			var $this = $(this);

if ($this.hasClass('PortableCSSPad-onoff-button-state-off')) { $this.removeClass('PortableCSSPad-onoff-button-state-off'); $textarea.on('keyup', textareaKeyup); updateStyle; } else { $this.addClass('PortableCSSPad-onoff-button-state-off'); $textarea.off('keyup', textareaKeyup); updateStyle(''); }		});

// close event $('#PortableCSSPad-close-button').click(Pad.close); }	// [private] Pad object Pad = { open: open, close: close, init: init };

/**	 * PortableCSSPad loader, specific to Wikia.com wikis * Skins supported: Oasis, Monobook */	$(function ($) {		var WikiaBar = window.WikiaBar,			$link = $('PortableCSSPad'),			$listItem = $('').append($link);

$('#PortableCSSPad-wikialoader-link').parent.remove;

if (WikiaBar) { // unbind click tracking on toolbar WikiaBar.wikiaBarWrapperObj.off('click', WikiaBar.clickTrackingHandler); WikiaBar.wikiaBarCollapseWrapperObj.off('click', WikiaBar.clickTrackingHandler); // add link to oasis toolbar WikiaBar.wikiaBarWrapperObj.find('.tools').append($listItem); } else { // add link to monobook toolbox $('#p-tb ul').append($listItem); }

// attach init handler to $link $link = $('#PortableCSSPad-wikialoader-link'); $link.one('click', function (event) {			event.stopPropagation;

// install draggable and resizable from MediaWiki's version of jQuery UI			mw.loader.using(['jquery.ui.draggable', 'jquery.ui.resizable'], function {				var $window = $(window);

// initialize the pad Pad.init({					left: Math.floor(($window.width / 2) - 190),					top: Math.floor(($window.height / 2) - 115)				});

// open or close the pad when clicking $link $link.click(function (event) {					event.stopPropagation;					Pad.open;				});

// open pad Pad.open; });		});	});

// Validation button for CSS articles (this is separate from PortableCSSPad architecturally,	// it's more of a small related feature that is hard to justify being a standalone script) var wgPageName = mw.config.get('wgPageName'), indexOfCSS = wgPageName.indexOf('.css'); if (indexOfCSS !== -1 && wgPageName.substring(indexOfCSS) === '.css') { $(function ($) {			var stylesheetURL = mw.config.get('wgServer') + '/index.php?title=' + wgPageName + '&action=raw&ctype=text/css&maxage=0&smaxage=0';			var validatorURL = 'http://jigsaw.w3.org/css-validator/validator?uri=' + window.encodeURIComponent(stylesheetURL) + '&profile=css3&usermedium=all&warning=1&vextwarning=&lang=' + mw.config.get('wgUserLanguage');			var buttonStyle = 'cursor: pointer; display: inline-block; border: 1px solid black; width: 20px; height: 20px; background-image: url(http://images1.wikia.nocookie.net/dev/images/1/19/PortableCSSPad-icons.png); background-position: 0 -20px;';			var $button = $(' ');			var skin = mw.config.get('skin');

$button.click(function {				window.open(validatorURL);			});

if (skin === 'oasis' || skin === 'wikia') { // oasis skin $('#WikiaPageHeader > div.tally').before($button); } else { // assume monobook $button.css('margin-left', '10px'); $('#firstHeading').append($button); }		});	} }(jQuery, mediaWiki, window, window.console));