home *** CD-ROM | disk | FTP | other *** search
- <HTML STYLE="font: messagebox">
- <HEAD>
- <TITLE id=dialogTitle>
- Replace
- </TITLE>
-
- <SCRIPT LANGUAGE=JavaScript>
-
- //+-------------------------------------------------------------------------
- //
- // This section contains code to be moved into a GLOBAL MODULE outside
- // of this particular dialog.
- //
- //--------------------------------------------------------------------------
-
-
- //----------------------------------------------------------------------
- //
- // Synopsis: Turns on the document's expando property. When this
- // property is on, it is possible to create new expando
- // properties or assign to existing ones.
- //
- // Arguments: none
- //
- // Returns: Nothing
- //
- //----------------------------------------------------------------------
-
- function expandoOn()
- {
- document.expando = true;
- } // expandoOn
-
-
- //----------------------------------------------------------------------
- //
- // Synopsis: Turns off the document's expando property. When this
- // property is off, it is possible to read the value of
- // existing expando properties, but not possible to create
- // new ones or modify existing ones.
- //
- // EXPANDO SHOULD BE OFF EXCEPT WHEN CREATING/MODIFYING
- // EXPANDO PROPERTIES. This will save hours debugging
- // accidentally created expando properties.
- //
- // Arguments: none
- //
- // Returns: Nothing.
- //
- //----------------------------------------------------------------------
-
- function expandoOff()
- {
- document.expando = false;
- } // expandoOff
-
-
- //+---------------------------------------------------------------------
- //
- // Synopsis: Given a string, returns the number the string represents.
- // This is needed because current localization tools can
- // only find strings.
- //
- // Arguments: string The string we're changing into a number.
- //
- // Returns: a number
- //
- //----------------------------------------------------------------------
-
- function number(string)
- {
- return parseFloat(string);
- } // number
-
- </SCRIPT>
-
- <SCRIPT LANGUAGE=JavaScript>
-
- //+--------------------------------------------------------------------------
- //
- // This section contains variables that need to be LOCALIZED
- //
- //---------------------------------------------------------------------------
-
- var L_Replace_DIALOG_Width_Text = "34.1em";
- var L_Replace_DIALOG_Height_Text = "14em";
-
- var L_FinishedDocument_Text = "Finished searching the document.";
- var L_FinishedReplaceAll_Text = "Finished replace all";
-
- var L_NoHelp_Text = "No help topic available.";
-
- </SCRIPT>
-
- <SCRIPT LANGUAGE="JavaScript">
-
- //+--------------------------------------------------------------------------
- //
- // This section contains code LOCAL to this particular dialog.
- //
- //---------------------------------------------------------------------------
-
- expandoOff();
-
- // Set dialog dimensions
- window.width = L_Replace_DIALOG_Width_Text;
- window.height = L_Replace_DIALOG_Height_Text;
-
- // Dim global variables
- var rngFoundText; // The found text
- var rngMaster; // The selection when the dialog is called
- var rngWorking; // A range we can play with
- var boolFoundText = false; // If the text has been found
- var boolFinishedSearch = false; // If we've reached the start or end of the document
- // or range
- var lngInsertion; // Where the insertion point is
- var dummy; // dummy variable
-
-
- //+---------------------------------------------------------------------
- //
- // Synopsis: Sets the focus to the find button. Also determines
- // whether something is selected in the document.
- //
- // Arguments: none
- //
- // Returns: nothing
- //
- //-----------------------------------------------------------------------
-
- function loadBdy()
- {
- docSearch = window.dialogArgs.document;
- txtFindText.focus(); // Set the focus to the first text box.
-
- rngMaster = docSearch.selection.createRange();
-
- //
- // If the selection is less than 16 characters, populate txtFind with the
- // selection
- //
- if ("Text" == docSearch.selection.type)
- {
- if ( 16 > rngMaster.text.length)
- {
- txtFindText.value = rngMaster.text;
-
- btnFind.disabled = false;
- btnReplace.disabled = false;
- btnReplaceAll.disabled = false;
-
- lngInsertion = rngMaster.end;
- }
- }
-
- if (("Control" != docSearch.selection.type) && (rngMaster.end != lngInsertion))
- {
- lngInsertion = rngMaster.start;
- }
-
- //
- // We've gotten the insertion point, the rngMaster becomes the entire body
- //
- rngMaster = docSearch.body.createTextRange();
-
- rngWorking = rngMaster.duplicate();
- } // loadBdy
-
-
- //+---------------------------------------------------------------------
- //
- // Synopsis: Checks the status of the appropriate checkboxes and
- // sets the flags for the rangeFromText method.
- //
- // Arguments: none
- //
- // returns: a number representing the flags for the rangeFromText
- // method. (See OM spec for more info.)
- //
- //----------------------------------------------------------------------
-
- function findFlags()
- {
- var htmlMatchWord = 2;
- var htmlMatchCase = 4;
-
- return (htmlMatchWord * document.all.chkWholeWord.checked)
- | (htmlMatchCase * document.all.chkMatchCase.checked)
- } // findFlags
-
-
- //+---------------------------------------------------------------------
- //
- // Synopsis: Three steps:
- // 1. Make sure there's something to find.
- // 2. Determine the direction and how far to search.
- // 3. Find and select the text.
- //
- // Arguments: none
- //
- // Returns: nothing
- //
- //-----------------------------------------------------------------------
-
- function btnFindClick()
- {
- var intDirection; // What direction to search and how far to search
-
- if (btnFind.disabled == true) // No text to search for!
- {
- return;
- }
-
- //
- // Set direction
- //
- if (radDirection[0].checked) // Search backwards
- {
- //
- // set range to search
- //
- if (!boolFoundText && !boolFinishedSearch)
- {
- //
- // Search from insertion point to beginning of document
- //
- rngWorking.end = lngInsertion;
- }
- else
- {
- //
- // Note: boolFoundText and boolFinishedSearch should never both be true.
- //
- if (boolFoundText)
- {
- //
- // Search from start of found text to start of document or range
- //
- rngWorking.end = rngFoundText.start;
- rngWorking.start = rngMaster.start;
- }
- if (boolFinishedSearch)
- {
- //
- // Search from end of document or range to start of document or range
- //
- lngInsertion = rngMaster.end;
- boolFinishedSearch = false;
- }
- }
- intDirection = rngWorking.start - rngWorking.end // Should be negative or 0
- }
- else // Search forwards
- {
- //
- // set range to search
- //
- if (!boolFoundText && !boolFinishedSearch)
- {
- //
- // Search from insertion point to end of document
- //
- rngWorking.start = lngInsertion;
- }
- else
- {
- //
- // Note: boolFoundText and boolFinishedSearch should never both be true.
- //
- if (boolFoundText)
- {
- //
- // Search from end of found text to end of document or range
- //
- rngWorking.start = rngFoundText.end;
- rngWorking.end = rngMaster.end;
- }
- if (boolFinishedSearch)
- {
- //
- // Search from start of document or range to end of document or range
- //
- lngInsertion = rngMaster.start;
- boolFinishedSearch = false;
- }
- }
- intDirection = rngWorking.end - rngWorking.start // Should be positive or 0
- }
-
- //
- // Here's where we do the dirty work (step 3) ...
- //
- rngFoundText = docSearch.rangeFromText(txtFindText.value, intDirection, findFlags(), rngWorking);
-
- if (rngFoundText == null) // Text was not found
- {
- alert(L_FinishedDocument_Text);
- rngWorking = rngMaster.duplicate();
- boolFoundText = false;
- boolFinishedSearch = true;
- }
- else // Text was found
- {
- rngFoundText.select();
- rngFoundText.scrollIntoView(true);
- boolFoundText = true;
- }
- } // btnFindClick
-
-
- //+---------------------------------------------------------------------
- //
- // Synopsis: Go through the entire document or range and replace all
- // occurrences of txtFindText with txtReplaceText
- //
- // Arguments: none
- //
- // Returns: nothing
- //
- //-----------------------------------------------------------------------
-
- function btnReplaceAllClick()
- {
- //
- // The 0 in the rangeFromText method below confines the search to the given range.
- //
- rngFindText = docSearch.rangeFromText(txtFindText.value, 0, findFlags(),
- docSearch.body.createTextRange());
-
- while (rngFindText != null) // Loop until text is no longer found.
- {
- rngFindText.text = txtReplaceText.value;
- rngWorking.start = rngFindText.end;
- rngFindText = docSearch.rangeFromText(txtFindText.value, 0, findFlags(),
- docSearch.body.createTextRange());
- }
-
- alert(L_FinishedReplaceAll_Text);
- } // btnReplaceAllClick
-
-
- //+----------------------------------------------------------------------
- //
- // Synopsis: Replace current seelction with value from txtReplaceText
- //
- // Arguments: none
- //
- // Returns: nothing
- //
- //-----------------------------------------------------------------------
-
- function btnReplaceClick()
- {
- rngWorking = docSearch.selection.createRange();
-
- if (txtFindText.value == rngWorking.text) // selected text equals text in Find what:
- {
- rngWorking.text = txtReplaceText.value;
- }
-
- btnFindClick();
- } // btnReplaceClick
-
- </SCRIPT>
-
- <SCRIPT LANGUAGE=JavaScript FOR=document EVENT="onkeypress()">
-
- //+---------------------------------------------------------------------
- //
- // Synopsis: Looks for the ENTER and ESC keypresses and runs the
- // appropriate action.
- //
- // Arguments: none
- //
- // Returns: nothing
- //
- //-----------------------------------------------------------------------
-
- var htmlKeyReturn = 13;
- var htmlKeyEscape = 27;
-
- if (event.keyCode == htmlKeyReturn) // Enter
- {
- btnFindClick();
- btnFind.focus();
- }
-
- if (event.keyCode == htmlKeyEscape) // Esc
- {
- btnCancelClick();
- }
-
- </SCRIPT>
-
- <SCRIPT LANGUAGE=JavaScript>
-
- function btnCancelClick()
- {
- window.close();
- }
-
- </SCRIPT>
-
- <SCRIPT LANGUAGE=JavaScript FOR=txtFindText EVENT="onkeyup()">
-
- //+----------------------------------------------------------------------------------
- //
- // Synopsis: Disables or enables the find button depending on whether
- // there is text in txtFindText.
- //
- // Arguments: none
- //
- // Returns: nothing
- //
- //-----------------------------------------------------------------------------------
-
- if ("" == txtFindText.value)
- {
- btnFind.disabled = true;
- btnReplace.disabled = true;
- btnReplaceAll.disabled = true;
- }
- else
- {
- btnFind.disabled = false;
- btnReplace.disabled = false;
- btnReplaceAll.disabled = false;
- }
-
- </SCRIPT>
-
- <SCRIPT LANGUAGE=JavaScript FOR=document EVENT="onhelp()">
-
- //+-------------------------------------------------------------------------
- //
- // Synopsis: Opens the help file with the appropriate helpid
- //
- // Arguments: none
- //
- // Returns: nothing
- //
- //--------------------------------------------------------------------------
-
- // BUGBUG Once we get help for the editing dialogs, this function
- // will have to change.
- alert(L_NoHelp_Text);
-
- </SCRIPT>
-
- </HEAD>
-
- <BODY ID=bdy onLoad="loadBdy()" style="font: messagebox; background: 'buttonface';">
-
- <BUTTON id=btnFind onclick="btnFindClick()" ACCESSKEY=f DISABLED=1 tabIndex=10
- style="font: messagebox; position: absolute;LEFT: '25.7em'; TOP: '1em'; WIDTH: '6.8em'; HEIGHT: '2.1em'">
- <U>F</U>ind Next
- </BUTTON>
-
- <BUTTON id=btnReplace onclick="btnReplaceClick()" ACCESSKEY=r DISABLED=1 tabIndex=15
- style="font: messagebox; position: absolute;LEFT: '25.7em'; TOP: '3.5em'; WIDTH: '6.8em'; HEIGHT: '2.1em'">
- <U>R</U>eplace
- </BUTTON>
-
- <BUTTON id=btnReplaceAll onclick="btnReplaceAllClick()" ACCESSKEY=a DISABLED=1 tabIndex=20
- style="font: messagebox; position: absolute;LEFT: '25.7em'; TOP: '6em'; WIDTH: '6.8em'; HEIGHT: '2.1em'">
- Replace <U>A</U>ll
- </BUTTON>
-
- <BUTTON id=btnCancel onclick="btnCancelClick()" tabIndex=25
- style="font: messagebox; position: absolute;LEFT: '25.7em'; TOP: '8.5em'; WIDTH: '6.8em'; HEIGHT: '2.1em'">
- Cancel
- </BUTTON>
-
- <INPUT type=text id=txtFindText ACCESSKEY=n tabIndex=30
- style="font: messagebox; position: absolute;LEFT: '7.2em'; TOP: '1em'; WIDTH: '17.5em'; HEIGHT: '2.1em'">
-
- <INPUT type=text id=txtReplaceText ACCESSKEY=p tabIndex=35
- style="font: messagebox; position: absolute;LEFT: '7.2em'; TOP: '3.5em'; WIDTH: '17.5em'; HEIGHT: '2.1em'">
-
- <DIV align=absMiddle style="font: messagebox; position: absolute; LEFT: '1em'; TOP: '1.3em'; WIDTH: '8em'; HEIGHT: '1em'">
- <LABEL FOR=txtFindText ID=lblFindText tabIndex="-1">
- Fi<U>n</U>d what:
- </LABEL>
- </DIV>
-
- <DIV align=absMiddle style="font: messagebox; position: absolute; LEFT: '1em'; TOP: '3.8em'; WIDTH: '8em'; HEIGHT: '1em'">
- <LABEL FOR=txtReplaceText ID=lblReplaceText tabIndex="-1">
- Re<U>p</U>lace with:
- </LABEL>
- </DIV>
-
- <INPUT id=chkWholeWord type=checkbox ACCESSKEY=w tabIndex=40
- style="font: messagebox; position: absolute;LEFT: '1em'; TOP: '7.6em'; WIDTH: '1em'; HEIGHT: '1em'">
-
- <INPUT id=chkMatchCase type=checkbox ACCESSKEY=c tabIndex=45
- style="font: messagebox; position: absolute;LEFT: '1em'; TOP: '9.4em'; WIDTH: '1em'; HEIGHT: '1em'">
-
- <DIV style="font: messagebox; position: absolute; LEFT: '2.6em'; TOP: '7.6em'; WIDTH: '11em'; HEIGHT: '1.3em'">
- <LABEL FOR=chkWholeWord id=lblWholeWord tabIndex="-1">
- Match <U>w</U>hole word only
- </LABEL>
- </DIV>
-
- <DIV style="font: messagebox; position: absolute; LEFT: '2.6em'; TOP: '9.4em'; WIDTH: '10em'; HEIGHT: '1em'">
- <LABEL FOR=chkMatchCase id=lblMatchCase tabIndex="-1">
- Match <U>C</U>ase
- </LABEL>
- </DIV>
-
- <TABLE cellspacing cellPadding=7 borderColorDark=buttonhighlight borderColorLight=buttonshadow border=1 noshade="yes"
- style="font: messagebox; position: absolute; LEFT: '14.5em'; TOP: '7.5em'; WIDTH: '9.5em'; HEIGHT: '3em'">
-
-
- <TR>
- <TD style="font: messagebox; position: relative; width: '6.4em'; height: '2em';">
- <DIV style="color: buttonface">a</DIV>
- </TD>
- </TR>
- </TABLE>
-
- <INPUT id=radDirectionUp type=radio name=radDirection ACCESSKEY=u tabIndex=50
- style="position: absolute;font: messagebox;top: '8.6em'; left: '15.3em'; width: '1em'; height: '1em';">
-
- <DIV style="position: absolute;font: messagebox;top: '8.6em'; left: '17em'; width: '2em'; height: '2em';">
- <LABEL FOR=radDirectionUp id=lblDirectionUp tabIndex="-1" STYLE="font: messagebox"> <U>U</U>p </LABEL>
- </DIV>
-
- <INPUT id=radDirectionDown type=radio CHECKED name=radDirection ACCESSKEY=d tabIndex=55
- style="position: absolute;font: messagebox;top: '8.6em'; left: '19.25em'; width: '1em'; height: '1em';">
-
- <DIV style="position: absolute;font: messagebox;top: '8.6em'; left: '20.75em'; width: '3em'; height: '1em';">
- <LABEL FOR=radDirectionDown id=lblDirectionDown tabIndex="-1" STYLE="font: messagebox"> <U>D</U>own </LABEL>
- </DIV>
-
- <DIV style="font: messagebox; position: absolute;background: buttonface; HEIGHT: '1em'; LEFT: '15em'; TOP: '7em'; WIDTH: '4.1em'">
- <LABEL id=lblDirection tabIndex="-1" STYLE="font: messagebox;">
- Direction </LABEL>
-
- </DIV>
- </BODY>
- </HTML>
-