home *** CD-ROM | disk | FTP | other *** search
/ PC/CD Gamer UK 45 / PCGAMER45.bin / netware / msie4pp / ie4_s3.cab / IE4_3.CAB / MSHTMENU.DLL / 2110 / EDLINK.DLG < prev    next >
Text File  |  1997-04-04  |  17KB  |  544 lines

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML 3.2//EN">
  2. <HTML id=dlgLink STYLE="font-family: 'ms sans serif'; font-size: '8pt';
  3. width: '32.7em'; height: '15em'">
  4. <HEAD>
  5. <META NAME=GENERATOR CONTENT="Trident 3411">
  6. <TITLE>Link</TITLE>
  7.  
  8. <SCRIPT LANGUAGE=JavaScript>
  9.  
  10. //+-------------------------------------------------------------------------
  11. //
  12. //  This section contains code to be moved into a GLOBAL MODULE outside
  13. //  of this particular dialog.
  14. //
  15. //--------------------------------------------------------------------------
  16.  
  17.  
  18.     //----------------------------------------------------------------------
  19.     //
  20.     //  Synopsis:   Turns on the document's expando property.  When this
  21.     //              property is on, it is possible to create new expando
  22.     //              properties or assign to existing ones.
  23.     //
  24.     //  Arguments:  none
  25.     //
  26.     //  Returns:    Nothing
  27.     //
  28.     //----------------------------------------------------------------------
  29.  
  30.     function expandoOn()
  31.     {
  32.         document.expando = true;
  33.     }   //  expandoOn
  34.  
  35.  
  36.     //----------------------------------------------------------------------
  37.     //
  38.     //  Synopsis:   Turns off the document's expando property.  When this
  39.     //              property is off, it is possible to read the value of
  40.     //              existing expando properties, but not possible to create
  41.     //              new ones or modify existing ones.
  42.     //
  43.     //              EXPANDO SHOULD BE OFF EXCEPT WHEN CREATING/MODIFYING
  44.     //              EXPANDO PROPERTIES.  This will save hours debugging
  45.     //              accidentally created expando properties.
  46.     //
  47.     //  Arguments:  none
  48.     //
  49.     //  Returns:    Nothing.
  50.     //
  51.     //----------------------------------------------------------------------
  52.  
  53.     function expandoOff()
  54.     {
  55.         document.expando = false;
  56.     }   //  expandoOff
  57.  
  58.  
  59.     //+---------------------------------------------------------------------
  60.     //
  61.     //  Synopsis:   Given a string, returns the number the string represents.
  62.     //              This is needed because current localization tools can
  63.     //              only find strings.
  64.     //
  65.     //  Arguments:  string  The string we're changing into a number.
  66.     //
  67.     //  Returns:    a number
  68.     //
  69.     //----------------------------------------------------------------------
  70.  
  71.     function number(string)
  72.     {
  73.         return parseFloat(string);
  74.     }   //  number
  75.  
  76. </SCRIPT>
  77.  
  78. <SCRIPT LANGUAGE=JavaScript>
  79.  
  80. //+--------------------------------------------------------------------------
  81. //
  82. //  This section contains variables that need to be LOCALIZED
  83. //
  84. //---------------------------------------------------------------------------
  85.  
  86. // var L_EditLink_DIALOG_Width_Text  =   "32.7em";
  87. // var L_EditLink_DIALOG_Height_Text =   "15em";
  88.  
  89. var L_NoHelp_Text = "No help topic available.";
  90.  
  91. </SCRIPT>
  92.  
  93.  
  94. <SCRIPT LANGUAGE="JavaScript">
  95.  
  96. //+-------------------------------------------------------------------------
  97. //
  98. //  This section contains code LOCAL to this particular dialog.
  99. //
  100. //--------------------------------------------------------------------------
  101.  
  102.     expandoOff();
  103.  
  104.     //  Set dialog dimensions
  105.     // window.width   =   L_EditLink_DIALOG_Width_Text;
  106.     // window.height  =   L_EditLink_DIALOG_Height_Text;
  107.  
  108.     //  Constants
  109.     var cmdCreateLink   = "CreateLink";
  110.     var cmdUnlink       = 2125;
  111.  
  112.     // Global variables
  113.     var globalDoc    = window.dialogArgs.document;
  114.     var gboolNewLink = true;                 // Is the link a new link?
  115.  
  116.  
  117.     //+----------------------------------------------------------------------
  118.     //
  119.     //  Synopsis:   Given a text range, returns an anchor element if that
  120.     //              element appears within or overlaps the range. If no
  121.     //              anchor exists, returns null.
  122.     //
  123.     //  Arguments:  range   The range we're looking for an element in.
  124.     //
  125.     //  Returns:    an anchor element if one is found, null if one is not.
  126.     //
  127.     //-----------------------------------------------------------------------
  128.  
  129.     function findAnchor(range)
  130.     {
  131.         var rangeWorking;
  132.         var elmWorking;
  133.         var index;
  134.  
  135.         //
  136.         //  First, look for the anchor as a parent element of the range
  137.         //  NOTE: This will only find an anchor under fairly special
  138.         //  circumstances (the first character of the range is part of an
  139.         //  anchor), but it's much faster than the method below.
  140.         //
  141.         elmWorking = range.parentElement( )
  142.  
  143.         while ("HTML" != elmWorking.tagName)
  144.         {
  145.             if ("A" == elmWorking.tagName)
  146.             {
  147.                 return elmWorking;
  148.             }
  149.             else
  150.             {
  151.                 elmWorking = elmWorking.parentElement
  152.             }
  153.         }
  154.  
  155.         //
  156.         //  That didn't work, so let's walk through each character in the
  157.         //  range and see if there's an anchor somewhere.
  158.         //
  159.         rangeWorking = range.duplicate( );
  160.  
  161.         //
  162.         //  Reduce rangeWorking to one character
  163.         //
  164.         rangeWorking.end = rangeWorking.start + 1;
  165.  
  166.         while (rangeWorking.end < range.end)
  167.         {
  168.             rangeWorking.move("Character");
  169.             //
  170.             //  "Wait!" you're saying. "You can't move rngWorking yet,
  171.             //  you'll miss the first character." If the first character
  172.             //  is part of an anchor, the section of code above will catch
  173.             //  it.
  174.             //
  175.             if (null != findAnchor(rangeWorking))
  176.             {
  177.                 return findAnchor(rangeWorking);
  178.             }
  179.         }
  180.  
  181.         //
  182.         //  Nothing yet found an anchor, so I guess there isn't one.
  183.         //
  184.         return null;
  185.     }   //  findAnchor
  186.  
  187.  
  188.     //+---------------------------------------------------------------------
  189.     //
  190.     //  Synopsis:   Returns the protocol when given a URL.
  191.     //
  192.     //  Arguments:  strURL  The URL to get the protocol from
  193.     //
  194.     //  Returns:    a string that matches a protocol or null if no match is
  195.     //              found.
  196.     //
  197.     //----------------------------------------------------------------------
  198.  
  199.     function getProtocolFromURL(strURL)
  200.     {
  201.         var index;
  202.  
  203.         //
  204.         //  We're assuming that the protocol ends at the first colon.
  205.         //
  206.         return strURL.substring(0, strURL.indexOf(":") + 1);
  207.     }
  208.  
  209.  
  210.     //+---------------------------------------------------------------------
  211.     //
  212.     //  Synopsis:   Updates the protocol combo box based on the entry in
  213.     //              the URL text box
  214.     //
  215.     //  Arguments:  None
  216.     //
  217.     //  Returns:    nothing
  218.     //
  219.     //----------------------------------------------------------------------
  220.  
  221.     function updateProtocolSel()
  222.     {
  223.         var index;
  224.         var strProtocol = getProtocolFromURL(txtURL.value);
  225.  
  226.         //
  227.         //  Loop through the options in selProtocol to see if one matches
  228.         //
  229.         selProtocol.value = strProtocol;
  230.  
  231.         //
  232.         //  No match was found. Select "other".
  233.         //
  234.         if (selProtocol.value != strProtocol)
  235.         {
  236.             selProtocol.value = "";
  237.         }
  238.     }   //  updateProtocolSel
  239.  
  240.  
  241.     //+---------------------------------------------------------------------
  242.     //
  243.     //  Synopsis:   Updates the protocol portion of txtURL based on the
  244.     //              selection in selProtocol
  245.     //
  246.     //  Arguments:  none
  247.     //
  248.     //  Returns:    nothing
  249.     //
  250.     //----------------------------------------------------------------------
  251.  
  252.     function updateProtocolTxt()
  253.     {
  254.         var strSlashProts   = " file:ftp:gopher:http:https:";    //  Some protocols are
  255.                                                                  //  followed by 2 slashes
  256.         var strProtocolTxt  = getProtocolFromURL(txtURL.value);
  257.         var strProtocolSel  = selProtocol.value;
  258.         var strTempURL;
  259.  
  260.         //
  261.         //  If the protocol is followed by two slashes, append them to the protocol
  262.         //
  263.         if ("//" == (txtURL.value.substring(strProtocolTxt.length, strProtocolTxt.length + 2)))
  264.         {
  265.             strProtocolTxt = strProtocolTxt + "//";
  266.         }
  267.  
  268.         //
  269.         //  Remove protocol from current URL
  270.         //
  271.         strTempURL = txtURL.value.substring(strProtocolTxt.length);
  272.  
  273.         if (0 < strSlashProts.indexOf(strProtocolSel))
  274.         {
  275.             strProtocolSel = strProtocolSel + "//";
  276.         }
  277.  
  278.         txtUrl.value = strProtocolSel + strTempURL;
  279.  
  280.     }   //  updateProtocolTxt
  281.  
  282.  
  283.     //----------------------------------------------------------------------
  284.     //
  285.     //  Synopsis:   Initialize the dialog
  286.     //
  287.     //  Arguments:  None
  288.     //
  289.     //  Returns:    nothing
  290.     //
  291.     //----------------------------------------------------------------------
  292.  
  293.     function bdyLoad()
  294.     {
  295.         var rngMaster;
  296.         var rngLink;
  297.         var elmLink;
  298.  
  299.         if (("Text" == globalDoc.selection.type) || ("None" == globalDoc.selection.type))
  300.         {
  301.             rngMaster = globalDoc.selection.createRange();
  302.             elmLink = findAnchor(rngMaster);
  303.  
  304.             if (null != elmLink)
  305.             {
  306.                 gboolNewLink = false;
  307.  
  308.                 //
  309.                 //  If the range contains an anchor, expand it to encompass the anchor
  310.                 //
  311.                 rngLink = globalDoc.rangeFromElement(elmLink);
  312.  
  313.                 if (rngLink.start < rngMaster.start)
  314.                 {
  315.                     rngMaster.start = rngLink.start;
  316.                 }
  317.                 if (rngLink.end > rngMaster.end)
  318.                 {
  319.                     rngMaster.end = rngLink.end;
  320.                 }
  321.                 rngMaster.select();
  322.  
  323.                 //
  324.                 //  Fill the dialog with info about the link
  325.                 //
  326.                 txtURL.value = elmLink.href
  327.                 updateProtocolSel();
  328.             }
  329.         }
  330.     }   // bdyLoad
  331.  
  332.  
  333.     //----------------------------------------------------------------------
  334.     //
  335.     //  Synopsis:   Discard the user's changes and dismiss the dialog.
  336.     //
  337.     //  Arguments:  none
  338.     //
  339.     //  Returns:    nothing
  340.     //
  341.     //----------------------------------------------------------------------
  342.  
  343.     function btnCancelClick()
  344.     {
  345.         window.close();
  346.     }   //  btnCancelClick
  347.  
  348.  
  349.     //+---------------------------------------------------------------------
  350.     //
  351.     //  Synopsis:   Inserts a link in the document
  352.     //
  353.     //  Arguments:  none
  354.     //
  355.     //  Returns:    nothing
  356.     //
  357.     //----------------------------------------------------------------------
  358.  
  359.     function btnOKClick()
  360.     {
  361.         var range;
  362.         var boolNoURL;  //  true if there's nothing typed into the txtURL
  363.         var strSlashProts = " file:ftp:gopher:http:https:"; //  Some protocols are
  364.                                                             //  followed by 2 slashes
  365.         var strProtocol = selProtocol.value;    //  The Protocol currently selected
  366.  
  367.         updateProtocolSel();
  368.  
  369.         if (0 < strSlashProts.indexOf(strProtocol))
  370.         {
  371.             strProtocol = strProtocol + "//";
  372.         }
  373.  
  374.         //
  375.         //  If txtURL is blank, then there's noURL
  376.         //
  377.         if ("" == txtURL.value)
  378.         {
  379.             boolNoURL = true;
  380.         }
  381.         //
  382.         //  If txtURL exactly matches the protocol, there's no URL
  383.         //
  384.         else if (txtURL.value == selProtocol.value)
  385.         {
  386.             boolNoURL = true;
  387.         }
  388.         //
  389.         //  If txtURL matches the protocol + "//" and the protocol is in strSlashProts,
  390.         //  There's no URL.
  391.         //
  392.         else if (strProtocol == txtURL.value)
  393.         {
  394.             boolNoURL = true;
  395.         }
  396.         //
  397.         //  All out of cases. There must be a URL.
  398.         //
  399.         else
  400.         {
  401.             boolNoURL = false;
  402.         }
  403.  
  404.         //
  405.         //  If no text (or only the protocol) is entered into txtURL, unlink the selection
  406.         //
  407.         if (boolNoURL)
  408.         {
  409.             range = globalDoc.selection.createRange();
  410.             range.execCommand(cmdUnlink);
  411.         }
  412.         else
  413.         {
  414.             //
  415.             //  If no text is selected, add the URL as the text, then select it.
  416.             //
  417.             if ("None" == globalDoc.selection.type)
  418.             {
  419.                 range = globalDoc.selection.createRange();
  420.                 range.text = txtURL.value;
  421.                 range.start = range.start - txtURL.value.length
  422.                 range.select();
  423.             }
  424.  
  425.             range = globalDoc.selection.createRange()
  426.  
  427.             range.execCommand(cmdCreateLink, false, txtURL.value);
  428.         }
  429.  
  430.         window.close();
  431.     }   //  btnOKClick
  432.  
  433. </SCRIPT>
  434.  
  435. <SCRIPT LANGUAGE=JavaScript FOR=document EVENT="onkeypress()">
  436.  
  437. //+---------------------------------------------------------------------
  438. //
  439. //  Synopsis:   Looks for the ENTER and ESC keypresses and runs the
  440. //              appropriate action.
  441. //
  442. //  Arguments:  none
  443. //
  444. //  Returns:    nothing
  445. //
  446. //-----------------------------------------------------------------------
  447.  
  448.     var htmlKeyReturn = 13;
  449.     var htmlKeyEscape = 27;
  450.  
  451.     if ((event.keyCode) == htmlKeyReturn)     //  Enter
  452.     {
  453.         btnOKClick();
  454.         btnOK.focus();
  455.     }
  456.  
  457.     if ((event.keyCode) == htmlKeyEscape)     //  Esc
  458.     {
  459.         btnCancelClick();
  460.     }
  461.  
  462. </SCRIPT>
  463.  
  464. <SCRIPT LANGUAGE=JavaScript FOR=document EVENT="onhelp()">
  465.  
  466. //+-------------------------------------------------------------------------
  467. //
  468. //  Synopsis:   Opens the help file with the appropriate helpid
  469. //
  470. //  Arguments:  none
  471. //
  472. //  Returns:    nothing
  473. //
  474. //--------------------------------------------------------------------------
  475.  
  476.     //  BUGBUG  Once we get help for the editing dialogs, this function
  477.     //          will have to change.
  478.     alert(L_NoHelp_Text);
  479.  
  480. </SCRIPT>
  481.  
  482. </HEAD>
  483.  
  484. <BODY  style="font-family: 'ms sans serif'; font-size: '8pt'; background: buttonface;" onLoad="bdyLoad()">
  485.  
  486. <TABLE cellPadding=7 cellspacing borderColorDark=buttonhighlight borderColorLight=buttonshadow noshade="yes" border=1
  487. style="font-family: 'ms sans serif'; font-size: '8pt'; position: absolute;LEFT: '1em'; TOP: '1.5em'; width: '30.5em'; height: '7em'">
  488.  
  489. <TR>
  490. <TD style="font: position: relative;LEFT: '0'; TOP: '0'; WIDTH: '20em'; HEIGHT: '4.5em'">
  491. <DIV style="color: buttonface;">a</DIV>
  492. </TD>
  493. </TR>
  494. </TABLE>
  495.  
  496.     <DIV style="position: absolute; LEFT: '2.4em'; TOP: '2.9em'; WIDTH: '8em'; HEIGHT: '2.1em'; font-family: 'ms sans serif'; font-size: '8pt';">
  497.     <LABEL FOR=selProtocol tabIndex=-1>
  498.     <u>H</u>yperlink Type:
  499.     </LABEL>
  500.     </DIV>
  501.  
  502.     <select id=selProtocol size=1 ACCESSKEY=h tabIndex=10 onchange="updateProtocolTxt()"
  503.     style="font-family: 'ms sans serif'; font-size: '8pt'; position: absolute;LEFT: '10.5em'; TOP:'2.6em'; WIDTH: '10em'; HEIGHT: '2.1em'">
  504.     <OPTION value="">                 (other) </OPTION>
  505.     <OPTION value="file:" SELECTED>   file:   </OPTION>
  506.     <OPTION value="ftp:">             ftp:    </OPTION>
  507.     <OPTION value="gopher:">          gopher: </OPTION>
  508.     <OPTION value="http:">            http:   </OPTION>
  509.     <OPTION value="https:">           https:  </OPTION>
  510.     <OPTION value="mailto:">          mailto: </OPTION>
  511.     <OPTION value="news:">            news:   </OPTION>
  512.     <OPTION value="telnet:">          telnet: </OPTION>
  513.     <OPTION value="wais:">            wais:   </OPTION>
  514.     </select>
  515.  
  516.     <DIV style="position: absolute; LEFT: '2.4em'; TOP: '5.8em'; WIDTH: '8em'; HEIGHT: '1.7em'; font-family: 'ms sans serif'; font-size: '8pt';">
  517.     <LABEL FOR=txtURL tabIndex=-1>
  518.     <u>U</u>RL:
  519.     </LABEL>
  520.     </DIV>
  521.  
  522.     <input accesskey=u ID="txtURL" value="file://" type=text size=35 maxlength=256 tabIndex=15
  523.     style="font-family: 'ms sans serif'; font-size: '8pt'; position: absolute;LEFT: '6em'; TOP: '5.5em'; WIDTH: '20em'; HEIGHT: '2.1em'">
  524.  
  525. <DIV style="font-family: 'ms sans serif'; font-size: '8pt'; position: absolute;background: buttonface; HEIGHT: '1em'; LEFT: '1.8em'; TOP: '1em'; WIDTH: '8em'">
  526. <LABEL tabindex=-1>  Link information</LABEL>
  527. </DIV>
  528.  
  529.  
  530. <BUTTON id=btnOK tabIndex=35 onclick="btnOKClick()"
  531. style="font-family: 'ms sans serif'; font-size: '8pt'; position: absolute;LEFT: '16em'; TOP: '9.5em'; WIDTH: '6.8em'; HEIGHT: '2.1em'">
  532. OK
  533. </BUTTON>
  534.  
  535. <BUTTON id=btnCancel tabIndex=40 onclick="btnCancelClick()"
  536. style="font-family: 'ms sans serif'; font-size: '8pt'; position: absolute;LEFT: '23.6em'; TOP: '9.5em'; WIDTH: '6.8em'; HEIGHT: '2.1em'">
  537. Cancel
  538. </BUTTON>
  539.  
  540.  
  541. </BODY >
  542.  
  543. </HTML>
  544.