views:

86

answers:

2
$("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.

+3  A: 

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.

Nick Craver
unfortunately this does not work for me. I edited my question. Maybe you know what is wrong there.
Rookian
@Rookian - 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.
Nick Craver
no there is no error.
Rookian
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?
Rookian
@Rookian - 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.
Nick Craver
thank you very much Nick Craver =)
Rookian
+1  A: 

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();
serg
this does not work too :( The overlay is still open
Rookian