Is there any way to enable custom JavaScript (i.e. Common.js, Wikia.js, global.js, etc) for the preview module? Or is it logistically impossible? I was thinking something similar to UnsafeScripts might be a viable solution. I've noticed recently that custom CSS now applies to previews, but I'm not sure if that's something Wikia did or if my using UnsafeScripts is the cause. Either way, it suggests that this may be possible.
I think something like this would be very handy, especially for editing the Oasis WikiNav when using the ExtendedNavigation script.
—RyaNayR (talk • contribs) 00:38, March 07, 2014 (UTC)
Use either this example:
$("body").on("DOMNodeInserted", ".ArticlePreviewInner", function() {
// do this
});
You can also create a repeating function (using setInterval or setTimeout, for example) to apply your scripts when the preview mode has loaded. If that's the case make sure that it's not applied on Monobook.
Another thing to remember is that if there's a certain script that runs both in preview mode and both in ordinary articles, you might want to create an entire function and to call in certain events, to prevent duplicated code.
Penguin-Pal (talk) 10:33, March 7, 2014 (UTC)
- There is luckily a simpler and efficient way to do it:
if (window.mediaWiki.config.get('skin') === 'oasis' && window.mediaWiki.config.get('wgAction') === 'edit') {
$(window).on('EditPageAfterRenderPreview', function(ev, popup) {
window.alert("LOADED!");
});
}