Skip to content

Commit 26a811b

Browse files
committed
1.4.2 updates
1 parent 4d0dce8 commit 26a811b

File tree

3 files changed

+48
-37
lines changed

3 files changed

+48
-37
lines changed

ChangeLog.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
==== SimpleModal ChangeLog ====
22

3+
== 1.4.2 ==
4+
* Date: October 06, 2011
5+
* Added a new 'fixed' option for fixed or absolute positioning
6+
* Changed overlay to use the document dimensions instead of window
7+
* Removed opera work-around for close() that was causing issues
8+
9+
310
== 1.4.1 ==
411
* Date: November 04, 2010
512
* Resolved the container height issue in IE6 & IE7 with jQuery 1.4.3

src/jquery.simplemodal.js

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* SimpleModal @VERSION - jQuery Plugin
33
* http://www.ericmmartin.com/projects/simplemodal/
4-
* Copyright (c) 2010 Eric Martin (http://twitter.com/ericmmartin)
4+
* Copyright (c) 2011 Eric Martin (http://twitter.com/ericmmartin)
55
* Dual licensed under the MIT and GPL licenses
66
* Date:
77
*/
@@ -47,11 +47,11 @@
4747
* overlayCss, containerCss, and dataCss options.
4848
*
4949
* SimpleModal has been tested in the following browsers:
50-
* - IE 6-9
51-
* - Firefox 2-4
52-
* - Opera 9, 10
53-
* - Safari 3-5
54-
* - Chrome 1-6
50+
* - IE 6+
51+
* - Firefox 2+
52+
* - Opera 9+
53+
* - Safari 3+
54+
* - Chrome 1+
5555
*
5656
* @name SimpleModal
5757
* @type jQuery
@@ -61,9 +61,12 @@
6161
* @version @VERSION
6262
*/
6363
;(function ($) {
64-
var ie6 = $.browser.msie && parseInt($.browser.version) === 6 && typeof window['XMLHttpRequest'] !== 'object',
64+
var d = [],
65+
doc = $(document),
66+
ie6 = $.browser.msie && parseInt($.browser.version) === 6 && typeof window['XMLHttpRequest'] !== 'object',
6567
ie7 = $.browser.msie && parseInt($.browser.version) === 7,
6668
ieQuirks = null,
69+
wndw = $(window),
6770
w = [];
6871

6972
/*
@@ -153,6 +156,8 @@
153156
* closeClass: (String:'simplemodal-close') The CSS class used to bind to the close event
154157
* escClose: (Boolean:true) Allow Esc keypress to close the dialog?
155158
* overlayClose: (Boolean:false) Allow click on overlay to close the dialog?
159+
* fixed: (Boolean:true) If true, the container will use a fixed position. If false, it will use a
160+
absolute position (the dialog will scroll with the page)
156161
* position: (Array:null) Position of container [top, left]. Can be number of pixels or percentage
157162
* persist: (Boolean:false) Persist the data across modal calls? Only used for existing
158163
DOM elements. If true, the data will be maintained across modal calls, if false,
@@ -186,6 +191,7 @@
186191
closeClass: 'simplemodal-close',
187192
escClose: true,
188193
overlayClose: false,
194+
fixed: true,
189195
position: null,
190196
persist: false,
191197
modal: true,
@@ -280,7 +286,7 @@
280286
var s = this;
281287

282288
// get the window properties
283-
w = s.getDimensions();
289+
s.getDimensions();
284290

285291
// add an iframe to prevent select options from bleeding through
286292
if (s.o.modal && ie6) {
@@ -305,8 +311,8 @@
305311
.css($.extend(s.o.overlayCss, {
306312
display: 'none',
307313
opacity: s.o.opacity / 100,
308-
height: s.o.modal ? w[0] : 0,
309-
width: s.o.modal ? w[1] : 0,
314+
height: s.o.modal ? d[0] : 0,
315+
width: s.o.modal ? d[1] : 0,
310316
position: 'fixed',
311317
left: 0,
312318
top: 0,
@@ -318,11 +324,11 @@
318324
s.d.container = $('<div></div>')
319325
.attr('id', s.o.containerId)
320326
.addClass('simplemodal-container')
321-
.css($.extend(s.o.containerCss, {
322-
display: 'none',
323-
position: 'fixed',
324-
zIndex: s.o.zIndex + 2
325-
}))
327+
.css($.extend(
328+
{position: s.o.fixed ? 'fixed' : 'absolute'},
329+
s.o.containerCss,
330+
{display: 'none', zIndex: s.o.zIndex + 2}
331+
))
326332
.append(s.o.close && s.o.closeHTML
327333
? $(s.o.closeHTML).addClass(s.o.closeClass)
328334
: '')
@@ -374,7 +380,7 @@
374380
}
375381

376382
// bind keydown events
377-
$(document).bind('keydown.simplemodal', function (e) {
383+
doc.bind('keydown.simplemodal', function (e) {
378384
if (s.o.modal && e.keyCode === 9) { // TAB
379385
s.watchTab(e);
380386
}
@@ -385,9 +391,9 @@
385391
});
386392

387393
// update window size
388-
$(window).bind('resize.simplemodal', function () {
394+
wndw.bind('resize.simplemodal orientationchange.simplemodal', function () {
389395
// redetermine the window width/height
390-
w = s.getDimensions();
396+
s.getDimensions();
391397

392398
// reposition the dialog
393399
s.o.autoResize ? s.setContainerDimensions() : s.o.autoPosition && s.setPosition();
@@ -398,7 +404,7 @@
398404
else if (s.o.modal) {
399405
// update the iframe & overlay
400406
s.d.iframe && s.d.iframe.css({height: w[0], width: w[1]});
401-
s.d.overlay.css({height: w[0], width: w[1]});
407+
s.d.overlay.css({height: d[0], width: d[1]});
402408
}
403409
});
404410
},
@@ -407,8 +413,8 @@
407413
*/
408414
unbindEvents: function () {
409415
$('.' + this.o.closeClass).unbind('click.simplemodal');
410-
$(document).unbind('keydown.simplemodal');
411-
$(window).unbind('resize.simplemodal');
416+
doc.unbind('keydown.simplemodal');
417+
wndw.unbind('.simplemodal');
412418
this.d.overlay.unbind('click.simplemodal');
413419
},
414420
/*
@@ -418,7 +424,7 @@
418424
var s = this, p = s.o.position;
419425

420426
// simulate fixed position - adapted from BlockUI
421-
$.each([s.d.iframe || null, !s.o.modal ? null : s.d.overlay, s.d.container], function (i, el) {
427+
$.each([s.d.iframe || null, !s.o.modal ? null : s.d.overlay, s.d.container.css('position') === 'fixed' ? s.d.container : null], function (i, el) {
422428
if (el) {
423429
var bch = 'document.body.clientHeight', bcw = 'document.body.clientWidth',
424430
bsh = 'document.body.scrollHeight', bsl = 'document.body.scrollLeft',
@@ -476,14 +482,14 @@
476482
}, 10);
477483
},
478484
getDimensions: function () {
479-
var el = $(window);
480-
481485
// fix a jQuery/Opera bug with determining the window height
482-
var h = $.browser.opera && $.browser.version > '9.5' && $.fn.jquery < '1.3'
486+
var s = this,
487+
h = $.browser.opera && $.browser.version > '9.5' && $.fn.jquery < '1.3'
483488
|| $.browser.opera && $.browser.version < '9.5' && $.fn.jquery > '1.2.6'
484-
? el[0].innerHeight : el.height();
489+
? wndw[0].innerHeight : wndw.height();
485490

486-
return [h, el.width()];
491+
d = [doc.height(), doc.width()];
492+
w = [h, wndw.width()];
487493
},
488494
getVal: function (v, d) {
489495
return v ? (typeof v === 'number' ? v
@@ -573,13 +579,14 @@
573579
setPosition: function () {
574580
var s = this, top, left,
575581
hc = (w[0]/2) - (s.d.container.outerHeight(true)/2),
576-
vc = (w[1]/2) - (s.d.container.outerWidth(true)/2);
582+
vc = (w[1]/2) - (s.d.container.outerWidth(true)/2),
583+
st = s.d.container.css('position') !== 'fixed' ? wndw.scrollTop() : 0;
577584

578585
if (s.o.position && Object.prototype.toString.call(s.o.position) === '[object Array]') {
579-
top = s.o.position[0] || hc;
586+
top = st + (s.o.position[0] || hc);
580587
left = s.o.position[1] || vc;
581588
} else {
582-
top = hc;
589+
top = st + hc;
583590
left = vc;
584591
}
585592
s.d.container.css({left: left, top: top});
@@ -685,13 +692,10 @@
685692
s.d.container.hide().remove();
686693
s.d.overlay.hide();
687694
s.d.iframe && s.d.iframe.hide().remove();
688-
setTimeout(function(){
689-
// opera work-around
690-
s.d.overlay.remove();
695+
s.d.overlay.remove();
691696

692-
// reset the dialog object
693-
s.d = {};
694-
}, 10);
697+
// reset the dialog object
698+
s.d = {};
695699
}
696700
}
697701
};

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.1
1+
1.4.2

0 commit comments

Comments
 (0)