Skip to content

Instantly share code, notes, and snippets.

@cowlby
Created November 19, 2009 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cowlby/238576 to your computer and use it in GitHub Desktop.
Save cowlby/238576 to your computer and use it in GitHub Desktop.
Collection of code snippets
(function() {
var keys = new Hash({ 16: false, 18: false }); // Shift + Option/Alt keys
if (Browser.Platform.win) { keys[17] = false; } // Control key
if (Browser.Platform.mac) { keys[91] = false; } // Command Key
window.addEvent('domready', function() {
$(document.body).addEvents({
'keydown': function(e) {
if (keys.has(e.code)) { keys[e.code] = true; }
},
'keyup': function(e) {
if (keys.has(e.code)) { keys[e.code] = false; }
}
})
});
Element.Events.cleanclick = {
base: 'click',
condition: function(e) { return !keys.hasValue(true) }
}
})();
(function(){
window.location = 'http://'+decodeURIComponent(document.location.search.substring(5));
})();
(function() {
Screensaver = new Class({
Implements: [Options, Events],
options: {/*
onActive: $empty,
onIdle: $empty,*/
events: ['click', 'keypress', 'mousemove', 'resize', 'scroll'],
target: window,
ttl: 10000
},
initialize: function(options) {
this.setOptions(options);
this.enabled = false;
var target = document.id(this.options.target);
this.options.events.each(function(ev) {
target.addEvent(ev, this.reset.bind(this));
}, this);
this.monitor();
},
monitor: function() {
this.timer = this.display.delay(this.options.ttl, this);
},
reset: function() {
$clear(this.timer);
if (this.enabled) {
this.fireEvent('active');
this.enabled = false;
}
this.monitor();
},
display: function() {
this.fireEvent('idle');
this.enabled = true;
}
});
Element.implement({
screensave: function(options) {
options.target = this;
return new Screensaver(options)
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment