Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When changing from one modal to another, remove and add is-active-class ... #44

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
When changing from one modal to another, remove and add is-active-cla…
…ss properly.
  • Loading branch information
4nduril committed Jun 17, 2013
commit 5c9217f6fb3c03a24e67eb047763dcfe81f01ecb
19 changes: 13 additions & 6 deletions modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
var modalElement = document.getElementById(hash);
var htmlClasses = document.documentElement.className;
var modalChild;
var oldModal;

// If the hash element exists
if (modalElement) {
Expand All @@ -79,12 +80,18 @@
modalChild = modalElement.children[0];

// When we deal with a modal and body-class `has-overlay` is not set
if (modalChild && modalChild.className.match(/modal-inner/) &&
!htmlClasses.match(/has-overlay/)) {

// Set an html class to prevent scrolling
document.documentElement.className += ' has-overlay';

if (modalChild && modalChild.className.match(/modal-inner/)) {
if (!htmlClasses.match(/has-overlay/)) {

// Set an html class to prevent scrolling
document.documentElement.className += ' has-overlay';
}

// Unmark previous active element
if (modal.activeElement) {
oldModal = modal.activeElement;
oldModal.className = oldModal.className.replace(' is-active', '');
}
// Mark modal as active
modalElement.className += ' is-active';
modal.activeElement = modalElement;
Expand Down