Extends the default Bootstrap Modal class. Responsive, stackable, ajax and more.

Overview

Note: Since this plugin was created to solve a lot of the issues with BS2, it still uses the BS2 markup syntax. Currently I believe the default BS3 modal addresses some of the bigger issues and is not worth maintaining two versions of this plugin.

Bootstrap Modal v2.2.6

See live demo here.

Extends Bootstrap's native modals to provide additional functionality. Introduces a ModalManager class that operates behind the scenes to handle multiple modals by listening on their events.

A single ModalManager is created by default on body and can be accessed through the jQuery plugin interface.

    $('body').modalmanager('loading');

Bootstrap-Modal can be used as a replacement for Bootstrap's Modal class or as a patch to the library.

Bootstrap 3

If you're using BS3, I've provided a compatible css patch. Include bootstrap-modal-bs3patch.css before the main bootstrap-modal.css file to use this plugin with Bootstrap 3.

If you're using the loading spinner functionality you may also need to change the default template to be compatible in js:

    $.fn.modal.defaults.spinner = $.fn.modalmanager.defaults.spinner = 
        '<div class="loading-spinner" style="width: 200px; margin-left: -100px;">' +
            '<div class="progress progress-striped active">' +
                '<div class="progress-bar" style="width: 100%;"></div>' +
            '</div>' +
        '</div>';

Overview

  • Backwards compatible
  • Responsive
  • Stackable
  • Full width
  • Load content via AJAX
  • Disable background scrolling

Installation

  • Include css/bootstrap-modal.css after the main bootstrap css files.
  • Include js/bootstrap-modalmanager.js and js/bootstrap-modal.js after the main bootstrap js files.
	<link href="css/bootstrap.css" rel="stylesheet" />
	<link href="css/bootstrap-responsive.css" rel="stylesheet" />
 	<link href="css/bootstrap-modal.css" rel="stylesheet" />

 	<script src="js/bootstrap.js"></script>
 	<script src="js/bootstrap-modalmanager.js"></script>
 	<script src="js/bootstrap-modal.js"></script>

Options

In addition to the standard bootstrap options, you now have access to the following options

Modal

  • width Set the initial width of the modal.

  • height Set the initial height of the modal.

  • maxHeight Set the max-height of the modal-body.

  • loading Toggle the loading state.

  • spinner Provide a custom image or animation for the loading spinner.

  • backdropTemplate Provide a custom modal backdrop.

  • consumeTab Used to enable tabindexing for modals with data-tabindex. This is set to true by default.

  • focusOn The element or selector to set the focus to once the modal is shown.

  • replace If set to true, the modal will replace the topmost modal when opened.

  • attentionAnimation Set the animation used by the attention method. Any animation in animate.css is supported but only the shake animation is included by default.

  • modalOverflow Set this property to true for modals with highly dynamic content. This will force the modal to behave as if it is larger than the viewport.

  • manager Set the modal's manager. By default this is set to the GlobalModalManager and will most likely not need to be overridden.

ModalManager

  • loading Toggle the loading state.

  • backdropLimit Limit the amount of backdrops that will appear on the page at the same time.

  • spinner Provide a custom image or animation for the loading spinner.

  • backdropTemplate Provide a custom modalmanager backdrop. This backdrop is used when $element.modalmanager('loading') is called.

Getting a reference to the modal manager

If you did not created your own ModalManager, perhaps you'll need a reference to it. That can be easily accomplished using the following snippet:

	var modalManager = $("body").data("modalmanager");
	var openModals = modalManager.getOpenModals();
	modalManager.removeLoading();

After that, you'll be able to call any methods that modal manager has, such as:

  • removeLoading (remove the loading and backdrop window);
  • getOpenModals (to get the modals that are already open);
  • etc;

Disable Background Scrolling

If you want to prevent the background page from scrolling (see demo for example) you must wrap the page contents in a <div class="page-container">. For example:

	<body>
	   <div class="page-container">
		  <div class="navbar navbar-fixed-top">...</div>
		  <div class="container">...</div>
	   </div>
	</body>

The reason for doing this instead of just simply setting overflow: hidden when a modal is open is to avoid having the page shift as a result of the scrollbar appearing/disappearing. This also allows the document to be scrollable when there is a tall modal but only to the height of the modal, not the entire page.

Constrain Modal to Window Size

You can bind the height of the modal body to the window with something like this:

    $.fn.modal.defaults.maxHeight = function(){
        // subtract the height of the modal header and footer
        return $(window).height() - 165; 
    }

