-----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Sergiu Dumitriu Sent: Thursday, May 14, 2009 10:55 AM To: XWiki Developers Subject: Re: [xwiki-devs] Macro requiring js/css
[email protected] wrote:
I wonder if we're looking at the wrong solution. In this case I want
to include a javascript resource file such as jQuery.js so what I really want is to specify a script tag to be added to the header rather than an embedded javascript extension object content.
I suppose I could look at the jsx extension code to see how this is
done as it is clearly doing this somehow?
You don't need to do that.
There is a plugin that allows to include links to local JS files, which from Velocity would be called as:
$xwiki.jsfx.use('/js/jquery/jquery.js'), provided that the file is located in <webapproot>/resources/js/jquery/jquery.js
Now, going through velocity is an unneeded detour, since velocity code goes back to Java through parsing and reflexion. The only problem is that there is no (easy and clean) way to get hold of a reference to the plugin, since rendering is in the new, "2.0" component world, while the plugin is in the old monolithic world. I've been planning to reimplement the skin extensions as components for a while, but since it wasn't a priority, it isn't done yet.
So, there are 2 solutions:
1. Make your macro depend on the xwiki-core and xwiki-plugin-skinx modules, then get a reference to the XWiki object from the execution context, then call getPlugin("jsfx") and call use("") on it.
This sound like a good approach. How might I get the XWiki object from the execution context. I see a macro is passed in a context but I don't see anything in it that looks like I could get an XWiki object from. Looks like I'll need an XWikiContext as well to call use(). Is this available from the macro execute callback? I had a similar open question about how to get a XWiki object from an HttpServlet but in that case there is not any rendering going on.
2. Manually inject the file in the list of pulled extension, duplicating the code from AbstractSkinExtensionPlugin#getPulledResources (see http://svn.xwiki.org/svnroot/xwiki/platform/xwiki- plugins/trunk/skinx/src/main/java/com/xpn/xwiki/plugin/skinx/AbstractSk inExtensionPlugin.java ) which means: from the execution context, get the xwiki context as a Map, from which you should get the value from "com.xpn.xwiki.plugin.skinx.JsSkinFileExtensionPlugin" (cast as a Set) and add "js/jquery/jquery.js" to it. -- Sergiu Dumitriu http://purl.org/net/sergiu/ _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs