home *** CD-ROM | disk | FTP | other *** search
- /* This script created by Christopher Bradford, Alive! Online.
-
- You may distribute this freely, but please keep the headers intact.
-
- This script requires HomeSite/CF Studio 4 RC4 and above.
-
- Installation:
- Create a custom button for the .js file
-
- Copyright 1998
- Christopher Bradford
- bradford@aliveonline.com
- */
-
- // MessageBox constants
- var hsOK = 0;
- var hsExclamation = 48;
- var hsInformation = 64;
-
- var app=Application;
- var active = app.ActiveDocument;
-
- function Main() {
-
- // first, get the current cursor position and selection to restore it later
- var startHere = active.SelStart;
- var intSelLength = active.SelLength;
-
- // now, select the current tag with a workaround
- active.BeginUpdate();
- active.GotoPreviousStartTag(false);
- active.GotoNextStartTag(true);
- var selectedText = active.SelText;
-
- // restore the original selection
- active.SelStart = startHere;
- active.SelLength = intSelLength;
- active.EndUpdate();
-
- var strHREF = app.HTMLGetAttribute(selectedText, "HREF");
-
- var ftpRE = /ftp:\/\//i;
- var httpRE = /http:\/\//i;
-
- if (strHREF.search(ftpRE) != -1) { // it's an FTP link
- app.MessageBox("This script can't open FTP links yet. Watch for an updated version.", "Not supported", hsOK);
- }
- else if (strHREF.search(httpRE) != -1) { // it's an absolute link
- var linkedFile = strHREF;
- var strURLFile = app.GetURL(strHREF);
- if (strURLFile != "") {
- app.NewDocument(false);
- active.Text = strURLFile;
- }
- else { app.MessageBox("Couldn't open file!", "Failure", hsOK + hsExclamation); }
- }
-
- else { // it's a relative link
- if (active.Filename == "") { // file has not yet been saved
- app.MessageBox("You must save the file before HomeSite can resolve relative links.", "Save file", hsOK + hsInformation);
- }
- else { // we can calculate relative paths
- var linkedFile = resolvedPath(strHREF);
- var success = app.OpenFile(linkedFile);
- if (!success) { app.MessageBox("Couldn't open file!", "Failure", hsOK + hsExclamation); }
- }
- }
-
- } // end Main
-
-
-
- function resolvedPath(strRelativePath) {
- var strCurrFilePathSlash = app.ExtractFilePath(active.Filename);
- var strCurrFilePath = strCurrFilePathSlash.slice(0, strCurrFilePathSlash.length-1);
- var arrAbsDirs = strCurrFilePath.split("\\");
- var arrRelDirs = strRelativePath.split("/");
- var arrNewRelDirs = new Array();
- var arrNewAbsDirs = new Array();
- var relPathUp = "..";
- var relFirstPart = arrRelDirs[0];
- while (relFirstPart == relPathUp) {
- arrNewAbsDirs = arrAbsDirs.slice(0, arrAbsDirs.length-1);
- arrNewRelDirs = arrRelDirs.slice(1, arrRelDirs.length);
- arrAbsDirs = arrNewAbsDirs;
- arrRelDirs = arrNewRelDirs;
- relFirstPart = arrRelDirs[0];
- } // end while
- strCurrFilePath = arrAbsDirs.join("\\");
- strRelativePath = arrRelDirs.join("\\");
- var strResolvedPath = strCurrFilePath + "\\" + strRelativePath;
- return strResolvedPath;
- }
-
-