From 7d14e93adabc68255c1ccb054a29d25745c69823 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Thu, 13 Jan 2022 23:43:35 +0100 Subject: [PATCH] Port localebox to TypeScript --- app/javascript/legacy/locale-box.coffee | 4 ---- app/javascript/packs/application.ts | 4 +++- app/javascript/packs/legacy.coffee | 1 - app/javascript/retrospring/features/locales/index.ts | 12 ++++++++++++ 4 files changed, 15 insertions(+), 6 deletions(-) delete mode 100644 app/javascript/legacy/locale-box.coffee create mode 100644 app/javascript/retrospring/features/locales/index.ts diff --git a/app/javascript/legacy/locale-box.coffee b/app/javascript/legacy/locale-box.coffee deleted file mode 100644 index a510575a3..000000000 --- a/app/javascript/legacy/locale-box.coffee +++ /dev/null @@ -1,4 +0,0 @@ -$(document).on 'click', '#locale-switch', (event) -> - event.preventDefault() - $('#locales-panel').slideToggle() - $("html, body").animate({ scrollTop: $(document).height() }, 1000) diff --git a/app/javascript/packs/application.ts b/app/javascript/packs/application.ts index 12161a366..b6a16cf73 100644 --- a/app/javascript/packs/application.ts +++ b/app/javascript/packs/application.ts @@ -11,6 +11,7 @@ import initQuestionbox from 'retrospring/features/questionbox'; import initQuestion from 'retrospring/features/question'; import initModeration from 'retrospring/features/moderation'; import initMemes from 'retrospring/features/memes'; +import initLocales from 'retrospring/features/locales'; start(); document.addEventListener('DOMContentLoaded', initAnswerbox); @@ -22,4 +23,5 @@ document.addEventListener('DOMContentLoaded', initQuestionbox); document.addEventListener('DOMContentLoaded', initQuestion); document.addEventListener('DOMContentLoaded', initModeration); document.addEventListener('DOMContentLoaded', initMemes); -document.addEventListener('turbolinks:load', initAnnouncements) \ No newline at end of file +document.addEventListener('turbolinks:load', initAnnouncements); +document.addEventListener('turbolinks:load', initLocales); \ No newline at end of file diff --git a/app/javascript/packs/legacy.coffee b/app/javascript/packs/legacy.coffee index 99148724f..50fbf0d14 100644 --- a/app/javascript/packs/legacy.coffee +++ b/app/javascript/packs/legacy.coffee @@ -7,7 +7,6 @@ import 'bootstrap' import 'particleground/jquery.particleground.min' import '../legacy/pagination' -import '../legacy/locale-box' import '../legacy/util' _ready = -> diff --git a/app/javascript/retrospring/features/locales/index.ts b/app/javascript/retrospring/features/locales/index.ts new file mode 100644 index 000000000..89e1f6536 --- /dev/null +++ b/app/javascript/retrospring/features/locales/index.ts @@ -0,0 +1,12 @@ +import registerEvents from 'utilities/registerEvents'; + +function localeSwitchHandler(event: Event): void { + event.preventDefault(); + document.querySelector('#locales-panel').classList.toggle('d-block'); +} + +export default (): void => { + registerEvents([ + { type: 'click', target: document.querySelector('#locale-switch'), handler: localeSwitchHandler } + ]); +} \ No newline at end of file