Skip to content
This repository was archived by the owner on Jan 4, 2021. It is now read-only.

Commit 65e8428

Browse files
author
Francois-Xavier Gentilhomme
committed
[DOC] Update documentation
1 parent 450f87a commit 65e8428

File tree

4 files changed

+691
-653
lines changed

4 files changed

+691
-653
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<link rel="stylesheet" href="../myscript/dist/myscript.min.css"/>
2+
<script type="text/javascript" src="../myscript/dist/myscript.min.js"></script>

docs/components/myscript-text-web/demo/programmatic-init.html

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,43 @@
1212
<link rel="stylesheet" href="demo.css">
1313
</head>
1414
<body touch-action="none">
15-
<div id="waiting">myscript-text-web will be loaded in 3 seconds with customs params.</div>
1615
<!-- Please change applicationkey and hmackey below with those send by mail during your registration. You can re-access them by connecting to your dashboard at developer.myscript.com with your myscript account -->
1716
<myscript-text-web
1817
host="webdemoapi.myscript.com">
1918
</myscript-text-web>
2019
</body>
2120
<script>
22-
window.addEventListener("load", function (event) {
23-
window.setTimeout(function () {
24-
var waitingDiv = document.querySelector('#waiting');
25-
waitingDiv.parentNode.removeChild(waitingDiv);
26-
console.log("All resources finished loading! Starting to init myscript-text-web");
27-
var mycustomconfiguration = {
28-
// Please change applicationkey and hmackey below with those send by mail during your registration. You can re-access them by connecting to your dashboard at developer.myscript.com with your myscript account
29-
applicationKey: '515131ab-35fa-411c-bb4d-3917e00faf60',
30-
hmacKey: '54b2ca8a-6752-469d-87dd-553bb450e9ad',
31-
language: 'zh_CN'
32-
};
33-
var myscriptTextWebElement = document.querySelector('myscript-text-web');
34-
myscriptTextWebElement.unloaded = true;
35-
// Testing if attributes binding via DOM, setAttribute or direct object manipulation is working.
36-
myscriptTextWebElement.setAttribute('applicationkey', mycustomconfiguration.applicationKey);
37-
myscriptTextWebElement.hmackey = mycustomconfiguration.hmacKey;
38-
// Testing if options are taken into account
39-
myscriptTextWebElement.configuration = {
40-
timestampFloatPrecision: 2,
41-
recognitionParams: {
42-
v3: {
43-
textParameter: {
44-
language: 'fr_FR'
21+
window.addEventListener("load", function () {
22+
var configurationChanged = false;
23+
var myscriptTextWebElement = document.querySelector('myscript-text-web');
24+
myscriptTextWebElement.addEventListener("myscript-text-web-load", function () {
25+
if (!configurationChanged) {
26+
console.log("All resources finished loading! Starting to init myscript-text-web");
27+
var mycustomconfiguration = {
28+
// Please change applicationkey and hmackey below with those send by mail during your registration. You can re-access them by connecting to your dashboard at developer.myscript.com with your myscript account
29+
applicationKey: '515131ab-35fa-411c-bb4d-3917e00faf60',
30+
hmacKey: '54b2ca8a-6752-469d-87dd-553bb450e9ad',
31+
language: 'zh_CN'
32+
};
33+
// Testing if attributes binding via DOM, setAttribute or direct object manipulation is working.
34+
myscriptTextWebElement.setAttribute('applicationkey', mycustomconfiguration.applicationKey);
35+
myscriptTextWebElement.hmackey = mycustomconfiguration.hmacKey;
36+
// Testing if options are taken into account
37+
myscriptTextWebElement.configuration = {
38+
timestampFloatPrecision: 2,
39+
recognitionParams: {
40+
v3: {
41+
textParameter: {
42+
language: 'fr_FR'
43+
}
4544
}
4645
}
47-
}
48-
};
49-
myscriptTextWebElement.language = mycustomconfiguration.language;
50-
myscriptTextWebElement.unloaded = false;
51-
console.log("myscript-text-web should be displayed");
52-
}, 3000);
46+
};
47+
myscriptTextWebElement.language = mycustomconfiguration.language;
48+
myscriptTextWebElement.unloaded = true;
49+
}
50+
configurationChanged = true;
51+
});
5352
});
5453
</script>
5554
</html>
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<!--
2+
Copyright © MyScript.
3+
LICENSE: [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0)
4+
-->
5+
<link rel="import" href="../polymer/polymer.html">
6+
7+
<dom-module id="myscript-text-candidates-element">
8+
<style>
9+
:host {
10+
display: block;
11+
overflow: auto;
12+
text-align: center;
13+
font-size: xx-large;
14+
min-height: 95px;
15+
max-height: 95px;
16+
}
17+
18+
.text {
19+
color: #1580CD;
20+
background-color: #EDF0F2;
21+
font-size: 1.75rem;
22+
padding: .5rem .75rem;
23+
border-radius: 3px;
24+
cursor: pointer;
25+
}
26+
27+
.text[selected] {
28+
color: #FFFFFF;
29+
background-color: #1580CD;
30+
}
31+
32+
.candidate[selected] * {
33+
color: inherit;
34+
background-color: inherit;
35+
}
36+
37+
.char.predicted {
38+
color: #73818C;
39+
}
40+
41+
.char.completed {
42+
color: #1A9FFF;
43+
}
44+
</style>
45+
<template>
46+
<template is="dom-repeat" id="textCandidateList" items="[[ result.textSegmentResult.candidates ]]"
47+
as="textCandidate"
48+
index-as="textIndex">
49+
<span class$="text {{ _getCandidateFlags(candidate) }}"
50+
selected$="[[ _isSelected(textIndex, result.textSegmentResult.selectedCandidateIdx) ]]"
51+
on-tap="_select">
52+
<template is="dom-if" if="[[ !textCandidate.children ]]">
53+
{{ textCandidate.label }}
54+
</template>
55+
<template is="dom-if" if="[[ textCandidate.children ]]"><!--WARN: templates needs to be inline to avoid carriage return after span-->
56+
<template is="dom-repeat" id="wordCandidateList"
57+
items="[[ _getChildCandidates(textCandidate, result, 'text') ]]" as="wordCandidate">
58+
<span class$="word {{ _getCandidateFlags(wordCandidate) }}">
59+
<template is="dom-if" if="[[ !wordCandidate.children ]]">
60+
{{ wordCandidate.label }}
61+
</template>
62+
<template is="dom-if" if="[[ wordCandidate.children ]]">
63+
<template is="dom-repeat" id="charCandidateList"
64+
items="[[ _getChildCandidates(wordCandidate, result, 'word') ]]"
65+
as="charCandidate"><span
66+
class$="char {{ _getCandidateFlags(charCandidate) }}">{{ charCandidate.label }}</span></template>
67+
</template>
68+
</span>
69+
</template>
70+
</template>
71+
</span>
72+
</template>
73+
</template>
74+
</dom-module>
75+
76+
<script>
77+
Polymer({
78+
is: 'myscript-text-candidates-element',
79+
properties: {
80+
/**
81+
* Recognition result.
82+
* @attribute result
83+
* @type {Object<String, Object>} Attributes depends on recognition type already configured.
84+
*/
85+
result: {
86+
type: Object,
87+
notify: true
88+
}
89+
},
90+
/**
91+
* Select a new candidate
92+
* @param e
93+
*/
94+
_select: function (e) {
95+
var result = this.result;
96+
result.textSegmentResult.selectedCandidateIdx = this.$.textCandidateList.indexForElement(e.target);
97+
this.result = {};
98+
this.result = result;
99+
this.dispatchEvent(new CustomEvent('myscript-text-candidates-element-change'), { detail: this.result });
100+
},
101+
_isSelected: function (index, selectedIndex) {
102+
return index === selectedIndex;
103+
},
104+
_getChildSegments: function (candidate, result, type) {
105+
var segments = [];
106+
107+
function addSegment(child, segment) {
108+
if (segment.inkRanges === child.inkRanges) {
109+
segment.selectedCandidateIdx = child.selectedCandidateIdx;
110+
segments.push(segment);
111+
}
112+
}
113+
114+
if (candidate.children) {
115+
candidate.children.forEach(function (child, index) {
116+
if (type === 'text' && result.wordSegments && result.wordSegments.length > -1) {
117+
result.wordSegments.forEach(function (segment) {
118+
addSegment(child, segment);
119+
});
120+
} else if (type === 'word' && result.charSegments && result.charSegments.length > -1) {
121+
if (!child.inkRanges) {
122+
var seg = {
123+
candidates: [{
124+
label: candidate.label.charAt(index),
125+
flags: candidate.flags
126+
}],
127+
selectedCandidateIdx: 0
128+
};
129+
segments.push(seg);
130+
} else {
131+
result.charSegments.forEach(function (segment) {
132+
addSegment(child, segment);
133+
});
134+
}
135+
}
136+
});
137+
}
138+
return segments;
139+
},
140+
_getChildCandidates: function (candidate, result, type) {
141+
var candidates = [];
142+
this._getChildSegments(candidate, result, type)
143+
.forEach(function (segment) {
144+
candidates.push(segment.candidates[segment.selectedCandidateIdx]);
145+
});
146+
return candidates;
147+
},
148+
_getCandidateFlags: function (candidate) {
149+
if (candidate.flags) {
150+
return candidate.flags.join(' ').toLowerCase();
151+
}
152+
return '';
153+
}
154+
});
155+
</script>

0 commit comments

Comments
 (0)