From 2d38cca2088217976b8a1209ce3b781831573c70 Mon Sep 17 00:00:00 2001 From: Zenoo Date: Thu, 1 Jul 2021 23:14:16 +0200 Subject: [PATCH] feat: Added modal:initialized callback + preload param + $.modal.get method --- README.md | 8 +++++++- examples/index.html | 49 +++++++++++++++++++++++++++++++++++++++++++++ jquery.modal.js | 37 +++++++++++++++++++++++++--------- jquery.modal.min.js | 6 +----- 4 files changed, 84 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 56c1a1f..20b6942 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,10 @@ _(Note that modals loaded with AJAX are removed from the DOM when closed)._ * Use `$.modal.isActive()` to check if a modal is currently being displayed. * Use `$.modal.getCurrent()` to retrieve a reference to the currently active modal instance, if any. +# Getting a modal instance + +* Use `$.modal.get($elm)` to a modal instance. + # Options These are the supported options and their default values: @@ -192,7 +196,8 @@ $.modal.defaults = { showSpinner: true, // Enable/disable the default spinner during AJAX requests. fadeDuration: null, // Number of milliseconds the fade transition takes (null means no transition) - fadeDelay: 1.0 // Point during the overlay's fade-in that the modal begins to fade in (.5 = 50%, 1.5 = 150%, etc.) + fadeDelay: 1.0, // Point during the overlay's fade-in that the modal begins to fade in (.5 = 50%, 1.5 = 150%, etc.) + preload: false // Preload the modal on init, without displaying it }; ``` @@ -201,6 +206,7 @@ $.modal.defaults = { The following events are triggered on the modal element at various points in the open/close cycle (see below for AJAX events). ```javascript +$.modal.INITIALIZED = 'modal:initialized'; // Fires when the modal content has been loaded. $.modal.BEFORE_BLOCK = 'modal:before-block'; // Fires just before the overlay (blocker) appears. $.modal.BLOCK = 'modal:block'; // Fires after the overlay (block) is visible. $.modal.BEFORE_OPEN = 'modal:before-open'; // Fires just before the modal opens. diff --git a/examples/index.html b/examples/index.html index 6c6fbe4..b7dab5c 100644 --- a/examples/index.html +++ b/examples/index.html @@ -534,6 +534,30 @@

# Example 8: Custom Class for Close

This modal has a fancy-shmancy close button.

+
+ +

# Example 9: Preload and display later

+
    +
  1. Preload the modal once
  2. +
  3. Open it with .open() when you need to.
  4. +
+
// Preload the modal
+  $('#preloaded-data').modal({
+    preload: true
+  });
+
+  // Open the modal when needed
+  $('#button').on('click', () => {
+    $.modal.get($('#preloaded-data')).open();
+  });
+
+ +Open Modal + + +