'use strict'; /* jQuery plugin to embed video from a pan.do/ra instance Usage: html:
js: $('#video').pandoravideo(); Options can be passed as data- attributes in the html or in an options object - read code for docs */ (function($) { $.fn.pandoravideo = function(options) { //get options, giving preference, in order, to data- attributes defined on the html element, options passed when instantiatiing $(element).pandoravideo(options), defaults. var options = options || {}, namespace = options.namespace || "pandora", optionTypes = { 'strings': ['api', 'base', 'resolution', 'action', 'id'], 'integers': ['width', 'interval'], 'floats': ['in', 'out'], 'arrays': ['layers', 'keys'], 'booleans': [] //'functions': ['callback'] FIXME: lets not. }; return this.each(function() { var $this = $(this), dataOptions = $.extend(options, $this.getDataOptions(optionTypes, namespace)), opts = $.extend({ 'id': 'ABC', //FIXME: throw an error if id is undefined at this point 'layers': ['transcripts', 'descriptions', 'keywords', 'places'], 'keys': ['layers'], //data keys to fetch from API call. FIXME: add more apt keys 'api': "//pad.ma/api/", //pandora instance api end-point - see http://pad.ma/api 'in': 0, //in point (float, in seconds) of clip 'out': 0, //out point of clip 'pandora_base': 'pad.ma/', //pandora instance from where to fetch video and image data 'resolution': '480p', //resolution of video (96p, 240p, or 480p) 'width': '640', //display (css) width 'interval': 300, //interval (in ms) to run updatePlayer polling loop 'action': 'get', //action POST param to send to url 'callback': function() { $.noop(); } //function to call after done instantiating pandoraVideo object, called with the object. }, dataOptions), id = opts.id, $loading = $('').addClass("pandoraLoading").text("Loading video...").appendTo($this), sendData = JSON.stringify({'id': id, 'keys': opts.keys}); //get the pandora id and instantiate a pandoraVideo object with the current element and render it and execute optional callback var deferred = $.post(opts.api, {'action': opts.action, 'data': sendData}, function(response) { $loading.hide().remove(); var pandora = new PandoraVideo(id, response.data, $this, opts); pandora.render(); opts.callback(pandora); }, "json"); deferred.error(function(data) { alert("failed to load video data"); }); }); }; /* pandoraVideo class Parameters: id: