Skip to content

Instantly share code, notes, and snippets.

@lorenzoplanas
Created March 5, 2014 16:14
Show Gist options
  • Save lorenzoplanas/9370366 to your computer and use it in GitHub Desktop.
Save lorenzoplanas/9370366 to your computer and use it in GitHub Desktop.
DOM hooks as functions
// DOM Hooks
this.$form = function() {
return $("form", this.$el);
};
this.$inputEmail = function() {
return $("input[name='email']", this.$el);
};
this.$inputPassword = function() {
return $("input[name='password']", this.$el);
};
this.$errorMessages = function() {
return $(".error", this.$el);
};
// Handle login form submit
this.logIn = function(e) {
e.preventDefault();
this.$errorMessages().remove();
options.user.login({
email: this.$inputEmail().val();
password: this.$inputPassword().val();
})
.fail(this.loginError.bind(this))
.done(this.loginSuccess.bind(this));
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment