From: Rick Waldron Date: Tue, 13 Sep 2011 20:58:42 +0000 (-0400) Subject: [#718] Do not attempt to reuse remote scripts. Includes tests X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=9c5a35ba12a8e2673486b94b01f22a6bc36c6af6;p=popcorn-js.git [#718] Do not attempt to reuse remote scripts. Includes tests --- diff --git a/popcorn.js b/popcorn.js index d653cfb..e2c7320 100644 --- a/popcorn.js +++ b/popcorn.js @@ -1579,21 +1579,6 @@ Popcorn.xhr.getJSONP = function( url, success, isScript ) { - // If this is a script request, ensure that we do not call something that has already been loaded - if ( isScript ) { - - var scripts = document.querySelectorAll( "script[src=\"" + url + "\"]" ); - - // If there are scripts with this url loaded, early return - if ( scripts.length ) { - - // Execute success callback and pass "exists" flag - success && success( true ); - - return; - } - } - var head = document.head || document.getElementsByTagName( "head" )[ 0 ] || document.documentElement, script = document.createElement( "script" ), paramStr = url.split( "?" )[ 1 ], @@ -1619,22 +1604,19 @@ // If a callback name already exists if ( !!window[ callback ] ) { - // Create a new unique callback name callback = Popcorn.guid( callback ); } // Define the JSONP success callback globally window[ callback ] = function( data ) { - + // Fire success callbacks success && success( data ); isFired = true; - }; // Replace callback param and callback name url = url.replace( parts.join( "=" ), parts[ 0 ] + "=" + callback ); - } script.onload = function() { diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 60a3ed9..01d741a 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -544,7 +544,7 @@ test("exec", function() { test( "cue (alias of exec)", function() { expect( 3 ); - ok( Popcorn.p.cue, "Popcorn.p.cue exists" ); + ok( Popcorn.p.cue, "Popcorn.p.cue exists" ); equal( typeof Popcorn.p.cue, "function", "Popcorn.p.cue is a function" ); deepEqual( Popcorn.p.cue, Popcorn.p.exec, "Popcorn.p.cue equals Popcorn.p.exec" ); }); @@ -3276,39 +3276,23 @@ test("Popcorn.getScript()", function() { ok( ("has" in window) , "Popcorn.getScript https://github.com/rwldrn/has.js/raw/master/has.js loaded: `has` is available"); plus(); - delete window["has"]; } ); + var cb = function( id ) { + if ( window.testFunction ) { + ok( true, "testFunction called by plugin id#: " + id ); + plus(); + } else { + ok( false, "testFunction called by plugin id#: " + id ); + plus(); + } + } - Popcorn.xhr({ - - url: "data/remoteA.js", - - dataType: "script", - - success: function( exists ) { - - ok( exists, "Success, remoteA loaded once"); - plus() - } - }); - - Popcorn.getScript( - - "data/remoteB.js", - - function( exists ) { - - ok( exists, "Success, remoteB loaded once"); - plus() - - } - ); - - + Popcorn.getScript( "testfunction.js", function() { cb( 1 ); } ); + Popcorn.getScript( "testfunction.js", function() { cb( 2 ); } ); });