Closed xeyownt closed 6 years ago
PgnViewerJS embeds a copy of JQuery, but MediaWiki already has JQuery loaded. But apparently JQuery is only available when loaded via ResourceLoader. When loaded with addHeadItem
, we get in browser console:
ReferenceError: jQuery is not defined [Learn More] pgnvjs.js:14:3
50 browser tabs later about learning on MediaWiki, Javascript, Node.js and whatever, I have some explanations about the issues:
pgnView
. As a result, the function must be loaded before parsing these inlined javascript, or we will get an unknown reference 'pgnView'
error.<script>
tag in the head
section. To have access to this context, one solution is to add an anonymous function in the ResourceLoader queue, RLQ.As a result, I went for the following solution:
<pgn>
, we will generate a small JS script that will record the content of wiki tag in a JS variable. This variable must be global, so will simply attach it to global context window
.
Ideally CSS & JS scripts must be loaded with MediaWiki ResourceLoader. Here a summary of things I tried.
Tried to import from
LocalSettings.php
using ResourceLoader.This does not work. Apparently the JS script is embeded in some kind of lambda expression in a mw loader call whatever thingy.
Found a working hack on Stackoverflow. Add to
LocalSettings.php
:I added the hook to the extension, and this works.
This must be a temporary solution only since now JS is added to all wiki pages. The SO page linked above contains many useful information on linking in a JS script. Maybe the solution is there.