Posted By

brianyang on 04/29/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

wirenaught


get script


 / Published in: JavaScript
 

  1. // more or less stolen form jquery core and adapted by paul irish
  2. function getScript(url,success){
  3. var script=document.createElement('script');
  4. script.src=url;
  5. var head=document.getElementsByTagName('head')[0],
  6. done=false;
  7. // Attach handlers for all browsers
  8. script.onload=script.onreadystatechange = function(){
  9. if ( !done && (!this.readyState
  10. || this.readyState == 'loaded'
  11. || this.readyState == 'complete') ) {
  12. done=true;
  13. success();
  14. script.onload = script.onreadystatechange = null;
  15. head.removeChild(script);
  16. }
  17. };
  18. head.appendChild(script);
  19. }
  20. getScript('http://code.jquery.com/jquery-latest.min.js',function() {
  21. if (typeof jQuery=='undefined') {
  22. msg='Sorry, but jQuery wasn\'t able to load';
  23. } else {
  24. msg='This page is now jQuerified with v' + jQuery.fn.jquery;
  25. if (otherlib) {msg+=' and noConflict(). Use $jq(), not $().';}
  26. }
  27. return showMsg();
  28. });
  29. function showMsg() {
  30. el.innerHTML=msg;
  31. b.appendChild(el);
  32. window.setTimeout(function() {
  33. if (typeof jQuery=='undefined') {
  34. b.removeChild(el);
  35. } else {
  36. jQuery(el).fadeOut('slow',function() {
  37. jQuery(this).remove();
  38. });
  39. if (otherlib) {
  40. $jq=jQuery.noConflict();
  41. }
  42. }
  43. } ,2500);
  44. }
  45. })();

Report this snippet  

You need to login to post a comment.