Skip to content

Commit

Permalink
Remove and add is-active-class properly on modals
Browse files Browse the repository at this point in the history
  • Loading branch information
4nduril authored and drublic committed Jun 27, 2013
1 parent d0648d5 commit 5187b3b
Showing 1 changed file with 13 additions and 6 deletions.
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

0 comments on commit 5187b3b

Please sign in to comment.