]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#718] Do not attempt to reuse remote scripts. Includes tests
authorRick Waldron <waldron.rick@gmail.com>
Tue, 13 Sep 2011 20:58:42 +0000 (16:58 -0400)
committerRick Waldron <waldron.rick@gmail.com>
Tue, 13 Sep 2011 20:58:42 +0000 (16:58 -0400)
popcorn.js
test/popcorn.unit.js

index d653cfb071102683a609e06aa8e2e5063593ee32..e2c7320a73229cfaa39255e2c7fe59c740cf6e82 100644 (file)
 
   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 ],
 
       //  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() {
index 60a3ed969b2e2131a30b44ae4c4387abb7bdfa03..01d741aaefa16acdfba8365ef59db5e7f7b9f9b5 100644 (file)
@@ -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 ); } );
 });