Skip to content

Commit 1785e38

Browse files
committed
1.4 updates
1 parent 87af4ea commit 1785e38

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

src/jquery.simplemodal.js

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
* properly in all browsers, yet provides the developer with the flexibility
4545
* to easily control the look and feel. The styling for SimpleModal can be
4646
* done through external stylesheets, or through SimpleModal, using the
47-
* overlayCss and/or containerCss options.
47+
* overlayCss, containerCss, and dataCss options.
4848
*
4949
* SimpleModal has been tested in the following browsers:
5050
* - IE 6, 7, 8
@@ -55,13 +55,13 @@
5555
*
5656
* @name SimpleModal
5757
* @type jQuery
58-
* @requires jQuery v1.2.2
58+
* @requires jQuery v1.2.4
5959
* @cat Plugins/Windows and Overlays
6060
* @author Eric Martin (http://ericmmartin.com)
6161
* @version @VERSION
6262
*/
6363
;(function ($) {
64-
var ie6 = $.browser.msie && parseInt($.browser.version) === 6 && typeof window['XMLHttpRequest'] !== "object",
64+
var ie6 = $.browser.msie && parseInt($.browser.version) === 6 && typeof window['XMLHttpRequest'] !== 'object',
6565
ieQuirks = null,
6666
w = [];
6767

@@ -107,6 +107,8 @@
107107
* minWidth: (Number:null) The minimum width for the container
108108
* maxHeight: (Number:null) The maximum height for the container. If not specified, the window height is used.
109109
* maxWidth: (Number:null) The maximum width for the container. If not specified, the window width is used.
110+
* autoResize: (Boolean:true) Automatically resize the container, if necessary, on window resize?
111+
* autoPosition: (Boolean:true) Automatically position the container upon creation and on window resize?
110112
* zIndex: (Number: 1000) Starting z-index value
111113
* close: (Boolean:true) If true, closeHTML, escClose and overClose will be used if set.
112114
If false, none of them will be used.
@@ -140,6 +142,8 @@
140142
minWidth: null,
141143
maxHeight: null,
142144
maxWidth: null,
145+
autoResize: true,
146+
autoPosition: true,
143147
zIndex: 1000,
144148
close: true,
145149
closeHTML: '<a class="modalCloseImg" title="Close"></a>',
@@ -151,18 +155,14 @@
151155
modal: true,
152156
onOpen: null,
153157
onShow: null,
154-
onClose: null,
155-
bodyStretch: true
158+
onClose: null
156159
};
157160

158161
/*
159162
* Main modal object
163+
* o = options
160164
*/
161165
$.modal.impl = {
162-
/*
163-
* Modal dialog options
164-
*/
165-
o: null,
166166
/*
167167
* Contains the modal dialog elements and is the object passed
168168
* back to the callback (onOpen, onShow, onClose) functions
@@ -354,8 +354,7 @@
354354
w = s.getDimensions();
355355

356356
// reposition the dialog
357-
// TODO setPosition or setContainerDimensions?
358-
s.setPosition();
357+
s.o.autoResize ? s.setContainerDimensions() : s.o.autoPosition && s.setPosition();
359358

360359
if (ie6 || ieQuirks) {
361360
s.fixIE();
@@ -381,9 +380,6 @@
381380
*/
382381
fixIE: function () {
383382
var s = this, p = s.o.position;
384-
385-
// TODO prevent this from causing scrollbars
386-
ie6 && s.o.bodyStretch && $('body').css({height: '100%', width: '100%'});
387383

388384
// simulate fixed position - adapted from BlockUI
389385
$.each([s.d.iframe || null, !s.o.modal ? null : s.d.overlay, s.d.container], function (i, el) {
@@ -450,14 +446,15 @@
450446

451447
return [h, el.width()];
452448
},
453-
getVal: function (v) {
454-
return typeof v === 'number' ? v
449+
getVal: function (v, d) {
450+
return v ? (typeof v === 'number' ? v
455451
: v === 'auto' ? 0
456-
: v.indexOf('%') > 0 ? v
457-
: parseInt(v.replace(/px/, ''));
452+
: v.indexOf('%') > 0 ? ((parseInt(v.replace(/%/, '')) / 100) * (d === 'h' ? w[0] : w[1]))
453+
: parseInt(v.replace(/px/, '')))
454+
: null;
458455
},
459456
/*
460-
* Update the container. Set new dimensions, if provided.
457+
* Update the container. Set new dimensions, if provided.
461458
* Focus, if enabled. Re-bind events.
462459
*/
463460
update: function (height, width) {
@@ -468,6 +465,10 @@
468465
return false;
469466
}
470467

468+
// reset orig values
469+
s.d.origHeight = s.getVal(height, 'h');
470+
s.d.origWidth = s.getVal(width, 'w');
471+
471472
// hide data to prevent screen flicker
472473
s.d.data.hide();
473474
height && s.d.container.css('height', height);
@@ -484,15 +485,21 @@
484485
var s = this;
485486

486487
// get the dimensions for the container and data
487-
var ch = $.browser.opera ? s.d.container.height() : s.getVal(s.d.container.css('height')),
488-
cw = $.browser.opera ? s.d.container.width() : s.getVal(s.d.container.css('width')),
488+
var ch = s.d.origHeight ? s.d.origHeight : $.browser.opera ? s.d.container.height() : s.getVal(s.d.container.css('height'), 'h'),
489+
cw = s.d.origWidth ? s.d.origWidth : $.browser.opera ? s.d.container.width() : s.getVal(s.d.container.css('width'), 'w'),
489490
dh = s.d.data.outerHeight(true), dw = s.d.data.outerWidth(true);
490491

491-
var mh = s.o.maxHeight && s.getVal(s.o.maxHeight) < w[0] ? s.getVal(s.o.maxHeight) : w[0],
492-
mw = s.o.maxWidth && s.getVal(s.o.maxWidth) < w[1] ? s.getVal(s.o.maxWidth) : w[1];
492+
s.d.origHeight = s.d.origHeight || ch;
493+
s.d.origWidth = s.d.origWidth || cw;
494+
495+
// mxoh = max option height, mxow = max option width
496+
var mxoh = s.o.maxHeight ? s.getVal(s.o.maxHeight, 'h') : null,
497+
mxow = s.o.maxWidth ? s.getVal(s.o.maxWidth, 'w') : null,
498+
mh = mxoh && mxoh < w[0] ? mxoh : w[0],
499+
mw = mxow && mxow < w[1] ? mxow : w[1];
493500

494-
// height
495-
var moh = s.o.minHeight ? s.getVal(s.o.minHeight) : 'auto';
501+
// moh = min option height
502+
var moh = s.o.minHeight ? s.getVal(s.o.minHeight, 'h') : 'auto';
496503
if (!ch) {
497504
if (!dh) {ch = moh;}
498505
else {
@@ -505,8 +512,8 @@
505512
ch = ch > mh ? mh : ch;
506513
}
507514

508-
// width
509-
var mow = s.o.minWidth ? s.getVal(s.o.minWidth) : 'auto';
515+
// mow = min option width
516+
var mow = s.o.minWidth ? s.getVal(s.o.minWidth, 'w') : 'auto';
510517
if (!cw) {
511518
if (!dw) {cw = mow;}
512519
else {
@@ -521,14 +528,14 @@
521528

522529
s.d.container.css({height: ch, width: cw});
523530
s.d.wrap.css({overflow: (dh > ch || dw > cw) ? 'auto' : 'visible'});
524-
s.setPosition();
531+
s.o.autoPosition && s.setPosition();
525532
},
526533
setPosition: function () {
527534
var s = this, top, left,
528535
hc = (w[0]/2) - (s.d.container.outerHeight(true)/2),
529536
vc = (w[1]/2) - (s.d.container.outerWidth(true)/2);
530537

531-
if (s.o.position && Object.prototype.toString.call(s.o.position) === "[object Array]") {
538+
if (s.o.position && Object.prototype.toString.call(s.o.position) === '[object Array]') {
532539
top = s.o.position[0] || hc;
533540
left = s.o.position[1] || vc;
534541
} else {
@@ -644,7 +651,7 @@
644651

645652
// reset the dialog object
646653
s.d = {};
647-
}, 10);
654+
}, 10);
648655
}
649656
}
650657
};

0 commit comments

Comments
 (0)