// If container id is not supplied, assumed to be same as player id
var ctor = function ( containerId, videoUrl ) {
- if ( !containerId ) {
- throw "Must supply an id!";
- } else if ( /file/.test( location.protocol ) ) {
- throw "Must run from a web server!";
- }
-
var vidId,
that = this,
- container = document.getElementById( containerId );
+ bounds,
+ // For flash embedding
+ params,
+ flashvars,
+ attributes = {};
this.addEventFn;
this.evtHolder;
this.previousVolume = this.volume;
this.evtHolder = new EventManager( this );
+ this._container = document.getElementById( containerId );
+ bounds = this._container.getBoundingClientRect();
+
// For calculating position relative to video (like subtitles)
- this.offsetWidth = this.width = container.getAttribute( "width" ) || "504";
- this.offsetHeight = this.height = container.getAttribute( "height" ) || "340";
- this.offsetLeft = 0;
- this.offsetTop = 0;
+ this.offsetWidth = this.width = this._container.getAttribute( "width" ) || 504;
+ this.offsetHeight = this.height = this._container.getAttribute( "height" ) || 340;
+ this.offsetLeft = bounds.left;
+ this.offsetTop = bounds.top;
// Try and get a video id from a vimeo site url
// Try either from ctor param or from iframe itself
}
if ( !vidId ){
- vidId = extractIdFromUrl( container.getAttribute("src") ) || extractIdFromUri( container.getAttribute("src") );
+ vidId = extractIdFromUrl( this._container.getAttribute("src") ) || extractIdFromUri( this._container.getAttribute("src") );
}
if ( !vidId ) {
dispatchEvent: function( evtName ) {
return this.evtHolder.dispatchEvent( evtName );
},
+ getBoundingClientRect: function() {
+ var b,
+ self = this;
+
+ if ( this.swfObj ) {
+ b = this.swfObj.getBoundingClientRect();
+
+ return {
+ bottom: b.bottom,
+ left: b.left,
+ right: b.right,
+ top: b.top,
+
+ // These not guaranteed to be in there
+ width: b.width || ( b.right - b.left ),
+ height: b.height || ( b.bottom - b.top )
+ };
+ } else {
+ b = this._container.getBoundingClientRect();
+
+ // Update bottom, right for expected values once the container loads
+ return {
+ left: b.left,
+ top: b.top,
+ width: self.offsetWidth,
+ height: self.offsetHeight,
+ bottom: b.top + this.width,
+ right: b.top + this.height
+ };
+ }
+ },
startTimeUpdater: function() {
var self = this,
seeked = 0;
}
function makeSWF( url, container ) {
- var params,
+ var bounds,
+ params,
flashvars,
attributes,
self = this;
throw "Could not find video id";
}
+ bounds = container.getBoundingClientRect();
+
// Determine width/height/etc based on container
this.width = container.getAttribute("width") || 460;
this.height = container.getAttribute("height") || 350;
this.width = parseFloat(this.width);
this.height = parseFloat(this.height);
+ // For calculating position relative to video (like subtitles)
this.offsetWidth = this.width;
this.offsetHeight = this.height;
+ this.offsetLeft = bounds.left;
+ this.offsetTop = bounds.top;
+
this.offsetParent = container.offsetParent;
- this.offsetLeft = container.offsetLeft;
- this.offsetTop = container.offsetTop;
flashvars = {
playerapiid: this.playerId
throw "This must be run from a web server.";
}
- var self = this,
- container = document.getElementById( elementId );;
+ var self = this;
this.playerId = elementId;
this.readyState = READY_STATE_HAVE_NOTHING;
- this.eventListeners = {};
+ this._eventListeners = {};
this.loadStarted = false;
this.loadedData = false;
this.fullyLoaded = false;
- this.timeUpdater = null;
- this.progressUpdater = null;
+
+ this._container = document.getElementById( elementId );
this.currentTime = this.previousCurrentTime = 0;
this.volume = this.previousVolume = this.preMuteVol = 1;
this.offsetWidth = this.video.offsetWidth;
this.offsetHeight = this.video.offsetHeight;
this.offsetParent = this.video.offsetParent;
- this.offsetLeft = this.video.offsetLeft;
- this.offsetTop = this.video.offsetTop;
// Set up stuff that requires the API to be loaded
this.registerYoutubeEventHandlers();
if ( loadedPlayers[this.playerId] ) {
this.video = registry[this.playerId].video;
- this.vidId = this.vidId || extractIdFromUrl( container.getAttribute( "src" ) ) || extractIdFromUri( container.getAttribute( "src" ) );
+ this.vidId = this.vidId || extractIdFromUrl( this._container.getAttribute( "src" ) ) || extractIdFromUri( this._container.getAttribute( "src" ) );
if (this.vidId !== registry[this.playerId].vidId ) {
this.video.cueVideoById( this.vidId );
}
this.dispatchEvent( 'load' );
- } else if ( container ) {
- makeSWF.call( this, url, container );
+ } else if ( this._container ) {
+ makeSWF.call( this, url, this._container );
} else {
// Container not yet loaded, get it on DOMDontentLoad
document.addEventListener( "DOMContentLoaded", function() {
- container = document.getElementById( elementId );
+ self._container = document.getElementById( elementId );
- if ( !container ) {
+ if ( !self._container ) {
throw "Could not find container!";
}
- makeSWF.call( self, url, container );
+ makeSWF.call( self, url, self._container );
}, false);
}
addEventListener: function( evt, func ) {
var evtName = evt.type || evt;
- if ( !this.eventListeners[evtName] ) {
- this.eventListeners[evtName] = [];
+ if ( !this._eventListeners[evtName] ) {
+ this._eventListeners[evtName] = [];
}
- this.eventListeners[evtName].push( func );
+ this._eventListeners[evtName].push( func );
},
/**
*/
dispatchEvent: function( name ) {
var evtName = name.type || name;
- if ( !this.eventListeners[evtName] ) {
+ if ( !this._eventListeners[evtName] ) {
return;
}
var self = this;
- Popcorn.forEach( this.eventListeners[evtName], function( evt ) {
+ Popcorn.forEach( this._eventListeners[evtName], function( evt ) {
evt.call( self, null );
});
},
playbackRate: function( arg ) {
},
+ getBoundingClientRect: function() {
+ var b,
+ self = this;
+
+ if ( this.video ) {
+ b = this.video.getBoundingClientRect();
+
+ return {
+ bottom: b.bottom,
+ left: b.left,
+ right: b.right,
+ top: b.top,
+
+ // These not guaranteed to be in there
+ width: b.width || ( b.right - b.left ),
+ height: b.height || ( b.bottom - b.top )
+ };
+ } else {
+ b = this._container.getBoundingClientRect();
+
+ // Update bottom, right for expected values once the container loads
+ return {
+ left: b.left,
+ top: b.top,
+ width: self.offsetWidth,
+ height: self.offsetHeight,
+ bottom: b.top + this.width,
+ right: b.top + this.height
+ };
+ }
+ },
+
startTimeUpdater: function() {
var state = this.video.getPlayerState(),
self = this,