From a5af0c4f289c750a92d16e4584031a15099223b8 Mon Sep 17 00:00:00 2001 From: stevenaw Date: Wed, 20 Apr 2011 20:21:29 -0400 Subject: [PATCH] [#422] Done. can be specified in ctor or styles --- players/vimeo/popcorn.vimeo.html | 7 ++++-- players/vimeo/popcorn.vimeo.js | 8 +------ players/vimeo/popcorn.vimeo.unit.html | 2 +- players/youtube/popcorn.youtube.html | 2 +- players/youtube/popcorn.youtube.js | 27 ++++++++++++----------- players/youtube/popcorn.youtube.unit.html | 4 ++-- 6 files changed, 24 insertions(+), 26 deletions(-) diff --git a/players/vimeo/popcorn.vimeo.html b/players/vimeo/popcorn.vimeo.html index fcad8da..a55c36f 100644 --- a/players/vimeo/popcorn.vimeo.html +++ b/players/vimeo/popcorn.vimeo.html @@ -101,7 +101,10 @@ //On document ready document.addEventListener( "DOMContentLoaded", function() { - var player = Popcorn( Popcorn.vimeo( "player_1" ) ) + var player = Popcorn( Popcorn.vimeo( "player_1", "http://player.vimeo.com/video/11127501", { + width: 500, + height: 281 + }) ) .footnote({ start: 5, // seconds end: 40, // seconds @@ -177,7 +180,7 @@
-

+

diff --git a/players/vimeo/popcorn.vimeo.js b/players/vimeo/popcorn.vimeo.js index 9c73f51..3f5be04 100644 --- a/players/vimeo/popcorn.vimeo.js +++ b/players/vimeo/popcorn.vimeo.js @@ -340,13 +340,7 @@ // Try and get a video id from a vimeo site url // Try either from ctor param or from iframe itself - if( videoUrl ) { - vidId = extractIdFromUrl( videoUrl ) || extractIdFromUri( videoUrl ); - } - - if ( !vidId ){ - vidId = extractIdFromUrl( this._container.getAttribute("src") ) || extractIdFromUri( this._container.getAttribute("src") ); - } + vidId = extractIdFromUrl( videoUrl ) || extractIdFromUri( videoUrl ); if ( !vidId ) { throw "No video id"; diff --git a/players/vimeo/popcorn.vimeo.unit.html b/players/vimeo/popcorn.vimeo.unit.html index 6b4bddb..91c9d37 100644 --- a/players/vimeo/popcorn.vimeo.unit.html +++ b/players/vimeo/popcorn.vimeo.unit.html @@ -23,6 +23,6 @@
    -
    +
    diff --git a/players/youtube/popcorn.youtube.html b/players/youtube/popcorn.youtube.html index c61f97d..b340c16 100644 --- a/players/youtube/popcorn.youtube.html +++ b/players/youtube/popcorn.youtube.html @@ -22,7 +22,7 @@ var paused = true, popcorn; - popcorn = Popcorn( Popcorn.youtube( 'video', 'http://www.youtube.com/watch?v=9oar9glUCL0' ) ); + popcorn = Popcorn( Popcorn.youtube( 'video', 'http://www.youtube.com/watch?v=9oar9glUCL0', { width: 400 } ) ); popcorn = popcorn .footnote({ diff --git a/players/youtube/popcorn.youtube.js b/players/youtube/popcorn.youtube.js index 0c093e1..8b23618 100644 --- a/players/youtube/popcorn.youtube.js +++ b/players/youtube/popcorn.youtube.js @@ -96,14 +96,6 @@ var onYouTubePlayerReady; makeSWF.call( self, url, container ); }, 1 ); return; - } - - // The video id for youtube (web or player formats) - // First check manually given url, if that doesn't work resort to "src" - this.vidId = this.vidId || extractIdFromUrl( container.getAttribute( "src" ) ) || extractIdFromUri( container.getAttribute( "src" ) ); - - if ( !this.vidId ) { - throw "Could not find video id"; } bounds = container.getBoundingClientRect(); @@ -158,17 +150,19 @@ var onYouTubePlayerReady; vid.dispatchEvent( "durationchange" ); } - Popcorn.youtube = function( elementId, url ) { - return new Popcorn.youtube.init( elementId, url ); + Popcorn.youtube = function( elementId, url, options ) { + return new Popcorn.youtube.init( elementId, url, options ); }; - Popcorn.youtube.init = function( elementId, url ) { + Popcorn.youtube.init = function( elementId, url, options ) { if ( !elementId ) { throw "Element id is invalid."; } else if ( /file/.test( location.protocol ) ) { throw "This must be run from a web server."; } + options = options || {}; + var self = this; this.playerId = elementId + Popcorn.guid(); @@ -178,11 +172,14 @@ var onYouTubePlayerReady; this.loadedData = false; this.fullyLoaded = false; + options.width = options.width && (+options.width)+"px"; + options.height = options.height && (+options.height)+"px"; + this._target = document.getElementById( elementId ); this._container = document.createElement( "div" ); this._container.id = this.playerId; - this._container.style.height = this._target.style.height = this._target.style.height || "350px"; - this._container.style.width = this._target.style.width = this._target.style.width || "460px"; + this._container.style.height = this._target.style.height = options.height || this._target.style.height || "350px"; + this._container.style.width = this._target.style.width = options.width || this._target.style.width || "460px"; this._target.appendChild( this._container ); this.offsetHeight = +this._target.offsetHeight; @@ -194,6 +191,10 @@ var onYouTubePlayerReady; this.vidId = extractIdFromUrl( url ) || extractIdFromUri( url ); + if ( !this.vidId ) { + throw "Could not find video id"; + } + this.addEventListener( "load", function() { // For calculating position relative to video (like subtitles) this.offsetWidth = this.video.offsetWidth; diff --git a/players/youtube/popcorn.youtube.unit.html b/players/youtube/popcorn.youtube.unit.html index 54c3f84..ce0a83c 100644 --- a/players/youtube/popcorn.youtube.unit.html +++ b/players/youtube/popcorn.youtube.unit.html @@ -28,8 +28,8 @@ Therefore, if failures occur for the first time, just run it again. Likely, failures would disappear the second time.

    -
    -
    +
    +
    -- 2.43.0