Menu

#2 Spell Checker

open
nobody
None
5
2002-02-16
2002-02-16
Anonymous
No

Would love to see a spell checker added. Or perhaps
the ability to chose between some of the different
commercial spell checkers available.

Discussion

  • Michael Keck

    Michael Keck - 2002-07-31

    Logged In: YES
    user_id=224032

    Hey!
    I've found a simple but cool spell checker in vbscript
    on microsoft.public.inetsdk.programming.dhtml_editing.
    It works fine!
    I've added this into my RTE:
    1: you must add in the Design Mode an new button for the
    spellchecker call like this:
    <td class="rebar"><img src="img/spell.gif" width="16"
    height="16" border="0" onclick="Chk_Spelling();" alt="Spell
    Check"></td>
    2. you must edit in the head section of your editor, wich will
    be included (not the index-file or multipart-file) in the head
    section the line below:
    <script language="VBScript" type="text/vbscript"
    src="rtespelling.vbs"></script>
    3. copy the code below in a new file named "rtespelling.vbs"

    '===================== BEGIN COPY ==
    function Chk_Spelling()
    Dim oWord
    Dim oDoc
    Dim sTemp
    Dim sData, sDataText
    Dim sError
    Dim sCheckIt
    Dim aArray, aArrayOrg
    On Error Resume Next
    '= 1 ===== MODIFY: this 2 lines below ====
    sData = doc.innerHTML 'yourEditorDiv.innerHTML
    sDataText = doc.innerText 'yourEditorDiv.innerText
    '=====================================
    if Trim(sDataText) <> "" then
    'user innertext to gather error words.
    'collect words, then prompt for suggestions
    'then searche and replacethe words in sData
    'save sData back to the editors div
    'Create a Word-App
    set oWord = GetObject("Word.Application")
    if TypeName(oWord) <> "Application" then
    err.Clear
    'Word not in memory, so create
    set oWord = CreateObject("Word.Application")
    end if
    'send error-info if creation failed
    if err.number <> 0 then
    set oWord = Nothing
    select case err.number
    case 429
    sError = "Please enable activeX in your browser security"_
    & "settings." & chr(13) _
    & chr(13) & "1. Open Internet Options from the Tools Menu." _
    & chr(13) & "2. Click the Security Tab." _
    & chr(13) & "3. Click the Trusted Sites icon." _
    & chr(13) & "4. Click the Sites button." _
    & chr(13) & "5. Type in this URL http://www.domain.com." _
    & chr(13) & "6. Click the Add button, then the OK button." _
    & chr(13) & "7. Click the Custom Level button." _
    & chr(13) & "8. Change initilize ActiveX controls not safe to"_
    & "Enabled."
    case else
    sError = err.description
    end select
    MsgBox "Error Loading Microsoft Word Spell Checker:"_
    & " Error : " & err.number & chr(13) & chr(13) & "Microsoft"_
    & " Word 2000 Required."_
    & chr(13) & chr(13) & "Description : "_
    & sError, ," Spell Checker"
    exit function
    end if
    'minimize
    oWord.WindowState = 2 ' 0 = show Word-App
    'show
    oWord.Visible = True 'false, Word-App is not seen
    'create new Word document
    set oDoc = oWord.Documents.Add
    oDoc.Content = sDataText
    'no prompt
    oDoc.CheckSpelling IgnoreUpperCase=True,
    AlwaysSuggest=false
    Dim oDocErrors
    set oDocErrors = oDoc.SpellingErrors
    if oDocErrors.Count > 0 then
    'build list
    sCheckIt = ""
    for each oDocError in oDocErrors
    sCheckIt = sCheckIt & oDocError.Text & "|"
    next
    'split into an array to reprocess
    aArray = split( sCheckIt , "|" )
    aArrayOrg = split( sCheckIt , "|" )
    sCheckIt = ""
    'loop all arry items
    for iCnt = 0 to UBound(aArray)
    if aArray(iCnt) <> "" then
    'hold temp var
    sCheckIt = aArray(iCnt)
    'check for user suggestion
    oDoc.Content = sCheckIt & " "
    'prompt
    oDoc.CheckSpelling
    'resave to array
    aArray(iCnt) = Trim( oDoc.Content )
    end if
    next
    'now replace all new words and loop all array items
    Dim objRegExp
    set objRegExp = New RegExp
    objRegExp.IgnoreCase = false
    objRegExp.Global = true
    for iCnt = 0 to UBound(aArray)
    if aArray(iCnt) <> "" then
    objRegExp.Pattern = "(\b" & Trim(aArrayOrg(iCnt)) & "\b)"
    sData = objRegExp.Replace(sData , aArray(iCnt))
    end if
    next
    set objRegExp = Nothing
    'return value
    '= 2 === MODIFY: 'yourEditorDiv.innerHTML=sData ====
    doc.innerHTML = sData
    '=====================================
    end if
    'kill objects
    oDoc.Close False
    set oDoc = Nothing
    oWord.Application.Quit True
    set oWord = Nothing
    end if
    MsgBox "The Spelling check is complete.", ,"Spell Checker"
    End function
    ' =============== END OF COPY ================

    4. modify in the vbs your editor-name:
    1. sData = doc.innerHTML '= your Editor-Div.innerHtml
    sDataText = doc.innerText '= your Editor-Div.innerText
    2. doc.innerHTML = sData 'your Editor-Div.innerHtml =

    That's it.

    But how does it work?
    1. It opens a new MS-Word - Document and copys your
    content into the new (unvisible) Word.
    2. The it starts the spell checker of MS-Word.
    3. You can modify, add new words and ignore, all that what
    MS-Word can do.

    What are the requirements?
    1. You need MS-Windows 9x/ME/NT/2K/XP
    2. You need MS-Word 2000/XP
    3. You need IE 5.5 or above
    4. Your browser settings, your firewalls and your Anti-Virus
    programms must be enabled to initialize and use this ActiveX:
    a). Open Internet Options from the Tools Menu
    b) Click the Security Tab
    c) Click the Trusted Sites icon
    d) Click the Sites button
    e) Type in the URL of your site (e.g. http://www.domain.com\)
    f) Click the Add button, then the OK button
    g) Click the Custom Level button
    h) Change Initilize ActiveX controls not safe to Enabled

    I hope this will help you all.

    Best regards

    Michael

     
  • Mark Short

    Mark Short - 2003-03-24

    Logged In: YES
    user_id=526320

    That is pretty slick, also requires site to be SSL site at least
    with my security settings, but still, that is a nice little slice of
    code.

    Mark

     

Log in to post a comment.