|
71 | 71 | </style>
|
72 | 72 | <template>
|
73 | 73 | <div class="resultField" hidden="[[ displayResultZone(hideresult, unloaded) ]]">
|
74 |
| - <template is="dom-repeat" id="textCandidateList" items="[[ candidates ]]" as="textCandidate" index-as="textIndex"> |
75 |
| - <span class$="text {{ _getCandidateFlags(candidate) }}" selected$="[[ _isSelected(textIndex, result.textSegmentResult.selectedCandidateIdx) ]]" on-tap="_select"> |
| 74 | + <template is="dom-repeat" id="textCandidateList" items="[[ candidates ]]" as="textCandidate" |
| 75 | + index-as="textIndex"> |
| 76 | + <span class$="text {{ _getCandidateFlags(candidate) }}" |
| 77 | + selected$="[[ _isSelected(textIndex, result.textSegmentResult.selectedCandidateIdx) ]]" |
| 78 | + on-tap="_select"> |
76 | 79 | <template is="dom-if" if="[[ !textCandidate.children ]]">
|
77 | 80 | {{ textCandidate.label }}
|
78 | 81 | </template>
|
79 | 82 | <template is="dom-if" if="[[ textCandidate.children ]]"><!--WARN: templates needs to be inline to avoid carriage return after span-->
|
80 |
| - <template is="dom-repeat" id="wordCandidateList" items="[[ _getChildCandidates(textCandidate, result, 'text') ]]" as="wordCandidate"> |
| 83 | + <template is="dom-repeat" id="wordCandidateList" |
| 84 | + items="[[ _getChildCandidates(textCandidate, result, 'text') ]]" as="wordCandidate"> |
81 | 85 | <span class$="word {{ _getCandidateFlags(wordCandidate) }}">
|
82 | 86 | <template is="dom-if" if="[[ !wordCandidate.children ]]">
|
83 | 87 | {{ wordCandidate.label }}
|
84 | 88 | </template>
|
85 | 89 | <template is="dom-if" if="[[ wordCandidate.children ]]">
|
86 |
| - <template is="dom-repeat" id="charCandidateList" items="[[ _getChildCandidates(wordCandidate, result, 'word') ]]" as="charCandidate"><span class$="char {{ _getCandidateFlags(charCandidate) }}">{{ charCandidate.label }}</span></template> |
| 90 | + <template is="dom-repeat" id="charCandidateList" |
| 91 | + items="[[ _getChildCandidates(wordCandidate, result, 'word') ]]" |
| 92 | + as="charCandidate"><span |
| 93 | + class$="char {{ _getCandidateFlags(charCandidate) }}">{{ charCandidate.label }}</span></template> |
87 | 94 | </template>
|
88 | 95 | </span>
|
89 | 96 | </template>
|
|
96 | 103 | applicationkey="{{ applicationkey }}"
|
97 | 104 | hidebuttons="{{ hidebuttons }}"
|
98 | 105 | hmackey="{{ hmackey }}"
|
99 |
| - options="[[ options ]]" |
| 106 | + configuration="[[ configuration ]]" |
100 | 107 | protocol="{{ protocol }}"
|
101 | 108 | host="{{ host }}"
|
102 | 109 | recognitiontriggerdelay="{{recognitiontriggerdelay}}"
|
103 | 110 | recognitionprocessdelay="{{recognitionprocessdelay}}"
|
104 | 111 | strokecolor="{{ strokecolor }}"
|
105 | 112 | strokewidth="{{ strokewidth }}"
|
106 | 113 | timeout="{{ timeout }}"
|
107 |
| - unloaded |
| 114 | + unloaded="{{ unloaded }}" |
108 | 115 | type="TEXT"
|
109 | 116 | disableclear="{{ disableclear }}"
|
110 | 117 | disablerecognize="{{ disablerecognize }}"
|
|
136 | 143 | *
|
137 | 144 | * @param myscriptTextWebElement
|
138 | 145 | */
|
139 |
| - function textBuildOptionsFromTextParam(myscriptTextWebElement) { |
| 146 | + function textBuildRecognitionParamsFromTextParam(myscriptTextWebElement) { |
140 | 147 | const textParameter = {};
|
141 | 148 | textParameter.language = myscriptTextWebElement.language;
|
142 | 149 | textParameter.textInputMode = myscriptTextWebElement.textinputmode;
|
|
158 | 165 | textParameter.textProperties.enableTagger = myscriptTextWebElement.enabletagger;
|
159 | 166 | textParameter.textProperties.spellingDistortion = myscriptTextWebElement.spellingdistortion;
|
160 | 167 |
|
161 |
| - return textParameter; |
| 168 | + const recognitionParams = {}; |
| 169 | + recognitionParams[myscriptTextWebElement.apiversion.toLowerCase()] = textParameter; |
| 170 | + return recognitionParams; |
162 | 171 | }
|
163 | 172 |
|
164 | 173 | /**
|
|
172 | 181 | myscriptTextWebElement.resultlabel = '';
|
173 | 182 | myscriptTextWebElement.candidates = [];
|
174 | 183 |
|
175 |
| - if (eventDetail.recognitionResult && eventDetail.recognitionResult['text/plain']) { |
176 |
| - myscriptTextWebElement.resultlabel = eventDetail.recognitionResult['text/plain']; |
| 184 | + if (eventDetail.recognitionResult && eventDetail.recognitionResult.TEXT) { |
| 185 | + myscriptTextWebElement.resultlabel = eventDetail.recognitionResult.TEXT; |
177 | 186 | }
|
178 | 187 | if (eventDetail.rawResult &&
|
179 | 188 | eventDetail.rawResult.result &&
|
|
195 | 204 | }
|
196 | 205 |
|
197 | 206 | function textAttachElementToDom(myscriptTextWebElement) {
|
198 |
| - if (myscriptTextWebElement.unloaded !== true && myscriptTextWebElement.connected === true) { |
| 207 | + myscriptTextWebElement.myscriptcommonelement = textQsWrapper(myscriptTextWebElement).querySelector('myscript-common-element'); |
| 208 | + myscriptTextWebElement.myscriptcommonelement.configuration = { |
| 209 | + recognitionParams: textBuildRecognitionParamsFromTextParam(myscriptTextWebElement) |
| 210 | + }; |
199 | 211 |
|
200 |
| - myscriptTextWebElement.myscriptcommonelement = textQsWrapper(myscriptTextWebElement).querySelector('myscript-common-element'); |
201 |
| - myscriptTextWebElement.myscriptcommonelement.options = { recognitionParams: { textParameter: textBuildOptionsFromTextParam(myscriptTextWebElement) } }; |
202 |
| - myscriptTextWebElement.myscriptcommonelement.removeAttribute('unloaded'); |
| 212 | + // Manage clear events |
| 213 | + function clearListener(event) { |
| 214 | + LOG('text ' + event.type + ' event intercepted', event); |
| 215 | + textManageResultEvent(myscriptTextWebElement, event.detail); |
| 216 | + myscriptTextWebElement.dispatchEvent(new CustomEvent('myscript-text-web-' + event.type, { detail: event.detail })); |
| 217 | + } |
203 | 218 |
|
204 |
| - myscriptTextWebElement.myscriptcommonelement.addEventListener('myscript-common-element-change', function (event) { |
205 |
| - LOG("text change intercepted", event); |
206 |
| - myscriptTextWebElement.dispatchEvent(new CustomEvent('myscript-text-web-change', { detail: event.detail })); |
207 |
| - }); |
208 |
| - myscriptTextWebElement.myscriptcommonelement.addEventListener('myscript-common-element-error', function (event) { |
209 |
| - LOG("text error intercepted", event); |
210 |
| - myscriptTextWebElement.dispatchEvent(new CustomEvent('myscript-text-web-error', { detail: event.detail })); |
211 |
| - }); |
212 |
| - myscriptTextWebElement.myscriptcommonelement.addEventListener('myscript-common-element-result', function (event) { |
213 |
| - LOG("text result intercepted", event); |
214 |
| - textManageResultEvent(myscriptTextWebElement, event.detail); |
215 |
| - myscriptTextWebElement.dispatchEvent(new CustomEvent('myscript-text-web-result', { detail: { result: myscriptTextWebElement.result, srcDetail: event.detail } })); |
216 |
| - }); |
217 |
| - myscriptTextWebElement.myscriptcommonelement.addEventListener('myscript-common-element-clear', function (event) { |
218 |
| - LOG("text clear intercepted", event); |
219 |
| - textManageClearEvent(myscriptTextWebElement, event.detail); |
220 |
| - myscriptTextWebElement.dispatchEvent(new CustomEvent('myscript-text-web-clear', { detail: event.detail })); |
221 |
| - }); |
| 219 | + // Manage result events |
| 220 | + function resultListener(event) { |
| 221 | + LOG('text ' + event.type + ' event intercepted', event); |
| 222 | + // Just forwarding event there. |
| 223 | + textManageResultEvent(myscriptTextWebElement, event.detail); |
| 224 | + var detail = event.detail; |
| 225 | + detail.result = myscriptTextWebElement.result; |
| 226 | + myscriptTextWebElement.dispatchEvent(new CustomEvent('myscript-text-web-' + event.type, { detail: detail })); |
| 227 | + } |
| 228 | + |
| 229 | + // Manage other events |
| 230 | + function defaultListener(event) { |
| 231 | + LOG('text ' + event.type + ' event intercepted', event); |
| 232 | + // Just forwarding event there. |
| 233 | + myscriptTextWebElement.dispatchEvent(new CustomEvent('myscript-text-web-' + event.type, { detail: event.detail })); |
222 | 234 | }
|
| 235 | + |
| 236 | + myscriptTextWebElement.currentListeners = {}; |
| 237 | + ['myscript-common-element-result'].forEach(function (type) { |
| 238 | + myscriptTextWebElement.currentListeners[type] = resultListener; |
| 239 | + }); |
| 240 | + ['myscript-common-element-clear'].forEach(function (type) { |
| 241 | + myscriptTextWebElement.currentListeners[type] = clearListener; |
| 242 | + }); |
| 243 | + ['myscript-common-element-undo', 'myscript-common-element-redo', 'myscript-common-element-typeset', 'myscript-common-element-recognize', 'myscript-common-element-change', 'myscript-common-element-error'] |
| 244 | + .forEach(function (type) { |
| 245 | + myscriptTextWebElement.currentListeners[type] = defaultListener; |
| 246 | + }); |
| 247 | + Object.keys(myscriptTextWebElement.currentListeners).forEach(function (type) { |
| 248 | + myscriptTextWebElement.myscriptcommonelement.addEventListener(type, myscriptTextWebElement.currentListeners[type]) |
| 249 | + }); |
| 250 | + } |
| 251 | + |
| 252 | + /** Remove listeners when common element is unloaded. */ |
| 253 | + function textDetachElementFromDom(myscriptTextWebElement) { |
| 254 | + Object.keys(myscriptTextWebElement.currentListeners).forEach(function (type) { |
| 255 | + myscriptTextWebElement.myscriptcommonelement.removeEventListener(type, myscriptTextWebElement.currentListeners[type]) |
| 256 | + }); |
223 | 257 | }
|
224 | 258 |
|
225 | 259 | Polymer({
|
|
346 | 380 | observer: 'unloadedChanged'
|
347 | 381 | },
|
348 | 382 | /**
|
349 |
| - * Set the additional options used to feed MyScript ink Paper (Structure of object as defined in MyScriptjs MyScriptJSOptions.js file) |
| 383 | + * Set the additional configuration used to feed MyScript ink Paper (Structure of object as defined in MyScriptjs MyScriptJSOptions.js file) |
350 | 384 | * Options values are taken into account when myscript-common-element is attach to the dom and when detached is set to false.
|
351 |
| - * Options values are not reflected to myscript-common-element attributes plus attributes values are always taken into account before options values (see demo/programmatic-init.html for a better understanding). |
| 385 | + * Options values are not reflected to myscript-common-element attributes plus attributes values are always taken into account before configuration values (see demo/programmatic-init.html for a better understanding). |
352 | 386 | */
|
353 |
| - options: { |
| 387 | + configuration: { |
354 | 388 | type: Object,
|
355 | 389 | notify: true
|
356 | 390 | },
|
|
524 | 558 | * This value must be between `1` and `20`.
|
525 | 559 | */
|
526 | 560 | textcandidatelistsize: {
|
527 |
| - type: Number, |
528 |
| - value: 1 |
| 561 | + type: Number, |
| 562 | + value: 1 |
529 | 563 | },
|
530 | 564 | /**
|
531 | 565 | * The size of the candidate lists that will be provided at the word level in the recognition result.
|
|
0 commit comments