-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #3, added scrollbar width compensation to avoid content moving …
…when modal overlay is displayed
- Loading branch information
Showing
2 changed files
with
44 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
var pluginNamespace = 'the-modal', | ||
// global defaults | ||
defaults = { | ||
lockClass: 'themodal-lock', | ||
overlayClass: 'themodal-overlay', | ||
|
||
closeOnEsc: true, | ||
|
@@ -22,16 +23,45 @@ | |
|
||
cloning: true | ||
}; | ||
|
||
function lockContainer() { | ||
$('html,body').addClass('lock'); | ||
} | ||
|
||
function unlockContainer() { | ||
$('html,body').removeClass('lock'); | ||
} | ||
|
||
function init(els, options) { | ||
var oMargin = {}; | ||
var ieBodyTopMargin = 0; | ||
|
||
function isIE() { | ||
return ((navigator.appName == 'Microsoft Internet Explorer') || | ||
(navigator.userAgent.match(/MSIE\s+\d+\.\d+/)) || | ||
(navigator.userAgent.match(/Trident\/\d+\.\d+/))); | ||
} | ||
|
||
function lockContainer(options) { | ||
var tags = $('html, body'); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
FlyingDR
Author
Contributor
|
||
tags.each(function () { | ||
var $this = $(this); | ||
oMargin[$this.prop('tagName')] = parseInt($this.css('margin-right')); | ||
}); | ||
var body = $('body'); | ||
var oWidth = body.outerWidth(true); | ||
body.addClass(options.lockClass); | ||
var sbWidth = body.outerWidth(true) - oWidth; | ||
if (isIE()) { | ||
ieBodyTopMargin = body.css('margin-top'); | ||
body.css('margin-top', 0); | ||
} | ||
tags.each(function () { | ||
$(this).css('margin-right', oMargin[$(this).prop('tagName')] + sbWidth); | ||
}); | ||
} | ||
|
||
function unlockContainer(options) { | ||
$('html, body').each(function () { | ||
var $this = $(this); | ||
$this.css('margin-right', oMargin[$this.prop('tagName')]).removeClass(options.lockClass); | ||
}); | ||
if (isIE()) { | ||
$('body').css('margin-top', ieBodyTopMargin); | ||
} | ||
} | ||
|
||
function init(els, options) { | ||
var modalOptions = options; | ||
|
||
if(els.length) { | ||
|
@@ -53,7 +83,7 @@ | |
$.modal().close(); | ||
} | ||
|
||
lockContainer(); | ||
lockContainer(localOptions); | ||
|
||
var overlay = $('<div/>').addClass(localOptions.overlayClass).prependTo('body'); | ||
overlay.data(pluginNamespace+'.options', options); | ||
|
@@ -110,7 +140,7 @@ | |
} | ||
|
||
overlay.remove(); | ||
unlockContainer(); | ||
unlockContainer(localOptions); | ||
|
||
if(localOptions.closeOnEsc) { | ||
$(document).unbind('keyup.'+pluginNamespace); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use of both tags causes margin doubling. Why not set right margin only on html or body?