Created
November 19, 2009 05:55
-
-
Save cowlby/238576 to your computer and use it in GitHub Desktop.
Collection of code snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) } | |
} | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
window.location = 'http://'+decodeURIComponent(document.location.search.substring(5)); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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