Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to show a LeanModal from a function call #26

Open
ghost opened this issue Dec 22, 2012 · 2 comments
Open

Is it possible to show a LeanModal from a function call #26

ghost opened this issue Dec 22, 2012 · 2 comments

Comments

@ghost
Copy link

ghost commented Dec 22, 2012

Have a scenario where I need to show a leanModal instance - but this time it is not because of a CLICK but because of another dom event.

How do I do that?

@Tizianol8
Copy link

I resolve "triggering" click event on a hided link that point to my modal window...

@kayaz
Copy link

kayaz commented Oct 5, 2014

(function($){
    $.fn.extend({
        leanModal:function(options){
                var defaults={
                    top:100,
                    overlay:0.5,
                    target:null,
                    closeButton:null,
                    auto:false
                    };
                var overlay=$("<div id='lean_overlay'></div>");

                $("body").append(overlay);
                options=$.extend(defaults,options);
                var o=options;
                if(o.auto == true) {
                        var modal_id=o.target;
                        $("#lean_overlay").click(function(){close_modal(modal_id)});
                        $(o.closeButton).click(function(e){close_modal(modal_id);e.preventDefault();});
                        var modal_height=$(modal_id).outerHeight();
                        var modal_width=$(modal_id).outerWidth();

                        $("#lean_overlay").css({"display":"block",opacity:0});
                        $("#lean_overlay").fadeTo(200,o.overlay);
                        $(modal_id).css({"display":"block","position":"fixed","opacity":0,"z-index":11000,"left":50+"%","margin-left":-(modal_width/2)+"px","top":o.top+"px"});
                        $(modal_id).fadeTo(200,1);
                }
                if(o.auto == false) {
                    return this.each(function(){
                        $(this).click(function(e){
                            var modal_id=$(this).attr("href");
                            $("#lean_overlay").click(function(){close_modal(modal_id)});
                            $(o.closeButton).click(function(e){close_modal(modal_id);e.preventDefault();});
                            var modal_height=$(modal_id).outerHeight();
                            var modal_width=$(modal_id).outerWidth();

                            $("#lean_overlay").css({"display":"block",opacity:0});
                            $("#lean_overlay").fadeTo(200,o.overlay);
                            $(modal_id).css({"display":"block","position":"fixed","opacity":0,"z-index":11000,"left":50+"%","margin-left":-(modal_width/2)+"px","top":o.top+"px"});
                            $(modal_id).fadeTo(200,1);
                            e.preventDefault()
                        })
                    });
                }
                function close_modal(modal_id){
                    $("#lean_overlay").fadeOut(200);$(modal_id).css({"display":"none"})
                }
            }
            })
            })(jQuery);

and then:

    $("").leanModal({top:200, target:"#thxforsend", closeButton: ".modal_close", auto:true});
    $("a[rel*=leanModal]").leanModal({top:200, closeButton: ".modal_close"});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants