[#915] Fixed review issues. Better defaults for height/width of media

This commit is contained in:
Matthew Schranz 2012-06-01 16:17:21 -04:00
Родитель 63119917f8
Коммит cd81d439da
2 изменённых файлов: 32 добавлений и 30 удалений

Просмотреть файл

@ -69,7 +69,7 @@
</video> </video>
</div> </div>
<div> <div>
<div id="mediaspawnerdiv"></div> <div id="mediaspawnerdiv" style="width: 25%"></div>
</div> </div>
</body> </body>
</html> </html>

Просмотреть файл

@ -5,7 +5,7 @@
* Start is the time that you want this plug-in to execute * Start is the time that you want this plug-in to execute
* End is the time that you want this plug-in to stop executing * End is the time that you want this plug-in to stop executing
* *
* @param {Object} options * @param {HTML} options
* *
* Example: * Example:
var p = Popcorn('#video') var p = Popcorn('#video')
@ -97,10 +97,6 @@
capContainer, capContainer,
regexResult; regexResult;
// Default width and height of media
options.width = options.width || "400";
options.height = options.height || "200";
// Check if mediaSource is passed and mediaType is NOT audio/video // Check if mediaSource is passed and mediaType is NOT audio/video
if ( !options.source ) { if ( !options.source ) {
Popcorn.error( "Error. Source must be specified." ); Popcorn.error( "Error. Source must be specified." );
@ -111,11 +107,35 @@
Popcorn.error( "Target MediaSpawner container doesn't exist." ); Popcorn.error( "Target MediaSpawner container doesn't exist." );
} }
regexResult = urlRegex.exec( options.source );
if ( regexResult ) {
mediaType = regexResult[ 1 ];
// our regex only handles youtu ( incase the url looks something like youtu.be )
if ( mediaType === "youtu" ) {
mediaType = "youtube";
}
}
else {
// if the regex didn't return anything we know it's an HTML5 source
mediaType = "HTML";
}
if ( mediaType === "vimeo" || mediaType === "soundcloud" ) {
Popcorn.error( "Vimeo and soundcloud are currently not supported by the MediaSpawner Plugin." );
}
// Store Reference to Type for use in end
options._type = mediaType;
// Create separate container for plugin // Create separate container for plugin
options._container = document.createElement( "div" ); options._container = document.createElement( "div" );
container = options._container; container = options._container;
container.id = "mediaSpawnerdiv-" + Popcorn.guid(); container.id = "mediaSpawnerdiv-" + Popcorn.guid();
// Default width and height of media
options.width = options.width || target.offsetWidth || "400";
options.height = options.height || target.offsetHeight || "200";
// Captions now need to be in their own container, due to the problem with flash players // Captions now need to be in their own container, due to the problem with flash players
// described in start/end // described in start/end
if ( options.caption ) { if ( options.caption ) {
@ -128,30 +148,10 @@
target && target.appendChild( container ); target && target.appendChild( container );
regexResult = urlRegex.exec( options.source );
if ( regexResult ) {
mediaType = regexResult[ 1 ];
// our regex only handles youtu ( incase the url looks something like youtu.be )
if ( mediaType === "youtu" ) {
mediaType = "youtube";
}
}
else {
// if the regex didn't return anything we know it's an HTML5 source
mediaType = "object";
}
if ( mediaType === "vimeo" || mediaType === "soundcloud" ) {
Popcorn.error( "Vimeo and soundcloud are currently not supported by the MediaSpawner Plugin." );
}
// Store Reference to Type for use in end
options.type = mediaType;
function constructMedia(){ function constructMedia(){
function checkPlayerTypeLoaded() { function checkPlayerTypeLoaded() {
if ( mediaType !== "object" && !window.Popcorn[ mediaType ] ) { if ( mediaType !== "HTML" && !window.Popcorn[ mediaType ] ) {
setTimeout( function() { setTimeout( function() {
checkPlayerTypeLoaded(); checkPlayerTypeLoaded();
}, 300 ); }, 300 );
@ -159,15 +159,17 @@
options.id = options._container.id; options.id = options._container.id;
options.popcorn = Popcorn.smart( "#" + options.id, options.source ); options.popcorn = Popcorn.smart( "#" + options.id, options.source );
if ( mediaType === "object" ) { if ( mediaType === "HTML" ) {
options.popcorn.controls( true ); options.popcorn.controls( true );
} }
options.popcorn.media.style.width = "0px";
options.popcorn.media.style.height = "0px";
options.popcorn.media.style.visibility = "hidden"; options.popcorn.media.style.visibility = "hidden";
} }
} }
if ( mediaType !== "object" && !window.Popcorn[ mediaType ] && !playerTypeLoading[ mediaType ] ) { if ( mediaType !== "HTML" && !window.Popcorn[ mediaType ] && !playerTypeLoading[ mediaType ] ) {
playerTypeLoading[ mediaType ] = true; playerTypeLoading[ mediaType ] = true;
Popcorn.getScript( "http://popcornjs.org/code/players/" + mediaType + "/popcorn." + mediaType + ".js", function() { Popcorn.getScript( "http://popcornjs.org/code/players/" + mediaType + "/popcorn." + mediaType + ".js", function() {
checkPlayerTypeLoaded(); checkPlayerTypeLoaded();
@ -230,7 +232,7 @@
options.popcorn.media.style.visibility = "hidden"; options.popcorn.media.style.visibility = "hidden";
// The Flash Players automagically pause themselves on end already // The Flash Players automagically pause themselves on end already
if ( options.type === "object" ) { if ( options._type === "HTML" ) {
options.popcorn.pause(); options.popcorn.pause();
} }