|
42 | 42 | max-height: 95px;
|
43 | 43 | }
|
44 | 44 |
|
45 |
| - .candidate { |
| 45 | + .text { |
46 | 46 | color: #1580CD;
|
47 | 47 | background-color: #EDF0F2;
|
48 | 48 | font-size: 1.75rem;
|
|
51 | 51 | cursor: pointer;
|
52 | 52 | }
|
53 | 53 |
|
54 |
| - .candidate[selected] { |
| 54 | + .text[selected] { |
55 | 55 | color: #FFFFFF;
|
56 | 56 | background-color: #1580CD;
|
57 | 57 | }
|
|
71 | 71 | </style>
|
72 | 72 | <template>
|
73 | 73 | <div class="resultField" hidden="[[ displayResultZone(hideresult, unloaded) ]]">
|
74 |
| - <template is="dom-repeat" id="candidateList" items="[[ candidates ]]" as="candidate"> |
75 |
| - <span id="candidate" class="candidate" selected$="[[ _isSelected(index, result.textSegmentResult.selectedCandidateIdx) ]]" |
76 |
| - inner-h-t-m-l="[[ candidate.customlabel ]]" on-tap="_select"></span> |
| 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"> |
| 76 | + <template is="dom-if" if="[[ !textCandidate.children ]]"> |
| 77 | + {{ textCandidate.label }} |
| 78 | + </template> |
| 79 | + <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"> |
| 81 | + <span class$="word {{ _getCandidateFlags(wordCandidate) }}"> |
| 82 | + <template is="dom-if" if="[[ !wordCandidate.children ]]"> |
| 83 | + {{ wordCandidate.label }} |
| 84 | + </template> |
| 85 | + <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> |
| 87 | + </template> |
| 88 | + </span> |
| 89 | + </template> |
| 90 | + </template> |
| 91 | + </span> |
77 | 92 | </template>
|
78 | 93 | </div>
|
79 | 94 | <myscript-common-element
|
|
162 | 177 | eventDetail.rawResult.result.textSegmentResult.candidates) {
|
163 | 178 |
|
164 | 179 | myscriptTextWebElement.result = eventDetail.rawResult.result;
|
165 |
| - myscriptTextWebElement.resultlabel = eventDetail.rawResult.result.textSegmentResult.candidates[eventDetail.rawResult.result.textSegmentResult.selectedCandidateIdx].label; |
166 |
| - myscriptTextWebElement.candidates = eventDetail.rawResult.result.textSegmentResult.candidates; |
167 |
| - textUpdateCandidatesCustomLabel(myscriptTextWebElement); |
| 180 | + myscriptTextWebElement.resultlabel = myscriptTextWebElement.result.textSegmentResult.candidates[myscriptTextWebElement.result.textSegmentResult.selectedCandidateIdx].label; |
| 181 | + myscriptTextWebElement.candidates = myscriptTextWebElement.result.textSegmentResult.candidates; |
168 | 182 | }
|
169 | 183 | }
|
170 | 184 |
|
|
176 | 190 | }
|
177 | 191 | }
|
178 | 192 |
|
179 |
| - /** |
180 |
| - * Update custom label of candidates by theirs owns properties |
181 |
| - */ |
182 |
| - function textUpdateCandidatesCustomLabel(myscriptTextWebElement) { |
183 |
| - var result = myscriptTextWebElement.result; |
184 |
| - result.textSegmentResult.candidates.forEach(function (candidate) { |
185 |
| - var textClasses = ['text']; |
186 |
| - if (candidate.flags) { |
187 |
| - textClasses.push(candidate.flags.join(' ').toLowerCase()); |
188 |
| - } |
189 |
| - var textLabel = '<span class="' + textClasses.join(' ') + '">'; |
190 |
| - if (result.wordSegments && result.wordSegments.length > -1) { |
191 |
| - myscriptTextWebElement._getChildSegments(candidate, result, 'text').forEach(function (wordSegment) { |
192 |
| - var wordCandidate = wordSegment.candidates[wordSegment.selectedCandidateIdx]; |
193 |
| - if (wordCandidate) { |
194 |
| - var wordClasses = ['word']; |
195 |
| - if (candidate.flags) { |
196 |
| - wordClasses.push(wordCandidate.flags.join(' ').toLowerCase()); |
197 |
| - } |
198 |
| - var wordLabel = '<span class="' + wordClasses.join(' ') + '">'; |
199 |
| - if (result.wordSegments && result.wordSegments.length > -1) { |
200 |
| - myscriptTextWebElement._getChildSegments(wordCandidate, result, 'word').forEach(function (charSegment) { |
201 |
| - var charCandidate = charSegment.candidates[charSegment.selectedCandidateIdx]; |
202 |
| - if (charCandidate) { |
203 |
| - var charClasses = ['char']; |
204 |
| - if (charCandidate.flags) { |
205 |
| - charClasses.push(charCandidate.flags.join(' ').toLowerCase()); |
206 |
| - } |
207 |
| - wordLabel += '<span class="' + charClasses.join(' ') + '">' + charCandidate.label + '</span>'; |
208 |
| - |
209 |
| - } |
210 |
| - }); |
211 |
| - } else { |
212 |
| - wordLabel += wordCandidate.label; |
213 |
| - } |
214 |
| - wordLabel += '</span>'; |
215 |
| - textLabel += wordLabel; |
216 |
| - } |
217 |
| - }); |
218 |
| - } else { |
219 |
| - textLabel += candidate.label; |
220 |
| - } |
221 |
| - candidate.customlabel = textLabel + '</span>'; |
222 |
| - }); |
223 |
| - } |
224 |
| - |
225 | 193 | function textAttachElementToDom(myscriptTextWebElement) {
|
226 | 194 | if (myscriptTextWebElement.unloaded !== true && myscriptTextWebElement.connected === true) {
|
227 | 195 |
|
|
516 | 484 | */
|
517 | 485 | resultdetail: {
|
518 | 486 | type: String,
|
519 |
| - value: 'TEXT' |
| 487 | + value: 'WORD' |
520 | 488 | },
|
521 | 489 | /**
|
522 | 490 | * The content types to use for the recognition.
|
|
798 | 766 | });
|
799 | 767 | }
|
800 | 768 | return segments;
|
| 769 | + }, |
| 770 | + _getChildCandidates: function (candidate, result, type) { |
| 771 | + var candidates = []; |
| 772 | + this._getChildSegments(candidate, result, type) |
| 773 | + .forEach(function (segment) { |
| 774 | + candidates.push(segment.candidates[segment.selectedCandidateIdx]); |
| 775 | + }); |
| 776 | + return candidates; |
| 777 | + }, |
| 778 | + _getCandidateFlags: function (candidate) { |
| 779 | + if (candidate.flags) { |
| 780 | + return candidate.flags.join(' ').toLowerCase(); |
| 781 | + } |
| 782 | + return ''; |
801 | 783 | }
|
802 | 784 | })
|
803 | 785 | ;
|
|
0 commit comments