2.3.6 • Published 2 years ago

quick-modal v2.3.6

Weekly downloads
24
License
-
Repository
-
Last release
2 years ago

quickModal

Create a custom modal quickly.

Doc

  • Installation

Simply import QuickModal into your HTML.

<link rel="stylesheet" type="text/css" href="https://unpkg.com/quick-modal@2.2.2/quickModal.min.css">
<script src="https://unpkg.com/quick-modal@2.2.2/quickModal.min.js"></script>	
  • How to use

Initialize your modal:

// Without jQuery
const modal = new QuickModal(options);

// Shorthand for a simple title + body
const modal = new QuickModal('Your title', 'Your message');

// With jQuery
$(document).quickModal(options);
  • Options
{
  document: window.document,        // Document in which the QuickModal should be opened into, window.document is used by default
  darkenBackground: true,           // Darken your page background when the modal is active
  isForm: true,                     // Your modal contains a form
  keepHidden: false,                // Hide the modal instead of destroying it on close
  closeText: 'OK',                  // Close button text
  classes: [],                      // Your modal classes (String[])
  attributes: {                     // Your modal additional attributes (attribute name : attribute value)
    'data-modal': 'true'
  },
  form: {                           // If isForm is set to true, this object will define your form properties
    action: 'path/to/your/form',    // Form ACTION attribute
    method: 'POST',                 // Form METHOD attribute
    id: 'formId',                   // Form ID
    classes: [],                    // Form classes (String[])
    submit: 'OK'                    // Form Submit text
  },
  header: '<div>Custom HTML</div>', // Modal header content
  body: [                           // Array containing all your modal lines
    {
      type: 'text',                 // Possible values ["text","form"] If set to 'text', creates a simple HTML node
      text: 'I am Text !',          // Your line text
      tag: 'h3',                    // Your line tag
      id: 'myId',                   // Your line id
      classes: [                    // Your line classes
        'class1',
        'class2'
      ],
      attributes: {                 // Your line additionnal attributes
        'data-modal': 'true'
      },
	  children: [                   // List of children elements
        {
          type: 'text',
          text: 'I am Text !',
          tag: 'h3',
          id: 'myId',
          classes: [
            'class1',
            'class2'
          ],
          attributes: {
            'data-modal': 'true'
          },
	      children: [ ... ]
        }
	  ]
    },
    {
      type: 'form',                 // Possible values ["text","form"] If set to 'form', create a new HTML Node with a label and your tag.
      label: 'I am Input !',        // Your input label
      inputType: 'text',            // If tag == 'input', set this to set your input TYPE attribute
      placeholder: 'Placeholder',   // If tag == 'input' or 'textarea', set this to set your input PLACEHOLDER attribute
      name: 'formText',             // Your input NAME attribute
      value: 'currentValue',        // Your input VALUE attribute
      tag: 'input',                 // Your input tag
      id: 'myInput',                // Your input ID
      classes: [                    // Your input classes
        'class1',
        'class2'
      ]
    },
    {
      type: 'form',
      label: 'I am Select !',
      name: 'formSelect',
      tag: 'select',
      id: 'mySelect',
      classes: [
        'class1',
        'class2'
      ],
      options: [                    // If tag == 'select', contains your select options
        {
          value: 'val', 
          text: 'Option 1', 
          selected: false,
          attributes: {             //Add attributes to your options
            'data-modal': 'true'
          }
        },
        {
          value: 'val2', 
          text: 'Option 2', 
          selected: true
        },
      ]
    }
  ],
  footer: [                          // Contains an array of links displayed at the bottom of your modal
    {
      text: 'I am Link !',           // Your link text
      href: 'path/to/link',          // Your link Href
      id: 'myLink',                  // Your link ID
      classes: [                     // Your link classes
        'class1',
        'class2'
      ]
    }
  ],
  afterOpen: function(modal) {},     // Callback triggered after the modal opens. Parameter is the modal NODE.
  beforeClose: function(modal) {},   // Callback triggered right before the modal closes. Parameter is the modal NODE.
  onSubmit: function(event, form) {} // Callback triggered when the form is submitted. Parameter are the event and the form NODE.
}
  • Methods
modal.open(); 		// Opens the modal (If previously closed)
modal.close(); 		// Closes the modal
modal.destroy(); 	// Destroys the modal
  • Example

See this JSFiddle for a working example

Authors

2.3.6

2 years ago

2.3.4

4 years ago

2.3.3

4 years ago

2.3.0

4 years ago

2.3.2

4 years ago

2.3.1

4 years ago

2.2.4

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.14

5 years ago

2.0.13

5 years ago

2.0.12

5 years ago

2.0.11

5 years ago

2.0.10

5 years ago

2.0.9

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.8.9

6 years ago

1.8.8

6 years ago

1.8.7

6 years ago

1.8.6

6 years ago

1.8.5

6 years ago

1.8.4

6 years ago

1.8.3

6 years ago

1.8.2

6 years ago

1.8.1

6 years ago

1.7.0

6 years ago

1.2.11

6 years ago

1.2.10

6 years ago

1.2.9

6 years ago

1.2.8

6 years ago

1.2.7

6 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.1.0

6 years ago