Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
For details, refer to Get Started with WProofreader Cloud AutoSearch and Get Started with WProofreader Server AutoSearch

WProofreader API.

Below you can find the samples showing how different WProofreader initialization approaches work depending on the integration and expected launch behavior.

1.

Excerpt

1. Initialization Options

There are several  several options letting you initialize WProofreader functionality in your web app, namely using: 

  • autoSearch option (config WEBSPELLCHECKER_CONFIG and inline data attributes);
  • init() method;
  • autocreate (inline data attributes).

The WEBSPELLCHECKER_CONFIG (further CONFIG) can be added in a script or loaded from the file as mentioned in Get Started with WProofreader Server (autoSearch) guide for Server version and Get Started with WProofreader Cloud (autoSearch). 

guides

After you have initialized WProofreader, you can customize the above-mentioned settings using WebSpellChecker API.

Tip
Table of Contents
maxLevel4
stylenone

1. Initializing using autoSearch 

The autoSearch feature enables detecting new editable fields on the page and proofreading the text they contain automatically on hover selectionin focus. If you choose this option, WProofreader is enabled in the selected WYSIWYG editor or HTML editable control, and no additional actions are required. 

  • autoSearch is useful when your web page has multiple controls, as you can add one script which is enabled in the areas in focus automatically compared with creating an init() method for each control. From a performance point of view, autoSearch also has a better performance as the grammar and spelling and style are checked only in active area compared with checking in all controls like in init(). 
  • autoSearch for a dynamic page where some fields can be hidden or added at a certain point is enabled automatically and releases the memory, helping to avoid possible  possible memory leaks. 

Initialization using inline attributes is suitable and useful if you want to have a single script with basic options option definitions. 

Note

In case of initialization using data attributes, a number of API parameters with array or number type are not supported. Thus, you cannot modify such parameters as actionItems, suggestionsCount, and moreSuggestionsCount described further in this section. When initializing WProofreader using CONFIG, all options are supported.

Example A: Initializing WProofreader with autoSearch and configuration options in CONFIG 

Example 1.1. Initializing using CONFIG 

This is an example of the WProofreader initialization with the autoSearch functionality turned on. All the configuration options are defined using CONFIG.

Code Block
languagejs
themeEmacs
<script>
    window.WEBSPELLCHECKER_CONFIG = {
		autoSearch:true,
		lang: 'uk_UA',
		...

    	};
</script>

<script type="text/javascript" src="http(s)://your_host_name/wscservice/wscbundle/wscbundle.js"></script>

Example

B: Initializing WProofreader with autoSearch and defining configuration options

1.2. Initializing using inline data attributes

This is an example of the WProofreader initialization with the autoSearch functionality turned on. All the configuration options are defined using inline data attributes. In this case, the naming of the options are formed as follows: data-wsc-option_name=”value”. For details, refer to the list of available options in WProofreader API documentation.

Code Block
languagejs
themeEmacs
<script
	data-wsc-autosearch="true"
	data-wsc-lang="uk_UA"
	...
    src="https://your_host_name/wscservice/wscbundle/wscbundle.js">
</script>
Example 2: Initializing WProofreader using autoSearch and init() method
Note

When

you initialize WProofreader using this method, in init () method we declare the container where WProofreader should be started. The options are to be obtained from the settings.

initializing using data attributes, a number of API parameters with array or number type are not supported. Thus, you cannot modify such parameters as actionItems, suggestionsCount, and moreSuggestionsCount described further in this section. When initializing WProofreader using CONFIG, all options are supported.

2. Initializing using init() method

Info

The init() method is a reasonable choice when you clearly know in which control you want to initialize in WProofreader. More than that you are aware of your page controls, and additional controls do not appear dynamically. 

  • If your web application page has several textareas where you want to initialize WProofreader, as soon as the user loads the page, WProofreader is enabled automatically. It is not required to select the area to enable grammar and spelling check in it compared with autoSearch method. 
  • With dynamic web page load using init() method, administrator needs to be monitor when it’s necessary to start WProofreader.

Initializing WProofreader using init() method in a defined container (div element) on the page and specifying configuration options directly in the init() function:

Code Block
languagejs
themeEmacs
<script type="text/javascript" src="http(s)://your_host_name/wscservice/wscbundle/wscbundle.js"></script>
<div contenteditable id="container1">
This sampl text is aimed at demonstrating the work of WProofreader in a contenteditable div element.
</div>
  
