Clone wiki

jquery.wakeup plugin / Home

JQuery.wakeup plugin

A JQuery plugin that will help detecting waking up from sleep and/or hibernation and executing assigned functions.

Based on code provided by Andrew Mu: http://stackoverflow.com/questions/4079115

Including

<script src="jquery.min.js" />
<script src="jquery.wakeup.js" />

Usage

$.wakeUp(callback_function, parameters, interval);

Examples

// assign a handler function to be executed after waking up
var bell_id = $.wakeUp(function(sleep_time) {
    alert("I have slept for " + sleep_time/1000 + " seconds")
});

// remove this handler
$.ignoreBell(bell_id);

// remove all handlers
$.dreamOn();

In complex applications (such as RIA) use additional parameter interval (time in miliseconds) to prevent plugin from glitching.

You can also pass additional parameters object to a handler function.

var bell_id = $.wakeUp(function(sleep_time, params) {
    alert("Hello " + params[name] + ", I've slept for " + sleep_time/1000 + " seconds.")
}, {name: "Paul"}, 300 000);

Updated