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
formatting fixes button
imported>Lisured
No edit summary
Line 1: Line 1:
var textbox = $('#wpTextbox1');
jQuery(document).ready(function($) {
var textbox = $('#wpTextbox1');


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

Revision as of 13:51, 6 June 2015

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')
						);
					}
				}
			}
		}
	});
});