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.

Rookian
  • 19,841
  • 28
  • 110
  • 180

7 Answers7

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.

Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
  • unfortunately this does not work for me. I edited my question. Maybe you know what is wrong there. – Rookian Jul 16 '10 at 16:18
  • @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 Jul 16 '10 at 16:32
  • 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 Jul 18 '10 at 11:48
  • 2
    @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 Jul 18 '10 at 12:04
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();
serg
  • 109,619
  • 77
  • 317
  • 330
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();
coderazzi
  • 51
  • 1
  • 2
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

Umesh Aawte
  • 4,590
  • 7
  • 41
  • 51
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

Parrots
  • 26,658
  • 14
  • 59
  • 78
Kowlown
  • 920
  • 10
  • 26
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'
 });    
Bo Persson
  • 90,663
  • 31
  • 146
  • 203
fivefty
  • 11
  • 1
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();
}
Reza Shek
  • 581
  • 1
  • 8
  • 18