Note: This will be overwritten by the responsiveness and is only set when the modal is displayed, not when the window is resized.

Tab Index for Modal Forms

You can use data-tabindex instead of the default tabindex to specify the tabindex within a modal.

    <input type="text" data-tabindex="1" />
    <input type="text" data-tabindex="2" />

See the stackable example on the demo page for an example.

Bitdeli Badge

Comments
  • Body width increases when modal is opened

    Body width increases when modal is opened

    When the modal is open, it applies the "modal-open" class to the body tag. The "overflow:hidden" style makes the body width to increase. If you have some horizontal centered content it moves a bit to the right, and back to the left when you close the modal. I tried it in the demo page and the same happened. Is there any way to avoid this?

    Only tested in Chrome.

    opened by pomber 41
  • Chopped off top

    Chopped off top

    It is possible to get the modal into a state where the top is chopped off at the top and there is no way to scroll up to see the top of it.

    Basically, if you resize the window to be almost the exact height of what the modal would open up to and then open the modal, you can see in the image that part of the top gets chopped off and I can't scroll up anymore to show it.

    http://www.evernote.com/shard/s178/sh/140ba535-e5a1-44d5-9702-5753be82c4a8/ae1007220cd598b8efb7ea4edc4d70c0

    I hope this is enough information to let you debug it. Let me know.

    opened by lookfirst 17
  • Events clashing

    Events clashing

    For me, custom events like show, hide, etc. are clashing with bootstrap-modal's events by the same name. I've appended .datepicker to all of that project's custom events and .modal to all of this project's events*. This sorts the problems I was noticing.

    * - For some reason I can't change $.Event('show') (bootstrap-modal.js:57) to $.Event('show.modal'); it breaks .modal('show') (with no console errors) and I've no idea why.

    I would issue a pull-request with the custom event name change but I can't because of the above issue. Does it even make sense that changing that line would break .modal('show')? I would think that's just the name of the event to be triggered, not the param name too.

    opened by adam-lynch 14
  • backbone events in modals

    backbone events in modals

    Backbone events doesn't fire when attached to a data-dismiss="modal" button. I'm trying to submit a form via a backbone event and dismiss the modal at the same time, but it doesn't work with backbone-modal. With the default class it works.

    I fact, if i remove the data-dismiss, the backbone action does not fire, instead the default action fire (form submit via GET request, instead of the js call the backbone event had defined)

    opened by gdiazlo 14
  • Unresponsive site after bootbox modal was hidden, because overlay

    Unresponsive site after bootbox modal was hidden, because overlay

    I have discovered problem after this patch.

    When I call bootbox.*(), so some dialog is opened, but when I close this dialog ( created with bootbox ), so the same or similar bug occurs.

    I'm using bootbox version 3.

    bootstrap-modal-1

    opened by silverqx 12
  • Load a Modal with remote contents

    Load a Modal with remote contents

    Hi,

    I have this modal:

    <a data-toggle="modal" data-remote="/users/6" data-target="#student_report">
            User 1
    </a>
    
    <div class="modal hide" id="student_report">
    
    </div>
    

    I want to be able to load the entire contents of the modal using ajax. Right now it just replaces the modal-body element.

    How can I configure bootstrap-modal to put the contents in .modal?

    Thanks!

    opened by Nerian 12
  • Double focus issue on modal

    Double focus issue on modal

    I am experiencing unexpected behaviour when using the modal plugin.

    Modal content is added to the DOM (standard html form: input fields, labels, some date/timepickers), afterwards modal.show is called with no extra options.

    When clicking one of the input fields in the content, focus on that field is immediately lost. Even when passing a 'focusOn' option parameter, the focus is not set when the modal appears. Instead, when clicking again a random field, focus is lost, after which eventually the focus is set on the element passed in the option parameter.

    It appears that the .focus event is triggered again when clicking on any field.

    I've tracked the issue down to line 98 in the bootstrap-modal-manager.js.

    var complete = function () {
    that.setFocus();
    modal.$element.triggerHandler('shown');
    };
    

    Commenting out 'that.setFocus()', resolves the issue. A less source-code-intrusive fix is subscribing to the focus event on the modal and preventing it from being executed.

    $modal.on('focus', function(e){
         e.preventDefault();
    });
    

    Any ideas about the cause of this issue?

    opened by henne001 11
  • ruby on rails examples

    ruby on rails examples

    would be nice to have a few ruby on rails examples. specifically with ajax.

    im working on getting it implemented so i can post some results to wiki once done. or if anyone else has any examples already

    opened by ndreckshage 11
  • 2.0 breaks tabs in the modal after modal is reloaded

    2.0 breaks tabs in the modal after modal is reloaded

    so I got adventurous and tried the new 2.0 of the modals.. I had to upgrade my css due to some changes there, and then exchange the manager and modal js files to the 2.0 version I then changed all the GlobalModalManager.loading(div); to $('body').modalmanager('loading') and I went to testing it out.. I have one modal that uses ajax to load its content -

    $("body").append(div);
    $.get('/My/Goodies.php', {what : what, id : id}, function(ret){
        div.html(ret).modal().drags({handle: '.modal-header'})
    })
    

    and within the content thats loaded is a bunch of tabs the user can browse through to find a gift to send to another use.. The tabs work fine when the modal is first loaded, but if we close it and reopen the modal the tabs no longer function, but it does in the current version (before 2.0)

    thats the only bug I found with how I've been using the modals.. If you'd like to see an example I can try to throw one together.. other than that I love how they're acting now! the scrollbar being on top for long modals is awesome, and it also brings my navbar back on top (which is what I had before I upgraded to use your modal plugin)

    opened by Yohn 11
  • .on('hidden') event called only once

    .on('hidden') event called only once

    For some reason the original modal event hidden is only called once when the modal is closed. Can be reproduced on the demo page by entering this into console and opening the first modal repeatedly.

    $('#responsive').on('hidden', function (e) {console.log('close')});
    
    opened by david-nguyen 10
  • Unresponsive site after .modal('destroy') because overlay

    Unresponsive site after .modal('destroy') because overlay

    Hi,

    when I call .modal('hide') so everything works as excepted.

    But when I call .modal('destroy'), so modal is destroyed, but some overlay is added. Now I have tried destroy on my other modal dialog and the same behavior.

    DOM after destroy looks like this: bootstrap-modal

    opened by silverqx 10
  • Activating Open Collective

    Activating Open Collective

    Hi, I'm making updates for Open Collective. Either you or a supporter signed this repo up for Open Collective. This pull request adds backers and sponsors from your Open Collective https://opencollective.com/bootstrap-modal ❤️

    It adds two badges at the top to show the latest number of backers and sponsors. It also adds placeholders so that the avatar/logo of new backers/sponsors can automatically be shown without having to update your README.md. [more info]. See how it looks on this repo. You can also add a "Donate" button to your website and automatically show your backers and sponsors there with our widgets. Have a look here: https://opencollective.com/widgets

    P.S: As with any pull request, feel free to comment or suggest changes. The only thing "required" are the placeholders on the README because we believe it's important to acknowledge the people in your community that are contributing (financially or with code!).

    Thank you for your great contribution to the open source community. You are awesome! 🙌 And welcome to the open collective community! 😊

    Come chat with us in the #opensource channel on https://slack.opencollective.com - great place to ask questions and share best practices with other open source sustainers!

    opened by monkeywithacupcake 0
  • Stackable: Close modal when clicked outside

    Stackable: Close modal when clicked outside

    First Thank you for the Modal Helpsalot.

    Problem

    On Stackable How do I close the modal all together when clicked outside the modal box.

    Ex: say i have staked 2 modals one on top of another. I want to close the modal all together when clicked outside. Right now it get backs to the previous modal.

    Please Help

    opened by nasfathr 0
  • make collapsable?

    make collapsable?

    I know bootstrap components can be made collapsable with a bit of work (although im not sure this works well with modals), but it would be good if you could provide a short cut to be able to collapse/minimize modals.

    perhaps a CSS class that can be added to modal-header or an element in the modal, such that when the element is clicked, the modal collapses to just that element...

    opened by JamesRamm 0
