padmaAPI/static/js/padmaApi.js

95 lines
2.6 KiB
JavaScript
Raw Permalink Normal View History

//REMOVE tmpl FROM HERE!!!
/*
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;
};
})();
// window.PADMA = new padmaApi();
function callPadma(api, callback, extra_params) {
2010-07-15 00:02:35 +00:00
var local_json_url = "/jPadma/?url=" + PADMA_BASE_URL;
var url = local_json_url + api;
$.getJSON(url, function(json) {
callback(json, extra_params);
});
}
function getSRT(id, track, callback) {
var url = local_srt_url;
$.get(url, {
'id': id,
'track': track
}, function(srt) {
callback(srt);
});
}
2010-07-17 15:18:44 +00:00
(function($) {
jQuery.fn.padma = function(id, options) {
var that = this;
var o = $.extend({
'videoSize': 320,
'startTime': '0:00:00',
'endTime': '0:00:00',
'tracks': ['description', 'transcript'],
'tmpl_id': '',
2010-07-13 12:08:50 +00:00
'baseUrl': PADMA_BASE_URL || 'http://pad.ma/',
'globalVar': 'PADMA',
'localUrl': '/padmaApi/'
}, options);
window[o.globalVar] = new P(id, o, that);
}
var P = function(id, options, container) {
this.o = options;
this.container = container;
this.init();
}
P.prototype.init = function() {
}
})(jQuery);