@@ -265,3 +265,56 @@ function initializeSampleBooks() {
265265 // Display initial books
266266 displayBooks ( ) ;
267267}
268+
269+ /*=================
270+ ** Event Listeners
271+ **/
272+
273+ // DOM Content Loaded
274+ document . addEventListener ( "DOMContentLoaded" , ( ) => {
275+ // Get DOM elements
276+ const newBookBtn = document . getElementById ( "new-book-btn" ) ;
277+ const bookFormModal = document . getElementById ( "book-form-modal" ) ;
278+ const closeModalBtn = document . getElementById ( "close-modal" ) ;
279+ const cancelFormBtn = document . getElementById ( "cancel-form" ) ;
280+ const bookForm = document . getElementById ( "book-form" ) ;
281+ const booksContainer = document . getElementById ( "books-container" ) ;
282+
283+ /*=================
284+ ** Event Listeners
285+ **/
286+
287+ // Add New Book button clicked
288+ newBookBtn . addEventListener ( "click" , ( ) => {
289+ bookFormModal . showModal ( ) ;
290+ } ) ;
291+
292+ // Close button clicked
293+ closeModalBtn . addEventListener ( "click" , ( ) => {
294+ bookFormModal . close ( ) ;
295+ } ) ;
296+
297+ // Cancel button clicked
298+ cancelFormBtn . addEventListener ( "click" , ( ) => {
299+ bookFormModal . close ( ) ;
300+ } ) ;
301+
302+ // Click outside of modal
303+ bookFormModal . addEventListener ( "click" , ( event ) => {
304+ if ( event . target === bookFormModal ) {
305+ bookFormModal . close ( ) ;
306+ }
307+ } ) ;
308+
309+ // Handle form submission
310+ bookForm . addEventListener ( "submit" , handleFormSubmit ) ;
311+
312+ // Handle remove book
313+ booksContainer . addEventListener ( "click" , handleRemoveBook ) ;
314+
315+ // Handle toggle read
316+ booksContainer . addEventListener ( "click" , handleToggleReadStatus ) ;
317+
318+ // Add sample books
319+ initializeSampleBooks ( ) ;
320+ } ) ;
0 commit comments