--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Popcorn 0.1 parser Plug-in Demo</title>
+
+ <script src="../../popcorn.js"></script>
+ <script src="../../test/jquery.js"></script>
+ <script src="../../plugins/flickr/popcorn.flickr.js"></script>
+ <script src="popcorn.parseXML.js"></script>
+ <script>
+ document.addEventListener('DOMContentLoaded', function () {
+ var p = Popcorn('#video')
+ .parseXML("data.XML")
+ .play();
+
+ }, false);
+
+ </script>
+</head>
+<body>
+ <h1 id="qunit-header">Popcorn 0.1 parser Plug-in Demo</h1>
+ <p></p>
+ <div>
+ <video id='video'
+ controls preload='none'
+ width= '250px'
+ poster="../../test/poster.png">
+
+ <source id='mp4'
+ src="../../test/trailer.mp4"
+ type='video/mp4; codecs="avc1, mp4a"'>
+
+ <source id='ogv'
+ src="../../test/trailer.ogv"
+ type='video/ogg; codecs="theora, vorbis"'>
+
+ <p>Your user agent does not support the HTML5 Video element.</p>
+
+ </video>
+ </div>
+
+ <div id="flickrdiv"></div>
+</body>
+</html>
--- /dev/null
+// PARSER: 0.1 XML
+
+(function (Popcorn) {
+
+ /**
+ *
+ *
+ */
+ Popcorn.parser( "parseXML", "XML", function( data ) {
+
+ // declare needed variables
+ var returnData = {
+ title: "",
+ remote: "",
+ data: []
+ },
+ manifestData = {};
+
+ // turns a node tree element into a straight up javascript object
+ // also converts in and out to start and end
+ // also links manifest data with ids
+ var objectifyAttributes = function ( nodeAttributes ) {
+
+ var returnObject = {};
+
+ for ( var i = 0, nal = nodeAttributes.length; i < nal; i++ ) {
+
+ var key = nodeAttributes.item(i).nodeName,
+ data = nodeAttributes.item(i).nodeValue;
+
+ // converts in into start
+ if (key === "in") {
+ returnObject.start = data;
+ // converts out into end
+ } else if ( key === "out" ){
+ returnObject.end = data;
+ // this is where ids in the manifest are linked
+ } else if ( key === "resourceid" ) {
+ Popcorn.extend( returnObject, manifestData[data] );
+ // everything else
+ } else {
+ returnObject[key] = data;
+ }
+
+ }
+
+ return returnObject;
+ };
+
+ // creates an object of all atrributes keyd by name
+ var createTrack = function( name, attributes ) {
+ var track = {};
+ track[name] = attributes;
+ return track;
+ };
+
+ // recursive function to process a node, or process the next child node
+ var parseNode = function ( node, allAttributes, manifest ) {
+ var attributes = {};
+ Popcorn.extend( attributes, allAttributes, objectifyAttributes( node.attributes ), { text: node.textContent } );
+
+ var childNodes = node.childNodes;
+
+ // processes the node
+ if ( childNodes.length < 1 || ( childNodes.length === 1 && childNodes[0].nodeType === 3 ) ) {
+
+ if ( !manifest ) {
+ returnData.data.push( createTrack( node.nodeName, attributes ) );
+ } else {
+ manifestData[attributes.id] = attributes;
+ }
+
+ // process the next child node
+ } else {
+
+ for ( var i = 0; i < childNodes.length; i++ ) {
+
+ if ( childNodes[i].nodeType === 1 ) {
+ parseNode( childNodes[i], attributes, manifest );
+ }
+
+ }
+ }
+ };
+
+ // this is where things actually start
+ var x = data.xml.documentElement.childNodes;
+
+ for ( var i = 0, xl = x.length; i < xl; i++ ) {
+
+ if ( x[i].nodeType === 1 ) {
+
+ // start the process of each main node type, manifest or timeline
+ if ( x[i].nodeName === "manifest" ) {
+ parseNode( x[i], {}, true );
+ } else { // timeline
+ parseNode( x[i], {}, false );
+ }
+
+ }
+ }
+
+ return returnData;
+ });
+
+})( Popcorn );
var tracksObject = definition( data );
// creating tracks out of parsed object
- for ( var key in tracksObject ) {
- if ( tracksObject.hasOwnProperty(key) ) {
+ for ( var i = 0, todl = tracksObject.data.length; i < todl; i++ ) {
- // an array of tracks of all one type
- if ( tracksObject[key].constructor === Array ) {
+ for ( var key in tracksObject.data[i] ) {
- for (var i = 0, tol = tracksObject[key].length; i < tol; i++) {
- if ( typeof that[key] === "function") {
- that[key]( tracksObject[key][i] );
- }
- }
-
- // one single track
- } else if ( typeof tracksObject[key] === "object" ) {
- if ( typeof that[key] === "function") {
- that[key]( tracksObject[key] );
- }
+ if ( tracksObject.data[i].hasOwnProperty(key) ) {
+ that[key]( tracksObject.data[i][key] );
}
}
}