Last active
December 3, 2017 10:47
-
-
Save scvalex/8286c980a8065bfb63c1 to your computer and use it in GitHub Desktop.
counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Counter</title> | |
<link rel="stylesheet" href="/r/screen.css" media="screen"> | |
<meta name="description" content="An HTML5 counter"> | |
<link rel="icon" type="image/png" href="/r/icon.png"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script> | |
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.2/react.js"></script> --> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.2/react.min.js"></script> | |
<script src="counter.js"></script> | |
</head> | |
<body> | |
<div id="counterContainer"> | |
</div> | |
<script> | |
counterInit(); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var svg = React.createFactory("svg"); | |
var g = React.createFactory("g"); | |
var circle = React.createFactory("circle"); | |
var text = React.createFactory("text"); | |
var Counter = React.createClass({ | |
getInitialState: function() { | |
return {clicks: 0}; | |
}, | |
handleClick: function(event) { | |
this.setState({clicks: this.state.clicks + 1}); | |
}, | |
render: function() { | |
return svg(_.extend({style: {cursor: "pointer"}, | |
onClick: this.handleClick}, this.props), | |
[g({transform: "translate(" + (this.props.width / 2) + ", " + (this.props.height / 2) + ")"}, | |
[circle({cx: 0, cy: 0, r: this.props.radius, | |
fill: "none", stroke: "#333", strokeWidth: 40}), | |
text({x: 0, y: 0, | |
style: {fontFamily: "monospace", | |
fontSize: this.props.radius, | |
fill: "#333", | |
stroke: "#333", | |
textAnchor: "middle", | |
dominantBaseline: "middle"}}, | |
this.state.clicks)])]); | |
}, | |
}); | |
var counter = React.createFactory(Counter); | |
function counterInit() { | |
var width = window.innerWidth; | |
var height = window.innerHeight - 20; | |
var radius = _.min([width, height]) / 3; | |
React.render( | |
counter({height: height, width: width, radius: radius}), | |
document.getElementById("counterContainer") | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment