Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
No ?jquery => inserts jquery.js
Browse files Browse the repository at this point in the history
Get the version from jQuery.fn.jquery instead of the url param
  • Loading branch information
gseguin committed May 16, 2012
1 parent 0ce3376 commit c155cab
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions js/jquery.tag.inserter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,38 @@
// Get the version from the url
var jqueryRE = /[\\?&]jquery=([^&#]*)/,
results = jqueryRE.exec( location.search ),
version = "1.7.1",
version = "",
myScriptTag = document.getElementsByTagName( "script" )[document.getElementsByTagName( "script" ).length - 1],
baseUrl = myScriptTag.src.replace( /(.*)\/.*$/, "$1/" ),
url;
url = baseUrl + "jquery.js";

if( results ) {
version = decodeURIComponent(results[results.length - 1].replace(/\+/g, " "));
}

switch( version ) {
// Local versions
case "1.6.4":
case "1.7.1":
case "1.7.2":
url = baseUrl + "jquery-" + version + ".js";
break;
// CDN versions
default:
url = "http://code.jquery.com/jquery-"+version+".js";
break;
}
switch( version ) {
// Local versions
case "1.6.4":
case "1.7.1":
case "1.7.2":
url = baseUrl + "jquery-" + version + ".js";
break;
// CDN versions
default:
url = "http://code.jquery.com/jquery-"+version+".js";
break;
}
}

document.write( "<script src='" + url + "'></script>" );

if ( parseInt( version.replace( /\./g, "" ), 10 ) < 170 && window.define && window.define.amd ) {
document.write( '<script>define( "jquery", [], function () { return jQuery; } );</script>' );
}
document.write(
'<script>' +
'console.warn( "jQuery version: " + jQuery.fn.jquery );' +
'if ( parseInt( jQuery.fn.jquery.replace( /\\./g, "" ), 10 ) < 170 && window.define && window.define.amd ) {' +
'console.warn( "Exporting \'jquery\' AMD module" );' +
'define( "jquery", [], function () { return jQuery; } );'+
'}'+
'</script>'
);

}());

0 comments on commit c155cab

Please sign in to comment.