Hi,
I try to use JQuery code in tag extension. Following the manuals I added in extension.json:
"ResourceModules": { "ext.Iframe" : { "scripts": [ "modules/ext.Iframe.js" ] } },
in my main.php file:
class IFrame {
public static function renderIframe( $str, array $argv, Parser $parser, PPFrame $frame ) { ... $parser->mOutput->addModules('ext.Iframe'); ... }
... }
and my modules/ext.Iframe.js looks like:
jquery(document).ready(function ($) { $(document.body).append("Hello World!"); });
I would have expected to see a "Hello World!" at the end of my wiki page, but nothing appears.
So I missed something. Any ideas what?
Thanks in advance
Sigbert
This might be a typo in your message, but it's jQuery, not jquery. Also you can shorten that page ready code, see: http://learn.jquery.com/using-jquery-core/document-ready/
By default, jQuery and it's alias $ are always available in MediaWiki. However, we often tend to import globals and then redefine $ and mw as function parameters. This is called the 'module pattern'. http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html You can find a practical example of it here for instance: https://github.com/wikimedia/mediawiki-extensions-3D/blob/master/modules/ext...
Note also that when inserting something regarding the content (which i suspect you are), then we usually use mw.hook('wikipage.content').add(function( content ) {} ), where content will give you the DOM collection of just the rendered page content. This helps when partial page updates occur, as with the Visual editor or the JS based previews of a page, which do not necessarily open a new page.
DJ
On Wed, Mar 14, 2018 at 1:15 PM, Sigbert Klinke sigbert@wiwi.hu-berlin.de wrote:
Hi,
I try to use JQuery code in tag extension. Following the manuals I added in extension.json:
"ResourceModules": { "ext.Iframe" : { "scripts": [ "modules/ext.Iframe.js" ] } },
in my main.php file:
class IFrame {
public static function renderIframe( $str, array $argv, Parser $parser, PPFrame $frame ) { ... $parser->mOutput->addModules('ext.Iframe'); ... }
... }
and my modules/ext.Iframe.js looks like:
jquery(document).ready(function ($) { $(document.body).append("Hello World!"); });
I would have expected to see a "Hello World!" at the end of my wiki page, but nothing appears.
So I missed something. Any ideas what?
Thanks in advance
Sigbert
-- https://hu.berlin/sk https://hu.berlin/mmstat3
MediaWiki-l mailing list To unsubscribe, go to: https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
You must have "ResourceFileModulePaths" set in your extension.json too, to make MediaWiki look for the file 'modules/ext.Iframe.js' in the right path. You don't mention whether you have it set or not. Like this:
"ResourceFileModulePaths": { "localBasePath": "", "remoteExtPath": "IFrame" },
(Where "IFrame" is the name of your extension's directory.)
Make sure to avoid typos, "Iframe" and "IFrame" are not the same, you used both in your example code and I don't know which is right :)
Hi,
"ResourceFileModulePaths": { "localBasePath": "", "remoteExtPath": "IFrame" },
I think that was it. I made it exactly like in the 3D extension. I used also console.log instead of the append and thsi txet appeared in web console now :D
(which i suspect you are) then we usually use mw.hook('wikipage.content').add(function( content ) {} ), where
I'll look in that, too. In fact, I most probably need a delayed loading of the embedded iframes.
Make sure to avoid typos, "Iframe" and "IFrame" are not the same, you used both in your example code and I don't know which is right :)
I'll try ;)
Thanks to DJ and you
Sigbert
mediawiki-l@lists.wikimedia.org