<script>
    var instance1 = WEBSPELLCHECKER.init({
	container: document.getElementById("container1"),
	lang: 'uk_UA',
	...
	    });
</script>

1.2: Initialization using init() method

When you initialize WProofreader using this method, you declare the container where WProofreader should be started. The options are to be obtained from the settings.

The init() method is a reasonable choice when you clearly know in which control you want to initialize in WProofreader. More than that you are aware of your page controls, and additional controls do not appear dynamically. 

  • If your web application page has several textareas editable elements where you want to initialize WProofreader, as soon as the user loads the page, WProofreader is enabled automatically. It is not required to select the area to enable grammar and spelling check in it compared with autoSearch method. 
  • With dynamic web page load using init() method, administrator needs to be monitor when it’s necessary to start WProofreader.

Example 2.1

:

. Initializing

WProofreader

in HTML element using init() method

Initializing WProofreader This is an example of WProofreader initialization in HTML contenteditable element (div) using init() method in a defined container (div element) on the page and specifying . The configuration options are specified directly in the init() function:.

Code Block
languagejs
themeEmacs
<script type="text/javascript" src="http(s)://your_host_name/wscservice/wscbundle/wscbundle.js"></script>

<div contenteditable id="container1">
This	<p>This sampl text is aimed at demonstrating the work of WProofreader in a contenteditable div element.</p>
</div>
  
<script>
    var instance1 = WEBSPELLCHECKER.init({
		container: document.getElementById("container1"),
		lang: 'uk_UA',
		...
	    });
</script>

Example 2.2

:

. Initializating

WProofreader

in multiple HTML elements using init() method

 

Initializing WProofreader This is an example of WProofreader initialization in HTML contenteditable element (div) and HTML editable element (textarea) using init() method in a defined container(s) on the page and specifying configuration options in WEBSPELLCHECKER_CONFIG is shown in the sample below. You can see two containers, namely, div and textarea which use a single configuration script:. The configuration options for both controls are defined separately in a single CONFIG.

Code Block
languagejs
themeEmacs
<script>
    	window.WEBSPELLCHECKER_CONFIG = {
		lang: 'uk_UA',
		...
    };
</script>

<script type="text/javascript" src="http(s)://your_host_name/wscservice/wscbundle/wscbundle.js"></script>

<div contenteditable id="container1">
This	<p>This sampl text is aimed at demonstrating the work of WProofreader in a contenteditable div element.</p>
</div>

<script>
    var instance1 = WEBSPELLCHECKER.init({
		container: document.getElementById("container1"),
	    });
</script>

<textarea id="container2" type="text">This sampl text is aimed at demonstrating the work of WProofreader in a textarea textform element.
</textarea>
  
<script>
    var instance2 = WEBSPELLCHECKER.init({
		container: document.getElementById("container2"),
	    });
</script>

Example

3: Initializing WProofreader in HTML elements using data-wsc-autocreate

This is an example of WProofreader initialization in HTML editable elements and elements with  and contenteditable attribute set to true using data-wsc-autocreate="true". The configuration options are to be defined separately in WEBSPELLCHECKER_CONFIG. This approach is similar to initializing WProofreader using init() method.

Note

Even though we have a CONFIG where we defined Ukrainian as a priority the language (Ukraine), the language for textarea will be taken from the data-wsc-lang="es_ES" setting. It will have higher priority and, thus, will rewrite the CONFIG settings in the sample below.

Code Block
languagejs
themeEmacs
<script>
    window.WEBSPELLCHECKER_CONFIG = {
        lang:’uk_UA’,       
    };
</script>
<script type="text/javascript" src="http(s)://your_host_name/wscservice/wscbundle/wscbundle.js"></script>
<div contenteditable data-wsc-autocreate="true">
This sampl text is aimed at demonstrating the work of WProofreader in a plain textarea element.
</div>
<textarea type="text" data-wsc-autocreate="true" data-wsc-lang="es_ES">This sampl text is aimed at demonstrating the work of WProofreader in a textarea textform element.
</textarea>
Example 4: Initializing WProofreader

2.3. Initializing in WYSIWYG editors using init() method

There is an option to explicitly initialize WProofreader in such Rich rich text editors as Froala Editor 3, CKEditor 4, and CKEditor 5 using init() method. However, it is strongly recommended to use this method with autoSearch and autoDestroy options in WEBSPELLCHECKER_ CONFIG.

Turn Turned on/enabled autoDestroy parameter to monitor will bemonitoring the state of the WEBSPELLCHECKER instance and handle handling its destroy after removal (deleted or hidden) of an editable container from the page. At the same time enabled autoSearch parameter will restore an instance when it is needed.   It can be useful for example, when switching to the code editing mode in the editor, WEBSPELLCHECKER instance must be deleted and then restored after returning back to the editor. Thus, it is the autoSearch that restores it.

Initializing WProofreader using init() in Froala Editor

Code Block
languagejs
themeEmacs
<div id="froala-editor">
    <p>These are an examples of a sentences with two mispelled words and grammar problems. Just type text with misspelling to see how it works.</p>
</div>

<!-- Include the WEBSPELLCHECKER_CONFIG variable. -->
<script>
    window.WEBSPELLCHECKER_CONFIG = {
autoSearch: true,
autoDestroy: true,
...	
    };
</script>
<script type="text/javascript" src="http(s)://your_host_name/wscservice/wscbundle/wscbundle.js"></script>
<script>
    new FroalaEditor('#froala-editor', {
        events: {
            'initialized': function() {
                WEBSPELLCHECKER.init({
                    container: this.el
                });
            }
        }
    });
</script>

Initializing WProofreader using init() in CKEditor 4

Excerpt Include
_include_initializing_wproofreader_using_init_in_ckeditor4_55x
_include_initializing_wproofreader_using_init_in_ckeditor4_55x
nopaneltrue

Excerpt Include
_include_initializing_wproofreader_using_init_in_ckeditor5_55x
_include_initializing_wproofreader_using_init_in_ckeditor5_55x
nopaneltrue

Excerpt Include
_include_initializing_wproofreader_using_init_in_froala_editor_55x
_include_initializing_wproofreader_using_init_in_froala_editor_55x
nopaneltrue

3. Initializing using data-wsc-autocreate

This approach is similar to initializing WProofreader using init() method.

Example 3.1. Initializing in HTML elements using data-wsc-autocreate

This is an example of WProofreader initialization in HTML contenteditable element (div) and HTML editable element (textarea) using data-wsc-autocreate="true". The configuration options are to be defined separately in CONFIG. 

Note

Even though we have a CONFIG where we defined Ukrainian as a language for check, the language for textarea will be obtained  from the data-wsc-lang="es_ES" setting. It will have higher priority and, thus, will rewrite the CONFIG settings in the sample below.

Code Block
languagejs
themeEmacs
<div id="ckeditor4-editor">
    <p>These are an examples of a sentences with two mispelled words and grammar problems. Just type text with misspelling to see how it works.</p>
</div>
<!-- Include the WEBSPELLCHECKER_CONFIG variable. -->
<script>
    window<script>
    window.WEBSPELLCHECKER_CONFIG = {
autoSearch: true,
autoDestroy: true,
...	
            lang:’uk_UA’,       
    };
</script>

<script type="text/javascript" src="http(s)://your_host_name/wscservice/wscbundle/wscbundle.js"></script>

<script>
CKEDITOR.on('instanceReady', function(event) {
    WEBSPELLCHECKER.init({
        container: event.editor.window.getFrame().$
    });
});
</script>

Initializing WProofreader using init() in CKEditor 5

Code Block
languagejs
themeEmacs
<div id="ckeditor5-editor">
    <p>These are an examples of a sentences with two mispelled words and grammar problems. Just type text with misspelling to see how it works.<div contenteditable data-wsc-autocreate="true">
	<p>This sampl text is aimed at demonstrating the work of WProofreader in a plain textarea element.</p>
</div>
<!-- Include the WEBSPELLCHECKER_CONFIG variable. -->
<script>
    window.WEBSPELLCHECKER_CONFIG = {
autoSearch: true,
autoDestroy: true,
...	
    };
</script>
<script 
<textarea type="text/javascript" src="http(s)://your_host_name/wscservice/wscbundle/wscbundle.js"></script>

<script>
ClassicEditor
    .create(document.querySelector('#editor5'))
    .then(editor => {
        WEBSPELLCHECKER.init({
            container: editor.ui._editableElements.get('main')
        });
    });
</script>

data-wsc-autocreate="true" data-wsc-lang="es_ES">This sampl text is aimed at demonstrating the work of WProofreader in a textarea textform element.</textarea>