Grammalecte  Check-in [ce33035715]

Overview
Comment:[doc] Web API update: add JSON.parse(event.detail)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | doc
Files: files | file ages | folders
SHA3-256: ce33035715dfbe72e3d7681ddcd1003112cee14b83d61accb48766d9833db0af
User & Date: olr on 2020-03-21 14:41:00
Other Links: manifest | tags
Context
2020-03-21
15:13
[fx] Web API: warn the webpage when the API script is loaded check-in: 2bedf50a10 user: olr tags: trunk, fx
14:41
[doc] Web API update: add JSON.parse(event.detail) check-in: ce33035715 user: olr tags: trunk, doc
14:35
[fr] tests supplémentaires check-in: 7f0b5b060e user: olr tags: trunk, fr
Changes

Modified doc/API_web.md from [b8843fe5b2] to [d27d7a87a4].

85
86
87
88
89
90
91

92
93


94
95
96
97
98
99
100
101
102
103
104
105
106
107

108
109


110
111
112
113
114
115
116
85
86
87
88
89
90
91
92


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109


110
111
112
113
114
115
116
117
118







+
-
-
+
+














+
-
-
+
+








If you don’t want Grammalecte to modify directly the node content, add the property: `data-grammalecte_result_via_event="true"`.

With this property, Grammalecte will send an event to the node each times the text is modified within the panel.
The text can be retrieved with:

    node.addEventListener("GrammalecteResult", function (event) {
        const detail = (typeof(event.detail) === 'string') && JSON.parse(event.detail);
        if (event.detail.sType  &&  event.detail.sType == "text") {
            let sText = event.detail.sText;
        if (detail.sType  &&  detail.sType == "text") {
            let sText = detail.sText;
            ...
        }
    }


### Parse a node and get errors

    oGrammalecteAPI.parseNode("node_id")
    oGrammalecteAPI.parseNode(node)

The node can be a textarea, an editable node or an iframe. The node must have an identifier.
Results (for each paragraph) will be sent in a succession of events at the node.

    node.addEventListener("GrammalecteResult", function (event) {
        const detail = (typeof(event.detail) === 'string') && JSON.parse(event.detail);
        if (event.detail.sType  &&  event.detail.sType == "proofreading") {
            let oResult = event.detail.oResult; // null when the text parsing is finished
        if (detail.sType  &&  detail.sType == "proofreading") {
            let oResult = detail.oResult; // null when the text parsing is finished
            ...
        }
    }

For the last event, `oResult` will be `null`.


125
126
127
128
129
130
131

132
133
134



135
136
137
127
128
129
130
131
132
133
134



135
136
137
138
139
140







+
-
-
-
+
+
+



- destination: node_id (string)

- request_identifier: a custom identifier (string) [default = ""]

Suggestions will be sent within an event at the node identified by `destination`.

    node.addEventListener("GrammalecteResult", function (event) {
        const detail = (typeof(event.detail) === 'string') && JSON.parse(event.detail);
        if (event.detail.sType  &&  event.detail.sType == "spellsugg") {
            let oResult = event.detail.oResult;
            let oInfo = event.detail.oInfo; // object containing the destination and the request_identifier
        if (detail.sType  &&  detail.sType == "spellsugg") {
            let oResult = detail.oResult;
            let oInfo = detail.oInfo; // object containing the destination and the request_identifier
            ...
        }
    }