From: rwldrn Date: Thu, 2 Jun 2011 13:27:14 +0000 (-0400) Subject: Relocate Popcorn.removePlugin() to more appropriate location X-Git-Tag: v0.7^2~53^2~4 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=b727e193de262e1d269c519e3c2c6fa7d98287e7;p=popcorn-js.git Relocate Popcorn.removePlugin() to more appropriate location --- diff --git a/popcorn.js b/popcorn.js index 387852a..97d4e57 100644 --- a/popcorn.js +++ b/popcorn.js @@ -651,59 +651,6 @@ }; - // removePlugin( type ) removes all tracks of that from all instances of popcorn - // removePlugin( obj, type ) removes all tracks of type from obj, where obj is a single instance of popcorn - Popcorn.removePlugin = function( obj, name ) { - - // Check if we are removing plugin from an instance or from all of Popcorn - if ( !name ) { - - // Fix the order - name = obj; - obj = Popcorn.p; - - var registryLen = Popcorn.registry.length, - registryIdx; - - // remove plugin reference from registry - for ( registryIdx = 0; registryIdx < registryLen; registryIdx++ ) { - if ( Popcorn.registry[ registryIdx ].name === name ) { - Popcorn.registry.splice( registryIdx, 1 ); - delete Popcorn.registryByName[ name ]; - - // delete the plugin - delete obj[ name ]; - - // plugin found and removed, stop checking, we are done - return; - } - } - - } - - var byStart = obj.data.trackEvents.byStart, - byEnd = obj.data.trackEvents.byEnd, - idx, sl; - - // remove all trackEvents - for ( idx = 0, sl = byStart.length; idx < sl; idx++ ) { - - if ( ( byStart[ idx ] && byStart[ idx ]._natives && byStart[ idx ]._natives.type === name ) && - ( byEnd[ idx ] && byEnd[ idx ]._natives && byEnd[ idx ]._natives.type === name ) ) { - - byStart.splice( idx, 1 ); - byEnd.splice( idx, 1 ); - - // update for loop if something removed, but keep checking - idx--; sl--; - if ( obj.data.trackEvents.startIndex <= idx ) { - obj.data.trackEvents.startIndex--; - obj.data.trackEvents.endIndex--; - } - } - } - }; - Popcorn.removeTrackEvent = function( obj, trackId ) { var historyLen = obj.data.history.length, @@ -940,6 +887,60 @@ return plugin; }; + // removePlugin( type ) removes all tracks of that from all instances of popcorn + // removePlugin( obj, type ) removes all tracks of type from obj, where obj is a single instance of popcorn + Popcorn.removePlugin = function( obj, name ) { + + // Check if we are removing plugin from an instance or from all of Popcorn + if ( !name ) { + + // Fix the order + name = obj; + obj = Popcorn.p; + + var registryLen = Popcorn.registry.length, + registryIdx; + + // remove plugin reference from registry + for ( registryIdx = 0; registryIdx < registryLen; registryIdx++ ) { + if ( Popcorn.registry[ registryIdx ].name === name ) { + Popcorn.registry.splice( registryIdx, 1 ); + delete Popcorn.registryByName[ name ]; + + // delete the plugin + delete obj[ name ]; + + // plugin found and removed, stop checking, we are done + return; + } + } + + } + + var byStart = obj.data.trackEvents.byStart, + byEnd = obj.data.trackEvents.byEnd, + idx, sl; + + // remove all trackEvents + for ( idx = 0, sl = byStart.length; idx < sl; idx++ ) { + + if ( ( byStart[ idx ] && byStart[ idx ]._natives && byStart[ idx ]._natives.type === name ) && + ( byEnd[ idx ] && byEnd[ idx ]._natives && byEnd[ idx ]._natives.type === name ) ) { + + byStart.splice( idx, 1 ); + byEnd.splice( idx, 1 ); + + // update for loop if something removed, but keep checking + idx--; sl--; + if ( obj.data.trackEvents.startIndex <= idx ) { + obj.data.trackEvents.startIndex--; + obj.data.trackEvents.endIndex--; + } + } + } + }; + + // Popcorn Plugin Inheritance Helper Methods // Internal use only Popcorn.plugin.getDefinition = function( name ) {