From 0c7da49f880f1f163c8fe58f53c05b2b25bae989 Mon Sep 17 00:00:00 2001 From: Kyle Fox Date: Wed, 22 Feb 2012 21:54:13 -0700 Subject: [PATCH] Bumped to v0.4 --- jquery.modal.js | 2 +- jquery.modal.min.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jquery.modal.js b/jquery.modal.js index fbe9dd2..d772974 100644 --- a/jquery.modal.js +++ b/jquery.modal.js @@ -1,6 +1,6 @@ /* A simple jQuery modal (http://github.com/kylefox/jquery-modal) - Version 0.3.1 + Version 0.4 */ (function($) { diff --git a/jquery.modal.min.js b/jquery.modal.min.js index 7a72468..3606744 100644 --- a/jquery.modal.min.js +++ b/jquery.modal.min.js @@ -1,5 +1,5 @@ /* A simple jQuery modal (http://github.com/kylefox/jquery-modal) - Version 0.3.1 + Version 0.4 */ -(function($){var current_modal=null;var open_modal_from_link=function(event){event.preventDefault();var target=$(this).attr('href');if(/^#/.test(target)){$(target).modal()}else{$.get(target,{},function(html){$('
').html(html).appendTo('body').on($.modal.CLOSE,function(event,modal){modal.elm.remove()}).modal()})}};var center_modal=function(modal){modal.elm.css({position:'fixed',top:"50%",left:"50%",marginTop:-(modal.elm.outerHeight()/2),marginLeft:-(modal.elm.outerWidth()/2),zIndex:modal.options.zIndex+1})};$.modal=function(el,options){var self=this;this.$elm=el;this.options=$.extend({},$.modal.defaults,options);if(this.$elm.attr('href')){this.$elm.click(open_modal_from_link);return}this.block=function(){current_modal.blocker=$('
').css({top:0,right:0,bottom:0,left:0,width:"100%",height:"100%",position:"fixed",zIndex:self.options.zIndex,background:self.options.overlay,opacity:self.options.opacity});if(self.options.escapeClose){$(document).on('keydown.modal',function(event){if(event.which==27){$.modal.close()}})}if(self.options.clickClose){current_modal.blocker.click($.modal.close)}$('body').append(current_modal.blocker);self.$elm.trigger($.modal.BLOCK,[current_modal])};this.show=function(){center_modal(current_modal);if(self.options.showClose){current_modal.closeButton=$(''+self.options.closeText+'');current_modal.elm.append(current_modal.closeButton)}self.$elm.addClass(self.options.modalClass+' current').show();self.$elm.trigger($.modal.OPEN,[current_modal])};current_modal={elm:this.$elm,options:this.options};this.$elm.trigger($.modal.BEFORE_BLOCK,[current_modal]);this.block();this.$elm.trigger($.modal.BEFORE_OPEN,[current_modal]);this.show()};$.modal.defaults={overlay:"#000",opacity:0.75,zIndex:1,escapeClose:true,clickClose:true,closeText:'Close',modalClass:"modal",showClose:true};$.modal.BEFORE_BLOCK='modal:before-block';$.modal.BLOCK='modal:block';$.modal.BEFORE_OPEN='modal:before-open';$.modal.OPEN='modal:open';$.modal.BEFORE_CLOSE='modal:before-close';$.modal.CLOSE='modal:close';$.modal.close=function(){if(event){event.preventDefault()}if(!current_modal){return}current_modal.elm.trigger($.modal.BEFORE_CLOSE,[current_modal]);if(current_modal.closeButton){current_modal.closeButton.remove()}current_modal.blocker.remove();current_modal.elm.removeClass('current').hide();current_modal.elm.trigger($.modal.CLOSE,[current_modal]);current_modal=null;$(document).off('keydown.modal')};$.modal.resize=function(){center_modal(current_modal)};$.fn.modal=function(options){new $.modal(this,options)};$(document).on('click','a[rel="modal:open"]',open_modal_from_link);$(document).on('click','a[rel="modal:close"]',$.modal.close)})(jQuery); \ No newline at end of file +(function($){var current=null;$.modal=function(el,options){var remove,target;this.options=$.extend({},$.modal.defaults,options);if(el.is('a')){target=el.attr('href');if(/^#/.test(target)){this.$elm=$(target);if(this.$elm.length!==1)return null;this.open()}else{this.$elm=$('
');remove=function(event,modal){modal.elm.remove()};$.get(target,function(html){if(!current)return;current.$elm.html(html).appendTo('body').on($.modal.CLOSE,remove);current.open()})}}else{this.$elm=el;this.open()}};$.modal.prototype={constructor:$.modal,open:function(){this.block();this.show();if(this.options.escapeClose){$(document).on('keydown.modal',function(event){if(event.which==27)$.modal.close()})}if(this.options.clickClose)this.blocker.click($.modal.close)},close:function(){this.unblock();this.hide();$(document).off('keydown.modal')},block:function(){this.$elm.trigger($.modal.BEFORE_BLOCK,[this._ctx()]);this.blocker=$('
').css({top:0,right:0,bottom:0,left:0,width:"100%",height:"100%",position:"fixed",zIndex:this.options.zIndex,background:this.options.overlay,opacity:this.options.opacity});$('body').append(this.blocker);this.$elm.trigger($.modal.BLOCK,[this._ctx()])},unblock:function(){this.blocker.remove()},show:function(){this.$elm.trigger($.modal.BEFORE_OPEN,[this._ctx()]);if(this.options.showClose){this.closeButton=$(''+this.options.closeText+'');this.$elm.append(this.closeButton)}this.$elm.addClass(this.options.modalClass+' current');this.center();this.$elm.show().trigger($.modal.OPEN,[this._ctx()])},hide:function(){this.$elm.trigger($.modal.BEFORE_CLOSE,[this._ctx()]);if(this.closeButton)this.closeButton.remove();this.$elm.removeClass('current').hide();this.$elm.trigger($.modal.CLOSE,[this._ctx()])},center:function(){this.$elm.css({position:'fixed',top:"50%",left:"50%",marginTop:-(this.$elm.outerHeight()/2),marginLeft:-(this.$elm.outerWidth()/2),zIndex:this.options.zIndex+1})},_ctx:function(){return{elm:this.$elm,blocker:this.blocker,options:this.options}}};$.modal.prototype.resize=$.modal.prototype.center;$.modal.close=function(event){if(!current)return;if(event)event.preventDefault();current.close();current=null};$.modal.resize=function(){if(!current)return;current.resize()};$.modal.defaults={overlay:"#000",opacity:0.75,zIndex:1,escapeClose:true,clickClose:true,closeText:'Close',modalClass:"modal",showClose:true};$.modal.BEFORE_BLOCK='modal:before-block';$.modal.BLOCK='modal:block';$.modal.BEFORE_OPEN='modal:before-open';$.modal.OPEN='modal:open';$.modal.BEFORE_CLOSE='modal:before-close';$.modal.CLOSE='modal:close';$.fn.modal=function(options){if(this.length===1){current=new $.modal(this,options)}return this};$(document).on('click','a[rel="modal:close"]',$.modal.close);$(document).on('click','a[rel="modal:open"]',function(event){event.preventDefault();$(this).modal()})})(jQuery); \ No newline at end of file