Releases(2.2.6)
jBox is a jQuery plugin that makes it easy to create customizable tooltips, modal windows, image galleries and more.

jBox jBox is a jQuery plugin that makes it easy to create customizable tooltips, modal windows, image galleries and more. Demo: https://stephanwagner.

Stephan Wagner 1.4k Dec 15, 2022
Bootstrap-Lightbox - Simple & lightweight lightbox for Bootstrap 5

Bootstrap-Lightbox Simple & lightweight lightbox for Bootstrap 5 Basic Usage Adding data-modal="bs-lightbox" in your A href tag. <a data-modal="bs-lig

null 1 Oct 11, 2022
Simple to use modal / alert / dialog / popup. Created with vanilla JS. No javascript knowledge required! Works on every browser and device! IE9

EinsModal The last modal / alert / dialog you will ever need! Full Documentation: https://www.einscms.com/modal EinsModal is the best solution to inte

EinsCMS 30 Oct 20, 2022
A simple vanilla and lightweight modal which is easy to expand

A simple vanilla and lightweight modal which is easy to expand

null 1 Jul 3, 2022
Avgrund is jQuery plugin with new modal concept for popups

Avgrund Avgrund is a jQuery plugin for your modal boxes and popups. It uses new concept showing depth between popup and page. It works in all modern b

