110 lines
3.5 KiB
JavaScript
110 lines
3.5 KiB
JavaScript
|
/*
|
||
|
function displayPadmaURL(linkData, elem, opts) {
|
||
|
if (linkData.type == 'tcRange') {
|
||
|
var videoId = linkData.videoId;
|
||
|
|
||
|
}
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
|
||
|
|
||
|
function setupPadmaLink(video, data) {
|
||
|
console.log(data);
|
||
|
var jq = $(data.jq);
|
||
|
var linkData = data.linkData;
|
||
|
jq.data("video", video);
|
||
|
jq.data("linkData", linkData);
|
||
|
jq.data("videoDisplayed", false);
|
||
|
jq.mouseover(function() {
|
||
|
if ($(this).data("videoDisplayed") == false) {
|
||
|
var $that = $(this);
|
||
|
var video = $(this).data("video");
|
||
|
var linkData = $(this).data("linkData");
|
||
|
var html = tmpl("tmpl_" + linkData.type, {'video': video, 'linkData': linkData});
|
||
|
var parentP = $(this).parents('p');
|
||
|
var appendElem = $('<div />').addClass('padmaVideo').data("sourceElem", $that).html(html).appendTo(parentP).hide().slideDown();
|
||
|
$(this).data("videoDisplayed", true);
|
||
|
} else {
|
||
|
var padmaElem = $(this).parents('p').find('.padmaWrapper');
|
||
|
if (!padmaElem.is(":visible")) {
|
||
|
padmaElem.slideDown();
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
$('.closeButton').live("click", function() {
|
||
|
$(this).parents('.padmaWrapper').slideUp();
|
||
|
});
|
||
|
/*
|
||
|
John Resig's templating utility - http://ejohn.org/blog/javascript-micro-templating/
|
||
|
Not updated code to resolve issue with single quotes from: http://www.west-wind.com/Weblog/posts/509108.aspx
|
||
|
define templates inside <script type="text/html" id="foo"> tags
|
||
|
get html of template with tmpl("foo", json)
|
||
|
*/
|
||
|
|
||
|
|
||
|
// Simple JavaScript Templating
|
||
|
// John Resig - http://ejohn.org/ - MIT Licensed
|
||
|
(function(){
|
||
|
var cache = {};
|
||
|
|
||
|
this.tmpl = function tmpl(str, data){
|
||
|
// Figure out if we're getting a template, or if we need to
|
||
|
// load the template - and be sure to cache the result.
|
||
|
var fn = !/\W/.test(str) ?
|
||
|
cache[str] = cache[str] ||
|
||
|
tmpl(document.getElementById(str).innerHTML) :
|
||
|
|
||
|
// Generate a reusable function that will serve as a template
|
||
|
// generator (and which will be cached).
|
||
|
new Function("obj",
|
||
|
"var p=[],print=function(){p.push.apply(p,arguments);};" +
|
||
|
|
||
|
// Introduce the data as local variables using with(){}
|
||
|
"with(obj){p.push('" +
|
||
|
|
||
|
// Convert the template into pure JavaScript
|
||
|
str
|
||
|
.replace(/[\r\t\n]/g, " ")
|
||
|
.split("<%").join("\t")
|
||
|
.replace(/((^|%>)[^\t]*)'/g, "$1\r")
|
||
|
.replace(/\t=(.*?)%>/g, "',$1,'")
|
||
|
.split("\t").join("');")
|
||
|
.split("%>").join("p.push('")
|
||
|
.split("\r").join("\\'")
|
||
|
+ "');}return p.join('');");
|
||
|
|
||
|
// Provide some basic currying to the user
|
||
|
return data ? fn( data ) : fn;
|
||
|
};
|
||
|
})();
|
||
|
|
||
|
/**
|
||
|
* 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;
|
||
|
}
|