You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@forrest.apache.org by Sjur Moshagen <sj...@mac.com> on 2007/01/26 17:59:23 UTC

javascript in dispatcher theme

Hello again,

A completely unrelated question:

How to I include a reference to a javascript in a dispatcher theme? I  
have a file-specific theme based on pelt.fv in which I want to output  
a script element in the resulting html file, containing a reference  
to a javascript file.

I couldn't find a proper contract for the job, so I took a shortcut,  
by just adding it to what seemed like another, similar construct:

...
     <forrest:contract name="siteinfo-meta" dataURI="lm:// 
project.build-info">
       <forrest:property name="custom">
          <meta http-equiv="content-type" content="text/html;  
charset=UTF-8"/>
          <script language="javascript" src="themes/risten.js"  
type="text/javascript"/> <== this line
       </forrest:property>
       <forrest:property name="theme" value="pelt"/>
     </forrest:contract>
...

Now, this seemed to work perfect, at least by first glance (ie in  
Safari). But when I tested the result in Firefox, the whole page was  
completely screwed up:

- all the content within the div#header was gone, logos, tabs, search  
box and everything
- Firefox reported the same content to be part of the html/head  
element, which it was not

The same could be observed in IE 6, whereas Opera behaved as nicely  
as Safari.

Just to be sure, I would like to either get confirmation that the  
above should be ok, or instructions on how to include a script  
element in a proper way.

Thanks a lot for your attention,
Sjur


Re: javascript in dispatcher theme

Posted by Thorsten Scherler <th...@apache.org>.
On Mon, 2007-01-29 at 13:43 +0200, Sjur Moshagen wrote:
> Found the problem.
> 
> It turns out that Firefox and IE do not like empty <script>  
> elements... As soon as I changed the tag from the empty style seen  
> below to a standard element with both an open and a close element,  
> everything looks fine again, both in MS IE and in Firefox.

Alternatively you could path injection. 

<!--If you want to inject the content into a certain DOM position and
              *not* the current position in the structurer, you can use the @xpath attribute. -->
          <forrest:part xpath="/html/head">
            Content going to a fixed location defined by the contract (here: /html/head).
          </forrest:part>

You are now using the meta contract but normally you should added it to
the contract. Some java scripts are share by more then one contract.
Then it should be extracted as helper (like the ajax helper or
helper-form-blank.ft). 

> 
> The dispatcher / skin difference is probably caused by the dispatcher  
> producing xml (ie xhtml), whereas the non-dispatcher version produced  
> plain html. Or rather, Firefox and MS IE do not correctly handle  
> xhtml in all its aspects, including empty elements.
> 
> Is there a way to tell dispatcher to serialize the final byte stream  
> as html, not xhtml? Is it desirable?

You can override it on a project base. You would need to implement: 
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.internal.dispatcher/internal.xmap?view=markup
<!--
        Last processing step. 
        Here we are overriding the default skin generation.
      -->
      <map:match pattern="**.html">
        <map:generate src="cocoon:/resolve.structurer.{1}" type="jx">
          <map:parameter name="lenient-xpath" value="true" />
          <map:parameter name="getRequest" value="{1}" />
          <map:parameter name="contextPath" value="{request:contextPath}" />
          <map:parameter name="getRequestExtension" value="html" />
        </map:generate>
        <map:transform type="dispatcher">
          <map:parameter name="cacheKey" value="{0}" />
          <map:parameter name="validityFile" value="cocoon:/resolve.structurer.{1}" />
          <map:parameter name="request" value="{1}" />
          <map:parameter name="type" value="html" />
          <map:parameter name="hooksTransformer" value="lm://hooks-to-html.xsl" 
            />
        </map:transform>
        <map:transform 
          src="lm://transform.xml.xml-namespace-stripped" 
          />
        <map:transform 
          src="resources/stylesheets/helper/strip-dispatcher-remains.xsl" 
          />
 <!--       <map:serialize type="xhtml" /> -->
        <map:serialize type="html" />
      </map:match>

Not sure to make it the default.

