From: rwldrn Date: Tue, 28 Dec 2010 17:32:32 +0000 (-0500) Subject: merg X-Git-Tag: v0.2~21 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=6486110951ff94f2409d6f24127bb3d187e3ee7b;p=popcorn-js.git merg --- diff --git a/popcorn.js b/popcorn.js index aecd9c1..9c8f11a 100644 --- a/popcorn.js +++ b/popcorn.js @@ -1,4 +1,3 @@ -<<<<<<< HEAD (function(global, document) { // Cache refs to speed up calls to native utils @@ -788,1054 +787,4 @@ // Exposes Popcorn to global context global.Popcorn = Popcorn; -})(window, window.document); -======= -/*global google: false, $: false, TWTR: false, jQuery: false*/ // This global comment is read by jslint - -(function() { - function getScript(url, test, success) { - if (test === 'undefined') { - var script = document.createElement('script'); - script.src = url; - var head = document.getElementsByTagName('head')[0], - done = false; - script.onload = script.onreadystatechange = function () { - if (!done && (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete')) { - done = true; - success(); - } - }; - head.appendChild(script); - } else { - success(); - } - } - - var popcorn = this.popcorn = {}; - - // The video manager manages a single video element, and all it's commands. - popcorn.VideoManager = function(videoElement) { - this.commandObjects = {}; - this.manifestObjects = {}; - this.videoElement = videoElement; - videoElement.videoManager = this; - popcorn.addInstance(this); - videoElement.setAttribute("ontimeupdate", "popcorn.update(this);"); - }; - - popcorn.VideoManager.prototype.addCommand = function(command) { - this.commandObjects[command.id] = command; - }; - - popcorn.VideoManager.prototype.removeCommand = function(command) { - delete this.commandObjects[command.id]; - }; - - popcorn.VideoManager.prototype.addManifestObject = function(manifestAttributes) { - var manifest = {}, - manifestId = ""; - for (var i = 0, pl = manifestAttributes.length; i < pl; i++) { - for (var j = 0, nl = manifestAttributes[i].length; j < nl; j++) { - var key = manifestAttributes[i].item(j).nodeName, - data = manifestAttributes[i].item(j).nodeValue; - if (key === "id") { - manifestId = data; - } else { - manifest[key] = data; - } - } - } - this.manifestObjects[manifestId] = manifest; - }; - - popcorn.VideoManager.prototype.removeManifestObject = function(itemId) { - delete this.manifestObjects[itemId]; - }; - - popcorn.VideoManager.prototype.loaded = function() {}; - - var inactiveTarget = {}; - - // Update is called on the video every time it's time changes. - popcorn.update = function(vid) { - var t = vid.currentTime, - commandObject = {}; // Loops through all commands in the manager, preloading data, and calling onIn() or onOut(). - for (var i in vid.videoManager.commandObjects) { - if (vid.videoManager.commandObjects.hasOwnProperty(i)) { - commandObject = vid.videoManager.commandObjects[i]; - if (commandObject.running && (commandObject.params["in"] > t || commandObject.params["out"] < t)) { - commandObject.running = false; - if (inactiveTarget[commandObject.params.target] <= 0 || --inactiveTarget[commandObject.params.target] <= 0) { - $("#" + commandObject.params.target + " .inactive").fadeIn(500); - } - commandObject.onOut(); - commandObject.extension.onOut(); - } - } - } - for (var j in vid.videoManager.commandObjects) { - if (vid.videoManager.commandObjects.hasOwnProperty(j)) { - commandObject = vid.videoManager.commandObjects[j]; - if (!commandObject.loaded && (commandObject.params["in"] - 5) < t && commandObject.params["out"] > t) { - commandObject.loaded = true; - commandObject.preload(); - } - if (!commandObject.running && commandObject.params["in"] < t && commandObject.params["out"] > t) { - commandObject.running = true; - - $("#" + commandObject.params.target + " .inactive").hide(); - inactiveTarget[commandObject.params.target]++; - - if (commandObject.params.target) { - $("#" + commandObject.params.target + " .overlay").show().fadeOut(500); - } - if (typeof commandObject.flash === "undefined") { - var section = $(commandObject.target).parents('section'); - if (!section.hasClass('hover')) { - section.addClass('hover'); - section.attr('hoveron', $('video')[0].currentTime); - } - } - commandObject.onIn(); - commandObject.extension.onIn(); - } - } - } - }; - - // Store VideoManager instances - popcorn.instances = []; - popcorn.instanceIds = {}; - popcorn.addInstance = function(manager) { - if (typeof manager.videoElement.id === 'undefined' || !manager.videoElement.id.length) { - manager.videoElement.id = "__video" + popcorn.instances.length; - } - popcorn.instanceIds[manager.videoElement.id] = popcorn.instances.length; - popcorn.instances.push(manager); - }; - - popcorn.getInstanceById = function(name) { - return popcorn.instances[popcorn.instanceIds[name]]; - }; - - popcorn.getInstance = function(index) { - return popcorn.instances[index]; - }; - - // Simple function to convert 0:05 to 0.5 in seconds - // acceptable formats are HH:MM:SS:MM, MM:SS:MM, SS:MM, SS - var toSeconds = function(time) { - var t = time.split(":"); - if (t.length === 1) { - return parseFloat(t[0], 10); - } else if (t.length === 2) { - return parseFloat(t[0], 10) + parseFloat(t[1] / 12, 10); - } else if (t.length === 3) { - return parseInt(t[0] * 60, 10) + parseFloat(t[1], 10) + parseFloat(t[2] / 12, 10); - } else if (t.length === 4) { - return parseInt(t[0] * 3600, 10) + parseInt(t[1] * 60, 10) + parseFloat(t[2], 10) + parseFloat(t[3] / 12, 10); - } - }; - - var offset = function(elem) { - if(!elem) elem = this; - - var x = elem.offsetLeft; - var y = elem.offsetTop; - - while (elem = elem.offsetParent) { - x += elem.offsetLeft; - y += elem.offsetTop; - } - - return { left: x, top: y }; - } - - //////////////////////////////////////////////////////////////////////////// - // Command objects - //////////////////////////////////////////////////////////////////////////// - - // Base class for all commands, SubtitleCommand, MapCommand, etc. - popcorn.VideoCommand = function(name, params, text, videoManager) { - this.name = name; - this.params = {}; - this.text = text; - this.videoManager = videoManager; - this.running = false; - this.loaded = false; - this.onIn = function() {}; - this.onOut = function() {}; - this.preload = function() {}; - this.extension = { - onIn: function() {}, - onOut: function() {} - }; - this.id = name + popcorn.VideoCommand.count++; - this.params["in"] = "0"; - this.params["out"] = this.videoManager.videoElement.duration; - - // Adds all attributes from the xml/json tag into this.params - for (var i = 0, pl = params.length; i < pl; i++) { - for (var j = 0, nl = params[i].length; j < nl; j++) { - var key = params[i].item(j).nodeName, - data = params[i].item(j).nodeValue; - if (key === "start_time") { - key = "in"; - } else if (key === "end_time") { - key = "out"; - } - if (key === "in" || key === "out") { - this.params[key] = (typeof data === "number" ? data : toSeconds(data)); - } else { - this.params[key] = data; - } - } - } - - // Checkes for a resourceid and gets all the attributes from that resource - if (this.params.resourceid) { - for (var attributeName in this.videoManager.manifestObjects[this.params.resourceid]) { - if (this.videoManager.manifestObjects[this.params.resourceid].hasOwnProperty(attributeName)) { - this.params[attributeName] = this.videoManager.manifestObjects[this.params.resourceid][attributeName]; - } - } - } - - if (!inactiveTarget[this.params.target]) { - inactiveTarget[this.params.target] = 0; - } - }; - popcorn.VideoCommand.count = 0; - - //////////////////////////////////////////////////////////////////////////// - // Subtitle Command - //////////////////////////////////////////////////////////////////////////// - - // Child commands. Uses onIn() and onOut() to do time based operations - popcorn.SubtitleCommand = function(name, params, text, videoManager) { - popcorn.VideoCommand.call(this, name, params, text, videoManager); - - // Creates a div for all subtitles to use - if (!popcorn.SubtitleCommand.subDiv) { - popcorn.SubtitleCommand.subDiv = document.createElement('div'); - popcorn.SubtitleCommand.subDiv.style.position = "absolute"; - popcorn.SubtitleCommand.subDiv.style.color = "white"; - popcorn.SubtitleCommand.subDiv.style.textShadow = "black 2px 2px 6px"; - popcorn.SubtitleCommand.subDiv.style.fontSize = "18px"; - popcorn.SubtitleCommand.subDiv.style.fontWeight = "bold"; - popcorn.SubtitleCommand.subDiv.style.textAlign = "center"; - - this.videoManager.videoElement.parentNode.appendChild(popcorn.SubtitleCommand.subDiv); - } - if (this.params.target) { - this.target = document.getElementById(this.params.target); - } else { - this.target = popcorn.SubtitleCommand.subDiv; - } - this.target.style.display = "none"; - - this.onIn = function() { - if (this.params.languagesrc) { - var i = document.getElementById(this.params.languagesrc).selectedIndex, - that = this; - if (document.getElementById(this.params.languagesrc).options[i].value !== (this.params.language || "") || - (this.params.accessibilitysrc && document.getElementById(this.params.accessibilitysrc).checked)) { - google.language.translate(this.text, '', document.getElementById(this.params.languagesrc).options[i].value, function(result) { - that.target.innerHTML = result.translation; - that.target.style.display = "inline"; - popcorn.SubtitleCommand.subDiv.style.top = offset(videoManager.videoElement).top + videoManager.videoElement.offsetHeight - 64 + "px"; - popcorn.SubtitleCommand.subDiv.style.left = offset(videoManager.videoElement).left + ((videoManager.videoElement.offsetWidth / 2) - (popcorn.SubtitleCommand.subDiv.offsetWidth / 2)) + "px"; - }); - } - } else { - this.target.innerHTML = this.text; - this.target.style.display = "inline"; - popcorn.SubtitleCommand.subDiv.style.top = offset(videoManager.videoElement).top + videoManager.videoElement.offsetHeight - 64 + "px"; - popcorn.SubtitleCommand.subDiv.style.left = offset(videoManager.videoElement).left + ((videoManager.videoElement.offsetWidth / 2) - (popcorn.SubtitleCommand.subDiv.offsetWidth / 2)) + "px"; - } - }; - this.onOut = function() { - this.target.innerHTML = ""; - this.target.style.display = "none"; - }; - }; - - //////////////////////////////////////////////////////////////////////////// - // Lower third text Command - //////////////////////////////////////////////////////////////////////////// - - popcorn.LowerThirdCommand = function(name, params, text, videoManager) { - popcorn.VideoCommand.call(this, name, params, text, videoManager); - - // Creates a div for all lower thirds - if (!popcorn.LowerThirdCommand.ltDiv) { - popcorn.LowerThirdCommand.ltDiv = document.createElement('div'); - popcorn.LowerThirdCommand.ltDiv.setAttribute('style', - 'padding-left:40px;padding-right:40px;padding-top:40px;position:absolute;top:150px;left:1px;color:white;font-weight:bold;font-family:sans-serif;text-shadow:black 1px 1px 3px;font-size:22px;width:450px;'); - this.videoManager.videoElement.parentNode.appendChild(popcorn.LowerThirdCommand.ltDiv); - } - if (this.params.target) { - this.target = document.getElementById(this.params.target); - } else { - this.target = popcorn.LowerThirdCommand.ltDiv; - } - - this.onIn = function() { - $(this.target).css("text-align", (this.params.align || 'left')); - if (this.params.languagesrc) { - var i = document.getElementById(this.params.languagesrc).selectedIndex; - var that = this; - google.language.translate((this.params.salutation || ""), '', document.getElementById(this.params.languagesrc).options[i].value, function(result) { - var span = document.createElement('span'); - span.innerHTML = result.translation + " "; - span.setAttribute('style', 'font-size:26px;'); - that.target.appendChild(span); - }); - google.language.translate((this.params.name || ""), '', document.getElementById(this.params.languagesrc).options[i].value, function(result) { - var span = document.createElement('span'); - span.innerHTML = result.translation; - span.setAttribute('style', 'font-size:26px;'); - that.target.appendChild(span); - }); - google.language.translate((this.params.role || ""), '', document.getElementById(this.params.languagesrc).options[i].value, function(result) { - that.target.innerHTML += "
" + result.translation; - }); - } else { - var span = document.createElement('span'); - span.innerHTML = (this.params.salutation || "") + " " + (this.params.name || ""); - span.setAttribute('style', 'font-size:26px;'); - this.target.appendChild(span); - this.target.innerHTML += "
" + (this.params.role || ""); - } - }; - this.onOut = function() { - this.target.innerHTML = ""; - }; - }; - - //////////////////////////////////////////////////////////////////////////// - // GoogleNews Command - //////////////////////////////////////////////////////////////////////////// - - popcorn.GoogleNewsCommand = function(name, params, text, videoManager) { - popcorn.VideoCommand.call(this, name, params, text, videoManager); - this.target = document.createElement('div'); - this.target.setAttribute('style', 'display:none;border:0px;'); - document.getElementById(this.params.target).appendChild(this.target); - this.target.setAttribute('id', this.id); - var content = document.getElementById(this.id); - var options = { - format : "300x250", - queryList : [ - {q: this.params.topic || "Top Stories"} - ] - }; - var newsShow = new google.elements.NewsShow(content, options); - - this.onIn = function() { - this.target.setAttribute('style', 'display:inline'); - $("a").each(function() { - this.setAttribute('target', '_blank'); - }); - document.getElementById(this.params.target).style.display = "inline"; - }; - this.onOut = function() { - this.target.setAttribute('style', 'display:none'); - document.getElementById(this.params.target).style.display = "none"; - }; - }; - - //////////////////////////////////////////////////////////////////////////// - // TagThisPerson Command - //////////////////////////////////////////////////////////////////////////// - - var people = function(){ - this.contains = {}; - this.toString = function() { - var r = []; - for (var i in this.contains) { - if (this.contains.hasOwnProperty(i)) { - r.push(" " + this.contains[i]); - } - } - return r.toString(); - }; - }; - popcorn.TagCommand = function(name, params, text, videoManager) { - popcorn.VideoCommand.call(this, name, params, text, videoManager); - - if (!popcorn.TagCommand[this.params.target]) { - popcorn.TagCommand[this.params.target] = new people(); - } - - this.onIn = function() { - popcorn.TagCommand[this.params.target].contains[this.text] = this.text; - document.getElementById(this.params.target).innerHTML = popcorn.TagCommand[this.params.target].toString(); - }; - this.onOut = function() { - delete popcorn.TagCommand[this.params.target].contains[this.text]; - document.getElementById(this.params.target).innerHTML = popcorn.TagCommand[this.params.target].toString(); - }; - }; - - //////////////////////////////////////////////////////////////////////////// - // Map Command - //////////////////////////////////////////////////////////////////////////// - - popcorn.MapCommand = function(name, params, text, videoManager) { - popcorn.VideoCommand.call(this, name, params, text, videoManager); - - // All data from Universal Subtitles comes from the text attribute - // so the data from that needs to enter the appropriate fields - if (typeof this.text === "string" && this.text !== "") { - // Universal Subtitles has no target attribute, so we create a default - this.params.target = "mapdiv"; - var split = this.text.split(", "); - this.params.lat = split[0]; - this.params.long = split[1]; - this.params.zoom = split[2]; - } - this.params.zoom = parseInt(this.params.zoom, 10); - // load the map - // http://code.google.com/apis/maps/documentation/javascript/reference.html#MapOptions <-- Map API - this.location = new google.maps.LatLng(this.params.lat, this.params.long); - if (!popcorn.MapCommand[this.params.target]) { - popcorn.MapCommand[this.params.target] = new google.maps.Map(document.getElementById(this.params.target), {mapTypeId: google.maps.MapTypeId.HYBRID}); - popcorn.MapCommand[this.params.target].setCenter(new google.maps.LatLng(0, 0)); - popcorn.MapCommand[this.params.target].setZoom(0); - } - this.onIn = function() { - popcorn.MapCommand[this.params.target].setCenter(this.location); - popcorn.MapCommand[this.params.target].setZoom(this.params.zoom); - if (this.params.src && this.params.mapinfo) { - var link = document.createElement("a"); - link.setAttribute("href", this.params.src); - link.setAttribute("target", "_blank"); - link.appendChild(document.createTextNode(this.params.description||this.params.src)); - document.getElementById(this.params.mapinfo).appendChild(link); - } - }; - this.onOut = function() { - popcorn.MapCommand[this.params.target].setCenter(new google.maps.LatLng(0, 0)); - popcorn.MapCommand[this.params.target].setZoom(0); - if (this.params.mapinfo) { - document.getElementById(this.params.mapinfo).innerHTML = ""; - } - }; - }; - - //////////////////////////////////////////////////////////////////////////// - // Lastfm Command - //////////////////////////////////////////////////////////////////////////// - - popcorn.LastfmCommand = function(name, params, text, videoManager) { - popcorn.VideoCommand.call(this, name, params, text, videoManager); - // Setup a default, hidden div to hold the images - var target = document.createElement('div'); - target.setAttribute('id', this.id); - document.getElementById(this.params.target).appendChild(target); - // Div is hidden by default - target.setAttribute('style', 'display:none'); - var htmlString = ''; - - // This uses jquery - $.getJSON("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist="+ this.params.artist +"&api_key=30ac38340e8be75f9268727cb4526b3d&format=json&callback=?", - function(data){ - htmlString += '

'+data.artist.name+'

'; - htmlString += ''; - htmlString += '

'+ data.artist.bio.summary +'

'; - htmlString += '

Tags

'; - htmlString += '

Similar

'; - target.innerHTML = htmlString; - } - ); - - this.target = target; - this.onIn = function() { - this.target.setAttribute('style', 'display:inline'); - }; - this.onOut = function() { - this.target.setAttribute('style', 'display:none'); - }; - this.preload = function() {}; // Probably going to need to preload this. - }; - - //////////////////////////////////////////////////////////////////////////// - // Twitter Command - //////////////////////////////////////////////////////////////////////////// - - popcorn.TwitterCommand = function(name, params, text, videoManager) { - popcorn.VideoCommand.call(this, name, params, text, videoManager); - - var that = this; - getScript("http://widgets.twimg.com/j/2/widget.js", typeof TWTR, function() { - // All data from Universal Subtitles comes from the text attribute - // so the data from that needs to enter the appropriate fields - if (typeof text === "string" && text !== "") { - that.params.source = text; - // Universal Subtitles has no target attribute, so we create a default - that.params.target = "twitterdiv"; - } - - // Setup a default, hidden div to hold the feed - that.target = document.createElement('div'); - that.target.setAttribute('id', that.id); - document.getElementById(that.params.target).appendChild(that.target); - - // Div is hidden by default - that.target.setAttribute('style', 'display:none'); - var widget = new TWTR.Widget({ - version: 2, - type: 'search', - id: that.target.getAttribute('id'), - search: that.params.source, - title: that.params.title || null, - subject: that.params.subject || null, - rpp: 30, - width: that.params.width || 250, - height: that.params.height || 200, - interval: 6000, - theme: { - shell: { - background: '#ffffff', - color: '#000000' - }, - tweets: { - background: '#ffffff', - color: '#444444', - links: '#1985b5' - } - }, - features: { - loop: true, - timestamp: true, - avatars: true, - hashtags: true, - toptweets: true, - live: true, - scrollbar: false, - behavior: 'default' - } - }).render().start(); - that.onIn = function() { - that.target.style.display = "inline";//.setAttribute('style', 'display:inline'); - document.getElementById(this.params.target).style.display = "inline"; - }; - that.onOut = function() { - that.target.style.display = "none";//.setAttribute('style', 'display:none'); - document.getElementById(this.params.target).style.display = "none"; - }; - that.preload = function() {}; // Probably going to need to preload this. - }); - }; - - //////////////////////////////////////////////////////////////////////////// - // Flickr Command - //////////////////////////////////////////////////////////////////////////// - - popcorn.FlickrCommand = function(name, params, text, videoManager) { - popcorn.VideoCommand.call(this, name, params, text, videoManager); - // Setup a default, hidden div to hold the images - var target = document.createElement('div'); - target.setAttribute('id', this.id); - document.getElementById(this.params.target).appendChild(target); - // Div is hidden by default - target.setAttribute('style', 'display:none'); - var height = this.params.height || "50px", - width = this.params.width || "50px", - count = this.params.numberofimages || 4, - padding = this.params.padding || "5px", - border = this.params.border || "0px"; - - // This uses jquery - $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=" + this.params.userid + "&lang=en-us&format=json&jsoncallback=?", function(data){ - target.innerHTML = "

" + data.title + "

"; - $.each(data.items, function(i, item) { - if (i < count) { - var link = document.createElement('a'); - link.setAttribute('href', item.link); - link.setAttribute("target", "_blank"); - var image = document.createElement('img'); - image.setAttribute('src', item.media.m); - image.setAttribute('height', height); - image.setAttribute('width', width); - image.setAttribute('style', 'border:' + border + ';padding:' + padding); - link.appendChild(image); - target.appendChild(link); - } else { - return false; - } - }); - }); - this.target = target; - - this.onIn = function() { - this.target.style.display = "inline";//.setAttribute('style', 'display:inline'); - document.getElementById(this.params.target).style.display = "inline"; - }; - this.onOut = function() { - this.target.style.display = "none";//.setAttribute('style', 'display:none'); - document.getElementById(this.params.target).style.display = "none"; - }; - }; - - //////////////////////////////////////////////////////////////////////////// - // Wiki Command - //////////////////////////////////////////////////////////////////////////// - - popcorn.WikiCommand = function(name, params, text, videoManager) { - popcorn.VideoCommand.call(this, name, params, text, videoManager); - - // All data from Universal Subtitles comes from the text attribute - // so the data from that needs to enter the appropriate fields - if (typeof text === "string" && text !== "") { - this.params.src = text; - // Universal Subtitles has no target attribute, so we create a default - this.params.target = "wikidiv"; - } - - //L10n - var src = this.params.src; - var lang = this.params.lang; - if (typeof lang === 'undefined') {lang="en";} - //end L10n - - var length = this.params.numberOfWords || 200; - // Setup a default, hidden div to hold the images - var target = document.createElement('div'); - target.setAttribute('id', this.id); - document.getElementById(this.params.target).appendChild(target); - // Div is hidden by default - target.setAttribute('style', 'display:none'); - // This uses jquery - $.getJSON("http://"+lang+".wikipedia.org/w/api.php?action=parse&props=text&page=" + ( this.params.title || src.slice(src.lastIndexOf("/")+1) ) + "&format=json&callback=?", function(data){ - if(data) { - //make a link to the document - var link = document.createElement('a'); - link.setAttribute('href', src); - link.setAttribute('target', '_blank'); - var p = document.createElement('p'); - p.innerHTML = data.parse.displaytitle; - link.appendChild(p); - // get the first 140 characters of the wiki content - var desc = document.createElement('p'); - var text = data.parse.text["*"].substr(data.parse.text["*"].indexOf('

')); - text = text.replace(/((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, ""); - desc.innerHTML = text.substr(0, ( length || 140 )) + " ..."; - target.appendChild(link); - target.appendChild(desc); - } - }); - - this.target = target; - this.onIn = function() { - this.target.setAttribute('style', 'display:inline'); - document.getElementById(this.params.target).style.display = "block"; - - }; - this.onOut = function() { - this.target.setAttribute('style', 'display:none'); - document.getElementById(this.params.target).style.display = "none"; - }; - }; - //////////////////////////////////////////////////////////////////////////// - // Footnote Command - //////////////////////////////////////////////////////////////////////////// - - popcorn.FootnoteCommand = function(name, params, text, videoManager) { - popcorn.VideoCommand.call(this, name, params, text, videoManager); - this.onIn = function() { - document.getElementById(this.params.target).innerHTML = this.text; - }; - this.onOut = function() { - document.getElementById(this.params.target).innerHTML = ""; - }; - }; - - //////////////////////////////////////////////////////////////////////////// - // Attribution Command - //////////////////////////////////////////////////////////////////////////// - - popcorn.AttributionCommand = function(name, params, text, videoManager) { - popcorn.VideoCommand.call(this, name, params, text, videoManager); - var attribution = ""; - var image = ""; - - if (this.params.nameofworkurl) { - attribution += ""; - } - if (this.params.nameofwork) { - attribution += this.params.nameofwork; - } - if (this.params.nameofworkurl) { - attribution += ""; - } - if (this.params.copyrightholderurl) { - attribution += ""; - } - if (this.params.copyrightholder) { - attribution += ", " + this.params.copyrightholder; - } - if (this.params.copyrightholderurl) { - attribution += ""; - } - if (this.params.license) { - if (this.params.license.toUpperCase() === "CC-BY" ) { - image = ""; - } else if (this.params.license.toUpperCase() === "CC-BY-SA") { - image = ""; - } else if (this.params.license.toUpperCase() === "CC-BY-ND") { - image = ""; - } else if (this.params.license.toUpperCase() === "CC-BY-NC") { - image = ""; - } else if (this.params.license.toUpperCase() === "CC-BY-NC-SA") { - image = ""; - } else if (this.params.license.toUpperCase() === "CC-BY-NC-ND") { - image = ""; - } - if (image) { - attribution = image + " " +attribution; - } else { - attribution += ", license: " + this.params.license; - } - } - if (this.params.licenseurl) { - attribution += ", License URL"; - } - //if the user did not specify any parameters just pull the text from the tag - if (attribution === "") { - attribution = this.text; - } - this.onIn = function() { - document.getElementById(this.params.target).innerHTML = attribution; - document.getElementById(this.params.target).style.display = "block";//setAttribute('style', 'display:inline'); - }; - this.onOut = function() { - document.getElementById(this.params.target).innerHTML = ""; - document.getElementById(this.params.target).style.display = "none";//.setAttribute('style', 'display:none'); - }; - }; - - //////////////////////////////////////////////////////////////////////////// - // Warp Command - //////////////////////////////////////////////////////////////////////////// - - popcorn.SeekCommand = function(name, params, text, videoManager) { - popcorn.VideoCommand.call(this, name, params, text, videoManager); - this.params["in"] = toSeconds(this.params.seekfrom); - this.params["out"] = toSeconds(this.params.seekfrom) + 1; - this.params.seekto = toSeconds(this.params.seekto); - this.onIn = function() { - this.videoManager.videoElement.currentTime = this.params.seekto; - }; - }; - - //////////////////////////////////////////////////////////////////////////// - // Script Command - //////////////////////////////////////////////////////////////////////////// - - popcorn.ScriptCommand = function(name, params, text, videoManager) { - popcorn.VideoCommand.call(this, name, params, text, videoManager); - this.start = eval(this.params.start) || function() {}; - this.stop = eval(this.params.stop) || function() {}; - this.onIn = function() { - this.start(); - }; - this.onOut = function() { - this.stop(); - }; - }; - - //////////////////////////////////////////////////////////////////////////// - // WebPage Command - //////////////////////////////////////////////////////////////////////////// - - popcorn.WebPageCommand = function(name, params, text, videoManager) { - popcorn.VideoCommand.call(this, name, params, text, videoManager); - - // Setup a default, iframe to hold the website - var target = document.createElement('iframe'); - target.setAttribute('src', this.params.src); - target.setAttribute('width', this.params.width); - target.setAttribute('height', this.params.height); - target.setAttribute('id', this.id); - document.getElementById(this.params.target).appendChild(target); - // iframe is hidden by default - target.setAttribute('style', 'display:none'); - // toggle display of the iframe - this.target = target; - this.onIn = function() { - this.target.setAttribute('style', 'display:inline'); - }; - this.onOut = function() { - this.target.setAttribute('style', 'display:none'); - }; - }; - //////////////////////////////////////////////////////////////////////////// - // Image Command - //////////////////////////////////////////////////////////////////////////// - - popcorn.ImageCommand = function(name, params, text, videoManager) { - popcorn.VideoCommand.call(this, name, params, text, videoManager); - - var src = this.params.src; - // Setup a default, hidden div to hold the image - var target = document.createElement('div'); - target.setAttribute('id', this.id); - - // Div is hidden by default - target.setAttribute('style', 'display:none'); - var image = document.createElement('img'); - image.setAttribute('src', this.params.src); - image.setAttribute('height', this.params.height); - image.setAttribute('width', this.params.width); - target.appendChild(image); - //apend to the target div provided in the xml - document.getElementById(this.params.target).appendChild(target); - - this.target = target; - this.onIn = function() { - this.target.setAttribute('style', 'display:inline'); - document.getElementById(this.params.target).style.display = "block"; - - }; - this.onOut = function() { - this.target.setAttribute('style', 'display:none'); - document.getElementById(this.params.target).style.display = "none"; - }; - }; - // Wrapper for accessing commands by name - // commands[name].create() returns a new command of type name - // Not sure if this is the best way; maybe it's too fancy? - // I liked it more than a switch, though - var commands = { - subtitle: { - create: function(name, params, text, videoManager) { - return new popcorn.SubtitleCommand(name, params, text, videoManager); - } - }, - flickr: { - create: function(name, params, text, videoManager) { - return new popcorn.FlickrCommand(name, params, text, videoManager); - } - }, - videotag: { - create: function(name, params, text, videoManager) { - return new popcorn.TagCommand(name, params, text, videoManager); - } - }, - location: { - create: function(name, params, text, videoManager) { - return new popcorn.MapCommand(name, params, text, videoManager); - } - }, - footnote: { - create: function(name, params, text, videoManager) { - return new popcorn.FootnoteCommand(name, params, text, videoManager); - } - }, - twitter: { - create: function(name, params, text, videoManager) { - return new popcorn.TwitterCommand(name, params, text, videoManager); - } - }, - attribution: { - create: function(name, params, text, videoManager) { - return new popcorn.AttributionCommand(name, params, text, videoManager); - } - }, - googlenews: { - create: function(name, params, text, videoManager) { - return new popcorn.GoogleNewsCommand(name, params, text, videoManager); - } - }, - wiki: { - create: function(name, params, text, videoManager) { - return new popcorn.WikiCommand(name, params, text, videoManager); - } - }, - lastfm: { - create: function(name, params, text, videoManager) { - return new popcorn.LastfmCommand(name, params, text, videoManager); - } - }, - lowerthird: { - create: function(name, params, text, videoManager) { - return new popcorn.LowerThirdCommand(name, params, text, videoManager); - } - }, - seek: { - create: function(name, params, text, videoManager) { - return new popcorn.SeekCommand(name, params, text, videoManager); - } - }, - script: { - create: function(name, params, text, videoManager) { - return new popcorn.ScriptCommand(name, params, text, videoManager); - } - }, - webpage: { - create: function(name, params, text, videoManager) { - return new popcorn.WebPageCommand(name, params, text, videoManager); - } - }, - image: { - create: function(name, params, text, videoManager) { - return new popcorn.ImageCommand(name, params, text, videoManager); - } - } - }; - - //////////////////////////////////////////////////////////////////////////// - // XML Converter - //////////////////////////////////////////////////////////////////////////// - - // Converts xml into command objects and adds them to the video manager - var convertXML = function(xmlDoc, videoManager) { - - var parseNode = function(node, attributes, manifest) { - var allAttributes = attributes.slice(0); - allAttributes.push(node.attributes); - var childNodes = node.childNodes; - if (childNodes.length < 1 || (childNodes.length === 1 && childNodes[0].nodeType === 3)) { - if (!manifest) { - videoManager.addCommand(commands[node.nodeName].create(node.nodeName, allAttributes, node.textContent, videoManager)); - } else { - videoManager.addManifestObject(allAttributes); - } - } else { - for (var i = 0; i < childNodes.length; i++) { - if (childNodes[i].nodeType === 1) { - parseNode(childNodes[i], allAttributes, manifest); - } - } - } - }; - - var x = xmlDoc.documentElement.childNodes; - for (var i = 0, xl = x.length; i < xl; i++) { - if (x[i].nodeType === 1) { - if (x[i].nodeName === "manifest") { - parseNode(x[i], [], true); - } else { - parseNode(x[i], [], false); - } - } - } - }; - - //////////////////////////////////////////////////////////////////////////// - // JSON Converter - //////////////////////////////////////////////////////////////////////////// - - // Converts json into command objects and adds them to the video manager - var convertJSON = function(jsonData, videoManager, type) { - - // loops through subtitles in the json - for (var j = 0, jl = jsonData.length; j < jl; j++) { - var allAttributes = [], - attributes = [], - l = 0, - text = ""; - // loops through attributes inside command, and packages them similar to how the xml data looks - for (var attribute in jsonData[j]) { - if (jsonData[j].hasOwnProperty(attribute)) { - if (attribute === "text") { - text = jsonData[j][attribute]; - } else { - attributes.push({"nodeName":attribute,"nodeValue":jsonData[j][attribute]}); - l++; - } - } - } - allAttributes = []; - // this object mimics the object used for xml - allAttributes.push({ - "att": attributes.slice(0), - "item": (function() { - return function(i) { - return this.att[i]; - }; - }()), - "length": l - }); - videoManager.addCommand(commands[type].create(type, allAttributes, text, videoManager)); - } - }; - - var convertData = function(video, manager, data, convert, type) { - var si = setInterval(function() { - if (video.readyState < 1) { return; } - clearInterval(si); - convert(data, manager, type); - manager.loaded(); - }, 50); - }; - - // Loads an external xml file, and returns the xml object - var getTimelineData = function(name) { - var xhttp = new XMLHttpRequest(); - if (xhttp) { - xhttp.open("GET", name, false); - xhttp.send(); - return xhttp; - } else { - return false; - } - }; - - // Automatic Initialization Method - var init = function() { - getScript('http://code.jquery.com/jquery.js', typeof jQuery, function() { - var video = document.getElementsByTagName('video'); - for (var i = 0, l = video.length; i < l; i++) { - var ind = i; - var videoSources = video[ind].getAttribute('data-timeline-sources'); - if (videoSources) { - var filename = videoSources, - dataXML = "", - dataJSON = ""; - var ext = (filename.toLowerCase()).match(/\.xml$/); - var manager = new popcorn.VideoManager(video[ind]); - if (ext !== null) { - convertData(video[ind], manager, getTimelineData(filename).responseXML, convertXML); - } else { - $.getJSON("http://dev.universalsubtitles.org/api/subtitles/?video_url=" + filename + "&callback=?", (function() { - return function(data) { - convertData(video[ind], manager, data, convertJSON, "subtitle"); - $.getJSON("http://dev.universalsubtitles.org/api/subtitles/?video_url=" + filename + "&language=meta-geo&callback=?", (function() { - return function(data) { - convertData(video[ind], manager, data, convertJSON, "location"); - $.getJSON("http://dev.universalsubtitles.org/api/subtitles/?video_url=" + filename + "&language=meta-tw&callback=?", (function() { - return function(data) { - convertData(video[ind], manager, data, convertJSON, "twitter"); - $.getJSON("http://dev.universalsubtitles.org/api/subtitles/?video_url=" + filename + "&language=meta-wiki&callback=?", (function() { - return function(data) { - convertData(video[ind], manager, data, convertJSON, "wiki"); - }; - }())); - }; - }())); - }; - }())); - }; - }())); - } - } - } - }); - }; - - document.addEventListener('DOMContentLoaded', init, false); - -}()); - ->>>>>>> 43b39ea3480a4c1825695592c87372a8da056348 +})(window, window.document); \ No newline at end of file