JSFiddle - React, Tailwind, and code Playground

by cgack

HTML

<!doctype html>
<html>
<head>
<title>Draw!</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<div id="wrapper">
<div class="menu">
    <ul>
        <li>
            <a  id="edit">Edit</a>
            <ul>
                <li><a  id="clear">Clear</a>
                <li><a  id="undo" title="ctrl + z">Undo</a>
                <li><a  id="redo" title="ctrl + y">Redo</a>
                <li><a  id="backout">Exit</a>                
            </ul>
        </li>
        <li>
            <a  id="draw">Draw</a>
            <ul id="colors">
                <li style="background-color:white;"><a>White</a>
                <li style="background-color:red;"><a>Red</a>
                <li style="background-color:orange;"><a>Orange</a>
                <li style="background-color:yellow;"><a>Yellow</a>
                <li style="background-color:green;"><a>Green</a>
                <li style="background-color:blue;"><a>Blue</a>
                <li style="background-color:indigo;"><a>Indigo</a>
                <li style="background-color:violet;"><a>Violet</a>
                <li style="background-color:black;"><a>Black</a>                
            </ul>            
        </li>
        <li>
            <a  id="text">Add Text</a>
            <ul id="fonts">
                <li style="font-family: 'Arial', Helvetica, sans-serif;"><a>Arial</a>
                <li style="font-family: 'Courier New', Courier, monospace;"><a>Courier New</a>
                <li style="font-family: 'Georgia', serif;"><a>Georgia</a>
                <li style="font-family: 'Lucida Console', Monaco, monospace"><a>Lucida Console</a>
                <li style="font-family: 'Times New Roman', Times, serif"><a>Times New Roman</a>
                <li style="font-family: 'Verdana', Geneva, sans-serif"><a>Verdana</a>
            </ul>
        </li>
        <label...

CSS

body, ul{     margin: 0;     padding: 0; } #wrapper{     margin: 0 auto;     width: 100%;     height: 100%; }  #canvas{      cursor: crosshair; } .menu ul {     background: none repeat scroll 0 0 #333333;     height: 2em;     list-style: none outside none;     padding : 0; } .menu li {     float: left;     padding:0;     border-right: 1px solid #cccccc; }  .menu label {     line-height: 2em;     color: #CCCCCC;     text-align: center;     text-decoration: none;     padding: 1em; }  .menu input {     width:3em; } .menu li a:hover {     background-color: #CCCCC4;     color: #333333;     cursor: pointer; }   .menu li a {     line-height: 2em;     color: #CCCCCC;     padding: 1em 1.5em;     text-align: center;     text-decoration: none; } .menu:after{     clear:both; }  /*submenu*/ .menu li ul{     background:none;     display:none;     height:auto;     padding:0;     position:absolute;     z-index:2; }  .menu li ul li{     background:#333333;   border: none; } .menu li:hover ul{     display:block; } .menu li li {     display:block;     height:2em;     float:none;     margin:0;     padding:0; } .menu li:hover li a{     background:none;     line-height: 2em;     color: #CCCCCC;     padding: 0 1.5em; } .menu li ul a{     display:block;     height:2em;     font-style:normal;     margin:0;     padding: 0;     text-align:left; } .menu li ul a:hover, .menu li ul li:hover a{      background-color: #CCCCC4;     color: #333333;     border:0;     text-decoration:none; }

JavaScript

/* ***** BEGIN LICENSE BLOCK *****  Version: MPL 1.1/GPL 2.0/LGPL 2.1    The contents of this file are subject to the Mozilla Public License Version   1.1 (the "License"); you may not use this file except in compliance with   the License. You may obtain a copy of the License at   http://www.mozilla.org/MPL/    Software distributed under the License is distributed on an "AS IS" basis,  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License  for the specific language governing rights and limitations under the  License.    The Original Code is drawings.    The Initial Developer of the Original Code is  cgack.  Portions created by the Initial Developer are Copyright (C) 2011  the Initial Developer. All Rights Reserved.    Contributor(s):  Cory Gack   Alternatively, the contents of this file may be used under the terms of  either the GNU General Public License Version 2 or later (the "GPL"), or  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),  in which case the provisions of the GPL or the LGPL are applicable instead  of those above. If you wish to allow use of your version of this file only  under the terms of either the GPL or the LGPL, and not to allow others to  use your version of this file under the terms of the MPL, indicate your  decision by deleting the provisions above and replace them with the notice  and other provisions required by the GPL or the LGPL. If you do not delete  the provisions above, a recipient may use your version of this file under  the terms of any one of the MPL, the GPL or the LGPL.    ***** END LICENSE BLOCK ***** */
(function() {
    var Mode = {
        drawing: 0,
        write: 1
    };
    var ctx = document.getElementById("canvas").getContext("2d"),
        canvas = document.getElementById("canvas"),
        $cvs = $("#canvas"),
        img, top = $cvs.offset().top,
        left = $cvs.offset().left,
        draw = 0,
        mode = Mode.drawing,
        curFont = "Helvetica",
       ...