From: rwldrn
" + 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");
+ };
+ }()));
+ };
+ }()));
+ };
+ }()));
+ };
+ }()));
++=======
+ (function(global, document) {
+
+ // Cache refs to speed up calls to native utils
+ var
+ forEach = Array.prototype.forEach,
+ hasOwn = Object.prototype.hasOwnProperty,
+ slice = Array.prototype.slice,
+
+ // ID string matching
+ rIdExp = /^(#([\w\-\_\.]+))$/,
+
+ // ready fn cache
+ readyStack = [],
+ readyBound = false,
+ readyFired = false,
+
+
+ // Declare a pseudo-private constructor
+ // Returns an instance object.
+ Popcorn = function( entity ) {
+ // Return new Popcorn object
+ return new Popcorn.p.init( entity );
+ };
+
+ // Declare a shortcut (Popcorn.p) to and a definition of
+ // the new prototype for our Popcorn constructor
+ Popcorn.p = Popcorn.prototype = {
+
+ init: function( entity ) {
+
+ var elem, matches;
+
+ // Supports Popcorn(function () { /../ })
+ // Originally proposed by Daniel Brooks
+
+ if ( typeof entity === "function" ) {
+
+ // If document ready has already fired
+ if ( document.readyState === "interactive" || document.readyState === "complete" ) {
+
+ entity(document, Popcorn);
+
+ return;
+ }
+
+
+ readyStack.push( entity );
+
+ // This process should happen once per page load
+ if ( !readyBound ) {
+
+ // set readyBound flag
+ readyBound = true;
+
+ var DOMContentLoaded = function () {
+
+ readyFired = true;
+
+ // remove this listener
+ document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
+
+ // Execute all ready function in the stack
+ for ( var i = 0; i < readyStack.length; i++ ) {
+
+ readyStack[i].call( document, Popcorn );
+
+ }
+ // GC readyStack
+ readyStack = null;
+ };
+
+ document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false);
+ }
+
+
+
+ return;
+ }
+
+
+ matches = rIdExp.exec( entity );
+
+ if ( matches.length && matches[2] ) {
+ elem = document.getElementById(matches[2]);
+ }
+
+
+ this.video = elem ? elem : null;
+
+ this.data = {
+ history: [],
+ events: {},
+ trackEvents: {
+ byStart: [{start: -1, end: -1}],
+ byEnd: [{start: -1, end: -1}],
+ startIndex: 0,
+ endIndex: 0,
+ previousUpdateTime: 0
+ }
+ };
+
+ var isReady = function( that ) {
+
+ if ( that.video.readyState >= 3 ) {
+ // adding padding to the front and end of the arrays
+ // this is so we do not fall off either end
+
+ var videoDurationPlus = that.video.duration + 1;
+ Popcorn.addTrackEvent( that, {
+ start: videoDurationPlus,
+ end: videoDurationPlus
+ });
+
+ that.video.addEventListener( "timeupdate", function( event ) {
+
+ var currentTime = this.currentTime,
+ previousTime = that.data.trackEvents.previousUpdateTime,
+ tracks = that.data.trackEvents,
+ tracksByEnd = tracks.byEnd,
+ tracksByStart = tracks.byStart;
+
+ // Playbar advancing
+ if ( previousTime < currentTime ) {
+
+ while ( tracksByEnd[tracks.endIndex] && tracksByEnd[tracks.endIndex].end <= currentTime ) {
+ if ( tracksByEnd[tracks.endIndex]._running === true ) {
+ tracksByEnd[tracks.endIndex]._running = false;
+ tracksByEnd[tracks.endIndex]._natives.end.call( that, event, tracksByEnd[tracks.endIndex] );
+ }
+ tracks.endIndex++;
+ }
+
+ while ( tracksByStart[tracks.startIndex] && tracksByStart[tracks.startIndex].start <= currentTime ) {
+ if ( tracksByStart[tracks.startIndex].end > currentTime && tracksByStart[tracks.startIndex]._running === false ) {
+ tracksByStart[tracks.startIndex]._running = true;
+ tracksByStart[tracks.startIndex]._natives.start.call( that, event, tracksByStart[tracks.startIndex] );
+ }
+ tracks.startIndex++;
+ }
+
+ // Playbar receding
+ } else if ( previousTime > currentTime ) {
+
+ while ( tracksByStart[tracks.startIndex] && tracksByStart[tracks.startIndex].start > currentTime ) {
+ if ( tracksByStart[tracks.startIndex]._running === true ) {
+ tracksByStart[tracks.startIndex]._running = false;
+ tracksByStart[tracks.startIndex]._natives.end.call( that, event, tracksByStart[tracks.startIndex] );
+ }
+ tracks.startIndex--;
+ }
+
+ while ( tracksByEnd[tracks.endIndex] && tracksByEnd[tracks.endIndex].end > currentTime ) {
+ if ( tracksByEnd[tracks.endIndex].start <= currentTime && tracksByEnd[tracks.endIndex]._running === false ) {
+ tracksByEnd[tracks.endIndex]._running = true;
+ tracksByEnd[tracks.endIndex]._natives.start.call( that, event, tracksByEnd[tracks.endIndex] );
+ }
+ tracks.endIndex--;
+ }
+ }
+ /*
+ // This empty block causes errors with jslint
+
+ else {
+ // When user seeks, currentTime can be equal to previousTime on the
+ // timeUpdate event. We are not doing anything with this right now, but we
+ // may need this at a later point and should be aware that this behavior
+ // happens in both Chrome and Firefox.
+ }
+ */
+ tracks.previousUpdateTime = currentTime;
+
+ }, false);
+ } else {
+ global.setTimeout( function() {
+ isReady( that );
+ }, 1);
+ }
+ };
+
+ isReady( this );
+
+ return this;
+ }
+ };
+
+ // This trick allows our api methods to be chained to
+ // instance references.
+ Popcorn.p.init.prototype = Popcorn.p;
+
+ Popcorn.forEach = function( obj, fn, context ) {
+
+ if ( !obj || !fn ) {
+ return {};
+ }
+
+ context = context || this;
+ // Use native whenever possible
+ if ( forEach && obj.forEach === forEach ) {
+ return obj.forEach(fn, context);
+ }
+
+ for ( var key in obj ) {
+ if ( hasOwn.call(obj, key) ) {
+ fn.call(context, obj[key], key, obj);
+ }
+ }
+
+ return obj;
+ };
+
+ Popcorn.extend = function( obj ) {
+ var dest = obj, src = slice.call(arguments, 1);
+
+ Popcorn.forEach( src, function( copy ) {
+ for ( var prop in copy ) {
+ dest[prop] = copy[prop];
+ }
+ });
+ return dest;
+ };
+
+
+ // A Few reusable utils, memoized onto Popcorn
+ Popcorn.extend( Popcorn, {
+ error: function( msg ) {
+ throw msg;
+ },
+ guid: function( prefix ) {
+ Popcorn.guid.counter++;
+ return ( prefix ? prefix : '' ) + ( +new Date() + Popcorn.guid.counter );
+ },
+ sizeOf: function ( obj ) {
+ var size = 0;
+
+ for ( var prop in obj ) {
+ size++;
+ }
+
+ return size;
+ },
+ nop: function () {}
+ });
+
+ // Memoization property
+ Popcorn.guid.counter = 1;
+
+ // Simple Factory pattern to implement getters, setters and controllers
+ // as methods of the returned Popcorn instance. The immediately invoked function
+ // creates and returns an object of methods
+ Popcorn.extend(Popcorn.p, (function () {
+
+ // todo: play, pause, mute should toggle
+ var methods = "load play pause currentTime playbackRate mute volume duration",
+ ret = {};
+
+
+ // Build methods, store in object that is returned and passed to extend
+ Popcorn.forEach( methods.split(/\s+/g), function( name ) {
+
+ ret[ name ] = function( arg ) {
+
+ if ( typeof this.video[name] === "function" ) {
+ this.video[ name ]();
+
+ return this;
+ }
+
+
+ if ( arg !== false && arg !== null && typeof arg !== "undefined" ) {
+
+ this.video[ name ] = arg;
+
+ return this;
+ }
+
+ return this.video[ name ];
+ };
+ });
+
+ return ret;
+
+ })()
+ );
+
+ Popcorn.extend(Popcorn.p, {
+
+ // getting properties
+ roundTime: function () {
+ return -~this.video.currentTime;
+ },
+
+
+ exec: function ( time, fn ) {
+
+ !fn && ( fn = Popcorn.nop );
+
+
+ var self = this,
+ guid = Popcorn.guid( "execCallback" ),
+ callback = function execCallback( event ) {
+
+ if ( this.currentTime() >= time && !callback.fired ) {
+
+ callback.fired = true;
+
+ this.unlisten("timeupdate", guid );
+
+ fn.call(self, event);
+
+ }
+ };
+
+ callback.fired = false;
+ callback.name = guid;
+
+ this.listen("timeupdate", callback);
+
+ return this;
+ },
+ removePlugin: function( name ) {
+
+ var byStart = this.data.trackEvents.byStart,
+ byEnd = this.data.trackEvents.byEnd;
+
+ delete Popcorn.p[ name ];
+
+ // remove plugin reference from registry
+ for ( var r = 0, rl = Popcorn.registry.length; r < rl; r++ ) {
+ if ( Popcorn.registry[r].type === name ) {
+ Popcorn.registry.splice(r, 1);
+ break; // plugin found, stop checking
+ }
+ }
+
+ // remove all trackEvents
+ for ( var s = 0, sl = byStart.length; s < sl; s++ ) {
+ if ( byStart[s] && byStart[s]._natives && byStart[s]._natives.type === name ) {
+ byStart.splice( s, 1 );
+ s--; sl--; // update for loop if something removed, but keep checking
+ if ( this.data.trackEvents.startIndex <= s ) {
+ this.data.trackEvents.startIndex--; // write test for this
+ }
+ }
+ }
+ for ( var e = 0, el = byEnd.length; e < el; e++ ) {
+ if ( byEnd[e] && byEnd[e]._natives && byEnd[e]._natives.type === name ) {
+ byEnd.splice( e, 1 );
+ e--; el--; // update for loop if something removed, but keep checking
+ if ( this.data.trackEvents.endIndex <= e ) {
+ this.data.trackEvents.endIndex--; // write test for this
+ }
+ }
+ }
+ return this;
+ }
+ });
+
+ Popcorn.Events = {
+ UIEvents: "blur focus focusin focusout load resize scroll unload ",
+ MouseEvents: "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave click dblclick",
+ Events: "loadstart progress suspend emptied stalled play pause " +
+ "loadedmetadata loadeddata waiting playing canplay canplaythrough " +
+ "seeking seeked timeupdate ended ratechange durationchange volumechange"
+ };
+
+ Popcorn.Events.Natives = Popcorn.Events.UIEvents + " " +
+ Popcorn.Events.MouseEvents + " " +
+ Popcorn.Events.Events;
+
+ Popcorn.events = {
+
+
+ isNative: function( type ) {
+
+ var checks = Popcorn.Events.Natives.split(/\s+/g);
+
+ for ( var i = 0; i < checks.length; i++ ) {
+ if ( checks[i] === type ) {
+ return true;
+ }
+ }
+
+ return false;
+ },
+ getInterface: function( type ) {
+
+ if ( !Popcorn.events.isNative( type ) ) {
+ return false;
+ }
+
+ var natives = Popcorn.Events, proto;
+
+ for ( var p in natives ) {
+ if ( p !== "Natives" && natives[p].indexOf(type) > -1 ) {
+ proto = p;
+ }
+ }
+
+ return proto;
+
+ },
+
+
+ all: Popcorn.Events.Natives.split(/\s+/g),
+
+ fn: {
+ trigger: function ( type, data ) {
+
+ // setup checks for custom event system
+ if ( this.data.events[type] && Popcorn.sizeOf(this.data.events[type]) ) {
+
+ var eventInterface = Popcorn.events.getInterface(type);
+
+ if ( eventInterface ) {
+
+ var evt = document.createEvent( eventInterface );
+ evt.initEvent(type, true, true, global, 1);
+
+ this.video.dispatchEvent(evt);
+
+ return this;
+ }
+
+ // Custom events
+ Popcorn.forEach(this.data.events[type], function ( obj, key ) {
+
+ obj.call( this, data );
+
+ }, this);
+
+ }
+
+ return this;
+ },
+ listen: function ( type, fn ) {
+
+ var self = this, hasEvents = true;
+
+ if ( !this.data.events[type] ) {
+ this.data.events[type] = {};
+ hasEvents = false;
+ }
+
+ // Register
+ this.data.events[type][ fn.name || ( fn.toString() + Popcorn.guid() ) ] = fn;
+
+ // only attach one event of any type
+ if ( !hasEvents && Popcorn.events.all.indexOf( type ) > -1 ) {
+
+ this.video.addEventListener( type, function( event ) {
+
+ Popcorn.forEach( self.data.events[type], function ( obj, key ) {
+ if ( typeof obj === "function" ) {
+ obj.call(self, event);
+ }
+
+ });
+
+ //fn.call( self, event );
+
+ }, false);
+ }
+ return this;
+ },
+ unlisten: function( type, fn ) {
+
+ if ( this.data.events[type] && this.data.events[type][fn] ) {
+
+ delete this.data.events[type][ fn ];
+
+ return this;
+ }
+
+ this.data.events[type] = null;
+ return this;
+ },
+ special: {
+ // handles timeline controllers
+ play: function () {
+ // renders all of the interally stored track commands
+ }
+ }
+ }
+ };
+
+ // Extend listen and trigger to all Popcorn instances
+ Popcorn.forEach( ["trigger", "listen", "unlisten"], function ( key ) {
+ Popcorn.p[key] = Popcorn.events.fn[key];
+ });
+
+ Popcorn.protect = {
+ natives: "load play pause currentTime playbackRate mute volume duration removePlugin roundTime trigger listen unlisten".toLowerCase().split(/\s+/)
+ };
+
+
+ Popcorn.addTrackEvent = function( obj, track ) {
+
+ if ( track._natives ) {
+ // supports user defined track event id
+ track._id = !track.id ? Popcorn.guid( track._natives.type ) : track.id;
+
+ // Push track event ids into the history
+ obj.data.history.push( track._id );
+ }
+
+ // Store this definition in an array sorted by times
+ obj.data.trackEvents.byStart.push( track );
+ obj.data.trackEvents.byEnd.push( track );
+ obj.data.trackEvents.byStart.sort( function( a, b ){
+ return ( a.start - b.start );
+ });
+ obj.data.trackEvents.byEnd.sort( function( a, b ){
+ return ( a.end - b.end );
+ });
+
+ };
+
+ Popcorn.removeTrackEvent = function( obj, trackId ) {
+
+ var historyLen = obj.data.history.length,
+ indexWasAt = 0,
+ byStart = [],
+ byEnd = [],
+ history = [];
+
+
+ Popcorn.forEach( obj.data.trackEvents.byStart, function( o, i, context) {
+
+ // Preserve the original start/end trackEvents
+ if ( !o._id ) {
+ byStart.push( obj.data.trackEvents.byStart[i] );
+ byEnd.push( obj.data.trackEvents.byEnd[i] );
+ }
+
+ // Filter for user track events (vs system track events)
+ if ( o._id ) {
+
+ // Filter for the trackevent to remove
+ if ( o._id !== trackId ) {
+ byStart.push( obj.data.trackEvents.byStart[i] );
+ byEnd.push( obj.data.trackEvents.byEnd[i] );
+ }
+
+ // Capture the position of the track being removed.
+ if ( o._id === trackId ) {
+ indexWasAt = i;
+ }
+ }
+ });
+
+
+ // Update
+ if ( indexWasAt <= obj.data.trackEvents.startIndex ) {
+ obj.data.trackEvents.startIndex--;
+ }
+
+ if ( indexWasAt <= obj.data.trackEvents.endIndex ) {
+ obj.data.trackEvents.endIndex--;
+ }
+
+
+ obj.data.trackEvents.byStart = byStart;
+ obj.data.trackEvents.byEnd = byEnd;
+
+
+ for ( var i = 0; i < historyLen; i++ ) {
+ if ( obj.data.history[i] !== trackId ) {
+ history.push( obj.data.history[i] );
+ }
+ }
+
+ obj.data.history = history;
+
+ };
+
+ Popcorn.getTrackEvents = function( obj ) {
+
+ var trackevents = [];
+
+ Popcorn.forEach( obj.data.trackEvents.byStart, function(o, i, context) {
+ if ( o._id ) {
+ trackevents.push(o);
+ }
+ });
+
+ return trackevents;
+ };
+
+
+ Popcorn.getLastTrackEventId = function( obj ) {
+ return obj.data.history[ obj.data.history.length - 1 ];
+ };
+
+ // Map TrackEvents functions to the {popcorn}.prototype
+ Popcorn.extend( Popcorn.p, {
+
+ getTrackEvents: function() {
+ return Popcorn.getTrackEvents.call( null, this );
+ },
+
+ getLastTrackEventId: function() {
+ return Popcorn.getLastTrackEventId.call( null, this );
+ },
+
+ removeTrackEvent: function( id ) {
+ Popcorn.removeTrackEvent.call( null, this, id );
+ return this;
+ }
+
+ });
+
+ // Plugin manifests
+ Popcorn.manifest = {};
+ // Plugins are registered
+ Popcorn.registry = [];
+ // An interface for extending Popcorn
+ // with plugin functionality
+ Popcorn.plugin = function( name, definition ) {
+
+ if ( Popcorn.protect.natives.indexOf( name.toLowerCase() ) >= 0 ) {
+ Popcorn.error("'" + name + "' is a protected function name");
+ return;
+ }
+
+ // Provides some sugar, but ultimately extends
+ // the definition into Popcorn.p
+
+ var reserved = [ "start", "end"],
+ plugin = {type: name},
+ pluginFn,
+ setup;
+
+ if ( typeof definition === "object" ) {
+
+ setup = definition;
+
+ /*if ( !( "timeupdate" in setup ) ) {
+ setup.timeupdate = Popcorn.nop;
+ }*/
+
+ pluginFn = function ( options ) {
+
+ if ( !options ) {
+ return this;
+ }
+
+ // storing the plugin natives
+ options._natives = setup;
+ options._natives.type = name;
+ options._running = false;
+
+ // Checks for expected properties
+ if ( !( "start" in options ) ) {
+ options.start = 0;
+ }
+
+ if ( !( "end" in options ) ) {
+ options.end = this.duration();
+ }
+
+ // If a _setup was declared, then call it before
+ // the events commence
+
+ if ( "_setup" in setup && typeof setup._setup === "function" ) {
+
+ // Resolves 239, 241, 242
+ options.target ||
+ ( setup.manifest.options.target &&
+ ( options.target = setup.manifest.options.target ) );
+
+ setup._setup.call( this, options );
+ }
+
+
+ Popcorn.addTrackEvent( this, options );
+
+
+ // Future support for plugin event definitions
+ // for all of the native events
+ Popcorn.forEach( setup, function ( callback, type ) {
+
+ if ( type !== "type" ) {
+
+ if ( reserved.indexOf(type) === -1 ) {
+
+ this.listen( type, callback );
+ }
+ }
+
+ }, this);
+
+ return this;
+ };
+ }
+
+ // If a function is passed...
+ if ( typeof definition === "function" ) {
+
+ // Execute and capture returned object
+ setup = definition.call(this);
+
+ // Ensure an object was returned
+ // it has properties and isnt an array
+ if ( typeof setup === "object" &&
+ !( "length" in setup ) ) {
+
+ Popcorn.plugin( name, setup );
+ }
+ return;
+ }
+
+ // Assign new named definition
+ plugin[ name ] = pluginFn;
+
+ // Extend Popcorn.p with new named definition
+ Popcorn.extend( Popcorn.p, plugin );
+
+ // Push into the registry
+ Popcorn.registry.push(plugin);
+
+
+ if ( !!( "manifest" in setup ) ) {
+
+ // Augment the manifest object
+ Popcorn.manifest[ name ] = setup.manifest;
+ }
+
+ return plugin;
+ };
+
+ // stores parsers keyed on filetype
+ Popcorn.parsers = {};
+
+ // An interface for extending Popcorn
+ // with parser functionality
+ Popcorn.parser = function( name, type, definition ) {
+
+ if ( Popcorn.protect.natives.indexOf( name.toLowerCase() ) >= 0 ) {
+ Popcorn.error("'" + name + "' is a protected function name");
+ return;
+ }
+
+ if ( typeof definition !== "function" ) {
+ return;
+ }
+
+ // Provides some sugar, but ultimately extends
+ // the definition into Popcorn.p
+
+ var natives = Popcorn.events.all,
+ parseFn,
+ parser = {};
+
+ parseFn = function ( filename ) {
+
+ if ( !filename ) {
+ return this;
+ }
+
+ var that = this;
+
+ Popcorn.xhr({
+ url: filename,
+ success: function( data ) {
+
+ var tracksObject = definition( data );
+
+ // creating tracks out of parsed object
+ for ( var i = 0, todl = tracksObject.data.length; i < todl; i++ ) {
+
+ for ( var key in tracksObject.data[i] ) {
+
+ if ( tracksObject.data[i].hasOwnProperty(key) ) {
+ that[key]( tracksObject.data[i][key] );
+ }
+ }
+ }
+ }
+ });
+
+ return this;
+ };
+
+ // Assign new named definition
+ parser[ name ] = parseFn;
+
+ // Extend Popcorn.p with new named definition
+ Popcorn.extend( Popcorn.p, parser );
+
+ // keys the function name by filetype extension
+ Popcorn.parsers[type] = name;
+
+ return parser;
+ };
+
+
+ var setup = {
+ url: '',
+ data: '',
+ dataType: '',
+ success: Popcorn.nop,
+ type: 'GET',
+ async: true,
+ xhr: function() {
+ return new global.XMLHttpRequest();
+ }
+ };
+
+ Popcorn.xhr = function ( options ) {
+
+ var settings = Popcorn.extend( {}, setup, options );
+
+ settings.ajax = settings.xhr();
+
+ if ( settings.ajax ) {
+
+ settings.ajax.open( settings.type, settings.url, settings.async );
+ settings.ajax.send( null );
+
+ return Popcorn.xhr.httpData( settings );
+ }
+ };
+
+
+ Popcorn.xhr.httpData = function ( settings ) {
+
+ var data, json = null;
+
+ settings.ajax.onreadystatechange = function() {
+
+ if ( settings.ajax.readyState === 4 ) {
+
+ try {
+ json = JSON.parse(settings.ajax.responseText);
+ } catch(e) {
+ //suppress
+ }
+
+ data = {
+ xml: settings.ajax.responseXML,
+ text: settings.ajax.responseText,
+ json: json
+ };
+
+ settings.success.call( settings.ajax, data );
+
+ }
+ };
+ return data;
+ };
+
+
+
+ // Exposes Popcorn to global context
+ global.Popcorn = Popcorn;
+
+ document.addEventListener( "DOMContentLoaded", function () {
+
+ var videos = document.getElementsByTagName( "video" );
+
+ Popcorn.forEach( videos, function ( iter, key ) {
+
+ var video = videos[ key ],
+ dataSources, popcornVideo;
+
+ // Ensure we're looking at a dom node and that it has an id
+ // otherwise Popcorn won't be able to find the video element
+ if ( video.nodeType && video.nodeType === 1 && video.id ) {
+
+ dataSources = video.getAttribute( "data-timeline-sources" );
+
+ // If the video has data sources, continue to load
+ if ( dataSources ) {
+
+ // Set up the video and load in the datasources
+ popcornVideo = Popcorn( "#" + video.id ).parseXML( dataSources );
+
+ // Only play the video if it was specified to do so
+ if ( !!popcornVideo.autoplay ) {
+ popcornVideo.play();
++>>>>>>> 1bbbbc011cb63ac2a33b7de34c1a52387d5963f2
}
}
}
});
++<<<<<<< HEAD
+ };
+
+ document.addEventListener('DOMContentLoaded', init, false);
+
+}());
+
++=======
+ }, false );
+
+ })(window, window.document);
++>>>>>>> 1bbbbc011cb63ac2a33b7de34c1a52387d5963f2