Thompson
Thompson

Reputation: 2000

Confused in calling this function in jQuery

I have one jQuery code as,

<script type="text/javascript">
$.idleTimeout('#idletimeout', '#idletimeout a', {
  idleAfter: 3,
  pollingInterval: 2,
  keepAliveURL: 'keepalive.php',
  serverResponseEquals: 'OK',
  onTimeout: function(){
    $(this).slideUp();
    window.location = "timeout.htm";
  },
  onIdle: function(){
    $(this).slideDown(); // show the warning bar
  },
  onCountdown: function( counter ){
    $(this).find("span").html( counter ); // update the counter
  },
  onResume: function(){
    $(this).slideUp(); // hide the warning bar
  }
});
//
</script>

Now if I call this, it's hiding the slider.

function loadXMLDoc(message)
{
$.get("test1.php?data="+message, function(result){

$('#idletimeout').slideUp(); // hide
    });
}
</script>

Is there any way to call onResume function (on top) in loadXMLDoc function? Thanks.

Upvotes: -1

Views: 765

Answers (1)

Bill
Bill

Reputation: 25555

Looking at the plug-in, it binds the resume function to the click handler of the second parameter that is passed in ('#idletimeout a' in your case). If you wanted to reset the timer manually, you should be able to just do:

$('#idletimeout a').click();

This will trigger the onResume function which will slide the div up and reset the timer.

For reference, I just took a look at the source code for the plug-in to see what was going on. You can see the relevant portion here. This is what happens when the resume element (the second parameter) is clicked on:

// bind continue link
this.resume.bind("click", function(e){
    e.preventDefault();

    win.clearInterval(self.countdown); // stop the countdown
    self.countdownOpen = false; // stop countdown
    self._startTimer(); // start up the timer again
    self._keepAlive( false ); // ping server
    options.onResume.call( self.warning ); // call the resume callback
}); 

If you just wanted to call it directly (and not have any of the internals of resetting the timer happen) you could do this as well:

var idlePlugin = $.idleTimeout('#idletimeout', '#idletimeout a', { ...

idlePlugin.options.onResume.call();

But keep in mind that this won't reset the timer, it will just call the onResume function directly. The only way to reset the timer is to call the click handler since that is where this functionality is defined.

Upvotes: 2

Related Questions