|Title|Page Header Customization
|Date|30-Jun-2006 17:23:22 EEST
|JSPWiki version|2.4.x and above
|Submitter|Nascif Abousalh-Neto
|[Idea Category]|GenericIdea
|[Idea Status]|NewIdea

Currently the only way to include new JavaScript libraries is to hack the .jsp or .js pages. This makes migrating to new versions hard, as you have to remember to make the same changes again. It is also something that MereMortals are not likely to do, making it harder to accept plugins that rely on functionality provided by those libraries.

Two ways around that would be:

1) A property in the jspwiki.properties file that would point to a file containing the fragment that includes the required library (or makes any other JavaScript setup necessary)

2) An API that allows plugins to "export" their required setup code back to the page rendering engine; this might require a two-pass analyses (first one to get the plugin header requirements, before second one that does the body rendering).


Already done.  The following fragment of code in your own JSP file will include an javascript library called "scripts/fckeditor/fckeditor.js" in the "script" -section.  Other possibilities are "jsfunction", "stylesheet", and "inlinecss".  Look for the <wiki:IncludeResources type="type"/> text in the default template to see where each of them gets included.

    WikiContext context = WikiContext.findContext( pageContext );
    TemplateManager.addResourceRequest( context, "script", "scripts/fckeditor/fckeditor.js" );

Sorry for the bad documentation on this part...  I just haven't gotten around to actually do it.

-- JanneJalkanen

Not quite. I would like a mechanism that would be easier to maintain, specially across JSPWiki version migrations.\\
Making the change in a .jsp file implies that either 1) I hacked one of the original files to create my own - won't survive a migration or 2) I am keeping my own template - I gave up on that, I just can't keep up with DF :-)

So I would like a mechanism that would allow me to develop plugins that can take advantage of javascript code, but without having to make changes to .jsp file that even if simple, are lost every time I migrate the wiki (or the wiki template).

-- NascifAbousalhNeto

You can also call that code from any plugin or filter you'd like.  Just use the WikiContext supplied.

Therefore, you could for example put in a PageFilter which would add a particular Javascript library to every page, or a plugin, which would add a JS library to only those pages which actually have the plugin.  As long as your template has the <wiki:IncludeResources> in the right place (and the default template will have it, regardless of any changes), your code will work.

-- JanneJalkanen