<html>
<head>
<link href="//cdn.jsdelivr.net/picnicss/4.1.1/picnic.min.css" rel="stylesheet">
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<h1>Hello Mag.JS!</h1>
<a target="_top" href="https://github.com/magnumjs/mag.js">GitHub</a>
<hr/>
<!-- TABS -->
<div id="reactExampleGoesHere">
<div class="countryList"></div>
<div class="cityList"></div>
</div>
<div class="template hide">
<div id="TabList">
<div class="list">
<a></a>
</div>
</div>
</div>
<!-- TABS -->
<hr/>
<script src="//rawgit.com/magnumjs/mag.js/master/mag-latest.min.js"></script>
<script src="//rawgit.com/magnumjs/mag.js/master/dist/mag.addons.0.22.min.js"></script>
</body>
</html>
.hide {
display: none;
}
.show {
display: inline-block;
}
.done, [completed="true"] {
text-decoration: line-through;
color: grey;
}
.simple-alert {
height: 70px;
padding: 20px;
border: solid 1px #ebebeb;
color: white;
vertical-align: middle;
}
.simple-alert i {
display: inline-block;
font-style: normal;
cursor: pointer;
}
.simple-alert i:before {
content: '✖';
}
.simple-alert.default {
background-color: blue;
}
.simple-alert.success {
background-color: green;
}
.simple-alert.error {
background-color: red;
}
#reactExampleGoesHere a,
#reactExampleGoesHere a {
border: 1px solid;
margin-right: 10px;
text-decoration: none;
background-color: #2bbb5b;
color: white;
padding: 10px;
}
#reactExampleGoesHere a.excited,
#reactExampleGoesHere a.excited {
background-color: #2bbb5b;
}
#reactExampleGoesHere a.neutral,
#reactExampleGoesHere a.neutral {
background-color: #39a5de;
}
#reactExampleGoesHere div.list,
#reactExampleGoesHere div.list {
height: 70px;
}
div#message {
display: none;
}
/* modal */
.modal {
position: fixed;
top: 10px;
left: 50%;
width: 80%;
z-index: 100;
background-color: transparent;
}
hr {
border: dashed 1px blue;
padding-left: 4px;
}
.modal .wrapper {
position: relative;
left: -50%;
background-color: #fff;
padding: 10px;
border: solid 2px #444;
border-radius: 10px;
}
.modal .content {
margin-bottom: 0;
margin-bottom: 0;
overflow-x: hidden;
overflow-y: scroll;
}
.modal .close-modal {
/* float: right; */
position: relative;
right: -7px;
bottom: 35px;
}
/* STARRED */
.hide {
display:none;
}
div[id^=star] {
line-height: 1.6em;
font-size: 50px;
float:left;
}
.favorite-star-character {
color: #ccd6dd;
font-weight: 300;
cursor: pointer;
display: inline-block;
transform: scale3d(1.0, 1.0, 1.0);
transform: scale3d(1.0, 1.0, 1.0);
transform: scale3d(1.0, 1.0, 1.0);
touch-callout: none;
user-select: none;
user-select: none;
user-select: none;
user-select: none;
}
@-webkit-keyframes favorite-star-bounce {
0% {
transform: scale3d(1.0, 1.0, 1.0);
}
50% {
transform: scale3d(1.4, 1.4, 1.0);
}
to {
transform: scale3d(1.0, 1.0, 1.0);
}
}
@-moz-keyframes favorite-star-bounce {
0% {
transform: scale3d(1.0, 1.0, 1.0);
}
50% {
transform: scale3d(1.4, 1.4, 1.0);
}
to {
transform: scale3d(1.0, 1.0, 1.0);
}
}
@keyframes favorite-star-bounce {
0% {
transform: scale3d(1.0, 1.0, 1.0);
}
50% {
transform: scale3d(1.4, 1.4, 1.0);
}
100% {
transform: scale3d(1.0, 1.0, 1.0);
}
}
.favorite-star-character.active {
color: #ffac33;
animation: favorite-star-bounce 0.3s ease-in-out;
animation: favorite-star-bounce 0.3s ease-in-out;
animation: favorite-star-bounce 0.3s ease-in-out;
}
.favorite-star-character.hover {
color: #ffac33;
}
// http://blog.arkency.com/2014/10/react-dot-js-and-dynamic-children-why-the-keys-are-important/
var TabList = {}
TabList.controller = function(props) {
this.active = 0
}
TabList.view = function(state, props) {
state.list = {
a: props.items.map(function(item, i) {
return {
_className: {
"excited": i == state.active,
"neutral": i != state.active
},
_href: "#",
_text: item,
_onclick: function(a, event) {
state.active = a
props.clickHandler(item, a, event);
}.bind(state, i)
}
})
}
}
var CountriesComponent = {}
CountriesComponent.controller = function(props) {
this['active-country'] = 0
this['active-city'] = 0
this.selectedCountry = props.countries[0]
this.handleClick = function(type, item, index, event) {
if (type == 'country') this.selectedCountry = item
this['active-' + type] = index
event.preventDefault();
}.bind(this)
}
CountriesComponent.view = function(state, props) {
state.countryList = mag.module("TabList", TabList, {
key: "countryList",
items: props.countries,
clickHandler: state.handleClick.bind(state, 'country')
})
state.cityList = mag.module("TabList", TabList, {
key: state.selectedCountry,
items: props.citiesPerCountry[state['active-country']],
clickHandler: state.handleClick.bind(state, 'city')
})
}
var citiesPerCountry = [
['New York', 'Detroit'],
['Ontario', 'Toronto']
]
var countries = ['USA', 'CAN']
var props = {
citiesPerCountry: citiesPerCountry,
countries: countries
}
mag.module("reactExampleGoesHere", CountriesComponent, props)
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. |