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

User:Lisured/common.js: Difference between revisions

From the Club Penguin Wiki, the free, editable encyclopedia about Club Penguin
Jump to navigation Jump to search
imported>Lisured
No edit summary
imported>Lisured
formatting fixes button
Line 1: Line 1:
var textbox = $('#wpTextbox1');
var textbox = $('#wpTextbox1');
// add keyboard shortcut for bold
textbox.keydown(function(e) {
textbox.keydown(function(e) {
if (textbox.is(':focus') && e.which == 66 && e.ctrlKey && !e.altKey) {
if (textbox.is(':focus') && e.which == 66 && e.ctrlKey && !e.altKey) {
$('.tool-button[rel="bold"]').click();
$('.tool-button[rel="bold"]').click();
e.preventDefault();
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')
// 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 .+ \(icon\)\]\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')
);
}
}
}
}
}
});
});

Revision as of 03:38, 6 June 2015

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')
						// 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 .+ \(icon\)\]\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')
					);
				}
			}
		}
	}
});