Dmitri Voronianski 1.8k Dec 14, 2022
A modal built with pure CSS, enhanced with JavaScript

CSS Modals Modals built out of pure CSS Please visit the website to read more about this project and refer to the FAQ in case of a question. What is i

Hans Christian Reinl 1.8k Dec 22, 2022
The simplest possible modal for jQuery

A simple & lightweight method of displaying modal windows with jQuery. For quick examples and demos, head to jquerymodal.com. Why another modal plugin

Kyle Fox 2.5k Dec 29, 2022
Toggle the state of a UI element to easily create components e.g. collapse, accordion, tabs, dropdown, dialog/modal.

Tiny UI Toggle Toggle the state of a UI element to easily create components e.g. collapse, accordion, tabs, dropdown, dialog/modal. Demo and documenta

Nigel O Toole 79 Dec 22, 2022
jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable.

fancyBox jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable. See the project page for doc

Jānis Skarnelis 7.2k Jan 2, 2023
Light and responsive lightbox script with focus on performance.

Magnific Popup Repository Fast, light and responsive lightbox plugin, for jQuery and Zepto.js. Documentation and getting started guide. Examples and p

Dmitry Semenov 11.3k Jan 2, 2023
A customizable, modular, responsive, lightbox gallery plugin.

lightGallery A customizable, modular, responsive, lightbox gallery plugin for jQuery. Demo JQuery lightGallery demo. Codepen demo Main features Fully

Sachin N 5.6k Jan 4, 2023
A Lightweight Responsive jQuery Tooltip Plugin

tipso A Lightweight Responsive jQuery Tooltip Plugin There is also a Wordpress version of this plugin. Get it here Getting started Include jQuery <scr

Bojan Petkovski 325 Dec 21, 2022
A modern dialog library which is highly configurable and easy to style. #hubspot-open-source

vex Demo Documentation vex is a modern dialog library which is highly configurable, easily stylable, and gets out of the way. You'll love vex because

HubSpot 6.9k Jan 5, 2023
:zap: Simple and easy to use lightbox script written in pure JavaScript

baguetteBox.js Simple and easy to use lightbox script written in pure JavaScript. Demo page Table of contents Features Installation Importing Usage Cu

Marek Grzybek 2.3k Jan 3, 2023
A modern dialog library which is highly configurable and easy to style. #hubspot-open-source

vex Demo Documentation vex is a modern dialog library which is highly configurable, easily stylable, and gets out of the way. You'll love vex because

HubSpot 6.9k Apr 1, 2021
Touch-friendly image lightbox for mobile and desktop

Touch-friendly image lightbox for mobile and desktop

Andre Rinas 938 Jan 5, 2023
Extends Bootstrap Tooltips and Popovers by adding custom classes. Available for Bootstrap 3 and Bootstrap 4.

Bootstrap Tooltip Custom Class Extends Bootstrap Tooltips and Popovers by adding custom classes. Available for Bootstrap 3 and Bootstrap 4. Define you

Andrei Victor Bulearca 14 Feb 10, 2022
⚡️The Fullstack React Framework — built on Next.js

The Fullstack React Framework "Zero-API" Data Layer — Built on Next.js — Inspired by Ruby on Rails Read the Documentation “Zero-API” data layer lets y

⚡️Blitz 12.5k Jan 4, 2023
Lightweight vanilla js modal component (just 2kb) , pure javascript Modal

Lightweight vanilla js modal component (just 2kb) pure javascript Modal , This is just 2kb Lightweight vanilla js modal component with zero dependenci

Salah Eddine Lalami 12 Dec 12, 2022
This JavaScript class generates a placeholder image or default profile image as SVG or PNG

This JavaScript class generates a placeholder image or default profile image as SVG or PNG. You can use the following parameters in the constructor:

Nils Köpke 4 Oct 12, 2022