|
1 | 1 | /*
|
2 | 2 | * SimpleModal @VERSION - jQuery Plugin
|
3 | 3 | * 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) |
5 | 5 | * Dual licensed under the MIT and GPL licenses
|
6 | 6 | * Date:
|
7 | 7 | */
|
|
47 | 47 | * overlayCss, containerCss, and dataCss options.
|
48 | 48 | *
|
49 | 49 | * 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+ |
55 | 55 | *
|
56 | 56 | * @name SimpleModal
|
57 | 57 | * @type jQuery
|
|
61 | 61 | * @version @VERSION
|
62 | 62 | */
|
63 | 63 | ;(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', |
65 | 67 | ie7 = $.browser.msie && parseInt($.browser.version) === 7,
|
66 | 68 | ieQuirks = null,
|
| 69 | + wndw = $(window), |
67 | 70 | w = [];
|
68 | 71 |
|
69 | 72 | /*
|
|
153 | 156 | * closeClass: (String:'simplemodal-close') The CSS class used to bind to the close event
|
154 | 157 | * escClose: (Boolean:true) Allow Esc keypress to close the dialog?
|
155 | 158 | * 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) |
156 | 161 | * position: (Array:null) Position of container [top, left]. Can be number of pixels or percentage
|
157 | 162 | * persist: (Boolean:false) Persist the data across modal calls? Only used for existing
|
158 | 163 | DOM elements. If true, the data will be maintained across modal calls, if false,
|
|
186 | 191 | closeClass: 'simplemodal-close',
|
187 | 192 | escClose: true,
|
188 | 193 | overlayClose: false,
|
| 194 | + fixed: true, |
189 | 195 | position: null,
|
190 | 196 | persist: false,
|
191 | 197 | modal: true,
|
|
280 | 286 | var s = this;
|
281 | 287 |
|
282 | 288 | // get the window properties
|
283 |
| - w = s.getDimensions(); |
| 289 | + s.getDimensions(); |
284 | 290 |
|
285 | 291 | // add an iframe to prevent select options from bleeding through
|
286 | 292 | if (s.o.modal && ie6) {
|
|
305 | 311 | .css($.extend(s.o.overlayCss, {
|
306 | 312 | display: 'none',
|
307 | 313 | 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, |
310 | 316 | position: 'fixed',
|
311 | 317 | left: 0,
|
312 | 318 | top: 0,
|
|
318 | 324 | s.d.container = $('<div></div>')
|
319 | 325 | .attr('id', s.o.containerId)
|
320 | 326 | .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 | + )) |
326 | 332 | .append(s.o.close && s.o.closeHTML
|
327 | 333 | ? $(s.o.closeHTML).addClass(s.o.closeClass)
|
328 | 334 | : '')
|
|
374 | 380 | }
|
375 | 381 |
|
376 | 382 | // bind keydown events
|
377 |
| - $(document).bind('keydown.simplemodal', function (e) { |
| 383 | + doc.bind('keydown.simplemodal', function (e) { |
378 | 384 | if (s.o.modal && e.keyCode === 9) { // TAB
|
379 | 385 | s.watchTab(e);
|
380 | 386 | }
|
|
385 | 391 | });
|
386 | 392 |
|
387 | 393 | // update window size
|
388 |
| - $(window).bind('resize.simplemodal', function () { |
| 394 | + wndw.bind('resize.simplemodal orientationchange.simplemodal', function () { |
389 | 395 | // redetermine the window width/height
|
390 |
| - w = s.getDimensions(); |
| 396 | + s.getDimensions(); |
391 | 397 |
|
392 | 398 | // reposition the dialog
|
393 | 399 | s.o.autoResize ? s.setContainerDimensions() : s.o.autoPosition && s.setPosition();
|
|
398 | 404 | else if (s.o.modal) {
|
399 | 405 | // update the iframe & overlay
|
400 | 406 | 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]}); |
402 | 408 | }
|
403 | 409 | });
|
404 | 410 | },
|
|
407 | 413 | */
|
408 | 414 | unbindEvents: function () {
|
409 | 415 | $('.' + 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'); |
412 | 418 | this.d.overlay.unbind('click.simplemodal');
|
413 | 419 | },
|
414 | 420 | /*
|
|
418 | 424 | var s = this, p = s.o.position;
|
419 | 425 |
|
420 | 426 | // 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) { |
422 | 428 | if (el) {
|
423 | 429 | var bch = 'document.body.clientHeight', bcw = 'document.body.clientWidth',
|
424 | 430 | bsh = 'document.body.scrollHeight', bsl = 'document.body.scrollLeft',
|
|
476 | 482 | }, 10);
|
477 | 483 | },
|
478 | 484 | getDimensions: function () {
|
479 |
| - var el = $(window); |
480 |
| - |
481 | 485 | // 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' |
483 | 488 | || $.browser.opera && $.browser.version < '9.5' && $.fn.jquery > '1.2.6'
|
484 |
| - ? el[0].innerHeight : el.height(); |
| 489 | + ? wndw[0].innerHeight : wndw.height(); |
485 | 490 |
|
486 |
| - return [h, el.width()]; |
| 491 | + d = [doc.height(), doc.width()]; |
| 492 | + w = [h, wndw.width()]; |
487 | 493 | },
|
488 | 494 | getVal: function (v, d) {
|
489 | 495 | return v ? (typeof v === 'number' ? v
|
|
573 | 579 | setPosition: function () {
|
574 | 580 | var s = this, top, left,
|
575 | 581 | 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; |
577 | 584 |
|
578 | 585 | 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); |
580 | 587 | left = s.o.position[1] || vc;
|
581 | 588 | } else {
|
582 |
| - top = hc; |
| 589 | + top = st + hc; |
583 | 590 | left = vc;
|
584 | 591 | }
|
585 | 592 | s.d.container.css({left: left, top: top});
|
|
685 | 692 | s.d.container.hide().remove();
|
686 | 693 | s.d.overlay.hide();
|
687 | 694 | 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(); |
691 | 696 |
|
692 |
| - // reset the dialog object |
693 |
| - s.d = {}; |
694 |
| - }, 10); |
| 697 | + // reset the dialog object |
| 698 | + s.d = {}; |
695 | 699 | }
|
696 | 700 | }
|
697 | 701 | };
|
|
0 commit comments