Welcome to the Club Penguin Wiki! Log in or Create an account to join the community!

User:Lisured/common.js

From the Club Penguin Wiki, the free, editable encyclopedia about Club Penguin
Revision as of 13:51, 6 June 2015 by imported>Lisured
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.
jQuery(document).ready(function($) {
	var textbox = $('#wpTextbox1');

	// add keyboard shortcut for bold
	textbox.keydown(function(e) {
		if (textbox.is(':focus') && e.which == 66 && e.ctrlKey && !e.altKey) {
			$('.tool-button[rel="bold"]').click();
			e.preventDefault();
		}
	});


	// add formatting fixes button
	textbox.wikiEditor('addToToolbar', {
		section: 'main',
		group: 'format',
		tools: {
			buttonId: {
				label: 'Common fixes',
				type: 'button',
				icon: '//upload.wikimedia.org/wikipedia/commons/a/a0/Toolbaricon_bold_F-1.png',
				action: {
					type: 'callback',
					execute: function(context) {
						console.log(context);
						context.$textarea.val(
							context.$textarea.val()
							// insert spaces around section headings (like wikipedia does)
							.replace(/^(==+)([^= ].+)\1$/gm, '$1 $2 $1')
							// remove redundant border from wikitable
							.replace(/border="1" class="wikitable"/gm, 'class="wikitable"')
							// remove redundant bolding in th
							.replace(/^(!)'''(.+?)'''(?:(!!)'''(.+?)'''(?:(!!)'''(.+?)'''(?:(!!)'''(.+?)'''(?:(!!)'''(.+?)'''(?:(!!)'''(.+?)''')?)?)?)?)?/gm, '$1$2$3$4$5$6$7$8$9$10$11$12')
							// insert spaces around equal signs in template params
							.replace(/^(\|[^=\n]*)(?:([^ ])| )=(?:([^ ])| )/gm, '$1$2 = $3')
							// fix table cell attributes incorrectly recognized as template params
							.replace(/^(\|(colspan|rowspan)) = /gm, '$1=')
							// use Photoswf template for background swfs
							.replace(/== SWF ==\n\*\[http:\/\/media1\.clubpenguin\.com\/play\/v2\/content\/global\/clothing\/icons\/(\d+)\.swf .+ \(icons?\)\]\n\*\[http:\/\/media1\.clubpenguin\.com\/play\/v2\/content\/global\/clothing\/photos\/\1\.swf .+ \(photos?\)\]/g, '{{Photoswf|$1}}')
							// insert a new line before interwiki links
							.replace(/([^\n])(\n\[\[pt:(?!\]\]).+\]\])/g, '$1\n$2')
							// insert a space after bullet point
							.replace(/^(\*+)([^ ])/gm, '$1 $2')
						);
					}
				}
			}
		}
	});
});