JSFiddle - React, Tailwind, and code Playground

by codef0rmer

HTML

<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script>
<!doctype html>
<html class="no-js" lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Addressbook in Backbone.js</title>
    <meta name="description" content="">
    <meta name="author" content="">
    <meta name="viewport" content="width=device-width">
</head>
<body>
<header>
Addressbook in Backbone.js    
</header>
<div class='table abWrapper'>
    <div class='row'>
        <div class='cell abLinks'>
            <a href='#add_new_contact'>Add New Contact</a><br />
            <a href='#list_contacts'>List all Contacts</a><br />
            <a href='#search_contacts'>Search any Contact</a><br />
        </div>
        <div class='cell abPanel'>Loading... Please Wait.</div>
    </div>
</div>


<!-- addNewContact View starts here -->
<script type='text/template' id='addContactTemplate'>
    <h2>Add New Contact</h2>
    <form id='frmAddContact'>
        <div>Full Name:</div> <input type='text' id='full_name' class='input' /> <span class='false full_name_error'></span><br />
        <div>Email Id:</div> <input type='text' id='email' class='input' />  <span class='false email_error'></span><br />
        <div>Phone:</div> <input type='text' id='phone' class='input' />  <span class='false phone_error'></span><br />
        <div>Address:</div> <textarea id='address' class='textarea'></textarea> <br /><br />        
        <input type='submit' value='Save Contact Details' class='button' />
        <span class='success'></span>
        <input type='hidden' id='id' class='input' />
    </form>
</script>
<!-- addNewContact View ends here -->
</body>
</html>

CSS

header {
    text-align:center;
    font-size: 30px;
    border-bottom: 1px solid black;
    padding-bottom: 20px;
    padding-top: 10px;
}
.table { display: table;}
.row { display:table-row;}
.cell { display:table-cell;}
.abWrapper {
    width : 95%;
    height: 500px;
    margin: 0 auto;
}
.abLinks {
    width: 150px;
}
.abLinks > a { 
    font-size: 14px; 
    line-height: 25px;
    text-decoration: none;
    border-bottom: 1px dotted blue;
}
.abPanel { 
    width : auto; 
    border-left: 1px solid black;
    padding-left: 20px;
}

div.abPanel div {
    float: left;
    width: 100px;
    height: 20px;
}
div.abPanel .input {
    width: 300px;
    height: 20px;
    margin: 0 0 5px 0;
}
div.abPanel .textarea {
    width: 295px;
    height: 80px;
}
div.abPanel .button {
    margin-left: 100px;
}
div.abPanel span.true {
    color: green;
}
div.abPanel span.false {
    color: red;
}
div.abPanel div#grid { width: 100%; }
table#contactsGrid a {
    cursor: pointer;
    text-decoration: underline;
    color: blue;
}

JavaScript

/* Author:
*  Addressbook in Backbone.js - Add New Contact
*  http://amitgharat.wordpress.com    
*/
var AB = {
    run: function () {
        this.addview = new this.addView();
        this.addview.addContactPage();
    }
};
AB.addView = Backbone.View.extend({
    el: 'div.abPanel', 
    
    template: _.template($('#addContactTemplate').html()), 
    
    initialize: function () {
        _.bindAll(this, 'addContactPage');
    }, 
    
    addContactPage: function (id) {
        this.$el.html(this.template());
    },
});

$(function () {
    AB.run();
});