Skip to content

Instantly share code, notes, and snippets.

@cowlby
Created November 18, 2009 21:31
Show Gist options
  • Save cowlby/238281 to your computer and use it in GitHub Desktop.
Save cowlby/238281 to your computer and use it in GitHub Desktop.
/**
* Script:
* Screensaver.js - Screensaver functionality written in MooTools.
*
* License:
* MIT-style license.
*
* Author:
* Jose Prado
*
* Copyright:
* Copyright (©) 2009 [Jose Prado](http://pradador.com/).
*
*/
var Screensaver = new Class({
Implements: [Options, Events],
options: { time: 10000 },
initialize: function(show, hide, options) {
this.setOptions(options);
this.show = show;
this.hide = hide;
this.enabled = false;
window.addEvents({
'click': this.reset.bind(this),
'keypress': this.reset.bind(this),
'mousemove': this.reset.bind(this)
});
this.start();
},
start: function() { this.clearID = this.display.delay(this.options.time, this); },
reset: function() {
$clear(this.clearID);
if (this.enabled) {
this.hide();
this.enabled = false;
this.fireEvent('hide');
}
this.start();
this.fireEvent('reset');
},
display: function() {
this.show();
this.enabled = true;
this.fireEvent('show');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment