diff --git a/messi.js b/messi.js
index 60a7285..cfbbb05 100644
--- a/messi.js
+++ b/messi.js
@@ -94,12 +94,14 @@ function Messi(data, options) {
if(_this.options.show) _this.show();
// controlamos el redimensionamiento de la pantalla
- jQuery(window).bind('resize', function(){ _this.resize(); });
+ jQuery(window).bind('resize scroll', function(){ _this.resize(); });
// configuramos el cierre automático
if(_this.options.autoclose != null) {
setTimeout(function(_this) {
- _this.hide();
+ var value = jQuery.data(this, 'value');
+ var after = (_this.options.callback != null) ? function () { _this.options.callback(value); } : null;
+ _this.hide(after);
}, _this.options.autoclose, this);
};
@@ -199,7 +201,7 @@ Messi.prototype = {
unload: function() {
if (this.visible) this.hide();
- jQuery(window).unbind('resize', function () { this.resize(); });
+ jQuery(window).unbind('resize scroll', function () { this.resize(); });
this.messi.remove();
},
diff --git a/messi.min.js b/messi.min.js
index ae5693d..875c2f4 100644
--- a/messi.min.js
+++ b/messi.min.js
@@ -8,4 +8,4 @@
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
-function Messi(e,t){var n=this;n.options=jQuery.extend({},Messi.prototype.options,t||{});n.messi=jQuery(n.template);n.setContent(e);if(n.options.title==null){jQuery(".messi-titlebox",n.messi).remove()}else{jQuery(".messi-title",n.messi).append(n.options.title);if(n.options.buttons.length===0&&!n.options.autoclose){if(n.options.closeButton){var r=jQuery('');r.bind("click",function(){n.hide()});jQuery(".messi-titlebox",this.messi).prepend(r)}}if(n.options.titleClass!=null)jQuery(".messi-titlebox",this.messi).addClass(n.options.titleClass)}if(n.options.width!=null)jQuery(".messi-box",n.messi).css("width",n.options.width);if(n.options.buttons.length>0){for(var i=0;i").data("value",n.options.buttons[i].val);o.bind("click",function(){var e=jQuery.data(this,"value");var t=n.options.callback!=null?function(){n.options.callback(e)}:null;n.hide(t)});jQuery(".messi-actions",this.messi).append(o)}}else{jQuery(".messi-footbox",this.messi).remove()}if(n.options.buttons.length===0&&n.options.title==null&&!n.options.autoclose){if(n.options.closeButton){var r=jQuery('');r.bind("click",function(){n.hide()});jQuery(".messi-content",this.messi).prepend(r)}}n.modal=n.options.modal?jQuery('').css({opacity:n.options.modalOpacity,width:jQuery(document).width(),height:jQuery(document).height(),"z-index":n.options.zIndex+jQuery(".messi").length}).appendTo(document.body):null;if(n.options.show)n.show();jQuery(window).bind("resize",function(){n.resize()});if(n.options.autoclose!=null){setTimeout(function(e){e.hide()},n.options.autoclose,this)}return n}Messi.prototype={options:{autoclose:null,buttons:[],callback:null,center:true,closeButton:true,height:"auto",title:null,titleClass:null,modal:false,modalOpacity:.2,padding:"10px",show:true,unload:true,viewport:{top:"0px",left:"0px"},width:"500px",zIndex:99999},template:'',content:"",visible:false,setContent:function(e){jQuery(".messi-content",this.messi).css({padding:this.options.padding,height:this.options.height}).empty().append(e)},viewport:function(){return{top:(jQuery(window).height()-this.messi.height())/2+jQuery(window).scrollTop()+"px",left:(jQuery(window).width()-this.messi.width())/2+jQuery(window).scrollLeft()+"px"}},show:function(){if(this.visible)return;if(this.options.modal&&this.modal!=null)this.modal.show();this.messi.appendTo(document.body);if(this.options.center)this.options.viewport=this.viewport(jQuery(".messi-box",this.messi));this.messi.css({top:this.options.viewport.top,left:this.options.viewport.left,"z-index":this.options.zIndex+jQuery(".messi").length}).show().animate({opacity:1},300);this.visible=true},hide:function(e){if(!this.visible)return;var t=this;this.messi.animate({opacity:0},300,function(){if(t.options.modal&&t.modal!=null)t.modal.remove();t.messi.css({display:"none"}).remove();t.visible=false;if(e)e.call();if(t.options.unload)t.unload()});return this},resize:function(){if(this.options.modal){jQuery(".messi-modal").css({width:jQuery(document).width(),height:jQuery(document).height()})}if(this.options.center){this.options.viewport=this.viewport(jQuery(".messi-box",this.messi));this.messi.css({top:this.options.viewport.top,left:this.options.viewport.left})}},toggle:function(){this[this.visible?"hide":"show"]();return this},unload:function(){if(this.visible)this.hide();jQuery(window).unbind("resize",function(){this.resize()});this.messi.remove()}};jQuery.extend(Messi,{alert:function(e,t,n){var r=[{id:"ok",label:"OK",val:"OK"}];n=jQuery.extend({closeButton:false,buttons:r,callback:function(){}},n||{},{show:true,unload:true,callback:t});return new Messi(e,n)},ask:function(e,t,n){var r=[{id:"yes",label:"Yes",val:"Y","class":"btn-success"},{id:"no",label:"No",val:"N","class":"btn-danger"}];n=jQuery.extend({closeButton:false,modal:true,buttons:r,callback:function(){}},n||{},{show:true,unload:true,callback:t});return new Messi(e,n)},img:function(e,t){var n=new Image;jQuery(n).load(function(){var e={width:jQuery(window).width()-50,height:jQuery(window).height()-50};var r=this.width>e.width||this.height>e.height?Math.min(e.width/this.width,e.height/this.height):1;jQuery(n).css({width:this.width*r,height:this.height*r});t=jQuery.extend(t||{},{show:true,unload:true,closeButton:true,width:this.width*r,height:this.height*r,padding:0});new Messi(n,t)}).error(function(){console.log("Error loading "+e)}).attr("src",e)},load:function(e,t){t=jQuery.extend(t||{},{show:true,unload:true,params:{}});var n={url:e,data:t.params,dataType:"html",cache:false,error:function(e,t,n){console.log(e.responseText)},success:function(e){new Messi(e,t)}};jQuery.ajax(n)}});
\ No newline at end of file
+function Messi(e,t){var n=this;n.options=jQuery.extend({},Messi.prototype.options,t||{});n.messi=jQuery(n.template);n.setContent(e);if(n.options.title==null){jQuery(".messi-titlebox",n.messi).remove()}else{jQuery(".messi-title",n.messi).append(n.options.title);if(n.options.buttons.length===0&&!n.options.autoclose){if(n.options.closeButton){var r=jQuery('');r.bind("click",function(){n.hide()});jQuery(".messi-titlebox",this.messi).prepend(r)}}if(n.options.titleClass!=null)jQuery(".messi-titlebox",this.messi).addClass(n.options.titleClass)}if(n.options.width!=null)jQuery(".messi-box",n.messi).css("width",n.options.width);if(n.options.buttons.length>0){for(var i=0;i").data("value",n.options.buttons[i].val);o.bind("click",function(){var e=jQuery.data(this,"value");var t=n.options.callback!=null?function(){n.options.callback(e)}:null;n.hide(t)});jQuery(".messi-actions",this.messi).append(o)}}else{jQuery(".messi-footbox",this.messi).remove()}if(n.options.buttons.length===0&&n.options.title==null&&!n.options.autoclose){if(n.options.closeButton){var r=jQuery('');r.bind("click",function(){n.hide()});jQuery(".messi-content",this.messi).prepend(r)}}n.modal=n.options.modal?jQuery('').css({opacity:n.options.modalOpacity,width:jQuery(document).width(),height:jQuery(document).height(),"z-index":n.options.zIndex+jQuery(".messi").length}).appendTo(document.body):null;if(n.options.show)n.show();jQuery(window).bind("resize scroll",function(){n.resize()});if(n.options.autoclose!=null){setTimeout(function(e){var v=jQuery.data(this,'value');var a=(e.options.callback!=null)?function(){e.options.callback(v);}:null;e.hide(a);},n.options.autoclose,this)}return n}Messi.prototype={options:{autoclose:null,buttons:[],callback:null,center:true,closeButton:true,height:"auto",title:null,titleClass:null,modal:false,modalOpacity:.2,padding:"10px",show:true,unload:true,viewport:{top:"0px",left:"0px"},width:"500px",zIndex:99999},template:'',content:"",visible:false,setContent:function(e){jQuery(".messi-content",this.messi).css({padding:this.options.padding,height:this.options.height}).empty().append(e)},viewport:function(){return{top:(jQuery(window).height()-this.messi.height())/2+jQuery(window).scrollTop()+"px",left:(jQuery(window).width()-this.messi.width())/2+jQuery(window).scrollLeft()+"px"}},show:function(){if(this.visible)return;if(this.options.modal&&this.modal!=null)this.modal.show();this.messi.appendTo(document.body);if(this.options.center)this.options.viewport=this.viewport(jQuery(".messi-box",this.messi));this.messi.css({top:this.options.viewport.top,left:this.options.viewport.left,"z-index":this.options.zIndex+jQuery(".messi").length}).show().animate({opacity:1},300);this.visible=true},hide:function(e){if(!this.visible)return;var t=this;this.messi.animate({opacity:0},300,function(){if(t.options.modal&&t.modal!=null)t.modal.remove();t.messi.css({display:"none"}).remove();t.visible=false;if(e)e.call();if(t.options.unload)t.unload()});return this},resize:function(){if(this.options.modal){jQuery(".messi-modal").css({width:jQuery(document).width(),height:jQuery(document).height()})}if(this.options.center){this.options.viewport=this.viewport(jQuery(".messi-box",this.messi));this.messi.css({top:this.options.viewport.top,left:this.options.viewport.left})}},toggle:function(){this[this.visible?"hide":"show"]();return this},unload:function(){if(this.visible)this.hide();jQuery(window).unbind("resize scroll",function(){this.resize()});this.messi.remove()}};jQuery.extend(Messi,{alert:function(e,t,n){var r=[{id:"ok",label:"OK",val:"OK"}];n=jQuery.extend({closeButton:false,buttons:r,callback:function(){}},n||{},{show:true,unload:true,callback:t});return new Messi(e,n)},ask:function(e,t,n){var r=[{id:"yes",label:"Yes",val:"Y","class":"btn-success"},{id:"no",label:"No",val:"N","class":"btn-danger"}];n=jQuery.extend({closeButton:false,modal:true,buttons:r,callback:function(){}},n||{},{show:true,unload:true,callback:t});return new Messi(e,n)},img:function(e,t){var n=new Image;jQuery(n).load(function(){var e={width:jQuery(window).width()-50,height:jQuery(window).height()-50};var r=this.width>e.width||this.height>e.height?Math.min(e.width/this.width,e.height/this.height):1;jQuery(n).css({width:this.width*r,height:this.height*r});t=jQuery.extend(t||{},{show:true,unload:true,closeButton:true,width:this.width*r,height:this.height*r,padding:0});new Messi(n,t)}).error(function(){console.log("Error loading "+e)}).attr("src",e)},load:function(e,t){t=jQuery.extend(t||{},{show:true,unload:true,params:{}});var n={url:e,data:t.params,dataType:"html",cache:false,error:function(e,t,n){console.log(e.responseText)},success:function(e){new Messi(e,t)}};jQuery.ajax(n)}});