From ff8e140bf91e2f9b72d01a397708ad1946c82320 Mon Sep 17 00:00:00 2001 From: Josiah Bond Date: Wed, 3 Aug 2011 04:05:59 +1000 Subject: [PATCH 1/2] Added support for ajax requests --- jquery.leanModal.js | 78 ++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/jquery.leanModal.js b/jquery.leanModal.js index ea74cf1..a9f48b5 100644 --- a/jquery.leanModal.js +++ b/jquery.leanModal.js @@ -1,4 +1,5 @@ (function($){ + var modal_no = 0; $.fn.extend({ @@ -16,43 +17,60 @@ var o = options; $(this).click(function(e) { - - var overlay = $("
"); - - var modal_id = $(this).attr("href"); + + $("body").append("
"); - $("body").append(overlay); - - $("#lean_overlay").click(function() { - close_modal(modal_id); + $this = $(this); + var href = $this.attr("href"); + + if(href.substr(0,1) == '#') + { + show_modal(href, o); + } + else + { + (function(){ + id = "modal-dialog-"+(modal_no++); + $(document.createElement('div')) + .appendTo('body') + .css({'display': 'none'}) + .attr('id',id) + .load(href,function(){show_modal("#"+id, o);}); + $this.attr('href',"#"+id); + })(); + } + + e.preventDefault(); + }); - - var modal_height = $(modal_id).outerHeight(); - var modal_width = $(modal_id).outerWidth(); + }); - $('#lean_overlay').css({ 'display' : 'block', opacity : 0 }); + function show_modal(modal_id, options){ + $("#lean_overlay").click(function() { + close_modal(modal_id); + }); + + var modal_height = $(modal_id).outerHeight(); + var modal_width = $(modal_id).outerWidth(); - $('#lean_overlay').fadeTo(200,o.overlay); + $('#lean_overlay').css({ 'display' : 'block', opacity : 0 }); - $(modal_id).css({ - - 'display' : 'block', - 'position' : 'fixed', - 'opacity' : 0, - 'z-index': 11000, - 'left' : 50 + '%', - 'margin-left' : -(modal_width/2) + "px", - 'top' : o.top + "px" - - }); + $('#lean_overlay').fadeTo(200,options.overlay); - $(modal_id).fadeTo(200,1); + $(modal_id).css({ + + 'display' : 'block', + 'position' : 'fixed', + 'opacity' : 0, + 'z-index': 11000, + 'left' : 50 + '%', + 'margin-left' : -(modal_width/2) + "px", + 'top' : options.top + "px" + + }); - e.preventDefault(); - - }); - - }); + $(modal_id).fadeTo(200,1); + } function close_modal(modal_id){ From 36a8090d7c1c786f0c87131b16c01617b48d5198 Mon Sep 17 00:00:00 2001 From: Josiah Bond Date: Tue, 23 Aug 2011 09:08:52 +1000 Subject: [PATCH 2/2] Dailed donw the z-index slightly to prevent conflict with CKEditor. --- jquery.leanModal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.leanModal.js b/jquery.leanModal.js index a9f48b5..9f47cc6 100644 --- a/jquery.leanModal.js +++ b/jquery.leanModal.js @@ -62,7 +62,7 @@ 'display' : 'block', 'position' : 'fixed', 'opacity' : 0, - 'z-index': 11000, + 'z-index': 9999, 'left' : 50 + '%', 'margin-left' : -(modal_width/2) + "px", 'top' : options.top + "px"