Monday, November 08, 2010 at 12:03 AM.
system.verbs.builtins.html.data.standardMacros.imageRef
on imageRef (imagespec, explanation=nil, hspace="", align="", usemap="", ismap=false, border=0, pageTable=nil, glossref="", vspace="", lowsrc="", rollsrc="", height="", width="", name="", id="", style="", class="", title="") {
<<Changes
<<5/14/10; 10:09:24 AM by DW
<<Went looking for a bug that might have been showing up in the Tool Catalog page in the OPML Editor, but it probably isn't here. Along the way I reformatted the code to current conventions.
<<07/05/00; 5:55:33 PM by PBS
<<Create a default alt attribute if explanation is nil or "". HTML standards require alt attributes for all images.
<<Put quotes around the values for all attributes.
<<Wednesday, January 07, 1998 at 4:24:37 PM by PBS
<<Removed timeModified check.
<<Added "name" parameter.
<<Fri, Feb 19, 1999 at 11:55:48 AM by PBS
<<Added title parameter.
<<Sunday, January 18, 1998 at 4:06:39 PM by PBS
<<Call html.getImagePath, a new script which builds relative URLs for images.
<<Thursday, January 01, 1998 at 12:52:02 PM by PBS
<<Added vspace, lowscr, and rollsrc parameters.
<<The rollsrc parameter specifies the image to display during
<<an on mouseover event.
<<Made Frontier smarter about writing out changed images.
<<11/15/97 at 5:59:03 AM by DW
<<doesn't run off html.data.page, instead it assumes that xxx has been set up.
<<takes pagetable as an optional param, facilitates debugging, allows calling from outside of html suite.
<<support for glossary references
local (htmlText = "");
local (imageTable, heightWidthString = "");
if pageTable == nil {
pageTable = html.getPageTableAddress ()};
<<scratchpad.imagerefparams = pagetable^
on add (s) {
htmlText = htmlText + s};
<<Get image data: url, path, address, mac file type, height, and width.
imageTable = html.getImageData (imageSpec, pageTable);
bundle { //get height and width of image; build heightWidthString
if height == "" {
height = imageTable.height};
if width == "" {
width = imageTable.width};
if height != 0 { //we may have failed to get image size
heightWidthString = "height=\"" + height + "\" "};
if width != 0 {
heightWidthString = heightWidthString + "width=\"" + width + "\""}};
bundle { //build html text
if name == "" { //optional name parameter
add ("<img src=\"" + imageTable.url + "\" " + heightWidthString)}
else {
add ("<img name=\"" + name + "\" src=\"" + imageTable.url + "\" " + heightWidthString)};
if id != "" {
add (" id=\"" + id + "\"")};
if lowsrc != "" {
local (lowSrcData = html.getImageData (lowsrc, pageTable));
add (" lowsrc=\"" + lowSrcData.url + "\"")};
if explanation == nil {
explanation = nameOf (imageTable.adrImage^) + " picture"};
if hspace != "" {
add (" hspace=\"" + hspace + "\"")};
if vspace != "" {
add (" vspace=\"" + vspace + "\"")};
if align != "" {
add (" align=\"" + align + "\"")};
if usemap != "" {
add (" usemap=\"#" + usemap + "\"")};
if ismap {
add (" ismap")};
if rollsrc != "" {
local (rollData = html.getImageData (rollsrc, pageTable));
add (" onmouseout=\"this.src='" + imageTable.url + "'\"");
add (" onmouseover=\"this.src='" + rollData.url + "'\"")};
if style != "" {
add (" style=\"" + style + "\"")};
if class != "" {
add (" class=\"" + class + "\"")};
if title != "" {
add (" title=\"" + title + "\"")};
add (" alt=\"" + explanation + "\""); //PBS 07/05/00: always add the alt attribute, as it's required by the HTML spec
add (" border=\"" + border + "\""); <<Wed, Dec 25, 1996 at 7:33:16 AM by DW
add (">")};
if glossref != "" { //5.0 enclose the imageref in an anchor or glosspatch
local (s = html.refGlossary (glossref));
<<assume we have a hard-coded link or a glosspatch
<<<a href="http://www.scripting.com/frontier/">Frontier</a> or
<<[[#glossPatch Welcome to Alpha User's Test Page!|websitessamples/randomStuff|]]
if s beginsWith "[[#" {
local (ix = string.patternMatch (' ', s));
s = string.delete (s, 1, ix);
s = string.nthField (s, '|', 2); <<this is the part we keep
htmltext = "[[#glossPatch " + htmltext + "|" + s + "|]]"}
else { <<assume it's an a href
s = string.nthField (s, '>', 1) + ">"; <<pop off the <a href="xxx"> part
htmltext = s + htmltext + "</a>"}};
return (htmltext)};
bundle { //test code
html.setpagetableaddress (@scratchpad.imagerefparams);
dialog.alert (imageref (@opmleditor.website.["#images"].theopmleditor))}
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.