<!-- eslint-disable --> <template> <div> <span class="dict-label" tabindex="0">{{dict_label}}</span> <h2 class="article_header" tabindex="0">{{header_text}}</h2> <h2 class="secondary_header" v-if="secondary_header_text.length" tabindex="0">{{secondary_header_text}}</h2> <span class="header_group_list" v-if="group_list.length" tabindex="0">{{group_list}}</span> <details :title="inflect_tooltip" @toggle="toggle()" v-if="inflected" :class="$vuetify.breakpoint.name"> <summary :class="dictionary" onclick="this.blur()" tabindex="0">bøying</summary> <div class="inflection-canvas"> <inflectionTable :lemmaList="lemmas_with_word_class_and_lang" :mq="$vuetify.breakpoint.name" /> </div> </details> </div> </template> <script> /* eslint-disable */ import helpers from '../utils/helpers.js' import inflectionTable from 'inflection-table' export default { name: 'Header', props: { lemmas: Array, dictionary: String, article_id: Number }, computed: { header_text: function() { return this.lemmas.map(lemma => lemma.lemma).join(', ') }, secondary_header_text: function() { let a_forms = [] this.lemmas.forEach((lemma, i) => { if (lemma.paradigm_info[0] && lemma.paradigm_info[0].inflection_group == 'VERB') { let inf2 = lemma.paradigm_info[0].inflection[1] && lemma.paradigm_info[0].inflection[1].word_form if (inf2 && inf2.length) { a_forms.push(inf2) } } }); return a_forms.join(', ') }, inflect_tooltip: function() { return this.dictionary == 'bob' ? 'Klikk for å se bøyinger' : 'Klikk for å sjå bøyingar' }, dict_label: function() { return { 'bob': 'bokmålsordboka', 'nob': 'nynorskordboka' }[this.dictionary] || '' }, group_list: function() { return helpers.group_list(this.lemmas, this.dictionary) }, inflection_groups_by_lemma: function() { let components = Object.keys(this.$options.components) return this.lemmas.map( function(lemma_){ let inflection_groups = lemma_.paradigm_info.reduce((acc, std) => Object.assign(acc, {[std.inflection_group]: []}), {}) lemma_.paradigm_info.forEach(std => inflection_groups[std.inflection_group].push(std)) return { lemma: lemma_.lemma, inflection_groups: Object.fromEntries(Object.entries(inflection_groups).filter(e => components.includes(e[0].replace('/', '_')))) } } ) }, lemmas_with_word_class_and_lang: function() { return this.lemmas.map(lemma => Object.assign({language: this.dictionary == 'bob' ? 'nob' : 'nno', word_class: lemma.paradigm_info[0].inflection_group.split('_')[0]}, lemma)) }, inflected: function() { return this.lemmas.reduce((acc, lemma) => acc += lemma.paradigm_info.reduce((acc2, digm) => acc2 += digm.inflection.length, 0), 0) > 0 } }, components: { inflectionTable }, data: function() { return { inflect_reported: false } }, methods: { toggle: function() { if (! this.inflect_reported) { this.$plausible.trackEvent('open inflection', {props: {article: `/${this.dictionary}/${this.article_id}/${this.lemmas[0].lemma}`}}) } this.inflect_reported = true } } } </script> <style> summary { width: 30em; text-align: center; } article h2 { padding-top: 4px; padding-bottom: 0px; font-family: Inria Serif; font-size: 30px; } article h2.secondary_header { padding-top: 0px; padding-bottom: 4px; } .word-classification { text-decoration: underline dashed; } .dict-label { color: var(--v-primary-base) ; font-weight: bold; padding-left: 5px; position: absolute; top: 0px; left: 15px; font-variant-caps: all-small-caps; } details { margin-top: 10px; position: relative; } details > summary { position: relative; max-width: 130px; list-style: none; border: solid 2px var(--v-primary-base); border-radius: 30px; padding-top: 6px; padding-bottom: 6px; padding-right: 10px; color: var(--v-primary-base); background-color: #ffffff; cursor: pointer; } details[open] > summary { box-shadow: 5px 5px 0px var(--v-primary-base) } details > summary:after { content: "⌄"; font-weight: bold; position: absolute; right: 0; top: 1px; margin-right: 3px; } details > summary.bob:before { content: "Se "; } details > summary.nob:before { content: "Sjå "; } details[open] > summary.bob:before, details[open] > summary.nob:before { content: "Skjul "; } details[open] > summary:after { content: "⌃"; font-weight: bold; position: absolute; right: 0; top: 8px; margin-right: 3px; } @keyframes open { 0% { opacity: 0; } 100% { opacity: 1; } } details[open] summary ~ * { animation: open 0.3s ease-in-out; } .inflection-canvas { overflow-x: auto; /*position: absolute;*/ z-index: 5; background-color: rgba(255, 255, 255, 0); /*max-width: 100vw;*/ padding-top: 10px; } details > summary::-webkit-details-marker { display: none; } .infl-wrapper { background-color: #ffffff; border: solid 1px; color: var(--v-primary-base); border-color: var(--v-border-base); border-radius: 10px; padding: 10px; width: min-content; margin: 5px; font-size: 14px; } .context { color: var(--v-primary-lighten4) !important; } div.lemma { display: none; } table { border-collapse: collapse; margin-top: 5px; border-color: var(--v-primary-base); } th, td { border: solid 1px; padding: 5px; } th { background-color: var(--v-tertiary-darken1); color: var(--v-primary-darken1); } .infl-label { text-align: center; vertical-align: top; } article:not(.righ_hand_column) .inflection-canvas { left: -35px; } td.hilite { background-color: var(--v-tertiary-base) } </style>