-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
65 lines (57 loc) · 2.43 KB
/
index.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
<!doctype html>
<head>
<link href="https://static.contentful.com/app/main-62e0abc7.css" media="all" rel="stylesheet" type="text/css">
<link href="https://static.contentful.com/app/vendor-976872d7.css" media="all" rel="stylesheet" type="text/css">
<link href="https://contentful.github.io/ui-extensions-sdk/cf-extension.css" media="all" rel="stylesheet"
type="text/css">
<script type="text/javascript" src="https://unpkg.com/contentful-ui-extensions-sdk@3"></script>
<style>
ul li {
list-style-type: circle;
padding-bottom:10px;
font-size: 14px;
font-weight: bold;
}
.cf-form-field{
min-height: 200px;
}
</style>
</head>
<div class="cf-form-field">
<input id="translated" type="hidden" class="form-control">
<div class="cf-form-hint">
<ul class="template"></ul>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/3.0.2/es6-promise.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/speakingurl/7.0.0/speakingurl.min.js"></script>
<script>
var cfExt = window.contentfulExtension || window.contentfulWidget
cfExt.init(function (api) {
var slugField = api.entry.fields.slug
var translatedField = api.field
var input = document.getElementById('translated')
api.window.updateHeight()
for(var i in api.locales.available){
slugField.onValueChanged(api.locales.available[i],setLocales)
}
/**
* Set the input value to 'slug' and update the status by checking for
* duplicates.
*/
function setLocales() {
var locales = '';
var html = '';
for (var i in api.entry.fields.slug._fieldLocales) {
if (api.entry.fields.slug._fieldLocales[i]._value && api.entry.fields.slug._fieldLocales[i]._value != '' && api.entry.fields.slug._fieldLocales[i]._value.indexOf('untitled-') < 0) {
locales += api.entry.fields.slug._fieldLocales[i].locale+',';
html += "<li>"+api.entry.fields.slug._fieldLocales[i].locale+"</li>"
}
}
input.value = locales;
translatedField.setValue(locales);
document.querySelector('.template').innerHTML =html;
}
})
</script>