Created
January 17, 2013 08:45
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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