totxt

What is totxt?

totxt is a futuristic program

totxt is a JavaScript program that transforms text with regular HTML formatting into text that looks like what you're reading right now. The file totxt.js contains the function load_totxt_generator, which, when run, finds text in HTML elements and converts that text into this. Before reading on, have a look at the following examples to see how it works:

Example 1
Example 2
Example 3

You might also want to take a look at how the examples look without the use of totxt:

Example 1 without totxt
Example 2 without totxt
Example 3 without totxt

 

totxt is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

 

totxt accepts two ways of ignoring default values: a global way, which has an effect on all totxt elements, and a local way, which only has an effect on a particular totxt element. An example:
Before running the load_totxt_generator function, define this inside a script tag:
totxt_DYNAMIC = 0
This will make all totxt elements dynamic, i.e. it will be possible to open and close totxt boxes. When closed, only the header is displayed, while in its open state, both the header, the subheader (if any) and the text will be visible. The 0 value means that all totxt elements first appear in their closed forms. Assigning a value of 1 will make all elements start out as open. Any other value than 0 or 1 will not work. Note that, by default, being dynamic also means that an element opens and closes in a sliding motion and that an element is opened by clicking on it and closed by doubleclicking on it.
Another way to defy normal values is to locally define changes. Applying 'dynamic0' as a class to a totxt element, such that it will look something like:
<h1 class='totxt dynamic0'>A header</h1>
will have the same effect as defining it the global way, except this will only affect the current element, and not all elements.


Below is a table describing the values of totxt.

 
Global variable Local definition Description Default value
totxt_WIDTH widthX Line width 80
totxt_DYNAMIC dynamicX Dynamic, open or closed? -1 (not dynamic)
totxt_DYNAMIC_SPEED speedX Speed of line removal/appending when sliding (in ms) 50
totxt_DYNAMIC_LINES linesX Amount of line(s) to (dis)appear per function call 1
totxt_QUICK_DYNAMIC quick_dynamic Open/close boxes instantly. Do not slide. false
totxt_DEL_XWS del_excess_whitespace Delete excess whitespace false
totxt_HEADER_ALIGN halignX Alignment of header (0 = left, 1 = center, 2 = right) 1 (center)
totxt_SUBHEADER_ALIGN shalignX Alignment of subheader 0 (left)
totxt_TEXT_ALIGN talignX Alignment of text 0 (left)

Furthermore, there are some global variables that can be used to modify the what classes to look for.

 
Global variable Description Default value
totxt_CLASSNAME Main class to look for. Only elements with this classname has a chance of becoming totxt elements. totxt
totxt_DYNAMIC_CLASSNAME   dynamic
totxt_DYNSPEED_CLASSNAME   speed
totxt_DYNLINES_CLASSNAME   lines
totxt_HALIGN_CLASSNAME   halign
totxt_SHALIGN_CLASSNAME   shalign
totxt_TALIGN_CLASSNAME   talign
totxt_WIDTH_CLASSNAME   width
totxt_DELXWS_CLASSNAME   del_excess_whitespace
totxt_QUICK_CLASSNAME   quick_dynamic
totxt_HEADER_ELEMENT Element type containing header text and totxt information in form of classes H1
totxt_SUBHEADER_ELEMENT Element type containing subheader text. Any information in classes will be ignored. H2
totxt_TEXT_ELEMENT Element type containing text. Any information in classes will be ignored. P

To use totxt, simply save it in a directory, then import it using a script tag. Something like this:

<html>
    <head>
        <script type='text/javascript' src='totxt.js'></script>
        <script type='text/javascript'>
            window.onload = load_totxt_generator
        </script>
    </head>
    
    <body>
        ...
    </body>
</html>

Note that this will run when the page importing it has loaded. It is of course also possible to execute totxt code on other actions.

load_totxt_generator can be run more than once, without any problems arising.


Important information (click to open)

Look no further!

totxt elements inherit all classes, any eventual id, and style if present, but only from the header element. When looking for text, totxt searches for subheader elements and text elements below the header element. If any other element than those appears, the search will halt. An example:

<h1 class='totxt'>Header</h1>
<p>This will be used.</p>
<p>This will also be used.</p>
<blockquote>
I fell asleep reading a dull book, and I dreamt that I was reading on, so I woke up from sheer boredom.
</blockquote>
<p>This will not be used.</p>

Last updated: 7 Aug 2009
 
$RIGHT$