TitleCSSINCLUDE.JS doesn't work - recurring bug
Date08-Oct-2005 08:40:33 EEST
Bug criticalityLightBug
Browser versionsafari
Bug statusClosedBug
PageProvider used
Servlet Container
Operating Systemos-x
Java version

The cssinclude.js doesn't get included properly by commonheader.jsp. Reason: cssinclude contains direct executed javascript with some jsp markup which gets expanded to point to the right location of the used JSPWiki template. This obviously only works when using the JSP include statement iso a ordinary <SCRIPT>...</SCRIPT tag.

In file commonheader.jsp, change line

  <script src="<wiki:BaseURL/>scripts/cssinclude.js" type="text/javascript"></script>


  <%@ include file="/scripts/cssinclude.js" %>

PS1: this seems to be a recurring bug. May be we need to put a comment in the commonheader.jsp not to touch the line anymore.


To avoid this jsp style of include, here is a possible workaround. (also a bit more xhtml compliant)
Put this in the commonheader.jsp :
<script src="<wiki:BaseURL/>templates/<wiki:TemplateDir/>/cssinclude.js" 
<script type="text/javascript">Wiki.loadBrowserSpecificCSS("<wiki:TemplateDir/>");</script>
and wrap the cssinclude.js javascript inside a function, like this:

 * issue a document.write statement with the link to the browser specific stylesheet
 * should always be execute from direct javascript during page-load
var Wiki = new Object();
Wiki.loadBrowserSpecificCSS  = function ( templatePath )
    var sheet = "";

    if( NS4 )
        sheet = "jspwiki_ns.css";
    else if( Mac )
        sheet = "jspwiki_mac.css";
    else if( IE )
        sheet = "jspwiki_ie.css";

    if( sheet != "" )
        //document.write("<link rel=\"stylesheet\" 
        //         href=\"templates/<wiki:TemplateDir />/"+sheet+"\" />");
        sheet = "templates/" +templatePath + "/" + sheet;
        document.write("<link rel=\"stylesheet\" href=\""+sheet+"\" />");

I suggest simply placing the script directly in common header; I believe little is gained by separating such a small file out. This is what I did in ConfigurableTemplate.

Another, perhaps related problem: After fixing this in ConfigurableTemplate and testing on IE, the (so that the script should load "jspwiki_ie.css"), this file occurs as every second entry in the breadcrumbs trail. -- Dirk, after you fixed it, can you perhaps verify whether you have the same problem? I am not sure whether this is a bug in Bread crumbs, or something I introduced in ConfigurableTemplate.

Gregor Hagedorn -- 2005-10-09

The proposed solution is working ok, and I don't experience the breadcrumbs problem. -- DF

With regard to the first solution: Reason why recurring is perhaps that the include file is misleadingly named js instead of the real jsp. So some action would be necessary. Similarly, jspwiki_ns.css should probably be renamed "jspwiki_ns4.css". Currently some confusion exists (especially since the code in JSPWiki 2.2 default template tests for NS6, combines with NS4 to NS, but then only uses NS4 to load stylesheet ...NS).

Second proposed solution is clean (although somewhat difficult to follow). In ContributedTemplate, the common header code simply includes:

<script language="javascript" type="text/javascript">
//<![CDATA[  /* Choose a suitable stylesheet based on browser */
  var IE4 = (document.all && !document.getElementById) ? true : false;
  var IE5 = (document.all && document.getElementById) ? true : false;
  var NS4 = (document.layers) ? true : false;
  var Mac = (navigator.platform.indexOf("Mac") == -1) ? false : true;
  var sheet = "";
  if      ( NS4 )        { sheet = "jspwiki_ns4.css" }
  else if ( Mac )        { sheet = "jspwiki_mac.css" }
  else if ( IE4 | IE5 ) { sheet = "jspwiki_ie.css" };
  if ( sheet != "" ) 
   document.write("<link rel=\"stylesheet\" 
                   href=\"templates/<wiki:TemplateDir />/"+sheet+"\" />"); 
<script src="<wiki:BaseURL/>scripts/search_highlight.js" type="text/javascript"></script>

-- Gregor

Is there a reason why you don't detect on the serverside which browser is making the request and let the server insert the appropiate stylesheet?

You can detect which browser is making the request by looking at (in the servlet/jsp) the request.getHeader("user-agent").

see: http://www.stardeveloper.com/articles/display.html?article=2001072201&page=1

-- KeesKuip

No, no reason. Patch appreciated :)

-- JanneJalkanen

Although this turns the bug report into an NewIdea: It would be great if someone who can do so, does implement a server-side way of handling browser differences! Please do!

Please see: Wiki Content Specific CSS Extensions for why this would be a great improvement by enabling new options.

-- Gregor Hagedorn, 2005-10-28

How to include a Browser Depedend .css stylesheets: This which is a bit akwards in the current JSPWiki, and could be moved to the server side. Plse check out this excellent article for a simple but efficient approach to this issue, solving it still client side !

--DF (GH: second part refactored to Wiki Content Specific CSS Extensions)

Does this bug still occur? Can we close it down?

Old bug. Fixed months ago. Definitely ok since 2.4.x. Tx.
BTW, I think there is no need for this anymore. Browser dependent switches can easily be added inside CSS, without the need for separate CSS files and JS to switch between them. Severals hacks are available. --DF

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-16) was last changed on 27-Jul-2010 15:29 by 孙兵