Go back to previous page
Forum URL: http://www.eyrie-productions.com/Forum/dcboard.cgi
Forum Name: Annotations
Topic ID: 27
Message ID: 21
#21, RE: Annotations: S1M1
Posted by cc on Dec-06-06 at 06:56 PM
In response to message #15
No need to go to all that trouble, there's a quick and dirty way to do that...

Just place the following code round your text (renamed as .html) file...


<html><head>
<script type="text/javascript" src="./notes.js"></script>
<style type="text/css">
input {
border:0px;font-size:6pt;vertical-align:super;
color:#00f;background-color:#fff;cursor:pointer;
}
</style>
</head><body onload="addn()"><pre id=annotate>

And the following after it (important: leave no blank lines)...


</pre></body></html>

Then cut-n-paste (from the browser) your notes into a text file
called 'notes.js', fire up vim (ok, you could do this with emacs,
but I've never learnt keyboard-twister, so I stick with what I
know), and run (cut-n-paste) the following substitution commands
to vim in command mode...


:1
:s/'/\\'/g999999
:1
:s/^[0-9][0-9]*/i&:'/999999
:1
:s/^i.*/&',/999999
:1
:s/:'[ ]*/:'/999999
:1

(This will convert it into proper javascript code.)

Finally add "var notes={" to the top and the following to the
end of your new notes.js file...


i0:''};
function note(n) {
if( notes['i'+n] ) {
alert( notes['i'+n] );
}
return false;
}
function addn() {
if( document.getElementById ) {
var nx=(''+document.getElementById('annotate').innerHTML).split('\n');
var n;
for( n=0; n<nx.length; ++n ) {
if( notes['i'+n] ) {
nx[n-1] += '<input type=button onclick="note('+n+')" value="['+n+']">';
} }
document.getElementById('anotate').innerHTML = nx.join('\n');
} }

Then, with a modern browser and any luck, the javascript should
automatically add a clickable button to the end of each line with
an associated note which will bring up a javascript alert with the
text of the note.

Now, would someone explain why I keep seeing one of your the music
notes as I write this...


/* Weird Al Yankovic "White & Nerdy" */