Created
July 23, 2015 18:18
-
-
Save anonymous/91e39ed6797ab1599c97 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/fenofa
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> | |
<script src="http://fb.me/react-0.13.1.js"></script> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var TweetBox = React.createClass({displayName: 'TweetBox', | |
render: function() { | |
return ( | |
React.createElement("div", {className: "well clearfix"}, | |
this.overflow(), | |
React.createElement("textarea", {className: "form-control", onChange: this.handleChange}), | |
React.createElement("br", null), | |
this.remainingCharacters(), | |
React.createElement("button", {className: "btn btn-primary pull-right", disabled: this.state.text.length == 0 && !this.state.photo}, "Tweet"), | |
React.createElement("button", {onClick: this.togglePhoto, className: "btn btn-default pull-right"}, " ", this.state.photo ? "✓ Photo Added" : "Add Photo" | |
) | |
) | |
); | |
}, | |
overflow: function() { | |
if (this.remainingCharacters() < 0) { | |
var okText = this.state.text.substring(140-10, 140); | |
var badText = this.state.text.substring(140); | |
return ( | |
React.createElement("div", {className: "alert alert-warning"}, | |
"Oops! Too Long: ...", okText, React.createElement("strong", {className: "bg-danger"}, badText) | |
) | |
) | |
} | |
}, | |
handleChange: function(event) { | |
this.setState({ text: event.target.value }); | |
}, | |
togglePhoto: function(event) { | |
this.setState({ photo: !this.state.photo }); | |
}, | |
remainingCharacters: function() { | |
base = 140 - this.state.text.length; | |
if (this.state.photo) { | |
base -= 23; | |
} | |
return base; | |
}, | |
getInitialState: function () { | |
return { | |
text: "", | |
photo: false | |
}; | |
} | |
}); | |
React.render( | |
React.createElement(TweetBox, null), | |
document.body | |
); | |
</script> | |
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
<html> | |
<head> | |
<script src="//fb.me/react-0.13.1.js"><\/script> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
</body> | |
</html></script> | |
<script id="jsbin-source-javascript" type="text/javascript">var TweetBox = React.createClass({ | |
render: function() { | |
return ( | |
<div className="well clearfix"> | |
{ this.overflow() } | |
<textarea className="form-control" onChange={this.handleChange}></textarea> | |
<br/> | |
{this.remainingCharacters()} | |
<button className="btn btn-primary pull-right" disabled={this.state.text.length == 0 && !this.state.photo}>Tweet</button> | |
<button onClick={this.togglePhoto} className="btn btn-default pull-right"> {this.state.photo ? "✓ Photo Added" : "Add Photo" } | |
</button> | |
</div> | |
); | |
}, | |
overflow: function() { | |
if (this.remainingCharacters() < 0) { | |
var okText = this.state.text.substring(140-10, 140); | |
var badText = this.state.text.substring(140); | |
return ( | |
<div className="alert alert-warning"> | |
Oops! Too Long: ...{okText}<strong className="bg-danger">{badText}</strong> | |
</div> | |
) | |
} | |
}, | |
handleChange: function(event) { | |
this.setState({ text: event.target.value }); | |
}, | |
togglePhoto: function(event) { | |
this.setState({ photo: !this.state.photo }); | |
}, | |
remainingCharacters: function() { | |
base = 140 - this.state.text.length; | |
if (this.state.photo) { | |
base -= 23; | |
} | |
return base; | |
}, | |
getInitialState: function () { | |
return { | |
text: "", | |
photo: false | |
}; | |
} | |
}); | |
React.render( | |
<TweetBox />, | |
document.body | |
);</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 TweetBox = React.createClass({displayName: 'TweetBox', | |
render: function() { | |
return ( | |
React.createElement("div", {className: "well clearfix"}, | |
this.overflow(), | |
React.createElement("textarea", {className: "form-control", onChange: this.handleChange}), | |
React.createElement("br", null), | |
this.remainingCharacters(), | |
React.createElement("button", {className: "btn btn-primary pull-right", disabled: this.state.text.length == 0 && !this.state.photo}, "Tweet"), | |
React.createElement("button", {onClick: this.togglePhoto, className: "btn btn-default pull-right"}, " ", this.state.photo ? "✓ Photo Added" : "Add Photo" | |
) | |
) | |
); | |
}, | |
overflow: function() { | |
if (this.remainingCharacters() < 0) { | |
var okText = this.state.text.substring(140-10, 140); | |
var badText = this.state.text.substring(140); | |
return ( | |
React.createElement("div", {className: "alert alert-warning"}, | |
"Oops! Too Long: ...", okText, React.createElement("strong", {className: "bg-danger"}, badText) | |
) | |
) | |
} | |
}, | |
handleChange: function(event) { | |
this.setState({ text: event.target.value }); | |
}, | |
togglePhoto: function(event) { | |
this.setState({ photo: !this.state.photo }); | |
}, | |
remainingCharacters: function() { | |
base = 140 - this.state.text.length; | |
if (this.state.photo) { | |
base -= 23; | |
} | |
return base; | |
}, | |
getInitialState: function () { | |
return { | |
text: "", | |
photo: false | |
}; | |
} | |
}); | |
React.render( | |
React.createElement(TweetBox, null), | |
document.body | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment