Skip to content

Instantly share code, notes, and snippets.

Created January 17, 2013 08:45
Show Gist options
  • Save anonymous/4554609 to your computer and use it in GitHub Desktop.
Save anonymous/4554609 to your computer and use it in GitHub Desktop.
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script>
<script type="text/javascript" src="/files/jwplayer/jwplayer.js" ></script>
<script type='text/javascript'>
/*
* Returns a list of the files in 'path' to the callback:
* cb(error, ['file1', 'file2', ...])
*/
//window.location.href.match(/files.*[^A-za-z0-9\.html]/)
function gotDirList(e, l) {
if(e) throw e;
else {
playList=[];
console.log(l);
$.makeArray(l).forEach(function(e){playList.push({file: e, title: e.replace(/\.[^.]*$/,'')});});
jwplayer("myElement").setup({
playlist: playList,
height: 360,
listbar: {
position: 'right',
size: 400
},
width: 1024
});
}
}
function apacheIndexList(path, cb) {
$.ajax({
url: path,
success: function(data) {
/* Sanity check: is this an Apache directory index?
*/
data = $('<html>').html(data);
/* Get all the hrefs after the "Parent Directory"
* link: these are the contents of the directory.
*/
var passedParentLink = false;
var files = $('a', data).filter(function(i, a) {
if(passedParentLink)
return true;
if(a.innerHTML.trim() === "Parent Directory")
passedParentLink = true;
return false;
});
var tidied = $(files).map(function(i, a) {
if(a.href.substr(-1) === '/')
return a.href.split('/').slice(-2,-1) + '/';
return a.href.split('/').pop();
});
cb(null, tidied);
},
error: function(jqXHR, error, errorThrown) {
cb(error);
}
});
}
$(document).ready(apacheIndexList('.', gotDirList));
</script>
<body>
<div id="myElement">Loading the player...</div>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment