зеркало из https://github.com/mozilla/popcorn-js.git
Merge commit 'rick/415' into 0.5
This commit is contained in:
Коммит
fecf32153b
57
popcorn.js
57
popcorn.js
|
@ -400,6 +400,35 @@
|
|||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
// Popcorn Object Element Utils
|
||||
position: function() {
|
||||
var media = this.video,
|
||||
clientRect = media.getBoundingClientRect(),
|
||||
bounds = {},
|
||||
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( clientRect.top + scrollTop - clientTop );
|
||||
left = Math.ceil( clientRect.left + scrollLeft - clientLeft );
|
||||
|
||||
for ( var p in clientRect ) {
|
||||
bounds[ p ] = Math.round( clientRect[ p ] );
|
||||
}
|
||||
|
||||
return Popcorn.extend({}, bounds, { top: top, left: left });
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1065,25 +1094,25 @@
|
|||
|
||||
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;
|
||||
|
|
|
@ -49,5 +49,58 @@
|
|||
|
||||
<audio id='audio' src="italia.ogg" data-timeline-sources="data/parserData.json" controls>
|
||||
</audio>
|
||||
|
||||
|
||||
<!-- Position Tests Adapted From jQuery offsets/dimensions Tests -->
|
||||
<style type="text/css" media="screen">
|
||||
#position-tests { display:none;margin:0; position: fixed;top:0px;left:0px; }
|
||||
|
||||
div.absolute { position: absolute; margin: 0px; width: 100px; height: 100px; background: #fff; }
|
||||
#absolute-1 { top: 0; left: 0; }
|
||||
#absolute-1-1 { top: 1px; left: 1px; }
|
||||
#absolute-1-1-1 { top: 1px; left: 1px; }
|
||||
#absolute-2 { top: 19px; left: 19px; }
|
||||
|
||||
div.relative { position: relative; top: 0; left: 0; width: 100px; height: 100px; background: #fff; overflow: hidden; }
|
||||
#relative-2 { top: 20px; left: 20px; }
|
||||
|
||||
div.fixed { position: fixed; width: 100px; height: 100px; background: #fff; overflow: hidden; }
|
||||
#fixed-1 { top: 0; left: 0; }
|
||||
#fixed-2 { top: 20px; left: 20px; }
|
||||
|
||||
div.static { position: static; top: 0; left: 0; width: 100px; height: 100px; background: #fff; overflow: hidden; }
|
||||
#static-2 { top: 20px; left: 20px; }
|
||||
|
||||
</style>
|
||||
|
||||
<div id="position-tests">
|
||||
<div id="absolute-1" class="absolute"><video id="vid-absolute-1" src="trailer.ogv" style="visibility:hidden"></video>
|
||||
<div id="absolute-1-1" class="absolute"><video id="vid-absolute-1-1"" src="trailer.ogv" style="visibility:hidden"></video>
|
||||
<div id="absolute-1-1-1" class="absolute"><video id="vid-absolute-1-1-1" src="trailer.ogv" style="visibility:hidden"></video></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="absolute-2" class="absolute"><video id="vid-absolute-2" src="trailer.ogv" style="visibility:hidden"></video></div>
|
||||
|
||||
<div id="relative-1" class="relative"><video id="vid-relative-1" src="trailer.ogv" style="visibility:hidden"></video>
|
||||
<div id="relative-1-1" class="relative"><video id="vid-relative-1-1" src="trailer.ogv" style="visibility:hidden"></video>
|
||||
<div id="relative-1-1-1" class="relative"><video id="vid-relative-1-1-1" src="trailer.ogv" style="visibility:hidden"></video></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="relative-2" class="relative"><video id="vid-relative-2" src="trailer.ogv" style="visibility:hidden"></video></div>
|
||||
|
||||
|
||||
<div id="fixed-1" class="fixed"><video id="vid-fixed-1" src="trailer.ogv" style="visibility:hidden"></video></div>
|
||||
<div id="fixed-2" class="fixed"><video id="vid-fixed-2" src="trailer.ogv" style="visibility:hidden"></video></div>
|
||||
|
||||
<div id="static-1" class="static"><video id="vid-static-1" src="trailer.ogv" style="visibility:hidden">
|
||||
<div id="static-1-1" class="static"><video id="vid-static-1-1" src="trailer.ogv" style="visibility:hidden">
|
||||
<div id="static-1-1-1" class="static"><video id="vid-static-1-1-1" src="trailer.ogv" style="visibility:hidden"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="static-2" class="static"><video id="vid-static-2" src="trailer.ogv" style="visibility:hidden"></div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -340,6 +340,112 @@ test("exec", function () {
|
|||
|
||||
});
|
||||
|
||||
module("Popcorn Position");
|
||||
test("position", function () {
|
||||
|
||||
expect(24);
|
||||
|
||||
var $absolute = $(".absolute"),
|
||||
$relative = $(".relative"),
|
||||
$fixed = $(".fixed"),
|
||||
$static = $(".static"),
|
||||
tests;
|
||||
|
||||
$("#position-tests").show();
|
||||
// console.log( $absolute );
|
||||
// console.log( $fixed );
|
||||
// console.log( $relative );
|
||||
// console.log( $static );
|
||||
|
||||
tests = [
|
||||
{ id: "absolute-1", top: 0, left: 0 },
|
||||
{ id: "absolute-1-1", top: 1, left: 1 },
|
||||
{ id: "absolute-1-1-1", top: 2, left: 2 },
|
||||
{ id: "absolute-2", top: 19, left: 19 }
|
||||
];
|
||||
|
||||
Popcorn.forEach( tests, function( test ) {
|
||||
equals( Popcorn( "#vid-" + test.id ).position().top, test.top, "Popcorn('#vid-" + test.id + "').position().top" );
|
||||
equals( Popcorn( "#vid-" + test.id ).position().left, test.left, "Popcorn('#vid-" + test.id + "').position().left" );
|
||||
});
|
||||
|
||||
tests = [
|
||||
{ id: "relative-1", top: 0, left: 0 },
|
||||
{ id: "relative-2", top: 120, left: 20 }
|
||||
];
|
||||
|
||||
Popcorn.forEach( tests, function( test ) {
|
||||
equals( Popcorn( "#vid-" + test.id ).position().top, test.top, "Popcorn('#vid-" + test.id + "').position().top" );
|
||||
equals( Popcorn( "#vid-" + test.id ).position().left, test.left, "Popcorn('#vid-" + test.id + "').position().left" );
|
||||
});
|
||||
|
||||
tests = [
|
||||
{ id: "fixed-1", top: 0, left: 0 },
|
||||
{ id: "fixed-2", top: 20, left: 20 }
|
||||
];
|
||||
|
||||
Popcorn.forEach( tests, function( test ) {
|
||||
equals( Popcorn( "#vid-" + test.id ).position().top, test.top, "Popcorn('#vid-" + test.id + "').position().top" );
|
||||
equals( Popcorn( "#vid-" + test.id ).position().left, test.left, "Popcorn('#vid-" + test.id + "').position().left" );
|
||||
});
|
||||
|
||||
tests = [
|
||||
{ id: "static-1", top: 200, left: 0 },
|
||||
{ id: "static-1-1", top: 0, left: 0 },
|
||||
{ id: "static-1-1-1", top: 0, left: 0 },
|
||||
{ id: "static-2", top: 300, left: 0 }
|
||||
];
|
||||
|
||||
Popcorn.forEach( tests, function( test ) {
|
||||
equals( Popcorn( "#vid-" + test.id ).position().top, test.top, "Popcorn('#vid-" + test.id + "').position().top" );
|
||||
equals( Popcorn( "#vid-" + test.id ).position().left, test.left, "Popcorn('#vid-" + test.id + "').position().left" );
|
||||
});
|
||||
|
||||
|
||||
$("#position-tests").hide();
|
||||
});
|
||||
|
||||
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");
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче