return this;
}
+ // Popcorn Object Element Utils
+ position: function() {
+ var media = this.video,
+ bounds = media.getBoundingClientRect(),
+ doc = media.ownerDocument,
+ docElem = document.documentElement,
+ body = document.body,
+ clientTop, clientLeft, scrollTop, scrollLeft, top, left;
+
+ // Determine correct clientTop/Left
+ clientTop = docElem.clientTop || body.clientTop || 0;
+ clientLeft = docElem.clientLeft || body.clientLeft || 0;
+
+ // Determine correct scrollTop/Left
+ scrollTop = (global.pageYOffset && docElem.scrollTop || body.scrollTop );
+ scrollLeft = (global.pageXOffset && docElem.scrollLeft || body.scrollLeft);
+
+ // Temp top/left
+ top = Math.ceil( bounds.top + scrollTop - clientTop );
+ left = Math.ceil( bounds.left + scrollLeft - clientLeft );
+
+ for ( var p in bounds ) {
+ bounds[ p ] = Math.round( bounds[ p ] );
+ }
+
+ return Popcorn.extend({}, bounds, { top: top, left: left });
+ }
});
Popcorn.Events = {
script.onload = script.onreadystatechange = function() {
- if ( !script.readyState || /loaded|complete/.test( script.readyState ) ) {
+ if ( !script.readyState || /loaded|complete/.test( script.readyState ) ) {
- // Handling remote script loading callbacks
- if ( isScript ) {
+ // Handling remote script loading callbacks
+ if ( isScript ) {
- // getScript
- success && success();
- }
+ // getScript
+ success && success();
+ }
- // Executing for JSONP requests
- if ( isFired ) {
+ // Executing for JSONP requests
+ if ( isFired ) {
- // Garbage collect the callback
- delete window[ callback ];
+ // Garbage collect the callback
+ delete window[ callback ];
- // Garbage collect the script resource
- head.removeChild( script );
- }
- }
+ // Garbage collect the script resource
+ head.removeChild( script );
+ }
+ }
};
script.src = url;
});
+module("Popcorn Position");
+test("position", function () {
+
+ var pops = [ Popcorn("#pos-1"),
+ Popcorn("#pos-2"),
+ Popcorn("#pos-3"),
+ Popcorn("#pos-4")
+ ],
+ expects = 22,
+ count = 0,
+ tests = [
+ {"top":0,"height":150,"width":300,"bottom":150,"left":1123,"right":1423},
+ {"top":100,"height":150,"width":300,"bottom":250,"left":1023,"right":1323},
+ {"height":150,"width":300,"left":1366,"right":1666},
+ {"top":0,"height":150,"width":300,"bottom":150,"left":1123,"right":1423}
+ ],
+ bounds,
+ against,
+ styles;
+
+ expect( expects );
+
+ function plus(){
+ if ( ++count == expects ) {
+ start();
+ }
+ }
+
+ stop( 10000 );
+
+ pops.forEach(function( pop, idx ) {
+
+ bounds = pop.position();
+ against = tests[ idx ];
+ styles = document.getElementById( pop.video.id ).style;
+
+ for ( var p in bounds ) {
+ if ( p in against ) {
+ equal( bounds[ p ], against[ p ], "video#" + pop.video.id + ": " + p );
+ plus();
+ }
+ }
+ });
+});
+
+test("position called from plugin", function () {
+
+ var $pop = Popcorn("#video"),
+ expects = 3,
+ count = 0;
+
+ expect( expects );
+
+ function plus(){
+ if ( ++count == expects ) {
+ start();
+ Popcorn.removePlugin("positionPlugin");
+ delete Popcorn.manifest.positionPlugin;
+ }
+ }
+
+ stop( 10000 );
+
+ Popcorn.plugin( "positionPlugin" , function(){
+ return {
+ _setup: function( options ) {
+ ok( "position" in this, "this.position() avaliable in _setup");
+ plus();
+ },
+ start: function(event, options){
+
+ ok( "position" in this, "this.position() avaliable in start");
+ plus();
+ },
+ end: function(event, options){
+ ok( "position" in this, "this.position() avaliable in end");
+ plus();
+ }
+ };
+ });
+
+ $pop.positionPlugin({
+ start: 0,
+ end: 1
+ }).currentTime(0).play();
+});
module("Popcorn Events");
}
});
- Popcorn.parser( "parseAudio", function( data ){
- ok( typeof data.json === "object", "data.json exists");
- plus();
- return data.json;
- });
+ Popcorn.parser( "parseAudio", function( data ){
+ ok( typeof data.json === "object", "data.json exists");
+ plus();
+ return data.json;
+ });
audiocorn.parseAudio("data/parserAudio.json", function() {