<html>
<head>
<title>Mustache experiment</title>
<link rel="stylesheet" href="http://mrmartineau.github.com/githubwatched/css/boost.css">
</head>
<body>
<ol id="foo">
</ol>
<a href="#" id="load_more" class="button">Load more</a>
<!-- ========== -->
<!-- === JS === -->
<!-- ========== -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="https://raw.github.com/janl/mustache.js/master/mustache.js" type="text/javascript"></script>
<script>
(function($) {
$(function() {
var siteSetup = {
i: 4,
ajaxSetup: function() {
$.ajaxSetup({
complete: function(xhr, textStatus) {
console.log("complete");
},
error: function(jqXHR, textStatus, errorThrown){
if(jqXHR.status&&jqXHR.status==400){
alert(jqXHR.responseText);
}else{
alert("Something went wrong");
}
$('#load_more').text('Sorry, no more results... :(').fadeOut(1000);
}
});
},
init: function() {
siteSetup.ajaxSetup();
loadJSON.init();
loadMore.init();
}
},
loadJSON = {
init: function() {
$.ajax({
url: "https://api.github.com/users/mrmartineau/watched?page="+ siteSetup.i +"&per_page=100",
success: function(data){
var template = $('#tpl1').html(); // Find the template
var html = Mustache.to_html(template, {arr:data});
$('#foo').html(html); // print the result
}
});
}
},
loadMore = {
init: function() {
$('#load_more').on('click', function (event) {
event.preventDefault();
siteSetup.i++;
console.log(siteSetup.i);
$.ajax({
url: "https://api.github.com/users/mrmartineau/watched?page="+ siteSetup.i +"&per_page=100",
success: function(data, textStatus, xhr) {
var template = $('#tpl1').html(); // Find the template
var html = Mustache.to_html(template, {arr:data});
console.log(html);
$(html).appendTo('#foo');
}
});
});
}
};
siteSetup.init();
});//End Doc Ready
})(jQuery);
</script>
<script id="tpl1" type="text/template">
{{#arr}}
<li>
<img src="{{owner.avatar_url}}" width="30">
<a href="{{html_url}}" title="{{name}}" class="item_name">{{name}}</a>
<a href="{{owner.url}}" title="{{owner.login}}" class="item_owner">{{owner.login}}</a>
<div class="item_description">{{description}}</div>
<div class="item_language">{{language}}</div>
</li>
{{/arr}}
</script>
</body>
</html>
Output
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. |