JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<p>Trials: <input type="text" id="trials" value="25" /></p>
<p>Tests per trial: <input type="text" id="tests" value="2000" /></p>
<button id="run-tests">Run</button> <span class="warning">This WILL freeze your browser. Open your console to view results. </span>
</div>
<div id="captions">
</div>
CSS
body {
font-family: "Helvetica";
}
.caption {
background-color: #DDD;
padding: 8px;
min-height: 40px;
border: 2px solid #888;
margin-bottom: 15px;
}
.caption .up {
background: url("http://s.imgur.com/images/site-sprite.png?1360350531") no-repeat scroll -23px -60px transparent;
}
.caption .down {
background: url("http://s.imgur.com/images/site-sprite.png?1360350531") no-repeat scroll -23px -80px transparent
}
.caption .up:hover {
background: url("http://s.imgur.com/images/site-sprite.png?1360350531") no-repeat scroll -2px -60px transparent;
}
.caption .down:hover {
background: url("http://s.imgur.com/images/site-sprite.png?1360350531") no-repeat scroll -2px -80px transparent
}
.caption .up:active {
background: url("http://s.imgur.com/images/site-sprite.png?1360350531") no-repeat scroll -44px -60px transparent;
}
.caption .down:active {
background: url("http://s.imgur.com/images/site-sprite.png?1360350531") no-repeat scroll -44px -80px transparent
}
.caption .votes .up, .votes .down {
display: block;
width: 20px;
height: 20px;
}
.caption .votes {
float: left;
margin: 0 10px 0 0;
}
.caption .meta {
height: 10px;
font-size: 10px;
padding: 0 0 4px 0;
}
.caption p {
display: inline-block;
margin: 0;
}
.warning {
background-color: #FFA;
padding: 5px;
}
JavaScript
/**
* A little thin DOM wrapper with chaining
* You can find this library at https://github.com/jacobgreenleaf/ThinDOM
*/
function ThinDOM(tag) {
this.el = document.createElement(tag);
}
ThinDOM.prototype.append = (function(other) {
if(other instanceof ThinDOM) {
// our thin dom wrapper library
this.el.appendChild(other.el);
} else if (other instanceof jQuery) {
// jquery
if(other.length > 1) {
var self = this;
other.each(function(i, otherEl) {
self.el.appendChild(otherEl);
});
}
else {
this.el.appendChild(other[0]);
}
} else if (other instanceof Element) {
// native dom
this.el.appendChild(other);
}
return this;
});
ThinDOM.prototype.css = (function(properties, value) {
if(properties.constructor === String) {
this.el.style.properties = value;
} else if (properties instanceof Object) {
for(var key in properties) {
this.el.style.key = properties[key];
}
}
return this;
});
ThinDOM.prototype.text = (function(txt) {
this.el.textContent = txt;
return this;
});
ThinDOM.prototype.attr = (function(properties, value) {
if(properties.constructor === String) {
this.el.setAttribute(properties, value);
} else if (properties instanceof Object) {
for(var key in properties) {
this.el.setAttribute(key, properties[key]);
}
}
return this;
});
ThinDOM.prototype.get = (function() {
return this.el;
});
function CreateCaptionThinDOM(caption) {
var points_plural = (caption['points'] === 1) ? '' : 's';
var captionDOM = new ThinDOM('div').attr('class', 'caption')
.append(new ThinDOM('div').attr('class', 'votes')
.append(new ThinDOM('a').attr({'class': 'up', 'href': '#'}))
.append(new ThinDOM('a').attr({'class': 'down', 'href': '#'})))
.append(new...