User:Husky/monobook.js
Jump to navigation
Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
The accompanying .css page for this skin is at User:Husky/monobook.css. |
// <nowiki><pre>
/* Insert some extra buttons for handy placing of templates */
// First make an array of all possible templates with their properties
var prefix = 'subst:Gebruiker:Husky/';
var templates = [
{ "template" : "Credit", "arguments" : 0, "signature" : false,"prefix": true },
{ "template" : "Credit|PD", "arguments" : 0, "signature" : false,"prefix": true }
];
var summaries = [
['+variants', 'Added some variants to this picture'],
['+cat', 'Added categories to this picture']
];
// Main function //
window.onload = function() {
// Stuff for the toolbar
var toolbar = document.getElementById("editpage-copywarn");
if (toolbar) {
toolbar.innerHTML = '';
var toolbox = document.createElement('div');
toolbox.className = 'toolbox';
// only add them if there is a toolbar
function addButton(i) {
var template = templates[i];
var button = document.createElement('a');
button.className = 'fakebutton';
button.innerHTML = template.template_name || template.template; // take the template_name, otherwise simply the tag
button.onclick = function() {
// see if there need to be arguments first
var args = '';
if (template.arguments) {
args = prompt("Enter argument (enter none for {{PAGENAME}} )");
args = '|' + args || '|{{PAGENAME}}';
}
var signature = '';
if (template.signature) {
signature = '~~~~';
}
if (template.prefix) {
template.template = prefix + template.template;
}
insertTags('{{' + template.template + args + '}} ' + signature, '', '');
}
// okay, add to the toolbar
toolbox.appendChild(button);
}
for(var i in templates) {
addButton(i);
} // for (var i in templates)
// Okay, add the toolbox to the toolbar
toolbar.appendChild(toolbox);
} // if (toolbar)
// Add summary templates
var sumTemplates = document.getElementById('wpSummaryLabel');
if (sumTemplates) {
function addSummary(i) {
var summaryAnchor = document.createElement('a');
summaryAnchor.innerHTML = summaries[i][0];
summaryAnchor.className = 'fakebutton';
summaryAnchor.onclick = function() {
// okay, put the summary in #wpSummary
var sum = document.getElementById('wpSummary');
sum.value = summaries[i][1];
}
// Build the <li>
sumTemplates.appendChild(summaryAnchor);
}
for (var i in summaries) {
addSummary(i);
}
sumTemplates += '<br clear="all" />';
} // if (sumTemplates)
} // window.onload
// </pre></nowiki>