Skip to content

Instantly share code, notes, and snippets.

Element.addMethods({
observeAll: function(element, eventHandlers){
$H(eventHandlers).each(function(handler){
Event.observe(element, handler.key, handler.value);
});
},
stopObservingAll: function(element, eventHandlers){
$H(eventHandlers).each(function(handler){
Event.stopObserving(element, handler.key, handler.value);
});
Element.addMethods({
isVisible: function(element){
return !$(element).getStyle('visibility').match('hidden');
},
makeVisible: function(element){
//IE doesn't work with others, so we don't handle them
return $(element).setStyle({visibility: 'visible'});
},
InputOnChange = Class.create({
initialize: function(elementToWatch, functionToExecute, delay){
this.id = null;
this.functionToExecute = functionToExecute;
this.delay = delay;
elementToWatch.observe('keyup', this.onKeyUp.bindAsEventListener(this));
},
onKeyUp: function(event){
if(this.id){
window.clearTimeout(this.id);
<html>
<head>
<title></title>
<script type="text/javascript" language="javascript" charset="utf-8">
function test(){
var div = document.getElementById('div');
div.style.visibility = 'hidden';
alert(div.style.visibility);
}
</script>
//Called on dom:ready
buttonDiv.observe('click', instantEstimate.submitOrder.bindAsEventListener(instantEstimate));
//instance method on instantEstimate
submitOrder: function(event){
event.stop();
if(this.isSubmitting){
return;
}
if(this.pendingSave || this.request){
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :username, :null => false # optional, you can use email instead, or both
t.string :email, :null => false # optional, you can use login instead, or both
t.string :crypted_password, :null => false # optional, see below
t.string :password_salt, :null => false # optional, but highly recommended
t.string :persistence_token, :null => false # required
t.string :single_access_token, :null => false # optional, see Authlogic::Session::Params
t.string :perishable_token, :null => false # optional, see Authlogic::Session::Perishability
document.observe('a:a', alert); // will call alert(event)
document.fire('a:a');
var remove = true;
$('time').options.each(function(element){
if(remove) element.remove();
remove = !remove;
});
//Put on a text area in java
String action = "'return Event.noBubble( event, RSACommon.limitLength( this, " + maxLength + " ) )'";
javascript = " onkeypress=" + action +
" onkeyup=" + action +
" onkeydown=" + action +
//RSACommon
limitLength: function( elem, maxLength ) {
if( elem.value.length > maxLength ) {
elem.value = elem.value.substring( 0, maxLength );
Object.extend(Array.prototype, {
union: function(otherArray){
if(!Object.isArray(otherArray)) return this;
return this.without.apply(this, this.without.apply(this, otherArray));
}
}