From 593976fe21cc55eec41c2c35cf9113be06302cb2 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Sun, 15 Apr 2018 00:33:35 -0400 Subject: [PATCH] Extract Backbone Lightbox view module --- js/views/attachment_view.js | 8 ++------ ts/backbone/index.ts | 6 +++++- ts/backbone/views/Lightbox.ts | 25 +++++++++++++++++++++++++ ts/backbone/views/index.ts | 6 ++++++ 4 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 ts/backbone/views/Lightbox.ts create mode 100644 ts/backbone/views/index.ts diff --git a/js/views/attachment_view.js b/js/views/attachment_view.js index b1544ff27..fc6a8bab8 100644 --- a/js/views/attachment_view.js +++ b/js/views/attachment_view.js @@ -117,10 +117,6 @@ return; } - const lightboxContainer = document.querySelector('.lightboxContainer'); - lightboxContainer.innerHTML = ''; - lightboxContainer.style.display = 'block'; - const props = { imageURL: this.objectUrl, }; @@ -128,10 +124,10 @@ Component: Signal.Components.Lightbox, props, onClose: () => { - lightboxContainer.style.display = 'none'; + Signal.Backbone.Views.Lightbox.hide(); }, }); - lightboxContainer.appendChild(this.lightboxView.el); + Signal.Backbone.Views.Lightbox.show(this.lightboxView.el); }, isVoiceMessage() { // eslint-disable-next-line no-bitwise diff --git a/ts/backbone/index.ts b/ts/backbone/index.ts index 431444a03..3c7864bb7 100644 --- a/ts/backbone/index.ts +++ b/ts/backbone/index.ts @@ -1,3 +1,7 @@ +/** + * @prettier + */ import * as Conversation from './Conversation'; +import * as Views from './views'; -export { Conversation }; +export { Conversation, Views }; diff --git a/ts/backbone/views/Lightbox.ts b/ts/backbone/views/Lightbox.ts new file mode 100644 index 000000000..cb9ca054e --- /dev/null +++ b/ts/backbone/views/Lightbox.ts @@ -0,0 +1,25 @@ +/** + * @prettier + */ +export const show = (element: HTMLElement): void => { + const container: HTMLDivElement | null = document.querySelector( + '.lightboxContainer' + ); + if (container === null) { + throw new TypeError("'.lightboxContainer' is required"); + } + container.innerHTML = ''; + container.style.display = 'block'; + container.appendChild(element); +}; + +export const hide = (): void => { + const container: HTMLDivElement | null = document.querySelector( + '.lightboxContainer' + ); + if (container === null) { + return; + } + container.innerHTML = ''; + container.style.display = 'none'; +}; diff --git a/ts/backbone/views/index.ts b/ts/backbone/views/index.ts new file mode 100644 index 000000000..397f19d78 --- /dev/null +++ b/ts/backbone/views/index.ts @@ -0,0 +1,6 @@ +/** + * @prettier + */ +import * as Lightbox from './Lightbox'; + +export { Lightbox };