1
0
Fork 0
frontend/bundle.js

85 lines
2.6 KiB
JavaScript
Raw Normal View History

2023-02-05 03:04:28 +00:00
$(function() {
2023-02-18 08:12:33 +00:00
$('#word').each(function(index, elem) {
2023-02-05 03:04:28 +00:00
$.getJSON(
2023-03-05 16:30:04 +00:00
'http://localhost:4567/words/' + $(elem).data('id'),
2023-02-05 03:04:28 +00:00
function(data) {
2023-02-18 11:47:55 +00:00
var primary_form = data['primary_form']
2023-02-18 08:12:33 +00:00
var part_of_speech = data['part_of_speech']
2023-02-19 05:09:55 +00:00
var commentary = data['commentary']
2023-02-18 08:12:33 +00:00
2023-02-18 14:24:07 +00:00
var translations = []
data['translations'].forEach(function(item) {
2023-02-18 14:31:04 +00:00
var commentary = ''
if (item['commentary']) {
commentary = ' (' + item['commentary'] + ')'
}
2023-02-18 14:24:07 +00:00
translations.push(
2023-02-18 14:31:04 +00:00
'<li>' + item['translation'] + commentary + '</li>'
2023-02-18 14:24:07 +00:00
)
})
2023-03-05 17:12:11 +00:00
var inflections = []
data['inflections'].forEach(function(item) {
2023-03-24 23:18:29 +00:00
var descr = item['descr']
var value = item['value'] || ''
2023-03-05 17:12:11 +00:00
inflections.push(
2023-03-24 23:18:29 +00:00
'<li><b>' + descr + '</b>: ' + value + '</li>'
2023-03-05 17:12:11 +00:00
)
})
2023-02-19 05:34:15 +00:00
2023-02-18 08:12:33 +00:00
var examples = []
2023-02-11 06:08:51 +00:00
data['examples'].forEach(function(item) {
2023-02-20 12:39:52 +00:00
var left = item['left']
var right = item['right']
var highlights = item['highlights']
var highlighted = []
if (highlights.length == 0) {
highlighted.push(left)
} else {
var last_pos = 0
highlights.forEach(function(highlight) {
var pos = highlight['pos']
var len = highlight['len']
if (pos > 0) { highlighted.push(left.substring(last_pos, pos)) }
last_pos = pos + len
highlighted.push(
2023-02-20 12:41:44 +00:00
'<span class="highlight">' +
left.substring(pos, pos + len) +
'</span>'
2023-02-20 12:39:52 +00:00
)
})
}
examples.push(
'<li>' + highlighted.join('') + ' &mdash; ' + right + '</li>'
)
2023-02-05 03:04:28 +00:00
})
2023-02-18 08:12:33 +00:00
2023-02-18 11:47:55 +00:00
$('#primary-form').text(primary_form)
2023-02-18 08:12:33 +00:00
$('#part-of-speech').text(part_of_speech)
2023-02-19 05:09:55 +00:00
if (commentary) {
$('#commentary-data').text(commentary)
$('#commentary').removeClass('invisible')
}
2023-02-18 14:24:07 +00:00
if (translations.length > 0) {
$('#translations-data').html('<ol>' + translations.join('') + '</ol>')
$('#translations').removeClass('invisible')
}
2023-03-05 17:12:11 +00:00
if (inflections.length > 0) {
$('#inflections-data').html('<ul>' + inflections.join('') + '</ul>')
2023-02-19 05:34:15 +00:00
$('#inflections').removeClass('invisible')
}
2023-02-18 08:12:33 +00:00
if (examples.length > 0) {
2023-02-18 08:14:19 +00:00
$('#examples-data').html('<ul>' + examples.join('') + '</ul>')
2023-02-18 08:12:33 +00:00
$('#examples').removeClass('invisible')
}
2023-02-05 03:04:28 +00:00
},
)
})
})