jQuery Tools: How to close an overlay?
Asked Answered
E

7

9
$("a[rel]").getOverlay().close();
$("a[rel]").close();

Both don't work.

$(document).ready(function () {
        $("a[rel]").overlay({
            mask: '#3B5872',
            effect: 'apple',
            onBeforeLoad: function () {
                var wrap = this.getOverlay().find(".contentWrap");
                wrap.load(this.getTrigger().attr("href"));
            },
            onLoad: function () {
                $('.contentWrap form').submit(function (event) {
                    event.preventDefault();
                    $("a[rel]").overlay().close();
                    hijack(this, update_employees, "html");
                });
            }
        });
    });

    function hijack(form, callback, format) {
        $.ajax({
            url: form.action,
            type: form.method,
            dataType: format,
            data: $(form).serialize(),
            success: callback
        });
    }

    function update_employees(result) {
        $("#gridcontainer").html(result);
    }

Any suggestions?

I use Chrome because the onLoad event seems not work correctly in FF.

Erasion answered 16/7, 2010 at 16:4 Comment(0)
O
18

Like this:

$("a[rel]").overlay().close();

For most of their scripting you call the original method, e.g. .overlay() then call the method you want on that object.

Orchestral answered 16/7, 2010 at 16:10 Comment(4)
unfortunately this does not work for me. I edited my question. Maybe you know what is wrong there.Erasion
@Erasion - Are you getting a javascript error elsewhere? The api is pretty straight forward, I tested the above against several sites...looks like something else is interfering.Orchestral
I have found the problem. I have more then one "a[rel]" element in my page. I have several edit buttons in a table and a create button that matches the "a[rel]" selector. How do I detect which "a[rel]" element is clicked or how do I cache the jQuery overlay that is popped up?Erasion
@Erasion - It should close all of them, but you could add a click handler to a[rel], like this: var overlayElem; $('a[rel]').click(function() { overlayElem = $(this); }); then when you want to close, overlayElem.overlay().close();, overlayElem being a global variable holding the last opened overlay.Orchestral
K
10

You need to set api:true in properties if you want to close it from js:

var overlay = $("a[rel]").overlay({
    ...
    api:true
});

overlay.close();
Kaohsiung answered 16/7, 2010 at 17:1 Comment(1)
Works for me. Closes overlay by class name. Thanks!Dhiman
B
5

The problem, in case of assigning the overlay to a class, is that there will be many overlay elements, so all must be closed:

$.each($(".caddy_grid"), function(i, v){$(v).overlay().close();})

Alternatively, it is possible to simulate a click on the close button:

The class that triggers the overlay in my case is caddy_grid_overlay, so the close button can be accessed as:

$('.caddy_grid_overlay .close').click();
Baty answered 20/7, 2011 at 2:50 Comment(0)
T
2

Try

$("a[rel]").data("overlay").close();

I use this to close my overlays.

source : http://forum.jquery.com/topic/having-trouble-timing-jquery-tools-overlay-to-close-after-a-few-seconds

Taylor answered 5/9, 2011 at 16:30 Comment(0)
A
2

It will work for you, Please refer code here,

var api = $("a[rel]").data("overlay");

api.close();//close this overlay

Reference :

http://jquerytools.org/documentation/overlay/index.html#api

http://jquerytools.org/documentation/scripting.html

Adachi answered 19/6, 2012 at 4:21 Comment(0)
B
1
 $(document).ready(function() { 
    var overlayObject = $("a[rel]").overlay({ 
        top: 50,
        expose: {
                    color: '#232323',
                    closeOnClick: true
                },

                onClose:function() {   
                    $('#reg-login').hide();
                    $('#reg-register').hide();
                },
        effect: 'apple'
 });    
Batruk answered 27/3, 2012 at 22:20 Comment(0)
R
0

you can create a function and call it from anywher you want.

this function gonna work based on class name and a link.

function closeOverlay() { alert('aa'); var overlay = $(\"a.ShowOverlay\").overlay({ api:true });

    overlay.close();
}
Rogozen answered 24/12, 2014 at 21:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.