github scan with select list
multi select is from http://loudev.com/
by Andy Bulka
HTML
<script src="https://dl.dropboxusercontent.com/u/2019810/scripts/github.bundle.min.js"></script>
<script src="https://dl.dropboxusercontent.com/u/2019810/scripts/jquery.multi-select.js"></script>
<link rel="stylesheet" href="https://dl.dropboxusercontent.com/u/2019810/scripts/multi-select.css">
<input type="button" id="done" value="Get Selected files">
<select multiple="multiple" id="my-select" name="my-select[]">
<!-- <option value='http://elem_1'>elem 1</option> -->
</select>
<div id="results">
Results:
</div>
CSS
.ms-container{
width: 700px;
background: transparent url('https://dl.dropboxusercontent.com/u/2019810/scripts/switch.png') no-repeat 50% 50%;
}
.ms-container .ms-list {
height: 250px;
}
JavaScript
var github = new Github();
var repo = github.getRepo('abulka', 'pynsource');
repo.getTree('master?recursive=true', function(err, tree) {
if (err != undefined) {
console.log(err);
return;
}
console.log(tree);
$.each(tree, function (index, value) {
if (value.path.endsWith('.py')) {
$('#my-select').append($('<option/>', {
value: value.url,
text : value.path
}));
}
});
$('#my-select').multiSelect()
});
$("#done").click(function(){
var selectedValues = [];
$("#my-select :selected").each(function(){
selectedValues.push({
'path': $(this).text(),
'url': $(this).val()
});
});
console.log(selectedValues);
$("#results").empty();
$.each(selectedValues, function (index, value) {
$.ajax({
url: value.url,
method: "GET",
dataType: 'text',
accepts: {
text: 'application/vnd.github-blob.raw'
},
}).done(function(data) {
$("#results" ).append("<h2>" + value.path + "</h2>");
$("#results" ).append("<p>" + value.url + "</p>");
$("#results" ).append("<pre>" + data + "</pre>");
});
});
});