Skip to content

Instantly share code, notes, and snippets.

@rmurphey
Created December 7, 2012 20:47
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 rmurphey/4236371 to your computer and use it in GitHub Desktop.
Save rmurphey/4236371 to your computer and use it in GitHub Desktop.
define([
'jquery',
'util',
'underscore',
'rsvp'
], function( $, util, _, RSVP ) {
var SearchResults = function( el ) {
if ( !(this instanceof SearchResults)) {
return new SearchResults( el );
}
this.el = $( el );
this._bindEvents();
};
SearchResults.prototype.setResults = function( results ) {
util.loadTemplate( 'people-detailed.tmpl' )
.then( _.bind( this._populate, this, results ) );
};
SearchResults.prototype.pending = function() {
this.el.html( '<li class="searching">Searching &hellip;</li>' );
};
SearchResults.prototype._bindEvents = function() {
this.el.on( 'click', '.btn.like', _.bind( this._handleClick, this ) );
};
SearchResults.prototype._handleClick = function( evt ) {
var name = $( evt.target ).closest( 'li.result' ).attr( 'data-name' );
this.trigger( 'like', name );
};
SearchResults.prototype._populate = function( results, tmpl ) {
var html = _.template( tmpl, { people: results } );
this.el.html( html );
};
RSVP.EventTarget.mixin( SearchResults.prototype );
return SearchResults;
});
@yoosuf
Copy link

yoosuf commented Dec 7, 2012

perfectoo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment