Page History
Excerpt | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1. Initialization OptionsThere are several several options letting you initialize WProofreader functionality in your web app, namely using:
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). After you have initialized WProofreader, you can customize the above-mentioned settings using WebSpellChecker WProofreader API.
Below you can find the samples showing how different WProofreader initialization approaches work depending on the integration and expected launch behavior. Example 1: Initializing WProofreader using autoSearchinfo
1. Initializing using autoSearchThe 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.
Initialization using inline attributes is suitable and useful if you want to have a single script with basic optionsoption definitions. When you initialize WProofreader using this method, you need to declare the container where WProofreader should be started in init () method. The options are to be obtained from the settings. Example 1.1. Initializing using CONFIGThis is an example of the WProofreader initialization with the autoSearch functionality turned on. All the configuration options are defined using CONFIG.
Example 1.2. Initializing using inline data attributesThis 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.
Example 2: Initializing WProofreader using autoSearch and init() methodWhen 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. Info |
2. Initializing using init() methodThe init() method is a reasonable choice when you clearly know in which control you want to initialize inWProofreader. More than that you are aware of your page controls, and additional controls do not appear dynamically.
Example 2.1. Initializing in HTML element using init() methodThis is an example of WProofreader initialization in HTML contenteditable element (div) using init() method in a defined container on the page and specifying. The configuration options are specified directly in the init() function :.
Example3: Initialization2.2. Initializating in multiple HTML elements using init() methodin a defined containerThis is an example of WProofreader initialization in HTML contenteditable element (div) and HTML editable element (textarea) using init() method. The configuration options for both controls are defined separately in a single CONFIG.
Initializing WProofreader using init() method in a defined container(s) on the page and specifying configuration options in CONFIG is shown in the sample below. You can see two containers, namely, div and textarea which use a single configuration script:
Example4: Initializing WProofreader by redefining options priority2.3. Initializing in WYSIWYG editors using init() methodThere is an option to explicitly initialize WProofreader in such 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 CONFIG. Turned on/enabled autoDestroy parameter will be monitoring the state of the WEBSPELLCHECKER instance and 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.
3. Initializing using data-wsc-autocreateInitializing WProofreader in HTML controls using data-wsc-autocreate="true" and specifying configuration options in CONFIG. This approach is similar to initializing WProofreader using init() method. Example 3.1. Initializing in HTML elements using data-wsc-autocreateThis 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.
Initializing WProofreader using init() method using autoSearch and autoDestroy in WYSIWYG editors such as Froala Editor 3, CKEditor 4 and CKEditor 5 and specifying the options in CONFIG.
Froala Editor code sample:
Example 5: Using init() method with autoSearch and autoDestroy in WYSIWYG editorsWhen initializing WProofreader using init() method with autoSearch and autoDestroy in WYSIWYG editors such as Froala Editor 3, CKEditor 4, and CKEditor 5 and specifying the options in CONFIG, the autoDestroy parameter turns on/off the auto-destroy functionality of a WebSpellChecker instance. By default, it is enabled for WProofreader initialized using autoSearch. It can be used to avoid monitoring the state of the instance and handling its destroying after removal of an editable container from the page. It can be useful for example, when we have created our instance, and later we don’t need to worry to remove it in certain cases. Deleting an instance from the page takes place when an edited element is deleted or hidden. When switching to the code editing mode in the editor we need to delete our instance and then to restore it after returning back to the editor. Thus, it is the autoSearch that restores it.
Froala Editor example:
|