Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

1.3.6b updates. See changelog for details.

  • Loading branch information...
commit 87af4ea01db90cf57cb4f864d99e486806ccff1c 1 parent 61c4d78
@ericmmartin authored
View
9 ChangeLog.txt
@@ -1,5 +1,14 @@
==== SimpleModal ChangeLog ====
+== 1.3.6 ==
+ * Date: July 22, 2010
+ * Added bodyStretch option (to force overlay to fill window in IE6)
+ * Removed the autoResize and autoPosition options
+ * Changed meaning of the focus option
+ * Added update() function
+ * Changed setContainerDimensions fucntion code
+ * Fixed Opera screen painting issues
+
== 1.3.5 ==
* Date: April 19, 2010
* Switched back to using $.boxModal to support older versions of jQuery
View
35 License.txt
@@ -1,20 +1,21 @@
-Copyright (c) 2009 Eric Martin http://ericmmartin.com
+You may use SimpleModal under the terms of either the MIT License or
+the GNU General Public License (GPL) Version 2.
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
+The MIT License is recommended for most projects. It is simple and
+easy to understand and it places almost no restrictions on what you
+can do with SimpleModal.
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
+If the GPL suits your project better you are also free to use
+SimpleModal under that license.
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+You don�t have to do anything special to choose one license or the
+other and you don�t have to notify anyone which license you are using.
+
+You are free to use SimpleModal in commercial projects as long as the
+copyright header is left intact. If you would like to remove the
+SimpleModal copyright, please contact me (eric@ericmmartin.com) regarding
+re-licensing.
+
+Licenses
+MIT License (MIT-LICENSE.txt)
+GPL (GPL-LICENSE.txt)
View
4 MIT-LICENSE.txt
@@ -1,4 +1,4 @@
-Copyright (c) 2007 John Resig, http://jquery.com/
+Copyright (c) 2010 Eric Martin http://ericmmartin.com
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
2  demo/index.html
@@ -70,7 +70,7 @@
<!-- Start of Flickr Badge -->
<div id="flickr_badge_uber_wrapper">
<div id="flickr_badge_wrapper">
- <script type="text/javascript" src="http://www.flickr.com/badge_code_v2.gne?count=5&display=latest&size=s&layout=x&source=user_set&user=11678844%40N07&set=72157623117460038&context=in%2Fset-72157623117460038%2F"></script>
+ <script type="text/javascript" src="http://www.flickr.com/badge_code_v2.gne?show_name=1&count=5&display=random&size=t&layout=x&source=user_set&user=11678844%40N07&set=72157612224583954&context=in%2Fset-72157612224583954%2F"></script>
</div>
<div id="flickr_link">
<a href="http://www.flickr.com" id="flickr_www">www.<strong style="color:#3993ff">flick<span style="color:#ff1c92">r</span></strong>.com</a>
View
4 demo/js/gallery.js
@@ -25,9 +25,9 @@ jQuery(function ($) {
closeHTML: '',
overlayId: 'gallery-overlay',
containerId: 'gallery-container',
- containerCss: {left:0, top:'10%', width:'100%'},
+ containerCss: {left:0, width:'100%'},
opacity: 80,
- autoPosition: false,
+ position: ['10%', null],
onOpen: G.open,
onClose: G.close
});
View
6 demo/js/jquery.simplemodal.js
@@ -1,8 +1,8 @@
/*
- * SimpleModal 1.3.5 - jQuery Plugin
+ * SimpleModal 1.3.6b - jQuery Plugin
* http://www.ericmmartin.com/projects/simplemodal/
- * Copyright (c) 2010 Eric Martin (http://twitter.com/EricMMartin)
+ * Copyright (c) 2010 Eric Martin (http://twitter.com/ericmmartin)
* Dual licensed under the MIT and GPL licenses
* Revision: $Id: jquery.simplemodal.js 245 2010-03-25 20:41:15Z emartin24 $
*/
-;(function($){var ie6=$.browser.msie&&parseInt($.browser.version)==6&&typeof window['XMLHttpRequest']!="object",ieQuirks=null,w=[];$.modal=function(data,options){return $.modal.impl.init(data,options);};$.modal.close=function(){$.modal.impl.close();};$.fn.modal=function(options){return $.modal.impl.init(this,options);};$.modal.defaults={appendTo:'body',focus:true,opacity:50,overlayId:'simplemodal-overlay',overlayCss:{},containerId:'simplemodal-container',containerCss:{},dataId:'simplemodal-data',dataCss:{},minHeight:null,minWidth:null,maxHeight:null,maxWidth:null,autoResize:false,autoPosition:true,zIndex:1000,close:true,closeHTML:'<a class="modalCloseImg" title="Close"></a>',closeClass:'simplemodal-close',escClose:true,overlayClose:false,position:null,persist:false,modal:true,onOpen:null,onShow:null,onClose:null};$.modal.impl={o:null,d:{},init:function(data,options){var s=this;if(s.d.data){return false;}ieQuirks=$.browser.msie&&!$.boxModel;s.o=$.extend({},$.modal.defaults,options);s.zIndex=s.o.zIndex;s.occb=false;if(typeof data=='object'){data=data instanceof jQuery?data:$(data);s.d.placeholder=false;if(data.parent().parent().size()>0){data.before($('<span></span>').attr('id','simplemodal-placeholder').css({display:'none'}));s.d.placeholder=true;s.display=data.css('display');if(!s.o.persist){s.d.orig=data.clone(true);}}}else if(typeof data=='string'||typeof data=='number'){data=$('<div></div>').html(data);}else{alert('SimpleModal Error: Unsupported data type: '+typeof data);return s;}s.create(data);data=null;s.open();if($.isFunction(s.o.onShow)){s.o.onShow.apply(s,[s.d]);}return s;},create:function(data){var s=this;w=s.getDimensions();if(s.o.modal&&ie6){s.d.iframe=$('<iframe src="javascript:false;"></iframe>').css($.extend(s.o.iframeCss,{display:'none',opacity:0,position:'fixed',height:w[0],width:w[1],zIndex:s.o.zIndex,top:0,left:0})).appendTo(s.o.appendTo);}s.d.overlay=$('<div></div>').attr('id',s.o.overlayId).addClass('simplemodal-overlay').css($.extend(s.o.overlayCss,{display:'none',opacity:s.o.opacity/100,height:s.o.modal?w[0]:0,width:s.o.modal?w[1]:0,position:'fixed',left:0,top:0,zIndex:s.o.zIndex+1})).appendTo(s.o.appendTo);s.d.container=$('<div></div>').attr('id',s.o.containerId).addClass('simplemodal-container').css($.extend(s.o.containerCss,{display:'none',position:'fixed',zIndex:s.o.zIndex+2})).append(s.o.close&&s.o.closeHTML?$(s.o.closeHTML).addClass(s.o.closeClass):'').appendTo(s.o.appendTo);s.d.wrap=$('<div></div>').attr('tabIndex',-1).addClass('simplemodal-wrap').css({height:'100%',outline:0,width:'100%'}).appendTo(s.d.container);s.d.data=data.attr('id',data.attr('id')||s.o.dataId).addClass('simplemodal-data').css($.extend(s.o.dataCss,{display:'none'})).appendTo('body');data=null;s.setContainerDimensions();s.d.data.appendTo(s.d.wrap);if(ie6||ieQuirks){s.fixIE();}},bindEvents:function(){var s=this;$('.'+s.o.closeClass).bind('click.simplemodal',function(e){e.preventDefault();s.close();});if(s.o.modal&&s.o.close&&s.o.overlayClose){s.d.overlay.bind('click.simplemodal',function(e){e.preventDefault();s.close();});}$(document).bind('keydown.simplemodal',function(e){if(s.o.modal&&s.o.focus&&e.keyCode==9){s.watchTab(e);}else if((s.o.close&&s.o.escClose)&&e.keyCode==27){e.preventDefault();s.close();}});$(window).bind('resize.simplemodal',function(){w=s.getDimensions();s.setContainerDimensions(true);if(ie6||ieQuirks){s.fixIE();}else if(s.o.modal){s.d.iframe&&s.d.iframe.css({height:w[0],width:w[1]});s.d.overlay.css({height:w[0],width:w[1]});}});},unbindEvents:function(){$('.'+this.o.closeClass).unbind('click.simplemodal');$(document).unbind('keydown.simplemodal');$(window).unbind('resize.simplemodal');this.d.overlay.unbind('click.simplemodal');},fixIE:function(){var s=this,p=s.o.position;$.each([s.d.iframe||null,!s.o.modal?null:s.d.overlay,s.d.container],function(i,el){if(el){var bch='document.body.clientHeight',bcw='document.body.clientWidth',bsh='document.body.scrollHeight',bsl='document.body.scrollLeft',bst='document.body.scrollTop',bsw='document.body.scrollWidth',ch='document.documentElement.clientHeight',cw='document.documentElement.clientWidth',sl='document.documentElement.scrollLeft',st='document.documentElement.scrollTop',s=el[0].style;s.position='absolute';if(i<2){s.removeExpression('height');s.removeExpression('width');s.setExpression('height',''+bsh+' > '+bch+' ? '+bsh+' : '+bch+' + "px"');s.setExpression('width',''+bsw+' > '+bcw+' ? '+bsw+' : '+bcw+' + "px"');}else{var te,le;if(p&&p.constructor==Array){var top=p[0]?typeof p[0]=='number'?p[0].toString():p[0].replace(/px/,''):el.css('top').replace(/px/,'');te=top.indexOf('%')==-1?top+' + (t = '+st+' ? '+st+' : '+bst+') + "px"':parseInt(top.replace(/%/,''))+' * (('+ch+' || '+bch+') / 100) + (t = '+st+' ? '+st+' : '+bst+') + "px"';if(p[1]){var left=typeof p[1]=='number'?p[1].toString():p[1].replace(/px/,'');le=left.indexOf('%')==-1?left+' + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"':parseInt(left.replace(/%/,''))+' * (('+cw+' || '+bcw+') / 100) + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"';}}else{te='('+ch+' || '+bch+') / 2 - (this.offsetHeight / 2) + (t = '+st+' ? '+st+' : '+bst+') + "px"';le='('+cw+' || '+bcw+') / 2 - (this.offsetWidth / 2) + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"';}s.removeExpression('top');s.removeExpression('left');s.setExpression('top',te);s.setExpression('left',le);}}});},focus:function(pos){var s=this,p=pos||'first';var input=$(':input:enabled:visible:'+p,s.d.wrap);input.length>0?input.focus():s.d.wrap.focus();},getDimensions:function(){var el=$(window);var h=$.browser.opera&&$.browser.version>'9.5'&&$.fn.jquery<='1.2.6'?document.documentElement['clientHeight']:$.browser.opera&&$.browser.version<'9.5'&&$.fn.jquery>'1.2.6'?window.innerHeight:el.height();return[h,el.width()];},getVal:function(v){return v=='auto'?0:v.indexOf('%')>0?v:parseInt(v.replace(/px/,''));},setContainerDimensions:function(resize){var s=this;if(!resize||(resize&&s.o.autoResize)){var ch=$.browser.opera?s.d.container.height():s.getVal(s.d.container.css('height')),cw=$.browser.opera?s.d.container.width():s.getVal(s.d.container.css('width')),dh=s.d.data.outerHeight(true),dw=s.d.data.outerWidth(true);var mh=s.o.maxHeight&&s.o.maxHeight<w[0]?s.o.maxHeight:w[0],mw=s.o.maxWidth&&s.o.maxWidth<w[1]?s.o.maxWidth:w[1];if(!ch){if(!dh){ch=s.o.minHeight;}else{if(dh>mh){ch=mh;}else if(dh<s.o.minHeight){ch=s.o.minHeight;}else{ch=dh;}}}else{ch=ch>mh?mh:ch;}if(!cw){if(!dw){cw=s.o.minWidth;}else{if(dw>mw){cw=mw;}else if(dw<s.o.minWidth){cw=s.o.minWidth;}else{cw=dw;}}}else{cw=cw>mw?mw:cw;}s.d.container.css({height:ch,width:cw});if(dh>ch||dw>cw){s.d.wrap.css({overflow:'auto'});}}if(s.o.autoPosition){s.setPosition();}},setPosition:function(){var s=this,top,left,hc=(w[0]/2)-(s.d.container.outerHeight(true)/2),vc=(w[1]/2)-(s.d.container.outerWidth(true)/2);if(s.o.position&&Object.prototype.toString.call(s.o.position)==="[object Array]"){top=s.o.position[0]||hc;left=s.o.position[1]||vc;}else{top=hc;left=vc;}s.d.container.css({left:left,top:top});},watchTab:function(e){var s=this;if($(e.target).parents('.simplemodal-container').length>0){s.inputs=$(':input:enabled:visible:first, :input:enabled:visible:last',s.d.data[0]);if((!e.shiftKey&&e.target==s.inputs[s.inputs.length-1])||(e.shiftKey&&e.target==s.inputs[0])||s.inputs.length==0){e.preventDefault();var pos=e.shiftKey?'last':'first';setTimeout(function(){s.focus(pos);},10);}}else{e.preventDefault();setTimeout(function(){s.focus();},10);}},open:function(){var s=this;s.d.iframe&&s.d.iframe.show();if($.isFunction(s.o.onOpen)){s.o.onOpen.apply(s,[s.d]);}else{s.d.overlay.show();s.d.container.show();s.d.data.show();}s.focus();s.bindEvents();},close:function(){var s=this;if(!s.d.data){return false;}s.unbindEvents();if($.isFunction(s.o.onClose)&&!s.occb){s.occb=true;s.o.onClose.apply(s,[s.d]);}else{if(s.d.placeholder){var ph=$('#simplemodal-placeholder');if(s.o.persist){ph.replaceWith(s.d.data.removeClass('simplemodal-data').css('display',s.display));}else{s.d.data.hide().remove();ph.replaceWith(s.d.orig);}}else{s.d.data.hide().remove();}s.d.container.hide().remove();s.d.overlay.hide().remove();s.d.iframe&&s.d.iframe.hide().remove();s.d={};}}};})(jQuery);
+;(function($){var ie6=$.browser.msie&&parseInt($.browser.version)===6&&typeof window['XMLHttpRequest']!=="object",ieQuirks=null,w=[];$.modal=function(data,options){return $.modal.impl.init(data,options);};$.modal.close=function(){$.modal.impl.close();};$.fn.modal=function(options){return $.modal.impl.init(this,options);};$.modal.defaults={appendTo:'body',focus:true,opacity:50,overlayId:'simplemodal-overlay',overlayCss:{},containerId:'simplemodal-container',containerCss:{},dataId:'simplemodal-data',dataCss:{},minHeight:null,minWidth:null,maxHeight:null,maxWidth:null,zIndex:1000,close:true,closeHTML:'<a class="modalCloseImg" title="Close"></a>',closeClass:'simplemodal-close',escClose:true,overlayClose:false,position:null,persist:false,modal:true,onOpen:null,onShow:null,onClose:null,bodyStretch:true};$.modal.impl={o:null,d:{},init:function(data,options){var s=this;if(s.d.data){return false;}ieQuirks=$.browser.msie&&!$.boxModel;s.o=$.extend({},$.modal.defaults,options);s.zIndex=s.o.zIndex;s.occb=false;if(typeof data==='object'){data=data instanceof jQuery?data:$(data);s.d.placeholder=false;if(data.parent().parent().size()>0){data.before($('<span></span>').attr('id','simplemodal-placeholder').css({display:'none'}));s.d.placeholder=true;s.display=data.css('display');if(!s.o.persist){s.d.orig=data.clone(true);}}}else if(typeof data==='string'||typeof data==='number'){data=$('<div></div>').html(data);}else{alert('SimpleModal Error: Unsupported data type: '+typeof data);return s;}s.create(data);data=null;s.open();if($.isFunction(s.o.onShow)){s.o.onShow.apply(s,[s.d]);}return s;},create:function(data){var s=this;w=s.getDimensions();if(s.o.modal&&ie6){s.d.iframe=$('<iframe src="javascript:false;"></iframe>').css($.extend(s.o.iframeCss,{display:'none',opacity:0,position:'fixed',height:w[0],width:w[1],zIndex:s.o.zIndex,top:0,left:0})).appendTo(s.o.appendTo);}s.d.overlay=$('<div></div>').attr('id',s.o.overlayId).addClass('simplemodal-overlay').css($.extend(s.o.overlayCss,{display:'none',opacity:s.o.opacity/100,height:s.o.modal?w[0]:0,width:s.o.modal?w[1]:0,position:'fixed',left:0,top:0,zIndex:s.o.zIndex+1})).appendTo(s.o.appendTo);s.d.container=$('<div></div>').attr('id',s.o.containerId).addClass('simplemodal-container').css($.extend(s.o.containerCss,{display:'none',position:'fixed',zIndex:s.o.zIndex+2})).append(s.o.close&&s.o.closeHTML?$(s.o.closeHTML).addClass(s.o.closeClass):'').appendTo(s.o.appendTo);s.d.wrap=$('<div></div>').attr('tabIndex',-1).addClass('simplemodal-wrap').css({height:'100%',outline:0,width:'100%'}).appendTo(s.d.container);s.d.data=data.attr('id',data.attr('id')||s.o.dataId).addClass('simplemodal-data').css($.extend(s.o.dataCss,{display:'none'})).appendTo('body');data=null;s.setContainerDimensions();s.d.data.appendTo(s.d.wrap);if(ie6||ieQuirks){s.fixIE();}},bindEvents:function(){var s=this;$('.'+s.o.closeClass).bind('click.simplemodal',function(e){e.preventDefault();s.close();});if(s.o.modal&&s.o.close&&s.o.overlayClose){s.d.overlay.bind('click.simplemodal',function(e){e.preventDefault();s.close();});}$(document).bind('keydown.simplemodal',function(e){if(s.o.modal&&e.keyCode===9){s.watchTab(e);}else if((s.o.close&&s.o.escClose)&&e.keyCode===27){e.preventDefault();s.close();}});$(window).bind('resize.simplemodal',function(){w=s.getDimensions();s.setPosition();if(ie6||ieQuirks){s.fixIE();}else if(s.o.modal){s.d.iframe&&s.d.iframe.css({height:w[0],width:w[1]});s.d.overlay.css({height:w[0],width:w[1]});}});},unbindEvents:function(){$('.'+this.o.closeClass).unbind('click.simplemodal');$(document).unbind('keydown.simplemodal');$(window).unbind('resize.simplemodal');this.d.overlay.unbind('click.simplemodal');},fixIE:function(){var s=this,p=s.o.position;ie6&&s.o.bodyStretch&&$('body').css({height:'100%',width:'100%'});$.each([s.d.iframe||null,!s.o.modal?null:s.d.overlay,s.d.container],function(i,el){if(el){var bch='document.body.clientHeight',bcw='document.body.clientWidth',bsh='document.body.scrollHeight',bsl='document.body.scrollLeft',bst='document.body.scrollTop',bsw='document.body.scrollWidth',ch='document.documentElement.clientHeight',cw='document.documentElement.clientWidth',sl='document.documentElement.scrollLeft',st='document.documentElement.scrollTop',s=el[0].style;s.position='absolute';if(i<2){s.removeExpression('height');s.removeExpression('width');s.setExpression('height',''+bsh+' > '+bch+' ? '+bsh+' : '+bch+' + "px"');s.setExpression('width',''+bsw+' > '+bcw+' ? '+bsw+' : '+bcw+' + "px"');}else{var te,le;if(p&&p.constructor===Array){var top=p[0]?typeof p[0]==='number'?p[0].toString():p[0].replace(/px/,''):el.css('top').replace(/px/,'');te=top.indexOf('%')===-1?top+' + (t = '+st+' ? '+st+' : '+bst+') + "px"':parseInt(top.replace(/%/,''))+' * (('+ch+' || '+bch+') / 100) + (t = '+st+' ? '+st+' : '+bst+') + "px"';if(p[1]){var left=typeof p[1]==='number'?p[1].toString():p[1].replace(/px/,'');le=left.indexOf('%')===-1?left+' + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"':parseInt(left.replace(/%/,''))+' * (('+cw+' || '+bcw+') / 100) + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"';}}else{te='('+ch+' || '+bch+') / 2 - (this.offsetHeight / 2) + (t = '+st+' ? '+st+' : '+bst+') + "px"';le='('+cw+' || '+bcw+') / 2 - (this.offsetWidth / 2) + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"';}s.removeExpression('top');s.removeExpression('left');s.setExpression('top',te);s.setExpression('left',le);}}});},focus:function(pos){var s=this,p=pos||'first';var input=$(':input:enabled:visible:'+p,s.d.wrap);setTimeout(function(){input.length>0?input.focus():s.d.wrap.focus();},10);},getDimensions:function(){var el=$(window);var h=$.browser.opera&&$.browser.version>'9.5'&&$.fn.jquery<'1.3'||$.browser.opera&&$.browser.version<'9.5'&&$.fn.jquery>'1.2.6'?el[0].innerHeight:el.height();return[h,el.width()];},getVal:function(v){return typeof v==='number'?v:v==='auto'?0:v.indexOf('%')>0?v:parseInt(v.replace(/px/,''));},update:function(height,width){var s=this;if(!s.d.data){return false;}s.d.data.hide();height&&s.d.container.css('height',height);width&&s.d.container.css('width',width);s.setContainerDimensions();s.d.data.show();s.o.focus&&s.focus();s.unbindEvents();s.bindEvents();},setContainerDimensions:function(){var s=this;var ch=$.browser.opera?s.d.container.height():s.getVal(s.d.container.css('height')),cw=$.browser.opera?s.d.container.width():s.getVal(s.d.container.css('width')),dh=s.d.data.outerHeight(true),dw=s.d.data.outerWidth(true);var mh=s.o.maxHeight&&s.getVal(s.o.maxHeight)<w[0]?s.getVal(s.o.maxHeight):w[0],mw=s.o.maxWidth&&s.getVal(s.o.maxWidth)<w[1]?s.getVal(s.o.maxWidth):w[1];var moh=s.o.minHeight?s.getVal(s.o.minHeight):'auto';if(!ch){if(!dh){ch=moh;}else{if(dh>mh){ch=mh;}else if(s.o.minHeight&&moh!=='auto'&&dh<moh){ch=moh;}else{ch=dh;}}}else{ch=ch>mh?mh:ch;}var mow=s.o.minWidth?s.getVal(s.o.minWidth):'auto';if(!cw){if(!dw){cw=mow;}else{if(dw>mw){cw=mw;}else if(s.o.minWidth&&mow!=='auto'&&dw<mow){cw=mow;}else{cw=dw;}}}else{cw=cw>mw?mw:cw;}s.d.container.css({height:ch,width:cw});s.d.wrap.css({overflow:(dh>ch||dw>cw)?'auto':'visible'});s.setPosition();},setPosition:function(){var s=this,top,left,hc=(w[0]/2)-(s.d.container.outerHeight(true)/2),vc=(w[1]/2)-(s.d.container.outerWidth(true)/2);if(s.o.position&&Object.prototype.toString.call(s.o.position)==="[object Array]"){top=s.o.position[0]||hc;left=s.o.position[1]||vc;}else{top=hc;left=vc;}s.d.container.css({left:left,top:top});},watchTab:function(e){var s=this;if($(e.target).parents('.simplemodal-container').length>0){s.inputs=$(':input:enabled:visible:first, :input:enabled:visible:last',s.d.data[0]);if((!e.shiftKey&&e.target===s.inputs[s.inputs.length-1])||(e.shiftKey&&e.target===s.inputs[0])||s.inputs.length===0){e.preventDefault();var pos=e.shiftKey?'last':'first';s.focus(pos);}}else{e.preventDefault();s.focus();}},open:function(){var s=this;s.d.iframe&&s.d.iframe.show();if($.isFunction(s.o.onOpen)){s.o.onOpen.apply(s,[s.d]);}else{s.d.overlay.show();s.d.container.show();s.d.data.show();}s.o.focus&&s.focus();s.bindEvents();},close:function(){var s=this;if(!s.d.data){return false;}s.unbindEvents();if($.isFunction(s.o.onClose)&&!s.occb){s.occb=true;s.o.onClose.apply(s,[s.d]);}else{if(s.d.placeholder){var ph=$('#simplemodal-placeholder');if(s.o.persist){ph.replaceWith(s.d.data.removeClass('simplemodal-data').css('display',s.display));}else{s.d.data.hide().remove();ph.replaceWith(s.d.orig);}}else{s.d.data.hide().remove();}s.d.container.hide().remove();s.d.overlay.hide();s.d.iframe&&s.d.iframe.hide().remove();setTimeout(function(){s.d.overlay.remove();s.d={};},10);}}};})(jQuery);
View
236 src/jquery.simplemodal.js
@@ -1,7 +1,7 @@
/*
* SimpleModal @VERSION - jQuery Plugin
* http://www.ericmmartin.com/projects/simplemodal/
- * Copyright (c) 2010 Eric Martin (http://twitter.com/EricMMartin)
+ * Copyright (c) 2010 Eric Martin (http://twitter.com/ericmmartin)
* Dual licensed under the MIT and GPL licenses
* Revision: $Id$
*/
@@ -10,7 +10,7 @@
* SimpleModal is a lightweight jQuery plugin that provides a simple
* interface to create a modal dialog.
*
- * The goal of SimpleModal is to provide developers with a cross-browser
+ * The goal of SimpleModal is to provide developers with a cross-browser
* overlay and container that will be populated with data provided to
* SimpleModal.
*
@@ -26,23 +26,23 @@
*
* 2) As a stand-alone function, like $.modal(data). The data parameter
* is required and an optional options object can be passed as a second
- * parameter. This method provides more flexibility in the types of data
+ * parameter. This method provides more flexibility in the types of data
* that are allowed. The data could be a DOM object, a jQuery object, HTML
* or a string.
- *
+ *
* @example $.modal('<div>my data</div>', {options});
* @example $.modal('my data', {options});
* @example $.modal($('#myDiv'), {options});
* @example $.modal(jQueryObject, {options});
- * @example $.modal(document.getElementById('myDiv'), {options});
- *
- * A SimpleModal call can contain multiple elements, but only one modal
+ * @example $.modal(document.getElementById('myDiv'), {options});
+ *
+ * A SimpleModal call can contain multiple elements, but only one modal
* dialog can be created at a time. Which means that all of the matched
* elements will be displayed within the modal container.
- *
+ *
* SimpleModal internally sets the CSS needed to display the modal dialog
* properly in all browsers, yet provides the developer with the flexibility
- * to easily control the look and feel. The styling for SimpleModal can be
+ * to easily control the look and feel. The styling for SimpleModal can be
* done through external stylesheets, or through SimpleModal, using the
* overlayCss and/or containerCss options.
*
@@ -50,8 +50,8 @@
* - IE 6, 7, 8
* - Firefox 2, 3
* - Opera 9, 10
- * - Safari 3, 4
- * - Chrome 1, 2, 3, 4
+ * - Safari 3, 4, 5
+ * - Chrome 1, 2, 3, 4, 5
*
* @name SimpleModal
* @type jQuery
@@ -61,13 +61,13 @@
* @version @VERSION
*/
;(function ($) {
- var ie6 = $.browser.msie && parseInt($.browser.version) == 6 && typeof window['XMLHttpRequest'] != "object",
+ var ie6 = $.browser.msie && parseInt($.browser.version) === 6 && typeof window['XMLHttpRequest'] !== "object",
ieQuirks = null,
w = [];
/*
* Stand-alone function to create a modal dialog.
- *
+ *
* @param {string, object} data A string, jQuery object or DOM object
* @param {object} [options] An optional object containing options overrides
*/
@@ -84,7 +84,7 @@
/*
* Chained function to create a modal dialog.
- *
+ *
* @param {object} [options] An optional object containing options overrides
*/
$.fn.modal = function (options) {
@@ -93,9 +93,9 @@
/*
* SimpleModal default options
- *
- * appendTo: (String:'body') The jQuery selector to append the elements to. For ASP.NET, use 'form'.
- * focus: (Boolean:true) Forces focus to remain on the modal dialog
+ *
+ * appendTo: (String:'body') The jQuery selector to append the elements to. For .NET, use 'form'.
+ * focus: (Boolean:true) Focus in the first visible, enabled element?
* opacity: (Number:50) The opacity value for the overlay div, from 0 - 100
* overlayId: (String:'simplemodal-overlay') The DOM element id for the overlay div
* overlayCss: (Object:{}) The CSS styling for the overlay div
@@ -107,22 +107,21 @@
* minWidth: (Number:null) The minimum width for the container
* maxHeight: (Number:null) The maximum height for the container. If not specified, the window height is used.
* maxWidth: (Number:null) The maximum width for the container. If not specified, the window width is used.
- * autoResize: (Boolean:false) Resize container on window resize? Use with caution - this may have undesirable side-effects.
- * autoPosition: (Boolean:true) Automatically position container on creation and window resize?
* zIndex: (Number: 1000) Starting z-index value
* close: (Boolean:true) If true, closeHTML, escClose and overClose will be used if set.
If false, none of them will be used.
- * closeHTML: (String:'<a class="modalCloseImg" title="Close"></a>') The HTML for the
- default close link. SimpleModal will automatically add the closeClass to this element.
+ * closeHTML: (String:'<a class="modalCloseImg" title="Close"></a>') The HTML for the default close link.
+ SimpleModal will automatically add the closeClass to this element.
* closeClass: (String:'simplemodal-close') The CSS class used to bind to the close event
- * escClose: (Boolean:true) Allow Esc keypress to close the dialog?
+ * escClose: (Boolean:true) Allow Esc keypress to close the dialog?
* overlayClose: (Boolean:false) Allow click on overlay to close the dialog?
* position: (Array:null) Position of container [top, left]. Can be number of pixels or percentage
* persist: (Boolean:false) Persist the data across modal calls? Only used for existing
DOM elements. If true, the data will be maintained across modal calls, if false,
the data will be reverted to its original state.
- * modal: (Boolean:true) If false, the overlay, iframe, and certain events will be disabled
- allowing the user to interace with the page below the dialog
+ * modal: (Boolean:true) User will be unable to interact with the page below the modal or tab away from the dialog.
+ If false, the overlay, iframe, and certain events will be disabled allowing the user to interact
+ with the page below the dialog.
* onOpen: (Function:null) The callback function used in place of SimpleModal's open
* onShow: (Function:null) The callback function used after the modal dialog has opened
* onClose: (Function:null) The callback function used in place of SimpleModal's close
@@ -141,8 +140,6 @@
minWidth: null,
maxHeight: null,
maxWidth: null,
- autoResize: false,
- autoPosition: true,
zIndex: 1000,
close: true,
closeHTML: '<a class="modalCloseImg" title="Close"></a>',
@@ -154,7 +151,8 @@
modal: true,
onOpen: null,
onShow: null,
- onClose: null
+ onClose: null,
+ bodyStretch: true
};
/*
@@ -166,7 +164,7 @@
*/
o: null,
/*
- * Contains the modal dialog elements and is the object passed
+ * Contains the modal dialog elements and is the object passed
* back to the callback (onOpen, onShow, onClose) functions
*/
d: {},
@@ -194,7 +192,7 @@
s.occb = false;
// determine how to handle the data based on its type
- if (typeof data == 'object') {
+ if (typeof data === 'object') {
// convert DOM object to a jQuery object
data = data instanceof jQuery ? data : $(data);
s.d.placeholder = false;
@@ -214,7 +212,7 @@
}
}
}
- else if (typeof data == 'string' || typeof data == 'number') {
+ else if (typeof data === 'string' || typeof data === 'number') {
// just insert the data as innerHTML
data = $('<div></div>').html(data);
}
@@ -253,7 +251,7 @@
s.d.iframe = $('<iframe src="javascript:false;"></iframe>')
.css($.extend(s.o.iframeCss, {
display: 'none',
- opacity: 0,
+ opacity: 0,
position: 'fixed',
height: w[0],
width: w[1],
@@ -279,27 +277,27 @@
zIndex: s.o.zIndex + 1
}))
.appendTo(s.o.appendTo);
-
+
// create the container
s.d.container = $('<div></div>')
.attr('id', s.o.containerId)
.addClass('simplemodal-container')
.css($.extend(s.o.containerCss, {
display: 'none',
- position: 'fixed',
+ position: 'fixed',
zIndex: s.o.zIndex + 2
}))
.append(s.o.close && s.o.closeHTML
? $(s.o.closeHTML).addClass(s.o.closeClass)
: '')
.appendTo(s.o.appendTo);
-
+
s.d.wrap = $('<div></div>')
.attr('tabIndex', -1)
.addClass('simplemodal-wrap')
.css({height: '100%', outline: 0, width: '100%'})
.appendTo(s.d.container);
-
+
// add styling and attributes to the data
// append to body to get correct dimensions, then move to wrap
s.d.data = data
@@ -330,7 +328,7 @@
e.preventDefault();
s.close();
});
-
+
// bind the overlay click to the close function, if enabled
if (s.o.modal && s.o.close && s.o.overlayClose) {
s.d.overlay.bind('click.simplemodal', function (e) {
@@ -338,13 +336,13 @@
s.close();
});
}
-
+
// bind keydown events
$(document).bind('keydown.simplemodal', function (e) {
- if (s.o.modal && s.o.focus && e.keyCode == 9) { // TAB
+ if (s.o.modal && e.keyCode === 9) { // TAB
s.watchTab(e);
}
- else if ((s.o.close && s.o.escClose) && e.keyCode == 27) { // ESC
+ else if ((s.o.close && s.o.escClose) && e.keyCode === 27) { // ESC
e.preventDefault();
s.close();
}
@@ -356,8 +354,9 @@
w = s.getDimensions();
// reposition the dialog
- s.setContainerDimensions(true);
-
+ // TODO setPosition or setContainerDimensions?
+ s.setPosition();
+
if (ie6 || ieQuirks) {
s.fixIE();
}
@@ -382,6 +381,9 @@
*/
fixIE: function () {
var s = this, p = s.o.position;
+
+ // TODO prevent this from causing scrollbars
+ ie6 && s.o.bodyStretch && $('body').css({height: '100%', width: '100%'});
// simulate fixed position - adapted from BlockUI
$.each([s.d.iframe || null, !s.o.modal ? null : s.d.overlay, s.d.container], function (i, el) {
@@ -402,17 +404,17 @@
}
else {
var te, le;
- if (p && p.constructor == Array) {
- var top = p[0]
- ? typeof p[0] == 'number' ? p[0].toString() : p[0].replace(/px/, '')
+ if (p && p.constructor === Array) {
+ var top = p[0]
+ ? typeof p[0] === 'number' ? p[0].toString() : p[0].replace(/px/, '')
: el.css('top').replace(/px/, '');
- te = top.indexOf('%') == -1
+ te = top.indexOf('%') === -1
? top + ' + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"'
: parseInt(top.replace(/%/, '')) + ' * ((' + ch + ' || ' + bch + ') / 100) + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"';
if (p[1]) {
- var left = typeof p[1] == 'number' ? p[1].toString() : p[1].replace(/px/, '');
- le = left.indexOf('%') == -1
+ var left = typeof p[1] === 'number' ? p[1].toString() : p[1].replace(/px/, '');
+ le = left.indexOf('%') === -1
? left + ' + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"'
: parseInt(left.replace(/%/, '')) + ' * ((' + cw + ' || ' + bcw + ') / 100) + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"';
}
@@ -434,70 +436,92 @@
// focus on dialog or the first visible/enabled input element
var input = $(':input:enabled:visible:' + p, s.d.wrap);
- input.length > 0 ? input.focus() : s.d.wrap.focus();
+ setTimeout(function () {
+ input.length > 0 ? input.focus() : s.d.wrap.focus();
+ }, 10);
},
getDimensions: function () {
var el = $(window);
// fix a jQuery/Opera bug with determining the window height
- var h = $.browser.opera && $.browser.version > '9.5' && $.fn.jquery <= '1.2.6' ? document.documentElement['clientHeight'] :
- $.browser.opera && $.browser.version < '9.5' && $.fn.jquery > '1.2.6' ? window.innerHeight :
- el.height();
+ var h = $.browser.opera && $.browser.version > '9.5' && $.fn.jquery < '1.3'
+ || $.browser.opera && $.browser.version < '9.5' && $.fn.jquery > '1.2.6'
+ ? el[0].innerHeight : el.height();
return [h, el.width()];
},
getVal: function (v) {
- return v == 'auto' ? 0
- : v.indexOf('%') > 0 ? v
+ return typeof v === 'number' ? v
+ : v === 'auto' ? 0
+ : v.indexOf('%') > 0 ? v
: parseInt(v.replace(/px/, ''));
},
- setContainerDimensions: function (resize) {
+ /*
+ * Update the container. Set new dimensions, if provided.
+ * Focus, if enabled. Re-bind events.
+ */
+ update: function (height, width) {
var s = this;
- if (!resize || (resize && s.o.autoResize)) {
- // get the dimensions for the container and data
- var ch = $.browser.opera ? s.d.container.height() : s.getVal(s.d.container.css('height')),
- cw = $.browser.opera ? s.d.container.width() : s.getVal(s.d.container.css('width')),
- dh = s.d.data.outerHeight(true), dw = s.d.data.outerWidth(true);
+ // prevent update if dialog does not exist
+ if (!s.d.data) {
+ return false;
+ }
- var mh = s.o.maxHeight && s.o.maxHeight < w[0] ? s.o.maxHeight : w[0],
- mw = s.o.maxWidth && s.o.maxWidth < w[1] ? s.o.maxWidth : w[1];
+ // hide data to prevent screen flicker
+ s.d.data.hide();
+ height && s.d.container.css('height', height);
+ width && s.d.container.css('width', width);
+ s.setContainerDimensions();
+ s.d.data.show();
+ s.o.focus && s.focus();
- // height
- if (!ch) {
- if (!dh) {ch = s.o.minHeight;}
- else {
- if (dh > mh) {ch = mh;}
- else if (dh < s.o.minHeight) {ch = s.o.minHeight;}
- else {ch = dh;}
- }
- }
- else {
- ch = ch > mh ? mh : ch;
- }
+ // rebind events
+ s.unbindEvents();
+ s.bindEvents();
+ },
+ setContainerDimensions: function () {
+ var s = this;
- // width
- if (!cw) {
- if (!dw) {cw = s.o.minWidth;}
- else {
- if (dw > mw) {cw = mw;}
- else if (dw < s.o.minWidth) {cw = s.o.minWidth;}
- else {cw = dw;}
- }
- }
+ // get the dimensions for the container and data
+ var ch = $.browser.opera ? s.d.container.height() : s.getVal(s.d.container.css('height')),
+ cw = $.browser.opera ? s.d.container.width() : s.getVal(s.d.container.css('width')),
+ dh = s.d.data.outerHeight(true), dw = s.d.data.outerWidth(true);
+
+ var mh = s.o.maxHeight && s.getVal(s.o.maxHeight) < w[0] ? s.getVal(s.o.maxHeight) : w[0],
+ mw = s.o.maxWidth && s.getVal(s.o.maxWidth) < w[1] ? s.getVal(s.o.maxWidth) : w[1];
+
+ // height
+ var moh = s.o.minHeight ? s.getVal(s.o.minHeight) : 'auto';
+ if (!ch) {
+ if (!dh) {ch = moh;}
else {
- cw = cw > mw ? mw : cw;
+ if (dh > mh) {ch = mh;}
+ else if (s.o.minHeight && moh !== 'auto' && dh < moh) {ch = moh;}
+ else {ch = dh;}
}
+ }
+ else {
+ ch = ch > mh ? mh : ch;
+ }
- s.d.container.css({height: ch, width: cw});
- if (dh > ch || dw > cw) {
- s.d.wrap.css({overflow:'auto'});
+ // width
+ var mow = s.o.minWidth ? s.getVal(s.o.minWidth) : 'auto';
+ if (!cw) {
+ if (!dw) {cw = mow;}
+ else {
+ if (dw > mw) {cw = mw;}
+ else if (s.o.minWidth && mow !== 'auto' && dw < mow) {cw = mow;}
+ else {cw = dw;}
}
}
-
- if (s.o.autoPosition) {
- s.setPosition();
+ else {
+ cw = cw > mw ? mw : cw;
}
+
+ s.d.container.css({height: ch, width: cw});
+ s.d.wrap.css({overflow: (dh > ch || dw > cw) ? 'auto' : 'visible'});
+ s.setPosition();
},
setPosition: function () {
var s = this, top, left,
@@ -521,24 +545,24 @@
s.inputs = $(':input:enabled:visible:first, :input:enabled:visible:last', s.d.data[0]);
// if it's the first or last tabbable element, refocus
- if ((!e.shiftKey && e.target == s.inputs[s.inputs.length -1]) ||
- (e.shiftKey && e.target == s.inputs[0]) ||
- s.inputs.length == 0) {
+ if ((!e.shiftKey && e.target === s.inputs[s.inputs.length -1]) ||
+ (e.shiftKey && e.target === s.inputs[0]) ||
+ s.inputs.length === 0) {
e.preventDefault();
var pos = e.shiftKey ? 'last' : 'first';
- setTimeout(function () {s.focus(pos);}, 10);
+ s.focus(pos);
}
}
else {
// might be necessary when custom onShow callback is used
e.preventDefault();
- setTimeout(function () {s.focus();}, 10);
+ s.focus();
}
},
/*
* Open the modal dialog elements
- * - Note: If you use the onOpen callback, you must "show" the
- * overlay and container elements manually
+ * - Note: If you use the onOpen callback, you must "show" the
+ * overlay and container elements manually
* (the iframe will be handled by SimpleModal)
*/
open: function () {
@@ -547,7 +571,7 @@
s.d.iframe && s.d.iframe.show();
if ($.isFunction(s.o.onOpen)) {
- // execute the onOpen callback
+ // execute the onOpen callback
s.o.onOpen.apply(s, [s.d]);
}
else {
@@ -556,15 +580,15 @@
s.d.container.show();
s.d.data.show();
}
-
- s.focus();
+
+ s.o.focus && s.focus();
// bind default events
s.bindEvents();
},
/*
* Close the modal dialog
- * - Note: If you use an onClose callback, you must remove the
+ * - Note: If you use an onClose callback, you must remove the
* overlay, container and iframe elements manually
*
* @param {boolean} external Indicates whether the call to this
@@ -599,7 +623,7 @@
ph.replaceWith(s.d.data.removeClass('simplemodal-data').css('display', s.display));
}
else {
- // remove the current and insert the original,
+ // remove the current and insert the original,
// unmodified data back into the DOM
s.d.data.hide().remove();
ph.replaceWith(s.d.orig);
@@ -612,11 +636,15 @@
// remove the remaining elements
s.d.container.hide().remove();
- s.d.overlay.hide().remove();
+ s.d.overlay.hide();
s.d.iframe && s.d.iframe.hide().remove();
+ setTimeout(function(){
+ // opera work-around
+ s.d.overlay.remove();
- // reset the dialog object
- s.d = {};
+ // reset the dialog object
+ s.d = {};
+ }, 10);
}
}
};
View
3  test/index.html
@@ -49,6 +49,8 @@
<li><a href='#' id='test26'>Max height/width</a> <pre><code>$('#modalContentOverflowTest').modal({maxHeight:500, maxWidth:700});</code></pre></li>
<li><a href='#' id='test27'>Disable focus</a> <pre><code>$('#modalContentTest').modal({focus:false});</code></pre></li>
<li><a href='#' id='test28'>Non-modal</a> <pre><code>$('#modalContentTest').modal({modal:false});</code></pre></li>
+ <li><a href='#' id='test29'>Update</a> <pre><code>$('#modalContentTest').modal({blahblah});</code></pre></li>
+ <li><a href='#' id='test30'>Update 2</a> <pre><code>$('#modalContentTest').modal({blahblah});</code></pre></li>
<li><a href='#' id='test7'>Modal Function w/ string/HTML - close: false</a> <pre><code>$.modal("&lt;div class='test'&gt;\
&lt;h1&gt;Sample Content&lt;/h1&gt;\
&lt;p&gt;This example uses a custom close.&lt;/p&gt;\
@@ -221,6 +223,7 @@
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.</p>
+ <input type='button' value='button' class='animate'/><br/>
</div>
<div style='height: 50px;'>&nbsp;</div>
</body>
View
6 test/js/jquery.simplemodal.js
@@ -1,8 +1,8 @@
/*
- * SimpleModal 1.3.5 - jQuery Plugin
+ * SimpleModal 1.3.6b - jQuery Plugin
* http://www.ericmmartin.com/projects/simplemodal/
- * Copyright (c) 2010 Eric Martin (http://twitter.com/EricMMartin)
+ * Copyright (c) 2010 Eric Martin (http://twitter.com/ericmmartin)
* Dual licensed under the MIT and GPL licenses
* Revision: $Id: jquery.simplemodal.js 245 2010-03-25 20:41:15Z emartin24 $
*/
-;(function($){var ie6=$.browser.msie&&parseInt($.browser.version)==6&&typeof window['XMLHttpRequest']!="object",ieQuirks=null,w=[];$.modal=function(data,options){return $.modal.impl.init(data,options);};$.modal.close=function(){$.modal.impl.close();};$.fn.modal=function(options){return $.modal.impl.init(this,options);};$.modal.defaults={appendTo:'body',focus:true,opacity:50,overlayId:'simplemodal-overlay',overlayCss:{},containerId:'simplemodal-container',containerCss:{},dataId:'simplemodal-data',dataCss:{},minHeight:null,minWidth:null,maxHeight:null,maxWidth:null,autoResize:false,autoPosition:true,zIndex:1000,close:true,closeHTML:'<a class="modalCloseImg" title="Close"></a>',closeClass:'simplemodal-close',escClose:true,overlayClose:false,position:null,persist:false,modal:true,onOpen:null,onShow:null,onClose:null};$.modal.impl={o:null,d:{},init:function(data,options){var s=this;if(s.d.data){return false;}ieQuirks=$.browser.msie&&!$.boxModel;s.o=$.extend({},$.modal.defaults,options);s.zIndex=s.o.zIndex;s.occb=false;if(typeof data=='object'){data=data instanceof jQuery?data:$(data);s.d.placeholder=false;if(data.parent().parent().size()>0){data.before($('<span></span>').attr('id','simplemodal-placeholder').css({display:'none'}));s.d.placeholder=true;s.display=data.css('display');if(!s.o.persist){s.d.orig=data.clone(true);}}}else if(typeof data=='string'||typeof data=='number'){data=$('<div></div>').html(data);}else{alert('SimpleModal Error: Unsupported data type: '+typeof data);return s;}s.create(data);data=null;s.open();if($.isFunction(s.o.onShow)){s.o.onShow.apply(s,[s.d]);}return s;},create:function(data){var s=this;w=s.getDimensions();if(s.o.modal&&ie6){s.d.iframe=$('<iframe src="javascript:false;"></iframe>').css($.extend(s.o.iframeCss,{display:'none',opacity:0,position:'fixed',height:w[0],width:w[1],zIndex:s.o.zIndex,top:0,left:0})).appendTo(s.o.appendTo);}s.d.overlay=$('<div></div>').attr('id',s.o.overlayId).addClass('simplemodal-overlay').css($.extend(s.o.overlayCss,{display:'none',opacity:s.o.opacity/100,height:s.o.modal?w[0]:0,width:s.o.modal?w[1]:0,position:'fixed',left:0,top:0,zIndex:s.o.zIndex+1})).appendTo(s.o.appendTo);s.d.container=$('<div></div>').attr('id',s.o.containerId).addClass('simplemodal-container').css($.extend(s.o.containerCss,{display:'none',position:'fixed',zIndex:s.o.zIndex+2})).append(s.o.close&&s.o.closeHTML?$(s.o.closeHTML).addClass(s.o.closeClass):'').appendTo(s.o.appendTo);s.d.wrap=$('<div></div>').attr('tabIndex',-1).addClass('simplemodal-wrap').css({height:'100%',outline:0,width:'100%'}).appendTo(s.d.container);s.d.data=data.attr('id',data.attr('id')||s.o.dataId).addClass('simplemodal-data').css($.extend(s.o.dataCss,{display:'none'})).appendTo('body');data=null;s.setContainerDimensions();s.d.data.appendTo(s.d.wrap);if(ie6||ieQuirks){s.fixIE();}},bindEvents:function(){var s=this;$('.'+s.o.closeClass).bind('click.simplemodal',function(e){e.preventDefault();s.close();});if(s.o.modal&&s.o.close&&s.o.overlayClose){s.d.overlay.bind('click.simplemodal',function(e){e.preventDefault();s.close();});}$(document).bind('keydown.simplemodal',function(e){if(s.o.modal&&s.o.focus&&e.keyCode==9){s.watchTab(e);}else if((s.o.close&&s.o.escClose)&&e.keyCode==27){e.preventDefault();s.close();}});$(window).bind('resize.simplemodal',function(){w=s.getDimensions();s.setContainerDimensions(true);if(ie6||ieQuirks){s.fixIE();}else if(s.o.modal){s.d.iframe&&s.d.iframe.css({height:w[0],width:w[1]});s.d.overlay.css({height:w[0],width:w[1]});}});},unbindEvents:function(){$('.'+this.o.closeClass).unbind('click.simplemodal');$(document).unbind('keydown.simplemodal');$(window).unbind('resize.simplemodal');this.d.overlay.unbind('click.simplemodal');},fixIE:function(){var s=this,p=s.o.position;$.each([s.d.iframe||null,!s.o.modal?null:s.d.overlay,s.d.container],function(i,el){if(el){var bch='document.body.clientHeight',bcw='document.body.clientWidth',bsh='document.body.scrollHeight',bsl='document.body.scrollLeft',bst='document.body.scrollTop',bsw='document.body.scrollWidth',ch='document.documentElement.clientHeight',cw='document.documentElement.clientWidth',sl='document.documentElement.scrollLeft',st='document.documentElement.scrollTop',s=el[0].style;s.position='absolute';if(i<2){s.removeExpression('height');s.removeExpression('width');s.setExpression('height',''+bsh+' > '+bch+' ? '+bsh+' : '+bch+' + "px"');s.setExpression('width',''+bsw+' > '+bcw+' ? '+bsw+' : '+bcw+' + "px"');}else{var te,le;if(p&&p.constructor==Array){var top=p[0]?typeof p[0]=='number'?p[0].toString():p[0].replace(/px/,''):el.css('top').replace(/px/,'');te=top.indexOf('%')==-1?top+' + (t = '+st+' ? '+st+' : '+bst+') + "px"':parseInt(top.replace(/%/,''))+' * (('+ch+' || '+bch+') / 100) + (t = '+st+' ? '+st+' : '+bst+') + "px"';if(p[1]){var left=typeof p[1]=='number'?p[1].toString():p[1].replace(/px/,'');le=left.indexOf('%')==-1?left+' + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"':parseInt(left.replace(/%/,''))+' * (('+cw+' || '+bcw+') / 100) + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"';}}else{te='('+ch+' || '+bch+') / 2 - (this.offsetHeight / 2) + (t = '+st+' ? '+st+' : '+bst+') + "px"';le='('+cw+' || '+bcw+') / 2 - (this.offsetWidth / 2) + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"';}s.removeExpression('top');s.removeExpression('left');s.setExpression('top',te);s.setExpression('left',le);}}});},focus:function(pos){var s=this,p=pos||'first';var input=$(':input:enabled:visible:'+p,s.d.wrap);input.length>0?input.focus():s.d.wrap.focus();},getDimensions:function(){var el=$(window);var h=$.browser.opera&&$.browser.version>'9.5'&&$.fn.jquery<='1.2.6'?document.documentElement['clientHeight']:$.browser.opera&&$.browser.version<'9.5'&&$.fn.jquery>'1.2.6'?window.innerHeight:el.height();return[h,el.width()];},getVal:function(v){return v=='auto'?0:v.indexOf('%')>0?v:parseInt(v.replace(/px/,''));},setContainerDimensions:function(resize){var s=this;if(!resize||(resize&&s.o.autoResize)){var ch=$.browser.opera?s.d.container.height():s.getVal(s.d.container.css('height')),cw=$.browser.opera?s.d.container.width():s.getVal(s.d.container.css('width')),dh=s.d.data.outerHeight(true),dw=s.d.data.outerWidth(true);var mh=s.o.maxHeight&&s.o.maxHeight<w[0]?s.o.maxHeight:w[0],mw=s.o.maxWidth&&s.o.maxWidth<w[1]?s.o.maxWidth:w[1];if(!ch){if(!dh){ch=s.o.minHeight;}else{if(dh>mh){ch=mh;}else if(dh<s.o.minHeight){ch=s.o.minHeight;}else{ch=dh;}}}else{ch=ch>mh?mh:ch;}if(!cw){if(!dw){cw=s.o.minWidth;}else{if(dw>mw){cw=mw;}else if(dw<s.o.minWidth){cw=s.o.minWidth;}else{cw=dw;}}}else{cw=cw>mw?mw:cw;}s.d.container.css({height:ch,width:cw});if(dh>ch||dw>cw){s.d.wrap.css({overflow:'auto'});}}if(s.o.autoPosition){s.setPosition();}},setPosition:function(){var s=this,top,left,hc=(w[0]/2)-(s.d.container.outerHeight(true)/2),vc=(w[1]/2)-(s.d.container.outerWidth(true)/2);if(s.o.position&&Object.prototype.toString.call(s.o.position)==="[object Array]"){top=s.o.position[0]||hc;left=s.o.position[1]||vc;}else{top=hc;left=vc;}s.d.container.css({left:left,top:top});},watchTab:function(e){var s=this;if($(e.target).parents('.simplemodal-container').length>0){s.inputs=$(':input:enabled:visible:first, :input:enabled:visible:last',s.d.data[0]);if((!e.shiftKey&&e.target==s.inputs[s.inputs.length-1])||(e.shiftKey&&e.target==s.inputs[0])||s.inputs.length==0){e.preventDefault();var pos=e.shiftKey?'last':'first';setTimeout(function(){s.focus(pos);},10);}}else{e.preventDefault();setTimeout(function(){s.focus();},10);}},open:function(){var s=this;s.d.iframe&&s.d.iframe.show();if($.isFunction(s.o.onOpen)){s.o.onOpen.apply(s,[s.d]);}else{s.d.overlay.show();s.d.container.show();s.d.data.show();}s.focus();s.bindEvents();},close:function(){var s=this;if(!s.d.data){return false;}s.unbindEvents();if($.isFunction(s.o.onClose)&&!s.occb){s.occb=true;s.o.onClose.apply(s,[s.d]);}else{if(s.d.placeholder){var ph=$('#simplemodal-placeholder');if(s.o.persist){ph.replaceWith(s.d.data.removeClass('simplemodal-data').css('display',s.display));}else{s.d.data.hide().remove();ph.replaceWith(s.d.orig);}}else{s.d.data.hide().remove();}s.d.container.hide().remove();s.d.overlay.hide().remove();s.d.iframe&&s.d.iframe.hide().remove();s.d={};}}};})(jQuery);
+;(function($){var ie6=$.browser.msie&&parseInt($.browser.version)===6&&typeof window['XMLHttpRequest']!=="object",ieQuirks=null,w=[];$.modal=function(data,options){return $.modal.impl.init(data,options);};$.modal.close=function(){$.modal.impl.close();};$.fn.modal=function(options){return $.modal.impl.init(this,options);};$.modal.defaults={appendTo:'body',focus:true,opacity:50,overlayId:'simplemodal-overlay',overlayCss:{},containerId:'simplemodal-container',containerCss:{},dataId:'simplemodal-data',dataCss:{},minHeight:null,minWidth:null,maxHeight:null,maxWidth:null,zIndex:1000,close:true,closeHTML:'<a class="modalCloseImg" title="Close"></a>',closeClass:'simplemodal-close',escClose:true,overlayClose:false,position:null,persist:false,modal:true,onOpen:null,onShow:null,onClose:null,bodyStretch:true};$.modal.impl={o:null,d:{},init:function(data,options){var s=this;if(s.d.data){return false;}ieQuirks=$.browser.msie&&!$.boxModel;s.o=$.extend({},$.modal.defaults,options);s.zIndex=s.o.zIndex;s.occb=false;if(typeof data==='object'){data=data instanceof jQuery?data:$(data);s.d.placeholder=false;if(data.parent().parent().size()>0){data.before($('<span></span>').attr('id','simplemodal-placeholder').css({display:'none'}));s.d.placeholder=true;s.display=data.css('display');if(!s.o.persist){s.d.orig=data.clone(true);}}}else if(typeof data==='string'||typeof data==='number'){data=$('<div></div>').html(data);}else{alert('SimpleModal Error: Unsupported data type: '+typeof data);return s;}s.create(data);data=null;s.open();if($.isFunction(s.o.onShow)){s.o.onShow.apply(s,[s.d]);}return s;},create:function(data){var s=this;w=s.getDimensions();if(s.o.modal&&ie6){s.d.iframe=$('<iframe src="javascript:false;"></iframe>').css($.extend(s.o.iframeCss,{display:'none',opacity:0,position:'fixed',height:w[0],width:w[1],zIndex:s.o.zIndex,top:0,left:0})).appendTo(s.o.appendTo);}s.d.overlay=$('<div></div>').attr('id',s.o.overlayId).addClass('simplemodal-overlay').css($.extend(s.o.overlayCss,{display:'none',opacity:s.o.opacity/100,height:s.o.modal?w[0]:0,width:s.o.modal?w[1]:0,position:'fixed',left:0,top:0,zIndex:s.o.zIndex+1})).appendTo(s.o.appendTo);s.d.container=$('<div></div>').attr('id',s.o.containerId).addClass('simplemodal-container').css($.extend(s.o.containerCss,{display:'none',position:'fixed',zIndex:s.o.zIndex+2})).append(s.o.close&&s.o.closeHTML?$(s.o.closeHTML).addClass(s.o.closeClass):'').appendTo(s.o.appendTo);s.d.wrap=$('<div></div>').attr('tabIndex',-1).addClass('simplemodal-wrap').css({height:'100%',outline:0,width:'100%'}).appendTo(s.d.container);s.d.data=data.attr('id',data.attr('id')||s.o.dataId).addClass('simplemodal-data').css($.extend(s.o.dataCss,{display:'none'})).appendTo('body');data=null;s.setContainerDimensions();s.d.data.appendTo(s.d.wrap);if(ie6||ieQuirks){s.fixIE();}},bindEvents:function(){var s=this;$('.'+s.o.closeClass).bind('click.simplemodal',function(e){e.preventDefault();s.close();});if(s.o.modal&&s.o.close&&s.o.overlayClose){s.d.overlay.bind('click.simplemodal',function(e){e.preventDefault();s.close();});}$(document).bind('keydown.simplemodal',function(e){if(s.o.modal&&e.keyCode===9){s.watchTab(e);}else if((s.o.close&&s.o.escClose)&&e.keyCode===27){e.preventDefault();s.close();}});$(window).bind('resize.simplemodal',function(){w=s.getDimensions();s.setPosition();if(ie6||ieQuirks){s.fixIE();}else if(s.o.modal){s.d.iframe&&s.d.iframe.css({height:w[0],width:w[1]});s.d.overlay.css({height:w[0],width:w[1]});}});},unbindEvents:function(){$('.'+this.o.closeClass).unbind('click.simplemodal');$(document).unbind('keydown.simplemodal');$(window).unbind('resize.simplemodal');this.d.overlay.unbind('click.simplemodal');},fixIE:function(){var s=this,p=s.o.position;ie6&&s.o.bodyStretch&&$('body').css({height:'100%',width:'100%'});$.each([s.d.iframe||null,!s.o.modal?null:s.d.overlay,s.d.container],function(i,el){if(el){var bch='document.body.clientHeight',bcw='document.body.clientWidth',bsh='document.body.scrollHeight',bsl='document.body.scrollLeft',bst='document.body.scrollTop',bsw='document.body.scrollWidth',ch='document.documentElement.clientHeight',cw='document.documentElement.clientWidth',sl='document.documentElement.scrollLeft',st='document.documentElement.scrollTop',s=el[0].style;s.position='absolute';if(i<2){s.removeExpression('height');s.removeExpression('width');s.setExpression('height',''+bsh+' > '+bch+' ? '+bsh+' : '+bch+' + "px"');s.setExpression('width',''+bsw+' > '+bcw+' ? '+bsw+' : '+bcw+' + "px"');}else{var te,le;if(p&&p.constructor===Array){var top=p[0]?typeof p[0]==='number'?p[0].toString():p[0].replace(/px/,''):el.css('top').replace(/px/,'');te=top.indexOf('%')===-1?top+' + (t = '+st+' ? '+st+' : '+bst+') + "px"':parseInt(top.replace(/%/,''))+' * (('+ch+' || '+bch+') / 100) + (t = '+st+' ? '+st+' : '+bst+') + "px"';if(p[1]){var left=typeof p[1]==='number'?p[1].toString():p[1].replace(/px/,'');le=left.indexOf('%')===-1?left+' + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"':parseInt(left.replace(/%/,''))+' * (('+cw+' || '+bcw+') / 100) + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"';}}else{te='('+ch+' || '+bch+') / 2 - (this.offsetHeight / 2) + (t = '+st+' ? '+st+' : '+bst+') + "px"';le='('+cw+' || '+bcw+') / 2 - (this.offsetWidth / 2) + (t = '+sl+' ? '+sl+' : '+bsl+') + "px"';}s.removeExpression('top');s.removeExpression('left');s.setExpression('top',te);s.setExpression('left',le);}}});},focus:function(pos){var s=this,p=pos||'first';var input=$(':input:enabled:visible:'+p,s.d.wrap);setTimeout(function(){input.length>0?input.focus():s.d.wrap.focus();},10);},getDimensions:function(){var el=$(window);var h=$.browser.opera&&$.browser.version>'9.5'&&$.fn.jquery<'1.3'||$.browser.opera&&$.browser.version<'9.5'&&$.fn.jquery>'1.2.6'?el[0].innerHeight:el.height();return[h,el.width()];},getVal:function(v){return typeof v==='number'?v:v==='auto'?0:v.indexOf('%')>0?v:parseInt(v.replace(/px/,''));},update:function(height,width){var s=this;if(!s.d.data){return false;}s.d.data.hide();height&&s.d.container.css('height',height);width&&s.d.container.css('width',width);s.setContainerDimensions();s.d.data.show();s.o.focus&&s.focus();s.unbindEvents();s.bindEvents();},setContainerDimensions:function(){var s=this;var ch=$.browser.opera?s.d.container.height():s.getVal(s.d.container.css('height')),cw=$.browser.opera?s.d.container.width():s.getVal(s.d.container.css('width')),dh=s.d.data.outerHeight(true),dw=s.d.data.outerWidth(true);var mh=s.o.maxHeight&&s.getVal(s.o.maxHeight)<w[0]?s.getVal(s.o.maxHeight):w[0],mw=s.o.maxWidth&&s.getVal(s.o.maxWidth)<w[1]?s.getVal(s.o.maxWidth):w[1];var moh=s.o.minHeight?s.getVal(s.o.minHeight):'auto';if(!ch){if(!dh){ch=moh;}else{if(dh>mh){ch=mh;}else if(s.o.minHeight&&moh!=='auto'&&dh<moh){ch=moh;}else{ch=dh;}}}else{ch=ch>mh?mh:ch;}var mow=s.o.minWidth?s.getVal(s.o.minWidth):'auto';if(!cw){if(!dw){cw=mow;}else{if(dw>mw){cw=mw;}else if(s.o.minWidth&&mow!=='auto'&&dw<mow){cw=mow;}else{cw=dw;}}}else{cw=cw>mw?mw:cw;}s.d.container.css({height:ch,width:cw});s.d.wrap.css({overflow:(dh>ch||dw>cw)?'auto':'visible'});s.setPosition();},setPosition:function(){var s=this,top,left,hc=(w[0]/2)-(s.d.container.outerHeight(true)/2),vc=(w[1]/2)-(s.d.container.outerWidth(true)/2);if(s.o.position&&Object.prototype.toString.call(s.o.position)==="[object Array]"){top=s.o.position[0]||hc;left=s.o.position[1]||vc;}else{top=hc;left=vc;}s.d.container.css({left:left,top:top});},watchTab:function(e){var s=this;if($(e.target).parents('.simplemodal-container').length>0){s.inputs=$(':input:enabled:visible:first, :input:enabled:visible:last',s.d.data[0]);if((!e.shiftKey&&e.target===s.inputs[s.inputs.length-1])||(e.shiftKey&&e.target===s.inputs[0])||s.inputs.length===0){e.preventDefault();var pos=e.shiftKey?'last':'first';s.focus(pos);}}else{e.preventDefault();s.focus();}},open:function(){var s=this;s.d.iframe&&s.d.iframe.show();if($.isFunction(s.o.onOpen)){s.o.onOpen.apply(s,[s.d]);}else{s.d.overlay.show();s.d.container.show();s.d.data.show();}s.o.focus&&s.focus();s.bindEvents();},close:function(){var s=this;if(!s.d.data){return false;}s.unbindEvents();if($.isFunction(s.o.onClose)&&!s.occb){s.occb=true;s.o.onClose.apply(s,[s.d]);}else{if(s.d.placeholder){var ph=$('#simplemodal-placeholder');if(s.o.persist){ph.replaceWith(s.d.data.removeClass('simplemodal-data').css('display',s.display));}else{s.d.data.hide().remove();ph.replaceWith(s.d.orig);}}else{s.d.data.hide().remove();}s.d.container.hide().remove();s.d.overlay.hide();s.d.iframe&&s.d.iframe.hide().remove();setTimeout(function(){s.d.overlay.remove();s.d={};},10);}}};})(jQuery);
View
33 test/js/simplemodal.js
@@ -125,6 +125,39 @@ $(document).ready(function () {
e.preventDefault();
$('#modalContentTest').modal({modal:false});
});
+ $('a#test29').click(function (e) {
+ e.preventDefault();
+ $('#modalContentTest').modal({
+ onShow: function (d) {
+ var m = this;
+ $('input.animate', d.data[0]).click(function () {
+ $('#modalContentTest', d.container[0]).html($('#modalContentOverflowTest').html());
+ m.update('auto', '600px');
+
+ $('input.animate', d.data[0]).click(function () {
+ $('#modalContentTest', d.container[0]).html($('#modalContentPersistTest').html());
+ m.update('auto', 'auto');
+ return false;
+ });
+
+ return false;
+ });
+ }
+ });
+ });
+ $('a#test30').click(function (e) {
+ e.preventDefault();
+ $('#modalContentTest').modal({
+ onShow: function (d) {
+ var m = this;
+ $('input.animate', d.data[0]).click(function () {
+ $('form', d.data[0]).after('<h1>Test</h1><p>Test<br/>Test</br></p>');
+ m.update('auto');
+ return false;
+ });
+ }
+ });
+ });
});
/**
View
2  version.txt
@@ -1 +1 @@
-1.3.5
+1.3.6b
Please sign in to comment.
Something went wrong with that request. Please try again.