This repository was archived by the owner on Jan 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathcustomize_style.html
279 lines (253 loc) · 11.8 KB
/
customize_style.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Those meta make the capture of handwriting inputs easier on mobile devices -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="HandheldFriendly" content="true"/>
<title>Customize style</title>
<link rel="stylesheet" href="../examples.css">
<style>
nav {
display: flex;
justify-content: baseline;
align-items: center;
flex-wrap: wrap;
padding: 12px;
}
nav span {
align-items: center;
display: flex;
flex-wrap: wrap;
}
.flex-item {
margin: 12px 12px 0 0;
}
#prompter-css {
height: 110px;
width: 70%;
margin-left: 36px;
padding: 24px;
position: absolute;
bottom: 60px;
z-index: 30;
border-radius: 6px;
background: rgba(240, 240, 240, 0.9);
}
.hidden {
display: none;
}
myscript-text-web {
height: calc(100% - 60px);
}
@media only screen and (min-device-width: 320px) and (max-device-width: 480px) {
myscript-text-web {
height: calc(100vh - 200px);
}
#prompter-css {
position: fixed;
bottom: 12px;
}
}
</style>
<script src="../../../webcomponentsjs/webcomponents-loader.js"></script>
<script src="../../../pepjs/dist/pep.min.js"></script>
<link rel="import" href="../../../paper-toggle-button/paper-toggle-button.html">
<link rel="import" href="../../../paper-swatch-picker/paper-swatch-picker.html">
<link rel="import" href="../../../paper-slider/paper-slider.html">
<link rel="import" href="../../../neon-animation/web-animations.html">
<link rel="import" href="../../../myscript-common-element/myscript-languages-element.html">
<link rel="import" href="../../myscript-text-web.html">
<custom-style>
<style>
myscript-text-web {
--myscript-text-web-background: url(https://farm6.staticflickr.com/5526/10976824044_aebaebdb12_z_d.jpg) no-repeat center center / cover;
--myscript-text-web-color: #ff7314;
--myscript-text-web-hover-color: #A44200;
--myscript-text-web-focus-color: #D05400;
--myscript-text-web-disabled-color: #FFD7BC;
--myscript-editor-line-pattern_-_background-image: repeating-linear-gradient(to bottom, #F5F6F7, #F5F6F7 1px, transparent 1px, transparent 72px);;
--myscript-text-web-line-pattern_-_background-size: none;
--myscript-text-web-loader-background: #ff7314;
--myscript-text-web-loader-color: #F5F6F7;
--myscript-text-web-error-background: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNzYgMjc2IiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWluWU1pbiBtZWV0Ij4KICAgIDxjaXJjbGUgY3g9IjEzOCIgY3k9IjEzOCIgcj0iMTI0IiBzdHJva2U9IiNCMzAwMDAiIHN0cm9rZS13aWR0aD0iMjgiIGZpbGw9Im5vbmUiLz4KICAgIDxsaW5lIHgxPSI0NSIgeTE9IjQ1IiB4Mj0iMjMxIiB5Mj0iMjMxIiBzdHJva2U9IiNCMzAwMDAiIHN0cm9rZS13aWR0aD0iMjIiLz4KPC9zdmc+Cg==);
--myscript-text-web-loader: {
background: url(http://myscript.com/wp-content/uploads/2014/01/text-logo.png) no-repeat center center / cover;
border: none;
border-radius: 0;
-webkit-animation: rotate-plan 2.4s infinite ease-in-out;
animation: rotate-plan 2.4s infinite ease-in-out;
};
--myscript-text-web-exports-color: #FF9917;
--myscript-text-web-exports-background-color: #EDF0F2;
--myscript-text-web-exports-selected-color: #FFFFFF;
--myscript-text-web-exports-selected-background-color: #FF9917;
--myscript-text-web-exports-predicted-color: #73818C;
--myscript-text-web-exports-completed-color: #ff7314;
}
</style>
</custom-style>
</head>
<body>
<nav>
<paper-toggle-button class="flex-item" id="penstyleclasses" checked>Apply pen style classes (greenThickPen)
</paper-toggle-button>
<span class="flex-item">
<paper-toggle-button id="penenabled">Enable pen color/width</paper-toggle-button>
<span id="pensettings" class="hidden">
<paper-swatch-picker id="pencolor"></paper-swatch-picker>
<paper-slider id="penwidth" snaps min="1" max="5" value="2"></paper-slider>
</span>
</span>
<span>
<label for="theme" class="flex-item">Theme:</label>
<select id="theme" class="flex-item">
<option value="normal-white">Normal white theme</option>
<option value="thin-green">Thin green theme</option>
<option value="bold-red">Bold red theme</option>
</select>
</span>
<div class="flex-item">
<label>Language:</label>
<myscript-languages-element id="language"
scheme="https"
host="webdemoapi.myscript.com"
applicationkey="515131ab-35fa-411c-bb4d-3917e00faf60"
hmackey="54b2ca8a-6752-469d-87dd-553bb450e9ad"
select>
</myscript-languages-element>
</div>
<div class="flex-item">
<label for="fonts">Font:</label>
<select id="fonts"></select>
</div>
</nav>
<!-- 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 -->
<myscript-text-web scheme="https"
host="webdemoapi.myscript.com"
applicationkey="515131ab-35fa-411c-bb4d-3917e00faf60"
hmackey="54b2ca8a-6752-469d-87dd-553bb450e9ad"
themewidth="2"
themecolor="#FFFFFF"
fontsize="12"
touch-action="none"
theme='{".green": {"color": "#00FF00", "-myscript-pen-width": "3"}}'
penstyleclasses="green">
</myscript-text-web>
<div id="prompter-css">
<div id="prompter-css-text">
Theme or pen style applied will be written here (where component is myscript-text-web).
</div>
</div>
<script>
function request(url) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = resolve;
xhr.onerror = reject;
xhr.send();
});
}
const themes = [{
name: 'normal-white',
color: '#FFFFFF',
width: 2,
fontsize: 12
}, {
name: 'thin-green',
color: '#2E7D32',
width: 1,
fontsize: 10
}, {
name: 'bold-red',
color: '#B71C1C',
width: 3,
fontsize: 14
}];
const component = document.querySelector('myscript-text-web');
const penSettings = document.querySelector('#pensettings');
const penColor = document.querySelector('#pencolor');
const penWidth = document.querySelector('#penwidth');
const penStyleClasses = document.querySelector('#penstyleclasses');
const langElement = document.querySelector('myscript-languages-element');
const fontsElement = document.getElementById('fonts');
const prompterText = document.getElementById('prompter-css-text');
function getFontsForLang(language) {
fontsElement.options.length = 0;
request('https://webdemoapi.myscript.com/api/v4.0/iink/font/google/language/' + language)
.then(function(e) {
res = JSON.parse(e.target.responseText).result;
Object.keys(res).forEach(function (index) {
fontsElement.options[fontsElement.options.length] = new Option(res[index], res[index]);
});
}, function(e) {
console.log('Error on get language', e);
});
}
function updatePrompter(values) {
prompterText.innerText = '';
values.forEach(function(value) {
prompterText.innerText += `${value[0]} = ${JSON.stringify(value[1])} \n`;
});
}
getFontsForLang(component.language);
langElement.addEventListener('change', (evt) => {
const lang = evt.detail.find(language => language.selected === true).value;
if (component.configuration && (lang !== component.language)) {
component.unloaded = true;
component.language = evt.detail.find(language => language.selected === true).value;
component.unloaded = false;
getFontsForLang(component.language);
prompterText.innerText = 'Theme reset'
}
});
fontsElement.addEventListener('change', function (e) {
component.fontfamily = e.target.value;
});
// Set penColor after to prevent taken into account too early
penColor.color = '#ff7314';
document.querySelector('#theme').addEventListener('change', (event) => {
const selectedTheme = themes.find(theme => theme.name === event.target.value);
if (selectedTheme) {
component.themecolor = selectedTheme.color;
component.themewidth = selectedTheme.width;
component.fontsize = selectedTheme.fontsize;
updatePrompter([['component.themecolor', selectedTheme.color], ['component.themewidth', selectedTheme.width], ['component.fontsize', selectedTheme.fontsize]]);
}
});
document.querySelector('#penenabled').addEventListener('change', (event) => {
if (event.target.checked) {
penSettings.classList.remove('hidden');
component.pencolor = penColor.color;
component.penwidth = penWidth.value;
updatePrompter([['component.pencolor', penColor.color], ['component.penwidth', penWidth.value]]);
} else {
penSettings.classList.add('hidden');
component.pencolor = undefined;
component.penwidth = undefined;
updatePrompter([['component.pencolor', undefined], ['component.penwidth', undefined]]);
}
});
penColor.addEventListener('color-changed', (event) => {
component.pencolor = event.target.color;
updatePrompter([['component.pencolor', event.target.color]])
});
penWidth.addEventListener('change', (event) => {
component.penwidth = event.target.value;
updatePrompter([['component.pencolor', event.target.value]])
});
penStyleClasses.addEventListener('change', (event) => {
if (event.target.checked) {
component.penstyleclasses = 'green';
updatePrompter([['component.penstyleclasses ', 'green']]);
} else {
component.penstyleclasses = '';
updatePrompter([['component.penstyleclasses', '']]);
}
});
</script>
</body>
</html>