metanohi-misc-subsites/projects/totxt/.page.php

289 lines
10 KiB
PHP
Raw Normal View History

2011-08-02 19:57:57 +02:00
<?php die(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta name='description' content='metanohi is the personal website of Niels Serup.' />
<meta name='keywords' content='nqpz, metanohi, web apps, web experiments, php experiments, javascript experiments, javascript games' />
<meta http-equiv='content-language' content='en' />
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
<title>metanohi :: totxt</title>
<link href='../../site/style.css' type='text/css' rel='stylesheet' />
<script type='text/javascript' src='../../lib/httpobj.js'></script>
<script type='text/javascript' src='../../site/script.js'></script>
<script type='text/javascript' src='totxt.js'></script>
<script type='text/javascript'>
function extra() {
load_totxt_generator()
}
</script>
<style type='text/css'>
pre.totxt.dynamic0:hover {
background-color: #ff0000;
cursor: pointer;
}
</style>
</head>
<body>
<div id='menu'>
<ul id='links'>
<li><a href='../../'>Start</a></li>
<li class='current'><a href='../../projects/'>Projects</a></li>
<li><a href='../../writings/'>Writings</a></li>
<li><a href='../../about/'>About metanohi</a></li>
<li><a href='../../aboutme/'>About me</a></li>
<li class='last'><a href='#' id='searchlink' class=''>Search</a></li>
</ul>
</div>
<form method='get' action='../../search/' id='searchform'>
<p>
<input id='searchfield' type='text' name='q' value='' />
<input type='submit' value='Search' />
</p>
</form>
<div id='logo'></div>
<div id='content'>
<div id='leftcolumn'>
<div id='text'>
<h1 style="font-family: &quot;dejavu sans mono&quot; monospace courier; font-size: 50px;">totxt</h1>
<h1 class="totxt">What is totxt?</h1>
<h2>totxt is a futuristic program</h2>
<p>
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 <a href="totxt.js">totxt.js</a> contains the function <span class="code">load_totxt_generator</span>, 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:<br/><br/>
<a href="example1.php">Example 1</a><br/>
<a href="example2.php">Example 2</a><br/>
<a href="example3.php">Example 3</a><br/>
<br/>
You might also want to take a look at how the examples look without the use of totxt:<br/><br/>
<a href="example1.php?n">Example 1 without totxt</a><br/>
<a href="example2.php?n">Example 2 without totxt</a><br/>
<a href="example3.php?n">Example 3 without totxt</a><br/>
</p>
<p>&nbsp;</p>
<p>totxt is free software; you can redistribute it and/or modify it under the terms of the <a href="http://www.gnu.org/licenses/gpl.html" rel="license">GNU General Public License</a> as published by the Free Software Foundation; either version 3 of the License, or (at your option)
any later version.</p>
<p>&nbsp;</p>
<p>
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. <span class="b">An example:</span><br/>
Before running the <span class="code">load_totxt_generator</span> function, define this inside a script tag:<br/>
totxt_DYNAMIC = 0<br/>
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.<br/>
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:<br/>
&lt;h1 class='totxt dynamic0'&gt;A header&lt;/h1&gt;<br/>
will have the same effect as defining it the global way, except this will only affect the current element, and not all elements.
</p>
<p><br/>Below is a table describing the values of totxt.</p>
<table class="border space">
<thead><tr>
<th>Global variable</th>
<th>Local definition</th>
<th>Description</th>
<th>Default value</th>
</tr>&nbsp;</thead>
<tbody>
<tr>
<td>totxt_WIDTH</td>
<td>widthX</td>
<td>Line width</td>
<td>80</td>
</tr>
<tr>
<td>totxt_DYNAMIC</td>
<td>dynamicX</td>
<td>Dynamic, open or closed?</td>
<td>-1 (not dynamic)</td>
</tr>
<tr>
<td>totxt_DYNAMIC_SPEED</td>
<td>speedX</td>
<td>Speed of line removal/appending when sliding (in ms)</td>
<td>50</td>
</tr>
<tr>
<td>totxt_DYNAMIC_LINES</td>
<td>linesX</td>
<td>Amount of line(s) to (dis)appear per function call</td>
<td>1</td>
</tr>
<tr>
<td>totxt_QUICK_DYNAMIC</td>
<td>quick_dynamic</td>
<td>Open/close boxes instantly. Do not slide.</td>
<td>false</td>
</tr>
<tr>
<td>totxt_DEL_XWS</td>
<td>del_excess_whitespace</td>
<td>Delete excess whitespace</td>
<td>false</td>
</tr>
<tr>
<td>totxt_HEADER_ALIGN</td>
<td>halignX</td>
<td>Alignment of header (0 = left, 1 = center, 2 = right)</td>
<td>1 (center)</td>
</tr>
<tr>
<td>totxt_SUBHEADER_ALIGN</td>
<td>shalignX</td>
<td>Alignment of subheader</td>
<td>0 (left)</td>
</tr>
<tr>
<td>totxt_TEXT_ALIGN</td>
<td>talignX</td>
<td>Alignment of text</td>
<td>0 (left)</td>
</tr>
</tbody>
</table>
<br/>
<p class="n">Furthermore, there are some global variables that can be used to modify the what classes to look for.</p>
<table class="border space">
<thead><tr>
<th>Global variable</th>
<th>Description</th>
<th>Default value</th>
</tr>&nbsp;</thead>
<tbody>
<tr>
<td>totxt_CLASSNAME</td>
<td>Main class to look for. Only elements with this classname has a chance of becoming totxt elements.</td>
<td>totxt</td>
</tr>
<tr>
<td>totxt_DYNAMIC_CLASSNAME</td>
<td>&nbsp;</td>
<td>dynamic</td>
</tr>
<tr>
<td>totxt_DYNSPEED_CLASSNAME</td>
<td>&nbsp;</td>
<td>speed</td>
</tr>
<tr>
<td>totxt_DYNLINES_CLASSNAME</td>
<td>&nbsp;</td>
<td>lines</td>
</tr>
<tr>
<td>totxt_HALIGN_CLASSNAME</td>
<td>&nbsp;</td>
<td>halign</td>
</tr>
<tr>
<td>totxt_SHALIGN_CLASSNAME</td>
<td>&nbsp;</td>
<td>shalign</td>
</tr>
<tr>
<td>totxt_TALIGN_CLASSNAME</td>
<td>&nbsp;</td>
<td>talign</td>
</tr>
<tr>
<td>totxt_WIDTH_CLASSNAME</td>
<td>&nbsp;</td>
<td>width</td>
</tr>
<tr>
<td>totxt_DELXWS_CLASSNAME</td>
<td>&nbsp;</td>
<td>del_excess_whitespace</td>
</tr>
<tr>
<td>totxt_QUICK_CLASSNAME</td>
<td>&nbsp;</td>
<td>quick_dynamic</td>
</tr>
<tr>
<td>totxt_HEADER_ELEMENT</td>
<td>Element type containing header text and totxt information in form of classes</td>
<td>H1</td>
</tr>
<tr>
<td>totxt_SUBHEADER_ELEMENT</td>
<td>Element type containing subheader text. Any information in classes will be ignored.</td>
<td>H2</td>
</tr>
<tr>
<td>totxt_TEXT_ELEMENT</td>
<td>Element type containing text. Any information in classes will be ignored.</td>
<td>P</td>
</tr>
</tbody>
</table>
<br/>
<p>To use totxt, simply save it in a directory, then import it using a script tag. Something like this:</p>
<pre>
&lt;html&gt;
&lt;head&gt;
&lt;script type='text/javascript' src='totxt.js'&gt;&lt;/script&gt;
&lt;script type='text/javascript'&gt;
window.onload = load_totxt_generator
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
...
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>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.</p>
<p><span class="code">load_totxt_generator</span> can be run more than once, without any problems arising.</p>
<br/>
<h1 class="totxt dynamic" style="color: #002244">Important information (click to open)</h1>
<h2>Look no further!</h2>
<p>
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. <span class="b">An example:</span><br/><br/>
&lt;h1 class='totxt'&gt;Header&lt;/h1&gt;<br/>
&lt;p&gt;This will be used.&lt;/p&gt;<br/>
&lt;p&gt;This will also be used.&lt;/p&gt;<br/>
&lt;blockquote&gt;<br/>
I fell asleep reading a dull book, and I dreamt that I was reading on, so I woke up from sheer boredom.<br/>
&lt;/blockquote&gt;<br/>
&lt;p&gt;This will <span class="b">not</span> be used.&lt;/p&gt;
</p>
<div id='lastupdated'>Last updated: 7 Aug 2009</div></div>
</div>
<div id='rightcolumn'>
<div id='headerbackground'>&nbsp;</div>
<div id='rightcontent'>
$RIGHT$
</div>
</div>
</div>
<div id='footer'>
<p><a href='../../browse/#projects/totxt/content.xml'>View source code</a><a href='../../about/' class='last'>Copyleft &copy; Niels Serup 2009, 2010. Text is released under CC-BY-SA 3.0.</a></p>
</div>
</body>
</html>