// ID string matching
rIdExp = /^(#([\w\-\_\.]+))$/,
+
+ // ready fn cache
+ readyStack = [],
+ readyBound = false,
+
// Declare a pseudo-private constructor
- // This constructor returns the instance object.
+ // Returns an instance object.
Popcorn = function( entity ) {
// Return new Popcorn object
return new Popcorn.p.init( entity );
var elem, matches;
+ // Supports Popcorn(function () { /../ })
+ // Originally proposed by Daniel Brooks
if ( typeof entity === "function" ) {
- document.addEventListener( "DOMContentLoaded", entity, false);
+ readyStack.push( entity );
+
+ // This process should happen once per page load
+ if ( !readyBound ) {
+
+ // set readyBound flag
+ readyBound = true;
+
+ var DOMContentLoaded = function () {
+
+ // 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 );
elem = document.getElementById(matches[2]);
}
+
this.video = elem ? elem : null;
this.data = {
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 ) {
-
- global.Popcorn = Popcorn;
+ // Exposes Popcorn and a shorthand to global context
+ global.Popcorn = global.$P = Popcorn;
})(window, document);
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Popcorn API</title>
+ <link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen">
+ <script src="../popcorn.js"></script>
+ <script>
+
+ Popcorn(function (e) {
+
+ console.log("Popcorn(function() { /../ }) 1");
+
+ var p = Popcorn("#video");
+
+
+ p.exec( 4, function () {
+
+
+
+ }).play();
+
+ });
+
+ Popcorn(function () {
+
+ console.log("Popcorn(function() { /../ }) 2");
+
+ });
+ </script>
+
+</head>
+<body>
+ <video id='video'style="display:"
+ controls
+ poster="http://media.w3.org/2010/05/sintel/poster.png">
+
+ <source id='mp4'
+ src="http://media.w3.org/2010/05/sintel/trailer.mp4"
+ type='video/mp4; codecs="avc1, mp4a"'>
+
+ <source id='ogv'
+ src="http://media.w3.org/2010/05/sintel/trailer.ogv"
+ type='video/ogg; codecs="theora, vorbis"'>
+
+ <p>Your user agent does not support the HTML5 Video element.</p>
+
+ </video>
+</body>
+</html>