Well, this has been a frustrating morning. Here's my account of the past few hours. What am I doing wrong? Please be gentle, I'm new.
How to include a simple Javascript script in a DokuWiki page
To avoid spam, we want to use the email riddler to encrypt a contact email address within a DokuWiki page.
We get the following generated code from the script wizard:
<script type="text/javascript">
/*<![CDATA[*/
/***********************************************
* Encrypt Email script- Please keep notice intact
* Tool URL: http://www.dynamicdrive.com/emailriddler/
* **********************************************/
<!-- Encrypted version of: avidwiki [at] ****************.*** //-->
var emailriddlerarray=[97,118,105,100,119,105,107,105,64,114,111,99,104,101,115,116,101,114,115,121,115,116,101,109,115,46,99,111,109]
var encryptedemail_id32='' //variable to contain encrypted email
for (var i=0; i<emailriddlerarray.length; i++)
encryptedemail_id32+=String.fromCharCode(emailriddlerarray[i])
document.write('<a href="mailto:'+encryptedemail_id32+'?subject=Request for AvidWiki Support Product">Request it.</a>')
/*]]>*/
</script>
and save it in a Notepad file for later reference.
We read DokuWiki's documentation for including this script:
http://wiki.splitbrain.org/wiki:devel:javascript
Whew! OK, let's decode this step by step.
First, we know we can't just paste this code into DokuWiki's editor for the page we want it in. The documentation tells us we have to create a file named script.js in our template directory. Which directory is that? Much further in the documentation at JavaScript Dispatcher, we find the answer:
lib/tpl/*/script.js (only from current template)
which for us is:
/lib/tpl/monobook/script.js
Second, we know that the generated code was meant to be pasted into a .htm file as inline code. It was not formatted as an external script (a .js file). We need to delete the <script> and CDATA related tags at the beginning and end of the code.
Third, we are told the Javascript code must pass the JSLint verifier. We go to this tool, paste in the code, run the verifier, and it fails. What now?
After an hour of research and fiddling with the code, there seems to be no good reason for the failure. Thinking about the intention behind this recommendation, and the philosophy of JSLint, we decide to go ahead and try the code as-is.
Next, we are told we need to do something with event handlers and DOM (document object model). What? This is getting confusing.
OK, here's the idea: originally, the Javascript code would be placed within an HTML page right where it needed to be, the spot where the contact email address will appear. Since we have moved the Javascript code to an external script, we need to give our code a name, and use that name to associate the code with the contact email address within the DokuWiki page.
It's a little unclear, but we have several choices for how to accomplish this - event handlers, inline scripts (isn't that where we started?!), and IDs. Oh, and further in the documentation, include syntax. What do we use?
Well, let's try inline script. We look back at the original generated code and compare the tags; they're not quite the same, so we make the changes and embed the script into our DokuWiki page.
It doesn't work in Preview, nor after being Saved. Now what?
Maybe include syntax? This requires going back to a .js version, naming it something other than script.js, and adding a special comment in the DokuWiki page where the script should be run. The script file needs to be placed in the same directory as the page .txt file.
OK, so I create emailriddler.js, place it in /data/pages/wiki/admin/, and edit my DokuWiki page to include the comment:
/* DOKUWIKI:include emailriddler.js */
That didn't work either.
It seems that embedding Javascript into a DokuWiki page using the editor is not possible.