tags:

views:

39

answers:

3

I have the following function in Javascript:

$find('mainWindow').repaint();

I need to run that inside this jQuery function:

    $("#tools").click(function() {
        if(get_cookie('visible')== null) {
            set_cookie('visible','no',2020,1,1,'/','.domain');
            $("#WinMain").animate({top: "25px"}, 200);
            **<!--INSERT FIND-->**
        } else {
            delete_cookie('visible','/','.domain');
            $("#WinMain").animate({top: "89px"}, 200);
            **<!--INSERT FIND-->**
        }
A: 

jQuery is JavaScript, so you can just insert your JavaScript call:

$("#tools").click(function() { 
    if(get_cookie('visible')== null) { 
        set_cookie('visible','no',2020,1,1,'/','.domain'); 
        $("#WinMain").animate({top: "25px"}, 200); 
    } else { 
        delete_cookie('visible','/','.domain'); 
        $("#WinMain").animate({top: "89px"}, 200); 
    }
    $find('mainWindow').repaint(); 
});

Note that I have put it after the if statement, as you wanted it put in both the true and false branch of the if statement.

Is there more to your question?

Mario Menger
A: 

Why not just

    $("#tools").click(function() {
        if(get_cookie('visible')== null) {
            set_cookie('visible','no',2020,1,1,'/','.domain');
            $("#WinMain").animate({top: "25px"}, 200);
        } else {
            delete_cookie('visible','/','.domain');
            $("#WinMain").animate({top: "89px"}, 200);
        }
        $find('mainWindow').repaint();

? Does this not work? What problems are you having?

Skilldrick
+1  A: 

A click handler is just that, an event handler...no one said you can have only one :) If multiple are attached, they'll run in the order they were bound...so if you can't modify that function, just attach your own .click() handler after the current one, like this:

$("#tools").click(function() {
  if(get_cookie('visible')== null) {
    set_cookie('visible','no',2020,1,1,'/','.domain');
    $("#WinMain").animate({top: "25px"}, 200);
  } else {
    delete_cookie('visible','/','.domain');
    $("#WinMain").animate({top: "89px"}, 200);
  }
});
//add your own handler later:
$("#tools").click(function() {
  $('#mainWindow').repaint();
});

I'm not really sure what $find('mainWindow') stood for, so I'm doing a bit of guessing in the handler above, grabbing it by ID. If you can modify the original handler, just stick the code you want to run in where you have placeholder comments now now.

Nick Craver