padmaAPI/static/js/padmaList.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

$(document).ready(function() {
var apiUrl = "/list/videos?listId=" + listId;
2010-07-15 00:02:35 +00:00
// console.log(apiUrl);
callPadma(apiUrl, initList);
prevSearchTerms = [];
2010-07-13 12:08:50 +00:00
});
var padmaVideos = [];
function initList(json) {
var videos = json.videos;
for (var v=0; v < videos.length; v++) {
var thisVideo = new padmaVideo(videos[v], v);
padmaVideos.push(thisVideo);
}
2010-07-13 12:08:50 +00:00
}
/**
* Returns time-code in npt format from pos in miliseconds
* @param {Int} pos Position in miliseconds
* @returns {String} Time-code in npt format.
*/
function ms2npt(pos) {
var h = Math.floor(pos / 3600000);
var m = Math.floor(pos % 3600000 / 60000);
var s = Math.floor(pos % 60000 / 1000);
var ms = pos % 1000;
return h.toString().pad('0', 2) + ':' + m.toString().pad('0', 2) + ':' + s.toString().pad('0', 2) + '.' + ms.toString().pad('0', 3);
// return strpad(h.toString(), '0', 2, 'left') + ':' + strpad(m.toString(), '0', 2, 'left') + ':' + strpad(s.toString(), '0', 2, 'left') + '.' + strpad(ms.toString(), '0', 3, 'left');
}
String.prototype.pad = function(pad, len, dir) {
if (typeof(dir) == 'undefined')
dir = 'left';
var str = this;
while (str.length < len) {
if (dir == 'left')
str = pad + str;
else if (dir == 'right')
str = str + pad;
}
return str;
}