Open Source Spell Check for javascript Typo.js

Viewed 36

As I try to use the typo.js spell checker in my file. But it's throw some error's I can't find the solutions. I just followed the Typo.js Documentation Here is the document link. https://github.com/cfinke/Typo.js/ Kindly check the below issue and help me to reach out this issue

Here is the console issue image

Here is the used code

JS

<!doctype html>
<html>

<head>
    <title>Typo.js Example</title>
    <meta charset="UTF-8" />
    <script type="text/javascript" src="typo/typo.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
    <script type="text/javascript">
        var dictionary = new Typo("en_US", false, false, { dictionaryPath: "typo/dictionaries" });

        // function load() {
        //     $('#loading-progress').append('Loading affix data...').append($('<br />'));

        //     $.get('typo/dictionaries/en_US/en_US.aff', function (affData) {
        //         $('#loading-progress').append('Loading English dictionary (this takes a few seconds)...').append($('<br />'));

        //         $.get('typo/dictionaries/en_US/en_US.dic', function (wordsData) {
        //             $('#loading-progress').append('Initializing Typo...');

        //             dictionary = new Typo("en_US", affData, wordsData);

        //             checkWord('mispelled');
        //         });
        //     });
        // }

        checkWord('mispelled');

        function checkWord(word) {
            var wordForm = $('#word-form');
            wordForm.hide();

            var resultsContainer = $('#results');
            resultsContainer.html('');

            resultsContainer.append($('<p>').text("Is '" + word + "' spelled correctly?"));

            var is_spelled_correctly = dictionary.check(word);

            resultsContainer.append($('<p>').append($('<code>').text(is_spelled_correctly ? 'yes' : 'no')));

            if (!is_spelled_correctly) {
                resultsContainer.append($('<p>').text("Finding spelling suggestions for '" + word + "'..."));

                var array_of_suggestions = dictionary.suggest(word);

                resultsContainer.append($('<p>').append($('<code>').text(array_of_suggestions.join(', '))));
            }

            wordForm.show();
        }
    </script>
</head>

<body>
    <h1>Typo.js Demo</h1>
    <p>This page is an example of how you could use <a href="http://github.com/cfinke/Typo.js">Typo.js</a> in a webpage
        if you need spellchecking beyond what the OS provides.</p>
    <p id="loading-progress"></p>
    <div id="results"></div>
    <form method="GET" action="" onsubmit="checkWord( document.getElementById( 'word' ).value ); return false;"
        id="word-form" style="display: none;">
        <p>Try another word:</p>
        <input type="text" id="word" value="mispelled" />
        <input type="submit" value="Spellcheck" />
    </form>
</body>

</html>
0 Answers
Related