Content deleted Content added
Polygnotus (talk | contribs) ←Created page with '// Add a custom reference button to Wikipedia's Visual Editor // Add this code to your common.js page on Wikipedia // (e.g., https://en.wikipedia.org/wiki/User:YourUsername/common.js) // Wait for the VisualEditor to be ready mw.loader.using(['ext.visualEditor.desktopArticleTarget']).then(function() { // Register our custom reference tool with VisualEditor mw.hook('ve.loadModules').add(function(addPlugin) { addPlugin(makeRefTool); }); // Also...' |
Polygnotus (talk | contribs) No edit summary |
||
Line 1:
// Add a custom reference button to Wikipedia's Visual Editor that inserts a pre-formatted source citation
// Add this code to your common.js page on Wikipedia
// (e.g., https://en.wikipedia.org/wiki/User:YourUsername/common.js)
Line 31:
// Function to create and register the reference command and tool
function makeRefTool() {
// Create a reference
// Using Parsoid-style structure to ensure proper template parsing
var refContent = [{
type: 'mwReference',
Line 40 ⟶ 41:
id: 'body-' + Math.random().toString(36).substring(2, 8), // Generate a unique ID
type: 'mwReferenceContents',
// This is the key part - using proper Parsoid structure for the template
html: '<span typeof="mw:Transclusion" data-mw=\'{"parts":[{"template":{"target":{"wt":"source","href":"./Template:Source"},"params":{"url":{"wt":"https://www.atlantanewsfirst.com/2025/04/07/questions-remain-after-dead-horse-found-downtown-atlanta/"},"title":{"wt":"Questions remain after dead horse found in downtown Atlanta"},"author":{"wt":"Adam Murphy"},"date":{"wt":"April 7, 2025"},"pub":{"wt":"Atlanta News First"}},"i":0}}]}\'></span>'
}
}
Line 61 ⟶ 63:
RefTool.static.name = 'reftool';
RefTool.static.group = 'insert';
RefTool.static.title = 'Insert Atlanta News Reference';
RefTool.static.commandName = 'myrefcommand';
RefTool.static.icon = 'reference'; // Using built-in reference icon
Line 96 ⟶ 98:
.attr('role', 'button')
.attr('tabindex', '0')
.attr('title', 'Insert Atlanta News Reference')
.appendTo($button);
Line 110 ⟶ 112:
$('<span>')
.addClass('oo-ui-tool-title')
.text('Atlanta Ref')
.appendTo($link);
Line 121 ⟶ 123:
var surface = ve.init.target.getSurface();
// Create reference content
var refContent = [{
type: 'mwReference',
Line 130 ⟶ 132:
id: 'body-' + Math.random().toString(36).substring(2, 8),
type: 'mwReferenceContents',
html: '<span typeof="mw:Transclusion" data-mw=\'{"parts":[{"template":{"target":{"wt":"source","href":"./Template:Source"},"params":{"url":{"wt":"https://www.atlantanewsfirst.com/2025/04/07/questions-remain-after-dead-horse-found-downtown-atlanta/"},"title":{"wt":"Questions remain after dead horse found in downtown Atlanta"},"author":{"wt":"Adam Murphy"},"date":{"wt":"April 7, 2025"},"pub":{"wt":"Atlanta News First"}},"i":0}}]}\'></span>'
}
}
Line 139 ⟶ 142:
var fragment = surface.getModel().getFragment();
fragment.insertContent(refContent, true);
// Optionally, you can add a notification to confirm the reference was added
if (ve.init.target.showNotifications) {
ve.init.target.showNotifications([
{ type: 'success', message: 'Atlanta News reference added' }
]);
}
});
|