From 620b95fbe833b19b752c8fe21e8f8b9c3e9c05d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Alby?= Date: Mon, 9 Mar 2020 08:36:29 -0500 Subject: [PATCH] Merge pull request #2656 from overleaf/jpa-import-709 [misc] fileOperationI18nNames: drop blocking DOM access GitOrigin-RevId: e6aab686fc8d4fe3b5515033b88548278c7bf7c0 --- .../app/views/project/editor/history/fileTreeV2.pug | 7 +++---- .../js/ide/file-tree/util/fileOperationI18nNames.js | 11 +++++++---- services/web/test/frontend/import_tests.js | 13 ------------- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/services/web/app/views/project/editor/history/fileTreeV2.pug b/services/web/app/views/project/editor/history/fileTreeV2.pug index a176e3c140..b6f298d418 100644 --- a/services/web/app/views/project/editor/history/fileTreeV2.pug +++ b/services/web/app/views/project/editor/history/fileTreeV2.pug @@ -56,7 +56,6 @@ script(type="text/ng-template", id="historyFileEntityTpl") file-entity="childEntity" ) -script(type="template", id="file_action_edited_str") #{ translate('file_action_edited') } -script(type="template", id="file_action_renamed_str") #{ translate('file_action_renamed') } -script(type="template", id="file_action_created_str") #{ translate('file_action_created') } -script(type="template", id="file_action_deleted_str") #{ translate('file_action_deleted') } +- var fileActionI18n = ['edited', 'renamed', 'created', 'deleted'].reduce((acc, i) => {acc[i] = translate('file_action_' + i); return acc}, {}) +script(type="text/javascript"). + window.fileActionI18n = JSON.parse('!{StringHelper.stringifyJsonForScript(fileActionI18n)}') diff --git a/services/web/frontend/js/ide/file-tree/util/fileOperationI18nNames.js b/services/web/frontend/js/ide/file-tree/util/fileOperationI18nNames.js index f3d9be6f1c..3a0297d624 100644 --- a/services/web/frontend/js/ide/file-tree/util/fileOperationI18nNames.js +++ b/services/web/frontend/js/ide/file-tree/util/fileOperationI18nNames.js @@ -1,8 +1,11 @@ define([], function() { + if (window.fileActionI18n !== undefined) { + return window.fileActionI18n + } return { - edited: document.getElementById('file_action_edited_str').innerText, - renamed: document.getElementById('file_action_renamed_str').innerText, - created: document.getElementById('file_action_created_str').innerText, - deleted: document.getElementById('file_action_deleted_str').innerText + edited: 'edited', + renamed: 'renamed', + created: 'created', + deleted: 'deleted' } }) diff --git a/services/web/test/frontend/import_tests.js b/services/web/test/frontend/import_tests.js index f6d2ee28fc..428ef6f909 100644 --- a/services/web/test/frontend/import_tests.js +++ b/services/web/test/frontend/import_tests.js @@ -25,19 +25,6 @@ chai.Assertion.addMethod('equalPos', function(expectedPos) { // Mock ExposedSettings window.ExposedSettings = {} -// Mock the file operation I18n names that are stored in the DOM -function mockFileOperationI18nNames(id, text) { - const el = document.createElement('div') - el.id = id - el.innerText = text - el.setAttribute('hidden', true) - document.body.appendChild(el) -} -mockFileOperationI18nNames('file_action_edited_str', 'edited') -mockFileOperationI18nNames('file_action_renamed_str', 'renamed') -mockFileOperationI18nNames('file_action_created_str', 'created') -mockFileOperationI18nNames('file_action_deleted_str', 'deleted') - /* * Bundle all test files together into a single bundle, and run tests against * this single bundle.