JSFiddle - React, Tailwind, and code Playground

by Peter Johnson

HTML

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://prz.in/files/html5number.js"></script>
<div id="wrapper" style="width:320px;height:320px;overflow:scroll;"><canvas id="sketchpad" width="300px" height="300px" ></canvas></div>
<input type="number" id="zoomFactor" min="1" max="4" step="1" value="1" />

CSS

/* Input Number Polyfilling for FF */
div.number-spin-btn-container {
  display: inline-block;
  position: relative;
  vertical-align: bottom;
  margin: 0;
  padding: 0; }

div.number-spin-btn {
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  border-width: 2px;
  border-color: #ededed #777777 #777777 #ededed;
  border-style: solid;
  background-color: #cccccc;
  width: 1.2em; }
  div.number-spin-btn:hover {
    cursor: pointer; }
  div.number-spin-btn:active {
    border-width: 2px;
    border-color: #5e5e5e #d8d8d8 #d8d8d8 #5e5e5e;
    border-style: solid;
    background-color: #999999; }

div.number-spin-btn-up {
  border-bottom-width: 1px;
  -moz-border-radius: 3px 3px 0px 0px;
  -webkit-border-radius: 3px 3px 0px 0px;
  border-radius: 3px 3px 0px 0px; }
  div.number-spin-btn-up:before {
    border-width: 0 0.3em 0.3em 0.3em;
    border-color: transparent transparent black transparent;
    top: 25%; }
  div.number-spin-btn-up:active {
    border-bottom-width: 1px; }
  div.number-spin-btn-up:active:before {
    border-bottom-color: white;
    top: 26%;
    left: 51%; }

div.number-spin-btn-down {
  border-top-width: 1px;
  -moz-border-radius: 0px 0px 3px 3px;
  -webkit-border-radius: 0px 0px 3px 3px;
  border-radius: 0px 0px 3px 3px; }
  div.number-spin-btn-down:before {
    border-width: 0.3em 0.3em 0 0.3em;
    border-color: black transparent transparent transparent;
    top: 75%; }
  div.number-spin-btn-down:active {
    border-top-width: 1px; }
  div.number-spin-btn-down:active:before {
    border-top-color: white;
    top: 76%;
    left: 51%; }

div.number-spin-btn-up:before,
div.number-spin-btn-down:before {
  content: "";
  width: 0;
  height: 0;
  border-style: solid;
  position: absolute;
  left: 50%;
  margin: -0.15em 0 0 -0.3em;
  padding: 0; }

input:disabled + div.number-spin-btn-container > div.number-spin-btn-up:active, input:disabled + div.number-spin-btn-container > div.number-spin-btn-down:active {
...

JavaScript

fabric.isTouchSupported = false; /* Nasty chrome... */

var myfabric=new fabric.Canvas("sketchpad",{selectionColor:"rgba(128,128,128,0.6)",backgroundColor:"#a00",selectionLineWidth:2});
var prev_zoom = 1; /* Global remembering previous zoom factor*/
/* Drawing some stuff...*/ 
var rect1 = new fabric.Rect({left:30,top:30,fill:'blue',width:50,height:50,selectable:true,evented:true});
var rect2 = new fabric.Rect({left:200,top:170,fill:'lime',width:50,height:50,selectable:true,evented:true});
var text = new fabric.Text("Zoom Test",{left:120,top:210,fill:"yellow"});
var img = new fabric.Image.fromURL("http://icons.iconarchive.com/icons/treetog/junior/256/earth-icon.png",function(oImg) {
    oImg.scaleToHeight(100);
    oImg.lockUniScaling = true;
    myfabric.add(oImg);
    oImg.center().setCoords();
});
var path = new fabric.Path('M121.32,0L44.58,0C36.67,0,29.5,3.22,24.31,8.41\
c-5.19,5.19-8.41,12.37-8.41,20.28c0,15.82,12.87,28.69,28.69,28.69c0,0,4.4,\
0,7.48,0C36.66,72.78,8.4,101.04,8.4,101.04C2.98,106.45,0,113.66,0,121.32\
c0,7.66,2.98,14.87,8.4,20.29l0,0c5.42,5.42,12.62,8.4,20.28,8.4c7.66,0,14.87\
-2.98,20.29-8.4c0,0,28.26-28.25,43.66-43.66c0,3.08,0,7.48,0,7.48c0,15.82,\
12.87,28.69,28.69,28.69c7.66,0,14.87-2.99,20.29-8.4c5.42-5.42,8.4-12.62,8.4\
-20.28l0-76.74c0-7.66-2.98-14.87-8.4-20.29C136.19,2.98,128.98,0,121.32,0z');

myfabric.add(path.set({left:90,top:100}));
myfabric.add(rect1);
myfabric.add(rect2);
myfabric.add(text);
myfabric.renderAll();

/* Zoom Handler */ 
(jQuery)("#zoomFactor").change(function(){
	var SCALE_FACTOR=parseInt((jQuery)("#zoomFactor").val());
				
	myfabric.setHeight(300 * SCALE_FACTOR);
	myfabric.setWidth(300 * SCALE_FACTOR);
	myfabric.calcOffset();				
						
	var objects =...