Tutorials/LifeViewer JavaScript plug-in: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
|||
| (9 intermediate revisions by 4 users not shown) | |||
| Line 1: | Line 1: | ||
The LifeViewer Javascript Plug-in lets you use | The [[LifeViewer]] Javascript Plug-in lets you use LifeViewer in you own web pages. | ||
==Getting Started: Download the LifeViewer plug-in== | ==Getting Started: Download the LifeViewer plug-in== | ||
| Line 9: | Line 9: | ||
==Lesson 1: Hello World--web page with glider in viewer== | ==Lesson 1: Hello World--web page with glider in viewer== | ||
[[image:tutoriallvpluginex1.png|framed|350px]] | [[image:tutoriallvpluginex1.png|framed|350px]] | ||
*A simple web page with a glider in a LifeViewer | *A simple web page with a glider in a LifeViewer ([https://golhobby.com/lv/ex1.htm run the example](dead link)) | ||
*Paste the code below in your text editor, save it and run it | *Paste the code below in your text editor, save it and run it | ||
<pre> | <pre> | ||
| Line 35: | Line 35: | ||
*Align viewer and textarea | *Align viewer and textarea | ||
*Note the textarea needs to be a few pixels narrower to properly align | *Note the textarea needs to be a few pixels narrower to properly align | ||
*[https://golhobby.com/lv/ex2.htm Run the example] | |||
<pre> | <pre> | ||
<!DOCTYPE html> | <!DOCTYPE html> | ||
| Line 70: | Line 71: | ||
*The rle may be entered manually or pasted into the textarea | *The rle may be entered manually or pasted into the textarea | ||
*The element that calls the updateMe function (button, link, whatever) must be inside the viewer container | *The element that calls the updateMe function (button, link, whatever) must be inside the viewer container | ||
*[https://golhobby.com/lv/ex3.htm Run the example] | |||
<pre> | <pre> | ||
<meta name="LifeViewer" content="viewer textarea"> <!--required tag--> | <!DOCTYPE html> | ||
<html> | |||
<head><meta name="LifeViewer" content="viewer textarea"> <!--required tag--> | |||
<script src="lv-plugin.js"></script> <!--assumes plug-in is in the same directory as html file--> | <script src="lv-plugin.js"></script> <!--assumes plug-in is in the same directory as html file--> | ||
<style> | <style> | ||
| Line 114: | Line 118: | ||
*This is done my moving the textarea containing the rle off the visible page using absolute positioning and setting the top to a negative number | *This is done my moving the textarea containing the rle off the visible page using absolute positioning and setting the top to a negative number | ||
*The textarea tag must remain inside the viewer container | *The textarea tag must remain inside the viewer container | ||
*[https://golhobby.com/lv/ex4.htm Run the example] | |||
<pre> | <pre> | ||
<meta name="LifeViewer" content="viewer textarea"> <!--required tag--> | <!DOCTYPE html> | ||
<html> | |||
<head><meta name="LifeViewer" content="viewer textarea"> <!--required tag--> | |||
<script src="lv-plugin.js"></script> <!--assumes plug-in is in the same directory as html file--> | <script src="lv-plugin.js"></script> <!--assumes plug-in is in the same directory as html file--> | ||
<style> | <style> | ||
| Line 142: | Line 149: | ||
==Lesson 5: Tips & Tricks== | ==Lesson 5: Tips & Tricks== | ||
*To disable user input in a textarea, add the readonly attribute: <textarea readonly>whatever</textarea> | *To disable user input in a textarea, add the readonly attribute: <textarea readonly>whatever</textarea> | ||
*You can put multiple LifeViewers on a single page; each must have its own <div> container with its own <textarea> and <canvas> inside | *RLEs can control the viewer using [[LifeViewer/Scripts|LifeViewer scripts]] | ||
* | *You can put multiple LifeViewers on a single page; each must have its own <div> container with its own <textarea> and <canvas> inside, or use iframes like [https://golhobby.com/ PatMan] does | ||
*For a full-featured web app illustrating the use of the LifeViewer plug-in, check out [https://golhobby.com/ Pattern Manager (PatMan)] | |||
**Shows how to use iframes to have a set of thumbnails on the same page that each open in a single viewer, like on LifeWiki pages | |||
**Downloadable source code and related files | |||
{{Tutorial}} | {{Tutorial}} | ||
Latest revision as of 06:27, 28 June 2025
The LifeViewer Javascript Plug-in lets you use LifeViewer in you own web pages.
Getting Started: Download the LifeViewer plug-in
- Use this link: download
- The javascript code will be displayed in your browser
- Do a "Save" or "Save as..." and save lv-plugin.js where you want it
- In this tutorial, we assume the plug-in is in the same folder as your html file
Lesson 1: Hello World--web page with glider in viewer

- A simple web page with a glider in a LifeViewer (run the example(dead link))
- Paste the code below in your text editor, save it and run it
<!DOCTYPE html> <html> <head> <meta name="LifeViewer" content="viewer textarea"> <!--required tag--> <script src="lv-plugin.js"></script> <!--assumes plug-in is in the same directory as html file--> </head> <body> <!--viewer container--> <div class="viewer"> <!--class=viewer is required--> <textarea>bo$2bo$3o!</textarea><br/> <!--textarea required in viewer container, with glider rle--> <canvas></canvas> <!--canvas required in viewer container--> </div> <!--end viewer container--> </body> </html>
Lesson 2: Add some style

- Size the textarea, change font, make it non-resizable
- Size viewer by sizing canvas using inline width and height attributes (not CSS)
- Align viewer and textarea
- Note the textarea needs to be a few pixels narrower to properly align
- Run the example
<!DOCTYPE html>
<html>
<head>
<meta name="LifeViewer" content="viewer textarea"> <!--required tag-->
<script src="lv-plugin.js"></script> <!--assumes plug-in is in the same directory as html file-->
<style>
body{
margin:50px;
}
.lv-rle{
font:12pt arial;
resize:none;
width:594px;
min-height:120px;
max-height:120px;
}
</style>
</head>
<body>
<!--viewer container-->
<div class="viewer">
<textarea class="lv-rle">bo$2bo$3o!</textarea><br/> <!--added classname for styling-->
<canvas height=400 width=600></canvas> <!--added width and height attributes for viewer-->
</div>
<!--end viewer container-->
</body>
</html>
Lesson 3: Update viewer with user input

- Add control buttons to clear the textarea and update the viewer with user-entered rle
- The rle may be entered manually or pasted into the textarea
- The element that calls the updateMe function (button, link, whatever) must be inside the viewer container
- Run the example
<!DOCTYPE html>
<html>
<head><meta name="LifeViewer" content="viewer textarea"> <!--required tag-->
<script src="lv-plugin.js"></script> <!--assumes plug-in is in the same directory as html file-->
<style>
body{
margin:50px;
}
button{
font:12pt arial;
}
.lv-rle{
resize:none;
width:594px;
min-height:120px;
max-height:120px;
font:12pt arial;
}
.lv-buttons{
margin-bottom:4px;
}
</style>
</head>
<body>
<!--viewer container-->
<div class="viewer">
<div class="lv-buttons">
<button onclick="document.getElementById('lv-text').innerHTML=''">Clear</button>
<button onclick="updateMe(this)">Show in Viewer</button>
<!--the element that calls updateMe must be in the viewer container-->
</div>
<textarea class="lv-rle" id="lv-text">o2bo3bo$o2bobobo$4o3bo$o2bobo$o2bobobo!</textarea><br/>
<canvas height=400 width=600></canvas>
</div>
<!--end viewer container-->
</body>
</html>
Lesson 4: Hide the textarea

- Used when you only want to display a specific pattern in a LifeViewer
- This is done my moving the textarea containing the rle off the visible page using absolute positioning and setting the top to a negative number
- The textarea tag must remain inside the viewer container
- Run the example
<!DOCTYPE html>
<html>
<head><meta name="LifeViewer" content="viewer textarea"> <!--required tag-->
<script src="lv-plugin.js"></script> <!--assumes plug-in is in the same directory as html file-->
<style>
body{
margin:50px;
}
.lv-rle{
position:absolute;
top:-1000px;
}
</style>
</head>
<body>
<!--viewer container-->
<div class="viewer">
<textarea class="lv-rle">bo$2bo$3o!</textarea>
<!--hide the textarea by moving it off the visible page with css-->
<!--note the textarea element's tag must stay within the viewer container-->
<canvas height=400 width=600></canvas>
</div>
<!--end viewer container-->
</body>
</html>
Lesson 5: Tips & Tricks
- To disable user input in a textarea, add the readonly attribute: <textarea readonly>whatever</textarea>
- RLEs can control the viewer using LifeViewer scripts
- You can put multiple LifeViewers on a single page; each must have its own <div> container with its own <textarea> and <canvas> inside, or use iframes like PatMan does
- For a full-featured web app illustrating the use of the LifeViewer plug-in, check out Pattern Manager (PatMan)
- Shows how to use iframes to have a set of thumbnails on the same page that each open in a single viewer, like on LifeWiki pages
- Downloadable source code and related files
| |||||||||||||||||