Bug 839634 - Add javascript to publican brand
Summary: Add javascript to publican brand
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Topic Tool
Classification: Other
Component: FUDCon Docs Hack
Version: unspecified
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Joshua Wulf
QA Contact: Joshua Wulf
URL:
Whiteboard:
Depends On:
Blocks: 838277
TreeView+ depends on / blocked
 
Reported: 2012-07-12 13:14 UTC by Joshua Wulf
Modified: 2014-10-19 23:01 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-04-22 09:04:00 UTC
Embargoed:


Attachments (Terms of Use)

Description Joshua Wulf 2012-07-12 13:14:08 UTC
Here is how to do it:

Create a brand xhtml.xsl:

<?xml version='1.0'?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		version='1.0'
		xmlns="http://www.w3.org/TR/xhtml1/transitional"
		xmlns:fo="http://www.w3.org/1999/XSL/Format"
		exclude-result-prefixes="#default">

<!-- Import the Docbook stylesheets -->
<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl"/>
<xsl:import href="../../../xsl/html-single.xsl"/>

<!-- Now inject our javascript into the head -->
<!-- through the user.header.content parameter -->
<xsl:template name="user.header.content">
   <xsl:variable name="codefile" select="document('Common_Content/mycode.html',/)"/>
   <xsl:copy-of select="$codefile/htmlcode/node()"/>
</xsl:template>

---------------------------------

And then put a file into the en-US directory (and others of course) of the brand, called "mycode.html" with this content:

<htmlcode>
 <script type="text/javascript" src="myjavascript.js"/>
</htmlcode>

---------------------
Put myjavascript.js in the Common_Content of the brand, and it will be included.

Comment 1 Joshua Wulf 2012-07-12 13:31:17 UTC
From here: http://www.sagehill.net/docbookxsl/InsertExtHtml.html

Comment 2 Joshua Wulf 2012-07-12 14:38:03 UTC
Actually, I could only get it to work through html.xsl and html-single.xsl. 

Additionally, I put the script inline in the xsl, rather than loading it from an external file.

Here's the relevant portion of html-single.xsl:

<!-- inject our javascript into the head -->
<!-- http://www.sagehill.net/docbookxsl/InsertExtHtml.html -->
<xsl:template name="user.head.content">
   <script type="text/javascript" src="Common_Content/skynet-book.js"/>
</xsl:template>

<!-- set the onload of the page -->
<!-- http://www.sagehill.net/docbookxsl/BodyAtts.html -->
<xsl:template name="body.attributes">
  <xsl:attribute name="onLoad">skynetBookLoad()</xsl:attribute>
</xsl:template>


-------------------------------------
It looks like arbitrary files in the Common_Content directory are not included in the brand.

Looking for a way to get the javascript in. Current workaround is to use a URL.

Comment 3 Joshua Wulf 2012-07-13 00:45:32 UTC
You can put the javascript file into either css or images and it will be included. It won't work in Common_Content itself, because publican will only accept .xml files there, and tries to validate them as xml.

Comment 4 Joshua Wulf 2012-07-22 01:56:35 UTC
This site: http://friendlybit.com/js/lazy-loading-asyncronous-javascript/

Shows how to do lazy asynchronous loading of javascript via a small function in the <head> element. This might be the way to go.

So we would inject this into the <head>:

<script type="text/javascript">
(function() {
    function async_load(){
        var s = document.createElement('script');
        s.type = 'text/javascript';
        s.async = true;
        s.src = u'css/skynetbook.js';
        var x = document.getElementsByTagName('script')[0];
        x.parentNode.insertBefore(s, x);
    }
    if (window.attachEvent)
        window.attachEvent('onload', async_load);
    else
        window.addEventListener('load', async_load, false);
})();</script>

Comment 5 Joshua Wulf 2012-09-06 12:29:37 UTC
Broken in Publican 3 atm...

Comment 6 Joshua Wulf 2013-04-22 09:04:00 UTC
Fixed in Publican 3.1 and rocking hard!


Note You need to log in before you can comment on or make changes to this bug.