// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0 // API host/endpoint var BaseUrl = window.location.protocol + "//" + window.location.host + url_prefix ; var htmlRegex = /<(.*)>.*?|<(.*)\/>/; document.addEventListener('DOMContentLoaded', function(){ var sidenavElems = document.querySelectorAll('.sidenav'); var sidenavInstances = M.Sidenav.init(sidenavElems); var app = new Vue({ el: '#app', delimiters: ['[[',']]'], data: { BaseUrl: BaseUrl, loading: true, error: "", langs: [], settings: {}, sourceLang: "", targetLang: "", loadingTranslation: false, inputText: "", inputTextareaHeight: 250, savedTanslatedText: "", translatedText: "", output: "", charactersLimit: -1, detectedLangText: "", copyTextLabel: {{ _("Copy text") }}, suggestions: false, isSuggesting: false, supportedFilesFormat : [], translationType: "text", inputFile: false, loadingFileTranslation: false, translatedFileUrl: false, filesTranslation: true, frontendTimeout: 500 }, mounted: function() { const self = this; const settingsRequest = new XMLHttpRequest(); settingsRequest.open("GET", BaseUrl + "/frontend/settings", true); const langsRequest = new XMLHttpRequest(); langsRequest.open("GET", BaseUrl + "/languages", true); settingsRequest.onload = function() { if (this.status >= 200 && this.status < 400) { self.settings = JSON.parse(this.response); self.sourceLang = self.settings.language.source.code; self.targetLang = self.settings.language.target.code; self.charactersLimit = self.settings.charLimit; self.suggestions = self.settings.suggestions; self.supportedFilesFormat = self.settings.supportedFilesFormat; self.filesTranslation = self.settings.filesTranslation; self.frontendTimeout = self.settings.frontendTimeout; if (langsRequest.response) { handleLangsResponse(self, langsRequest); } else { langsRequest.onload = function() { handleLangsResponse(self, this); } } } else { self.error = "Cannot load /frontend/settings"; self.loading = false; } }; settingsRequest.onerror = function() { self.error = "Error while calling /frontend/settings"; self.loading = false; }; langsRequest.onerror = function() { self.error = "Error while calling /languages"; self.loading = false; }; settingsRequest.send(); langsRequest.send(); }, updated: function(){ if (this.isSuggesting) return; M.FormSelect.init(this.$refs.sourceLangDropdown); M.FormSelect.init(this.$refs.targetLangDropdown); if (this.$refs.inputTextarea){ this.$refs.inputTextarea.focus() if (this.inputText === ""){ this.$refs.inputTextarea.style.height = this.inputTextareaHeight + "px"; this.$refs.translatedTextarea.style.height = this.inputTextareaHeight + "px"; } else{ this.$refs.inputTextarea.style.height = this.$refs.translatedTextarea.style.height = "1px"; this.$refs.inputTextarea.style.height = Math.max(this.inputTextareaHeight, this.$refs.inputTextarea.scrollHeight + 32) + "px"; this.$refs.translatedTextarea.style.height = Math.max(this.inputTextareaHeight, this.$refs.translatedTextarea.scrollHeight + 32) + "px"; } } if (this.charactersLimit !== -1 && this.inputText.length >= this.charactersLimit){ this.inputText = this.inputText.substring(0, this.charactersLimit); } // Update "selected" attribute (to overcome a vue.js limitation) // but properly display checkmarks on supported browsers. // Also change the