From c51cdabce0abd9315ee01729caad77fd2f59c0fb Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 9 Oct 2021 15:00:54 -0500 Subject: [PATCH] Course intro: Inprove translate html - refs BT#19044 --- assets/js/document.js | 5 +- assets/js/translatehtml.js | 80 ++++++++++++------------- assets/js/vendor.js | 5 +- assets/vue/mixins/TranslateHtmlMixin.js | 62 ------------------- assets/vue/views/course/Home.vue | 7 +-- 5 files changed, 51 insertions(+), 108 deletions(-) delete mode 100644 assets/vue/mixins/TranslateHtmlMixin.js diff --git a/assets/js/document.js b/assets/js/document.js index 8405bf08db..b933e12677 100644 --- a/assets/js/document.js +++ b/assets/js/document.js @@ -1,3 +1,6 @@ /** This JS will be included when loading an HTML in the Document tool */ -require('./translatehtml.js'); +import translateHtml from './translatehtml.js'; +document.addEventListener('DOMContentLoaded', function () { + translateHtml(); +}); diff --git a/assets/js/translatehtml.js b/assets/js/translatehtml.js index 5364d1c887..38536fa5cc 100644 --- a/assets/js/translatehtml.js +++ b/assets/js/translatehtml.js @@ -1,52 +1,52 @@ /* For licensing terms, see /license.txt */ -document.addEventListener('DOMContentLoaded', function () { - if ( +export default function translateHtml() { + if ( window.user && window.user.locale && window.config && window.config['editor.translate_html'] && 'true' === window.config['editor.translate_html'] - ) { - var isoCode = window.user.locale; - const translateElement = document.querySelector('.mce-translatehtml'); - if (translateElement) { - document.querySelectorAll('.mce-translatehtml').forEach(function (el) { - el.style.display = 'none'; - }); - const selectedLang = document.querySelectorAll('[lang="' + isoCode + '"]'); - if (selectedLang.length > 0) { - selectedLang.forEach(function (userLang) { - userLang.classList.remove('hidden') - userLang.style.display = 'block'; + ) { + var isoCode = window.user.locale; + const translateElement = document.querySelector('.mce-translatehtml'); + if (translateElement) { + document.querySelectorAll('.mce-translatehtml').forEach(function (el) { + el.style.display = 'none'; }); + const selectedLang = document.querySelectorAll('[lang="' + isoCode + '"]'); + if (selectedLang.length > 0) { + selectedLang.forEach(function (userLang) { + userLang.classList.remove('hidden') + userLang.style.display = 'block'; + }); + } } - } - - // it checks content from old version - const langs = document.querySelectorAll('span[lang]:not(.mce-translatehtml)'); - if (langs.length > 0) { - // it hides all contents with lang - langs.forEach(function (el) { - el.style.display = 'none'; - }); - // To show only the content by user language. - if (isoCode == 'pl_PL') { - isoCode = 'pl'; - } - if (isoCode == 'fr_FR') { - isoCode = 'fr'; - } - if (isoCode == 'en_US') { - isoCode = 'en'; - } - const selectedLang = document.querySelectorAll('span[lang="' + isoCode + '"]'); - if (selectedLang.length > 0) { - selectedLang.forEach(function (userLang) { - userLang.classList.remove('hidden') - userLang.style.display = 'block'; + // it checks content from old version + const langs = document.querySelectorAll('span[lang]:not(.mce-translatehtml)'); + if (langs.length > 0) { + // it hides all contents with lang + langs.forEach(function (el) { + el.style.display = 'none'; }); + + // To show only the content by user language. + if (isoCode == 'pl_PL') { + isoCode = 'pl'; + } + if (isoCode == 'fr_FR') { + isoCode = 'fr'; + } + if (isoCode == 'en_US') { + isoCode = 'en'; + } + const selectedLang = document.querySelectorAll('span[lang="' + isoCode + '"]'); + if (selectedLang.length > 0) { + selectedLang.forEach(function (userLang) { + userLang.classList.remove('hidden') + userLang.style.display = 'block'; + }); + } } } - } -}); +} diff --git a/assets/js/vendor.js b/assets/js/vendor.js index 81a4ffcae7..ffeed6816f 100644 --- a/assets/js/vendor.js +++ b/assets/js/vendor.js @@ -21,4 +21,7 @@ global.textcomplete = textcomplete; require('chart.js'); require('./annotation.js'); -require('./translatehtml.js'); +import translateHtml from './translatehtml.js'; +document.addEventListener('DOMContentLoaded', function () { + translateHtml(); +}); diff --git a/assets/vue/mixins/TranslateHtmlMixin.js b/assets/vue/mixins/TranslateHtmlMixin.js deleted file mode 100644 index 07b6337957..0000000000 --- a/assets/vue/mixins/TranslateHtmlMixin.js +++ /dev/null @@ -1,62 +0,0 @@ - -export default { - methods: { - translate() { - // this script checks the tags with attribute lang to show them with the current user language - if (document.readyState == "loaded" || document.readyState == "interactive" || document.readyState == "complete") { - if ( - window.user && window.user.locale && - window.config && - window.config['editor.translate_html'] && - 'true' === window.config['editor.translate_html'] - ) { - - var isoCode = window.user.locale; - const translateElement = document.querySelector('.mce-translatehtml'); - if (translateElement) { - document.querySelectorAll('.mce-translatehtml').forEach(function (el) { - el.style.display = 'none'; - }); - const selectedLang = document.querySelectorAll('[lang="' + isoCode + '"]'); - if (selectedLang.length > 0) { - selectedLang.forEach(function (userLang) { - userLang.classList.remove('hidden') - userLang.style.display = 'block'; - }); - } - } - - // it checks content from old version - const langs = document.querySelectorAll('span[lang]:not(.mce-translatehtml)'); - if (langs.length > 0) { - // it hides all contents with lang - langs.forEach(function (el) { - el.style.display = 'none'; - }); - - // To show only the content by user language. - if (isoCode == 'pl_PL') { - isoCode = 'pl'; - } - if (isoCode == 'fr_FR') { - isoCode = 'fr'; - } - if (isoCode == 'en_US') { - isoCode = 'en'; - } - - const selectedLang = document.querySelectorAll('span[lang="' + isoCode + '"]'); - if (selectedLang.length > 0) { - selectedLang.forEach(function (userLang) { - userLang.classList.remove('hidden') - userLang.style.display = 'block'; - }); - } - } - - } - - } - } - } -}; diff --git a/assets/vue/views/course/Home.vue b/assets/vue/views/course/Home.vue index b705d1edf4..b8c8139bbc 100644 --- a/assets/vue/views/course/Home.vue +++ b/assets/vue/views/course/Home.vue @@ -176,12 +176,11 @@ import axios from "axios"; import {ENTRYPOINT} from '../../config/entrypoint'; import {computed, onMounted, reactive, toRefs} from 'vue' import {mapGetters, useStore} from "vuex"; -import TranslateHtmlMixin from '../../mixins/TranslateHtmlMixin'; +import translateHtml from '../../../js/translatehtml.js'; export default { name: 'Home', servicePrefix: 'Courses', - mixins: [TranslateHtmlMixin], components: { Loading, Toolbar, @@ -237,7 +236,7 @@ export default { if (!isEmpty(response)) { // first item state.intro = response[0]; - TranslateHtmlMixin.methods.translate(); + translateHtml(); } }); @@ -253,7 +252,7 @@ export default { if (!isEmpty(response)) { state.createInSession = false; state.intro = response[0]; - TranslateHtmlMixin.methods.translate(); + translateHtml(); } }); }