|
44 | 44 | * properly in all browsers, yet provides the developer with the flexibility
|
45 | 45 | * to easily control the look and feel. The styling for SimpleModal can be
|
46 | 46 | * done through external stylesheets, or through SimpleModal, using the
|
47 |
| - * overlayCss and/or containerCss options. |
| 47 | + * overlayCss, containerCss, and dataCss options. |
48 | 48 | *
|
49 | 49 | * SimpleModal has been tested in the following browsers:
|
50 | 50 | * - IE 6, 7, 8
|
|
55 | 55 | *
|
56 | 56 | * @name SimpleModal
|
57 | 57 | * @type jQuery
|
58 |
| - * @requires jQuery v1.2.2 |
| 58 | + * @requires jQuery v1.2.4 |
59 | 59 | * @cat Plugins/Windows and Overlays
|
60 | 60 | * @author Eric Martin (http://ericmmartin.com)
|
61 | 61 | * @version @VERSION
|
62 | 62 | */
|
63 | 63 | ;(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', |
65 | 65 | ieQuirks = null,
|
66 | 66 | w = [];
|
67 | 67 |
|
|
107 | 107 | * minWidth: (Number:null) The minimum width for the container
|
108 | 108 | * maxHeight: (Number:null) The maximum height for the container. If not specified, the window height is used.
|
109 | 109 | * 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? |
110 | 112 | * zIndex: (Number: 1000) Starting z-index value
|
111 | 113 | * close: (Boolean:true) If true, closeHTML, escClose and overClose will be used if set.
|
112 | 114 | If false, none of them will be used.
|
|
140 | 142 | minWidth: null,
|
141 | 143 | maxHeight: null,
|
142 | 144 | maxWidth: null,
|
| 145 | + autoResize: true, |
| 146 | + autoPosition: true, |
143 | 147 | zIndex: 1000,
|
144 | 148 | close: true,
|
145 | 149 | closeHTML: '<a class="modalCloseImg" title="Close"></a>',
|
|
151 | 155 | modal: true,
|
152 | 156 | onOpen: null,
|
153 | 157 | onShow: null,
|
154 |
| - onClose: null, |
155 |
| - bodyStretch: true |
| 158 | + onClose: null |
156 | 159 | };
|
157 | 160 |
|
158 | 161 | /*
|
159 | 162 | * Main modal object
|
| 163 | + * o = options |
160 | 164 | */
|
161 | 165 | $.modal.impl = {
|
162 |
| - /* |
163 |
| - * Modal dialog options |
164 |
| - */ |
165 |
| - o: null, |
166 | 166 | /*
|
167 | 167 | * Contains the modal dialog elements and is the object passed
|
168 | 168 | * back to the callback (onOpen, onShow, onClose) functions
|
|
354 | 354 | w = s.getDimensions();
|
355 | 355 |
|
356 | 356 | // reposition the dialog
|
357 |
| - // TODO setPosition or setContainerDimensions? |
358 |
| - s.setPosition(); |
| 357 | + s.o.autoResize ? s.setContainerDimensions() : s.o.autoPosition && s.setPosition(); |
359 | 358 |
|
360 | 359 | if (ie6 || ieQuirks) {
|
361 | 360 | s.fixIE();
|
|
381 | 380 | */
|
382 | 381 | fixIE: function () {
|
383 | 382 | 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%'}); |
387 | 383 |
|
388 | 384 | // simulate fixed position - adapted from BlockUI
|
389 | 385 | $.each([s.d.iframe || null, !s.o.modal ? null : s.d.overlay, s.d.container], function (i, el) {
|
|
450 | 446 |
|
451 | 447 | return [h, el.width()];
|
452 | 448 | },
|
453 |
| - getVal: function (v) { |
454 |
| - return typeof v === 'number' ? v |
| 449 | + getVal: function (v, d) { |
| 450 | + return v ? (typeof v === 'number' ? v |
455 | 451 | : 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; |
458 | 455 | },
|
459 | 456 | /*
|
460 |
| - * Update the container. Set new dimensions, if provided. |
| 457 | + * Update the container. Set new dimensions, if provided. |
461 | 458 | * Focus, if enabled. Re-bind events.
|
462 | 459 | */
|
463 | 460 | update: function (height, width) {
|
|
468 | 465 | return false;
|
469 | 466 | }
|
470 | 467 |
|
| 468 | + // reset orig values |
| 469 | + s.d.origHeight = s.getVal(height, 'h'); |
| 470 | + s.d.origWidth = s.getVal(width, 'w'); |
| 471 | + |
471 | 472 | // hide data to prevent screen flicker
|
472 | 473 | s.d.data.hide();
|
473 | 474 | height && s.d.container.css('height', height);
|
|
484 | 485 | var s = this;
|
485 | 486 |
|
486 | 487 | // 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'), |
489 | 490 | dh = s.d.data.outerHeight(true), dw = s.d.data.outerWidth(true);
|
490 | 491 |
|
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]; |
493 | 500 |
|
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'; |
496 | 503 | if (!ch) {
|
497 | 504 | if (!dh) {ch = moh;}
|
498 | 505 | else {
|
|
505 | 512 | ch = ch > mh ? mh : ch;
|
506 | 513 | }
|
507 | 514 |
|
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'; |
510 | 517 | if (!cw) {
|
511 | 518 | if (!dw) {cw = mow;}
|
512 | 519 | else {
|
|
521 | 528 |
|
522 | 529 | s.d.container.css({height: ch, width: cw});
|
523 | 530 | s.d.wrap.css({overflow: (dh > ch || dw > cw) ? 'auto' : 'visible'});
|
524 |
| - s.setPosition(); |
| 531 | + s.o.autoPosition && s.setPosition(); |
525 | 532 | },
|
526 | 533 | setPosition: function () {
|
527 | 534 | var s = this, top, left,
|
528 | 535 | hc = (w[0]/2) - (s.d.container.outerHeight(true)/2),
|
529 | 536 | vc = (w[1]/2) - (s.d.container.outerWidth(true)/2);
|
530 | 537 |
|
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]') { |
532 | 539 | top = s.o.position[0] || hc;
|
533 | 540 | left = s.o.position[1] || vc;
|
534 | 541 | } else {
|
|
644 | 651 |
|
645 | 652 | // reset the dialog object
|
646 | 653 | s.d = {};
|
647 |
| - }, 10); |
| 654 | + }, 10); |
648 | 655 | }
|
649 | 656 | }
|
650 | 657 | };
|
|
0 commit comments