s3/GiveCatJS/givecat.extended.js
/**
 * Epic javascript function that basically checks if the script has been successfully loaded
 * - This gets us around the Content Security Policy (CSP)
 *
 * Solution found here: http://stackoverflow.com/questions/538745/how-to-tell-if-a-script-tag-failed-to-load (I love stake overflow!)
 **/
Epic javascript function that basically checks if the script has been successfully loaded
- This gets us around the Content Security Policy (CSP)


Epic javascript function that basically checks if the script has been successfully loaded - This gets us around the Content Security Policy ( CSP )
function jsLoader() {
  var o = this;
  o.timer = function (t, i, d, f, fend, b) {
    if (t == -1 || t > 0) {
      setTimeout(function () {
        b = (f()) ? 1 : 0;
        o.timer((b) ? 0 : (t > 0) ? --t : t, i + ((d) ? d : 0), d, f, fend, b);
      }, (b || i < 0) ? 0.1 : i);
    } else if (typeof fend == "function") {
      setTimeout(fend, 1);
    }
  };
  o.addEvent = function (el, eventName, eventFunc) {
    if (typeof el != "object") {
      return false;
    }
    if (el.addEventListener) {
      el.addEventListener(eventName, eventFunc, false);
      return true;
    }
    if (el.attachEvent) {
      el.attachEvent("on" + eventName, eventFunc);
      return true;
    }
    return false;
  };
  o.require = function (s, delay, baSync, fCallback, fErr) 
  {
    tempCatScript = document.createElement("script"),
    oHead = document.getElementsByTagName("head")[0];
    if (!oHead) {
      return false;
    }
    setTimeout(function () {
      var f = (typeof fCallback == "function") ? fCallback : function () {};
      fErr = (typeof fErr == "function") ? fErr : function () {
        alert("require: Cannot load resource -" + s);
      },
      fe = function () {
        if (!tempCatScript.__es) {
          tempCatScript.__es = true;
          tempCatScript.id = "failed";
          fErr(tempCatScript);
        }
      };
      tempCatScript.onload = function () {
        tempCatScript.id = "loaded";
        f(tempCatScript);
      };
      tempCatScript.type = "text/javascript";
      tempCatScript.async = (typeof baSync == "boolean") ? baSync : false;
      tempCatScript.charset = "utf-8";
      o.__es = false;
      o.addEvent(tempCatScript, "error", fe); 
      o.timer(15, 1000, 0, function () {
        return (tempCatScript.id == "loaded");
      }, function () {
        if (tempCatScript.id != "loaded") {
          fe();
        }
      });
      tempCatScript.src = s;
      setTimeout(function () {
        try {
          oHead.appendChild(tempCatScript);
        } catch (e) {
          fe();
        }
      }, 1);
    }, (typeof delay == "number") ? delay : 1);
    return true;
  };
}
function jsLoader ( ) { var o = this ; o . timer = function ( t , i , d , f , fend , b ) { if ( t == - 1 || t > 0 ) { setTimeout ( function ( ) { b = ( f ( ) ) ? 1 : 0 ; o . timer ( ( b ) ? 0 : ( t > 0 ) ? -- t : t , i + ( ( d ) ? d : 0 ) , d , f , fend , b ) ; } , ( b || i < 0 ) ? 0.1 : i ) ; } else if ( typeof fend == "function" ) { setTimeout ( fend , 1 ) ; } } ; o . addEvent = function ( el , eventName , eventFunc ) { if ( typeof el != "object" ) { return false ; } if ( el . addEventListener ) { el . addEventListener ( eventName , eventFunc , false ) ; return true ; } if ( el . attachEvent ) { el . attachEvent ( "on" + eventName , eventFunc ) ; return true ; } return false ; } ; o . require = function ( s , delay , baSync , fCallback , fErr ) { tempCatScript = document . createElement ( "script" ) , oHead = document . getElementsByTagName ( "head" ) [ 0 ] ; if ( ! oHead ) { return false ; } setTimeout ( function ( ) { var f = ( typeof fCallback == "function" ) ? fCallback : function ( ) { } ; fErr = ( typeof fErr == "function" ) ? fErr : function ( ) { alert ( "require: Cannot load resource -" + s ) ; } , fe = function ( ) { if ( ! tempCatScript . __es ) { tempCatScript . __es = true ; tempCatScript . id = "failed" ; fErr ( tempCatScript ) ; } } ; tempCatScript . onload = function ( ) { tempCatScript . id = "loaded" ; f ( tempCatScript ) ; } ; tempCatScript . type = "text/javascript" ; tempCatScript . async = ( typeof baSync == "boolean" ) ? baSync : false ; tempCatScript . charset = "utf-8" ; o . __es = false ; o . addEvent ( tempCatScript , "error" , fe ) ; o . timer ( 15 , 1000 , 0 , function ( ) { return ( tempCatScript . id == "loaded" ) ; } , function ( ) { if ( tempCatScript . id != "loaded" ) { fe ( ) ; } } ) ; tempCatScript . src = s ; setTimeout ( function ( ) { try { oHead . appendChild ( tempCatScript ) ; } catch ( e ) { fe ( ) ; } } , 1 ) ; } , ( typeof delay == "number" ) ? delay : 1 ) ; return true ; } ; }
Epic javascript function that basically checks if the script has been successfully loaded
 - This gets us around the Content Security Policy (CSP)
Epic javascript function that basically checks if the script has been successfully loaded - This gets us around the Content Security Policy ( CSP )
//An unstoppable repeat timer, when t=-1 means endless, when function f() returns true it can be stopped // add script to dom // when supported // when error event is not supported fall back to timer