Skip to content

Instantly share code, notes, and snippets.

@kaievns
Created August 11, 2010 07:52
Show Gist options
  • Save kaievns/518654 to your computer and use it in GitHub Desktop.
Save kaievns/518654 to your computer and use it in GitHub Desktop.
RJS1 vs RJS2 example
/**
* the old Autocompleter constructor
* uses RightJS 1 and `Class`
*/
initialize: function(input, options) {
this.input = $(input); // don't low it down!
this.$super(options);
// storing the callbacks so we could detach them later
this._watch = this.watch.bind(this);
this._hide = this.hide.bind(this);
this.input.onKeyup(this._watch).onBlur(this._hide);
this.holder = $E('div', {'class': 'right-autocompleter'}).insertTo(this.input, 'after');
this.container = $E('div', {'class': 'autocompleter'}).insertTo(this.holder);
this.input.autocompleter = Autocompleter.instances[$uid(input)] = this;
}
/**
* new Autocompleter constructor
* using RightJS 2 and private dom-wrappers
*/
initialize: function(input, options) {
this.input = $(input); // KEEP IT before the super call
this
.$super('autocompleter', options)
.insert(this.list = $E('ul', {'class': 'right-dd-menu'}))
.insertTo(this.input, 'after')
.onClick(this.clicked);
this.input.autocompleter = this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment