Skip to content
This repository has been archived by the owner on Jun 29, 2018. It is now read-only.

Commit

Permalink
[#976180] Back out new event system until it can fire multiple events…
Browse files Browse the repository at this point in the history
… of one type with events of that type being removed while it fires
  • Loading branch information
ScottDowne committed Feb 25, 2014
1 parent 5835bbf commit 7fd0345
Showing 1 changed file with 13 additions and 51 deletions.
64 changes: 13 additions & 51 deletions wrappers/common/popcorn._MediaElementProto.js
Expand Up @@ -101,62 +101,24 @@
// Mimic DOM events with custom, namespaced events on the document.
// Each media element using this prototype needs to provide a unique
// namespace for all its events via _eventNamespace.
protoElement.addEventListener = function( evtName, fn ) {

if ( !events[ evtName ] ) {

events[ evtName ] = [];
}

events[ evtName ].push( fn );
protoElement.addEventListener = function( type, listener, useCapture ) {
document.addEventListener( this._eventNamespace + type, listener, useCapture );
};

protoElement.removeEventListener = function( evtName, fn ) {
var i,
listeners = events[ evtName ];

if ( !listeners ){

return;
}

// walk backwards so we can safely splice
for ( i = events[ evtName ].length - 1; i >= 0; i-- ) {

if( fn === listeners[ i ] ) {

listeners.splice( i, 1 );
}
}
protoElement.removeEventListener = function( type, listener, useCapture ) {
document.removeEventListener( this._eventNamespace + type, listener, useCapture );
};

protoElement.dispatchEvent = function( oEvent ) {
protoElement.dispatchEvent = function( name ) {
var customEvent = document.createEvent( "CustomEvent" ),
detail = {
type: name,
target: this.parentNode,
data: null
};

var evt,
self = this,
eventInterface,
eventName = oEvent.type;

// A string was passed, create event object
if ( !eventName ) {

eventName = oEvent;
eventInterface = Popcorn.events.getInterface( eventName );

if ( eventInterface ) {

evt = document.createEvent( eventInterface );
evt.initEvent( eventName, true, true, window, 1 );
}
}

if ( events[ eventName ] ) {

for ( var i = 0; i < events[ eventName ].length; i++ ) {

events[ eventName ][ i ].call( self, evt, self );
}
}
customEvent.initCustomEvent( this._eventNamespace + name, false, false, detail );
document.dispatchEvent( customEvent );
};

protoElement.load = Popcorn.nop;
Expand Down

0 comments on commit 7fd0345

Please sign in to comment.