From 303258ce10fc6de1d8892f6ba1ef1fc2604858bb Mon Sep 17 00:00:00 2001 From: Kumi Date: Tue, 30 Jul 2024 13:48:35 +0200 Subject: [PATCH] refactor: separate task creation logic from Kanblendar class Moved event listener for task button from Kanblendar init method to DOMContentLoaded handler. This change simplifies the Kanblendar class and improves modularity by placing event listening logic closer to the button initialization. Helps maintain separation of concerns and makes the code easier to manage and test. --- example.js | 4 +++- kanblendar.js | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example.js b/example.js index e1fb0ae..ebb42f9 100644 --- a/example.js +++ b/example.js @@ -1,3 +1,5 @@ document.addEventListener('DOMContentLoaded', () => { - new Kanblendar(); + const kanblendar = new Kanblendar(); + const createTaskBtn = document.getElementById('createTaskBtn'); + createTaskBtn.addEventListener('click', () => kanblendar.openModal()); }); \ No newline at end of file diff --git a/kanblendar.js b/kanblendar.js index fc13970..8297cc2 100644 --- a/kanblendar.js +++ b/kanblendar.js @@ -33,7 +33,6 @@ class Kanblendar { } init() { - this.createTaskBtn = document.getElementById('createTaskBtn'); this.kanbanSection = document.getElementById('kanblendar'); if (this.config.generateModal) { @@ -44,7 +43,6 @@ class Kanblendar { this.taskForm = document.getElementById('kanblendar-taskForm'); } - this.createTaskBtn.addEventListener('click', () => this.openModal()); this.closeModal.addEventListener('click', () => this.closeModalFunc()); window.addEventListener('click', (event) => { if (event.target === this.taskModal) {