Skip to content

Instantly share code, notes, and snippets.

@tobsn
Created December 10, 2010 19:50
Show Gist options
  • Select an option

  • Save tobsn/736705 to your computer and use it in GitHub Desktop.

Select an option

Save tobsn/736705 to your computer and use it in GitHub Desktop.

Revisions

  1. Tobias O. revised this gist Dec 16, 2010. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions jquery.loader.js
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,27 @@
    (function(j,q,u,e,r,y,r,o,x){try{o=jQuery;if(o&&(!r||(r&&o.fn.jquery==r))){x=true}}catch(r){}if(!x||(r&&o.fn.jquery!=r)){(q=j.createElement(q)).type='text/javascript';if(r){q.async=true}q.src='//ajax.googleapis.com/ajax/libs/jquery/'+(r||1)+'/jquery.min.js';u=j.getElementsByTagName(u)[0];q.onload=q.onreadystatechange=(function(){if(!e&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){e=true;x=jQuery;jQuery.noConflict(true)(function(){y(x)});q.onload=q.onreadystatechange=null;u.removeChild(q)}});u.appendChild(q)}else{y(o)}})(document,'script','head',false,false,(function($){$(function(){
    (function(j,q,u,e,r,y,R,o,x){try{o=jQuery;if(o&&(!R||(R&&o.fn.jquery==R))){x=true}}catch(er){}if(!x||(R&&o.fn.jquery!=R)){(q=j.createElement(q)).type='text/javascript';if(r){q.async=true}q.src='//ajax.googleapis.com/ajax/libs/jquery/'+(R||1)+'/jquery.min.js';u=j.getElementsByTagName(u)[0];q.onload=q.onreadystatechange=(function(){if(!e&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){e=true;x=jQuery;jQuery.noConflict(true)(function(){y(x)});q.onload=q.onreadystatechange=null;u.removeChild(q)}});u.appendChild(q)}else{y(o)}})(document,'script','head',false,false,(function($){$(function(){
    /* code goes here */
    console.log($.fn.jquery);
    })}));


    // readable:
    (function (j, q, u, e, r, y, r, o, x ) {
    (function (j, q, u, e, r, y, R, o, x ) {
    // IE8 undefined crash fix
    try {
    // check if we can assign jQuery
    o=jQuery;
    // if jquery is defined and version is not set or version is set and matches the existing one
    if( o && ( !r || ( r && o.fn.jquery == r ) ) ) {
    if( o && ( !R || ( R && o.fn.jquery == R ) ) ) {
    x = true;
    }
    }
    catch(r) {}
    catch(er) {}
    // if jquery isnt set or version is defined and its not matching
    if( !x || ( r && o.fn.jquery != r ) ) {
    if( !x || ( R && o.fn.jquery != R ) ) {
    (q = j.createElement(q)).type = 'text/javascript';
    if (r) { q.async = true; }
    // dont need http|https - /1/ means latest 1.x version
    q.src = '//ajax.googleapis.com/ajax/libs/jquery/'+(r||1)+'/jquery.min.js';
    q.src = '//ajax.googleapis.com/ajax/libs/jquery/'+(R||1)+'/jquery.min.js';
    u = j.getElementsByTagName(u)[0];
    // onload event for callback
    q.onload = q.onreadystatechange = (function () {
  2. Tobias O. revised this gist Dec 13, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion jquery.loader.js
    Original file line number Diff line number Diff line change
    @@ -39,7 +39,7 @@
    u.appendChild(q);
    }
    else {
    // jquery is already there and version matches
    // jquery is already there and version matches or we dont care about version
    y( o );
    }
    // async callback
  3. Tobias O. revised this gist Dec 13, 2010. 1 changed file with 48 additions and 33 deletions.
    81 changes: 48 additions & 33 deletions jquery.loader.js
    Original file line number Diff line number Diff line change
    @@ -1,37 +1,52 @@
    (function(j,q,u,e,r,y){if(typeof(jQuery)=='undefined'){(q=j.createElement(q)).type='text/javascript';if(r){q.async=true;}q.src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';u=j.getElementsByTagName(u)[0];q.onload=q.onreadystatechange=(function(){if(!e&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){e=true;y();q.onload=q.onreadystatechange=null;u.removeChild(q);}});u.appendChild(q);}else{y();}})(document,'script','head',false,false,(function(){$(function(){
    /* code goes here */
    });}));
    (function(j,q,u,e,r,y,r,o,x){try{o=jQuery;if(o&&(!r||(r&&o.fn.jquery==r))){x=true}}catch(r){}if(!x||(r&&o.fn.jquery!=r)){(q=j.createElement(q)).type='text/javascript';if(r){q.async=true}q.src='//ajax.googleapis.com/ajax/libs/jquery/'+(r||1)+'/jquery.min.js';u=j.getElementsByTagName(u)[0];q.onload=q.onreadystatechange=(function(){if(!e&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){e=true;x=jQuery;jQuery.noConflict(true)(function(){y(x)});q.onload=q.onreadystatechange=null;u.removeChild(q)}});u.appendChild(q)}else{y(o)}})(document,'script','head',false,false,(function($){$(function(){
    /* code goes here */
    console.log($.fn.jquery);
    })}));


    // readable:
    (function (j, q, u, e, r, y) {
    if (typeof(jQuery) == 'undefined') {
    (q = j.createElement(q)).type = 'text/javascript';
    if (r) { q.async = true; }
    // dont need http|https - /1/ means latest 1.x version
    q.src = '//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
    u = j.getElementsByTagName(u)[0];
    // onload event for callback
    q.onload = q.onreadystatechange = (function () {
    // first fire when completely loaded and parsed & check if this happened before
    if (!e && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
    e = true;
    // execute your jquery code now
    y();
    // IE memory leak protection
    q.onload = q.onreadystatechange = null;
    u.removeChild(q);
    }
    });
    u.appendChild(q);
    }
    else {
    // looks like jquery is already loaded - just execute code right away
    y();
    }
    (function (j, q, u, e, r, y, r, o, x ) {
    // IE8 undefined crash fix
    try {
    // check if we can assign jQuery
    o=jQuery;
    // if jquery is defined and version is not set or version is set and matches the existing one
    if( o && ( !r || ( r && o.fn.jquery == r ) ) ) {
    x = true;
    }
    }
    catch(r) {}
    // if jquery isnt set or version is defined and its not matching
    if( !x || ( r && o.fn.jquery != r ) ) {
    (q = j.createElement(q)).type = 'text/javascript';
    if (r) { q.async = true; }
    // dont need http|https - /1/ means latest 1.x version
    q.src = '//ajax.googleapis.com/ajax/libs/jquery/'+(r||1)+'/jquery.min.js';
    u = j.getElementsByTagName(u)[0];
    // onload event for callback
    q.onload = q.onreadystatechange = (function () {
    // first fire when completely loaded and parsed & check if this happened before
    if (!e && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
    e = true;
    // copy space into new var, release control and execute callbacks with passed in own version of jQ
    x = jQuery;
    jQuery.noConflict(true)(function(){y(x);});
    // IE memory leak protection
    q.onload = q.onreadystatechange = null;
    u.removeChild(q);
    }
    });
    u.appendChild(q);
    }
    else {
    // jquery is already there and version matches
    y( o );
    }
    // async callback
    })(document, 'script', 'head', false, false, (function () {
    $(function(){
    /* code goes here */
    });
    }));
    })(document, 'script', 'head', false, false, (function ($) {
    $(function(){
    /* code goes here */
    console.log( $.fn.jquery );
    });
    // version if needed - optional (see compressed version above)
    }),'1.4.2');
  4. Tobias O. revised this gist Dec 10, 2010. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions jquery.loader.js
    Original file line number Diff line number Diff line change
    @@ -8,19 +8,25 @@
    if (typeof(jQuery) == 'undefined') {
    (q = j.createElement(q)).type = 'text/javascript';
    if (r) { q.async = true; }
    // dont need http|https - /1/ means latest 1.x version
    q.src = '//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
    u = j.getElementsByTagName(u)[0];
    // onload event for callback
    q.onload = q.onreadystatechange = (function () {
    // first fire when completely loaded and parsed & check if this happened before
    if (!e && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
    e = true;
    // execute your jquery code now
    y();
    // IE memory leak protection
    q.onload = q.onreadystatechange = null;
    u.removeChild(q);
    }
    });
    u.appendChild(q);
    }
    else {
    // looks like jquery is already loaded - just execute code right away
    y();
    }
    // async callback
  5. Tobias O. revised this gist Dec 10, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion jquery.loader.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    (function(j,q,u,e,r,y){if(typeof(jQuery)=='undefined'){(q=j.createElement(q)).type='text/javascript';q.src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';u=j.getElementsByTagName(u)[0];q.onload=q.onreadystatechange=(function(){if(!e&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){e=true;y();q.onload=q.onreadystatechange=null;u.removeChild(q);}});u.appendChild(q);}else{y();}})(document,'script','head',false,false,(function(){$(function(){
    (function(j,q,u,e,r,y){if(typeof(jQuery)=='undefined'){(q=j.createElement(q)).type='text/javascript';if(r){q.async=true;}q.src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';u=j.getElementsByTagName(u)[0];q.onload=q.onreadystatechange=(function(){if(!e&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){e=true;y();q.onload=q.onreadystatechange=null;u.removeChild(q);}});u.appendChild(q);}else{y();}})(document,'script','head',false,false,(function(){$(function(){
    /* code goes here */
    });}));

  6. Tobias O. revised this gist Dec 10, 2010. 1 changed file with 10 additions and 8 deletions.
    18 changes: 10 additions & 8 deletions jquery.loader.js
    Original file line number Diff line number Diff line change
    @@ -1,28 +1,30 @@
    (function(j,q,e,r,y){if(typeof(jQuery)=='undefined'){(q=j.createElement(q)).type='text/javascript';q.src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';e=j.getElementsByTagName(e)[0];q.onload=q.onreadystatechange=(function(){if(!r&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){r=true;y();q.onload=q.onreadystatechange=null;e.removeChild(q);}});e.appendChild(q);}else{y();}})(document,'script','head',false,(function(){$(function(){
    (function(j,q,u,e,r,y){if(typeof(jQuery)=='undefined'){(q=j.createElement(q)).type='text/javascript';q.src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';u=j.getElementsByTagName(u)[0];q.onload=q.onreadystatechange=(function(){if(!e&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){e=true;y();q.onload=q.onreadystatechange=null;u.removeChild(q);}});u.appendChild(q);}else{y();}})(document,'script','head',false,false,(function(){$(function(){
    /* code goes here */
    });}));


    // readable:
    (function (j, q, e, r, y) {
    (function (j, q, u, e, r, y) {
    if (typeof(jQuery) == 'undefined') {
    (q = j.createElement(q)).type = 'text/javascript';
    if (r) { q.async = true; }
    q.src = '//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
    e = j.getElementsByTagName(e)[0];
    u = j.getElementsByTagName(u)[0];
    q.onload = q.onreadystatechange = (function () {
    if (!r && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
    r = true;
    if (!e && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
    e = true;
    y();
    q.onload = q.onreadystatechange = null;
    e.removeChild(q);
    u.removeChild(q);
    }
    });
    e.appendChild(q);
    u.appendChild(q);
    }
    else {
    y();
    }
    })(document, 'script', 'head', false, (function () {
    // async callback
    })(document, 'script', 'head', false, false, (function () {
    $(function(){
    /* code goes here */
    });
  7. Tobias O. revised this gist Dec 10, 2010. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions jquery.loader.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    (function(j,q,e,r,y){if(typeof(jQuery)=='undefined'){(q=j.createElement(q)).type='text/javascript';q.src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';e=j.getElementsByTagName(e)[0];q.onload=q.onreadystatechange=(function(){if(!r&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){r=true;y();q.onload=q.onreadystatechange=null;e.removeChild(q);}});e.appendChild(q);}else{y();}})(document,'script','head',false,(function(){
    /* code goes here */
    }));
    (function(j,q,e,r,y){if(typeof(jQuery)=='undefined'){(q=j.createElement(q)).type='text/javascript';q.src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';e=j.getElementsByTagName(e)[0];q.onload=q.onreadystatechange=(function(){if(!r&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){r=true;y();q.onload=q.onreadystatechange=null;e.removeChild(q);}});e.appendChild(q);}else{y();}})(document,'script','head',false,(function(){$(function(){
    /* code goes here */
    });}));


    // readable:
    @@ -23,5 +23,7 @@
    y();
    }
    })(document, 'script', 'head', false, (function () {
    /* code goes here */
    $(function(){
    /* code goes here */
    });
    }));
  8. Tobias O. renamed this gist Dec 10, 2010. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. Tobias O. created this gist Dec 10, 2010.
    27 changes: 27 additions & 0 deletions jquery.loader
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    (function(j,q,e,r,y){if(typeof(jQuery)=='undefined'){(q=j.createElement(q)).type='text/javascript';q.src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';e=j.getElementsByTagName(e)[0];q.onload=q.onreadystatechange=(function(){if(!r&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){r=true;y();q.onload=q.onreadystatechange=null;e.removeChild(q);}});e.appendChild(q);}else{y();}})(document,'script','head',false,(function(){
    /* code goes here */
    }));


    // readable:
    (function (j, q, e, r, y) {
    if (typeof(jQuery) == 'undefined') {
    (q = j.createElement(q)).type = 'text/javascript';
    q.src = '//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
    e = j.getElementsByTagName(e)[0];
    q.onload = q.onreadystatechange = (function () {
    if (!r && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
    r = true;
    y();
    q.onload = q.onreadystatechange = null;
    e.removeChild(q);
    }
    });
    e.appendChild(q);
    }
    else {
    y();
    }
    })(document, 'script', 'head', false, (function () {
    /* code goes here */
    }));