[comp.sys.mac.hypercard] Hypertext fields

miner@aai3.uucp (Stephen E. Miner) (09/09/88)

Here's what I use for hypertext fields.  These scripts are based on
ideas I've seen on the net and in various stacks so I don't claim that
they are original.  I hope you find them useful.

Steve Miner
miner@sri.com


-- HyperText Fields
-- by Steve Miner

-- These scripts allow a locked field to be used like "real" HyperText.
-- HyperText links in the text should be indicated by a suffix of a
-- single "punctuation" character (usually "*").  For example, this
-- might be a Link*.  The field must be locked so that the mouseUp
-- message will be sent when the user clicks on a word in the field.
-- If the word has the proper suffix, then the system will go to a
-- card of that name (not including the suffix.)  Otherwise, a beep
-- will sound.

-- An option space can be used in both the text and the name of the
-- card in order to treat contiguous words as a single unit.


-- A locked field (lockText property set to true) will receive a
-- mouseUp message when the user clicks on it.
on mouseUp
  followHyperLink
end mouseUp

on followHyperLink
  get HyperLink(the mouseLoc, "*")
  if it is not empty then
    visual effect zoom open
    go to cd it
  else
    beep
  end if
end followHyperLink

-- The HYPERLINK function selects and returns the hypertext link word
-- at the location MLOC.  To be a valid hypertext link, the word must
-- be followed immediately by the LINKCHAR, which must be a punctuation
-- character (such as "*" in HyperCard.)  The LINKCHAR is not included as
-- part of the returned word.  If the word is not a valid hypertext
-- link, the function returns the empty string.
function HyperLink mLoc, linkChar
  get the userLevel
  if it < 2 then set userLevel to 2
  set lockText of the target to false
  click at mLoc
  click at mLoc  -- just like double clicking to select a word
  set lockText of the target to true
  if hyperLinkp(linkChar) then
    return (the selection)
  else
    select empty
    return empty
  end if
  set userLevel to it   -- restore the old userLevel
end HyperLink

function hyperLinkp linkChar
  if the selection is empty then return false
  else return (char ((fourth word of the selectedChunk) + 1)  ---
  of target is linkChar)
end hyperLinkp


Stephen E. Miner
miner@sri.com

	       *** My other computer is a Macintosh ***