JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.1/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script>
<script src="http://www.parsecdn.com/js/parse-1.2.7.min.js"></script>
<div id="todoapp">
<div class="title">
<h1>Parse Todos</h1>
</div>
<div class="content">
</div>
</div>
<div id="credits">
Powered by <a href="https://www.parse.com">Parse</a> using the <a href="https://www.parse.com/docs/js_guide">JavaScript SDK</a>.<br /><br />
Learn how we built it in the <a href='https://parse.com/tutorials/todo-app-with-javascript'>tutorial</a>.
</div>
<!-- Templates -->
<script type="text/template" id="login-template">
<header id="header"></header>
<div class="login">
<form class="login-form">
<h2>Log In</h2>
<div class="error" style="display:none"></div>
<input type="text" id="login-username" placeholder="Username" />
<input type="password" id="login-password" placeholder="Password" />
<button>Log In</button>
</form>
<form class="signup-form">
<h2>Sign Up</h2>
<div class="error" style="display:none"></div>
<input type="text" id="signup-username" placeholder="Username" />
<input type="password" id="signup-password" placeholder="Create a Password" />
<button>Sign Up</button>
</form>
</div>
</script>
<script type="text/template" id="manage-todos-template">
<div id="user-info">
Signed in as <%= Parse.User.current().get("username") %> (<a href="#" class="log-out">Log out</a>)
</div>
<div class="section">
<header id="header">
<input id="new-todo" placeholder="<%= input_label%> " type="text" />
</header>
<div id="main">
<input id="toggle-all" type="checkbox">
<label...
JavaScript
$(function() {
Parse.$ = jQuery;
// Initialize Parse with your Parse application javascript keys
Parse.initialize("0Oq3tTp9JMvd72LOrGN25PiEq9XgVHCxo57MQbpT",
"vUFy2o7nFx3eeKVlZneYMPI2MBoxT5LhWNoIWPja");
var LogInView = Parse.View.extend({
events: {
"submit form.login-form": "logIn",
"submit form.signup-form": "signUp"
},
el: ".content",
initialize: function() {
_.bindAll(this, "logIn", "signUp");
this.render();
},
logIn: function(e) {
var self = this;
var username = this.$("#login-username").val();
var password = this.$("#login-password").val();
Parse.User.logIn(username, password, {
success: function(user) {
new ManageTodosView();
self.undelegateEvents();
delete self;
},
error: function(user, error) {
self.$(".login-form .error").html("Invalid username or password. Please try again.").show();
this.$(".login-form button").removeAttr("disabled");
}
});
this.$(".login-form button").attr("disabled", "disabled");
return false;
},
signUp: function(e) {
var self = this;
var username = this.$("#signup-username").val();
var password = this.$("#signup-password").val();
Parse.User.signUp(username, password, { ACL: new Parse.ACL() }, {
success: function(user) {
new ManageTodosView();
self.undelegateEvents();
delete self;
},
error: function(user, error) {
self.$(".signup-form .error").html(error.message).show();
this.$(".signup-form button").removeAttr("disabled");
}
});
this.$(".signup-form button").attr("disabled", "disabled");
return false;
},
render: function() {
this.$el.html(_.template($("#login-template").html()));
this.delegateEvents();
}
});
// The main view for the app
var...