Welcome to the Club Penguin Wiki! Log in or Create an account to join the community!
User:Lisured/common.js: Difference between revisions
Jump to navigation
Jump to search
imported>Lisured run toolbar customizations after the toolbar has loaded |
imported>Lisured introduced more dangerous replacements |
||
Line 37: | Line 37: | ||
// 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 .+ \(icons?\)\]\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 | // insert a blank line before interwiki links | ||
.replace(/([^\n])(\n\[\[pt:(?!\]\]).+\]\])/g, '$1\n$2') | .replace(/([^\n])(\n\[\[pt:(?!\]\]).+\]\])/g, '$1\n$2') | ||
// insert a blank line before headings | |||
.replace(/([^\n])\n(==+)(.+)\2$/gm, '$1\n\n$2$3$2') | |||
// insert blank line after infobox | |||
.replace(/^\}\}([^\n])/gm, '}}\n\n$1') | |||
// insert a space after bullet point | // insert a space after bullet point | ||
.replace(/^( | .replace(/^([#:*]+)([^ ])/gm, '$1 $2') | ||
); | ); | ||
} | } |
Revision as of 14:48, 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
var customizeToolbar = function() {
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 blank line before interwiki links
.replace(/([^\n])(\n\[\[pt:(?!\]\]).+\]\])/g, '$1\n$2')
// insert a blank line before headings
.replace(/([^\n])\n(==+)(.+)\2$/gm, '$1\n\n$2$3$2')
// insert blank line after infobox
.replace(/^\}\}([^\n])/gm, '}}\n\n$1')
// insert a space after bullet point
.replace(/^([#:*]+)([^ ])/gm, '$1 $2')
);
}
}
}
}
});
};
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
mw.loader.using('user.options', function () {
// This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]])
if (mw.user.options.get('usebetatoolbar') == 1) {
$.when(
mw.loader.using('ext.wikiEditor.toolbar'), $.ready
).then(customizeToolbar);
}
});
}
// Add the customizations to LiquidThreads' edit toolbar, if available
mw.hook('ext.lqt.textareaCreated').add(customizeToolbar);