Bug 839634 - Add javascript to publican brand
Add javascript to publican brand
Status: CLOSED CURRENTRELEASE
Product: Topic Tool
Classification: Other
Component: FUDCon Docs Hack (Show other bugs)
unspecified
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Joshua Wulf
Joshua Wulf
:
Depends On:
Blocks: 838277
  Show dependency treegraph
 
Reported: 2012-07-12 09:14 EDT by Joshua Wulf
Modified: 2014-10-19 19:01 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-04-22 05:04:00 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Joshua Wulf 2012-07-12 09:14:08 EDT
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 09:31:17 EDT
From here: http://www.sagehill.net/docbookxsl/InsertExtHtml.html
Comment 2 Joshua Wulf 2012-07-12 10:38:03 EDT
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-12 20:45:32 EDT
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-21 21:56:35 EDT
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 08:29:37 EDT
Broken in Publican 3 atm...
Comment 6 Joshua Wulf 2013-04-22 05:04:00 EDT
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.