Jump to content

Topic on Project:Support desk

Use JavaScript modules from other sites

2
Ricordisamoa (talkcontribs)

I am searching for a way to dynamically require some useful MediaWiki modules from an external project, specifically toollabs:dewkin. The parts most concerned with my purpose are mediawiki.api, mediawiki.jqueryMsg and mediawiki.language (for PLURAL parsing). Is there a simple way to load them with all dependencies (via https://bits.wikimedia.org/www.mediawiki.org/load.php) and actually use them without having to load the entire "mediawiki" module? Or is it worth reimplementing the whole stuff?

Krinkle (talkcontribs)

This is unofficial, but I'd recommend trying it like this:


<head>
  <meta charset="utf-8">
  <title>Example</title>
  <link rel=stylesheet href="myapp.css">
  <script src="//bits.wikimedia.org/www.mediawiki.org/load.php?lang=en&amp;modules=startup&amp;only=scripts"></script>
</head>
<body>
 <div class="mw-body-content">
   ..
 </div>
 ...
 <script src="myapp.js">
  // Skip unsupported browsers or in case of an error
  if (!window.mw) { return; }
  // Load these modules first, as needed by "MYAPP.init()".
  mw.loader.using(['mediawiki.api', 'mediawiki.jqueryMsg'], MYAPP.init);
 </script>
</body>
Reply to "Use JavaScript modules from other sites"