salu2

> 
> Sjur
> 
> Den 26. jan. 2007 kl. 18.59 skrev Sjur Moshagen:
> 
> > Hello again,
> >
> > A completely unrelated question:
> >
> > How to I include a reference to a javascript in a dispatcher theme?  
> > I have a file-specific theme based on pelt.fv in which I want to  
> > output a script element in the resulting html file, containing a  
> > reference to a javascript file.
> >
> > I couldn't find a proper contract for the job, so I took a  
> > shortcut, by just adding it to what seemed like another, similar  
> > construct:
> >
> > ...
> >     <forrest:contract name="siteinfo-meta" dataURI="lm:// 
> > project.build-info">
> >       <forrest:property name="custom">
> >          <meta http-equiv="content-type" content="text/html;  
> > charset=UTF-8"/>
> >          <script language="javascript" src="themes/risten.js"  
> > type="text/javascript"/> <== this line
> >       </forrest:property>
> >       <forrest:property name="theme" value="pelt"/>
> >     </forrest:contract>
> > ...
> >
> > Now, this seemed to work perfect, at least by first glance (ie in  
> > Safari). But when I tested the result in Firefox, the whole page  
> > was completely screwed up:
> >
> > - all the content within the div#header was gone, logos, tabs,  
> > search box and everything
> > - Firefox reported the same content to be part of the html/head  
> > element, which it was not
> >
> > The same could be observed in IE 6, whereas Opera behaved as nicely  
> > as Safari.
> >
> > Just to be sure, I would like to either get confirmation that the  
> > above should be ok, or instructions on how to include a script  
> > element in a proper way.
> >
> > Thanks a lot for your attention,
> > Sjur
> >
> 
-- 
thorsten

"Together we stand, divided we fall!" 
Hey you (Pink Floyd)



Re: javascript in dispatcher theme

Posted by Sjur Moshagen <sj...@mac.com>.
Found the problem.

It turns out that Firefox and IE do not like empty <script>  
elements... As soon as I changed the tag from the empty style seen  
below to a standard element with both an open and a close element,  
everything looks fine again, both in MS IE and in Firefox.

The dispatcher / skin difference is probably caused by the dispatcher  
producing xml (ie xhtml), whereas the non-dispatcher version produced  
plain html. Or rather, Firefox and MS IE do not correctly handle  
xhtml in all its aspects, including empty elements.

Is there a way to tell dispatcher to serialize the final byte stream  
as html, not xhtml? Is it desirable?

Sjur

Den 26. jan. 2007 kl. 18.59 skrev Sjur Moshagen:

> Hello again,
>
> A completely unrelated question:
>
> How to I include a reference to a javascript in a dispatcher theme?  
> I have a file-specific theme based on pelt.fv in which I want to  
> output a script element in the resulting html file, containing a  
> reference to a javascript file.
>
> I couldn't find a proper contract for the job, so I took a  
> shortcut, by just adding it to what seemed like another, similar  
> construct:
>
> ...
>     <forrest:contract name="siteinfo-meta" dataURI="lm:// 
> project.build-info">
>       <forrest:property name="custom">
>          <meta http-equiv="content-type" content="text/html;  
> charset=UTF-8"/>
>          <script language="javascript" src="themes/risten.js"  
> type="text/javascript"/> <== this line
>       </forrest:property>
>       <forrest:property name="theme" value="pelt"/>
>     </forrest:contract>
> ...
>
> Now, this seemed to work perfect, at least by first glance (ie in  
> Safari). But when I tested the result in Firefox, the whole page  
> was completely screwed up:
>
> - all the content within the div#header was gone, logos, tabs,  
> search box and everything
> - Firefox reported the same content to be part of the html/head  
> element, which it was not
>
> The same could be observed in IE 6, whereas Opera behaved as nicely  
> as Safari.
>
> Just to be sure, I would like to either get confirmation that the  
> above should be ok, or instructions on how to include a script  
> element in a proper way.
>
> Thanks a lot for your attention,
> Sjur
>