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() {
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" );
});
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 ); } );
});