home *** CD-ROM | disk | FTP | other *** search
- function URLFormat(strText, strTarget) {
- //
- // THIS FUNCTION REQUIRES MICROSOFT JSCRIPT 3.1
- //
- // Available for download at:
- // http://www.microsoft.com/scripting/
- //
- // Pass this function a variable containting the text you want to
- // process, and a string indicating the target of the anchor. If
- // you do not wish to specify a target, send an empty string ("")
- // for the second parameter.
- //
- // Joel Mueller
- // Creative Internet Solutions
- // jmueller@creativeis.com
- //
-
- /*@cc_on @*/
- /*@if (@_jscript_version < 3) @*/
- return "You must have JScript 3 or greater.";
- /*@else @*/
- var app = Application;
- if (strTarget.length > 0) {
- strTarget = app.TagCase(' TARGET="') + strTarget + '"';
- }
- var strResults = new String();
- if (strText.length > 0) {
- var index = 0;
- var newindex = 0;
- var objSearch = /((((https?:|ftp:|gopher:)\/\/)|(www\.|ftp\.))[\-\w\?\%\.,\/!@:=\+~_]+[A-Za-z0-9\/])/ig;
- if (objSearch.test(strText)) {
- var resArray = strText.match(objSearch);
- for (i=0; resArray.length > i; i++) {
- newindex = strText.indexOf(resArray[i], index);
- strResults = strResults + strText.substring(index, newindex);
- if (strResults.substring((strResults.length - 1),strResults.length) != "@") {
- strResults = strResults + app.TagCase('<A HREF="');
- if (resArray[i].substring(0,4) == "www.") {
- strResults = strResults + "http://";
- }
- else {
- if (resArray[i].substring(0,4) == "ftp.") {
- strResults = strResults + "ftp://";
- }
- }
- strResults = strResults + resArray[i] + '"' + strTarget + '>' + resArray[i] + app.TagCase('</A>');
- } else {
- strResults = strResults + resArray[i];
- }
- index = newindex + resArray[i].length;
- }
- if (index < strText.length) {
- strResults = strResults + strText.substring(index, strText.length);
- }
- } else {
- strResults = strText;
- }
- }
- return strResults;
- /*@end @*/
- }
-
- function MailToFormat(strText) {
- //
- // THIS FUNCTION REQUIRES MICROSOFT JSCRIPT 3.1
- //
- // Available for download at:
- // http://www.microsoft.com/scripting/
- //
- // Pass this function a string, and it will turn any e-mail addresses
- // into mailto links.
- //
- // Joel Mueller
- // Creative Internet Solutions
- // jmueller@creativeis.com
- //
-
- /*@cc_on @*/
- /*@if (@_jscript_version < 3) @*/
- return "You must have JScript 3 or greater.";
- /*@else @*/
- var strResults = new String();
- var app = Application;
- if (strText.length > 0) {
- var index = 0;
- var newindex = 0;
- var objSearch = /[\w\.\-]+@([\w\.]+\.)+[A-Za-z]{2,4}/ig;
- if (objSearch.test(strText)) {
- var resArray = strText.match(objSearch);
- for (i=0; resArray.length > i; i++) {
- newindex = strText.indexOf(resArray[i], index);
- strResults = strResults + strText.substring(index, newindex);
- strResults = strResults + app.TagCase('<A HREF="mailto:' + resArray[i] + '">') + resArray[i] + app.TagCase('</A>');
- index = newindex + resArray[i].length;
- }
- if (index < strText.length) {
- strResults = strResults + strText.substring(index, strText.length);
- }
- } else {
- strResults = strText;
- }
- }
- return strResults;
- /*@end @*/
- }
-
- function Main() {
- var app = Application;
- var intSelection = app.ActiveDocument.SelLength;
-
- var strText = eval("app.ActiveDocument." + ((intSelection > 0) ? "SelText" : "Text"));
-
- strText = MailToFormat(URLFormat(strText, ""));
-
- eval("app.ActiveDocument." + ((intSelection > 0) ? "SelText" : "Text") + " = strText");
- }
-