<html>
<head>
<script src="https://cdn.rawgit.com/lodash/lodash/3.0.1/lodash.min.js"></script>
<script src="https://unpkg.com/react/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom/umd/react-dom.development.js"></script>
<script src="https://code.jquery.com/jquery.min.js"></script>
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">-->
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">-->
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id="app"></div>
</div>
</body>
</html>
class Application extends React.Component {
constructor() {
super();
this.state = {
stopPropagationOnCapture: false,
stopPropagationOnBubble: false,
stopPropagationOnClick: false,
logLines: [],
};
["_handleClickCapture", "_handleClickBubble", "_handleClick"].forEach(name => {
this[name] = this[name].bind(this);
});
}
render() {
return (
<div>
<div id="grandparent" onClickCapture={this._handleClickCapture}>
<div id="parent" onClick={this._handleClickBubble}>
<button id="elem" onClick={this._handleClick}>Click me!</button>
</div>
</div>
<hr />
{this.renderOptions()}
{this.renderLogLines()}
</div>
);
}
_handleClickCapture(e) {
this._log("Handling click via capture on red div");
if (this.state.stopPropagationOnCapture) {
e.stopPropagation();
}
}
_handleClickBubble(e) {
this._log("Handling click via bubble on blue div");
if (this.state.stopPropagationOnBubble) {
e.stopPropagation();
}
}
_handleClick(e) {
this._log("Handling click directly on button");
if (this.state.stopPropagationOnClick) {
e.stopPropagation();
}
}
_log(msg) {
this.setState(s => ({logLines: s.logLines.concat([msg])}));
}
renderOptions() {
return (
<div>
<div>
<label>
<input type="checkbox" value={this.state.stopPropagationOnCapture}
onChange={e => this.setState({"stopPropagationOnCapture": e.target.checked})} />
Stop Propagation on Capture (red div)
</label>
</div>
<div>
<label>
<input type="checkbox" value={this.state.stopPropagationOnBubble}
onChange={e => this.setState({"stopPropagationOnBubble": e.target.checked})} />
Stop Propagation on Bubble (blue div)
</label>
</div>
<div>
<label>
<input type="checkbox" value={this.state.stopPropagationOnClick}
onChange={e => this.setState({"stopPropagationOnClick": e.target.checked})} />
Stop Propagation on Click (button)
</label>
</div>
<div>
<button onClick={() => this.setState({logLines: []})}>Clear Log</button>
</div>
</div>
);
}
renderLogLines() {
return <textarea value={this.state.logLines.join("\n")} />;
}
}
ReactDOM.render(<Application />, document.getElementById("app"));
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |