Skip to content

Instantly share code, notes, and snippets.

@nambrot
Created October 24, 2012 16:11
Show Gist options
  • Save nambrot/3947019 to your computer and use it in GitHub Desktop.
Save nambrot/3947019 to your computer and use it in GitHub Desktop.
countdown = 2
cb = ->
console.log countdown
countdown = countdown - 1
user.trigger 'change' if countdown == 0
$.ajax
type: 'GET'
url: "https://www.credport.org/api/v1/users/#{user.get('id')}/socialconnections?include=verifications"
contentType: "application/json"
dataType: 'jsonp'
success: (resp) ->
user.socialconnectionsobject = new SocialConnections resp.data
complete: cb
$.ajax
type: 'GET'
url: "https://www.credport.org/api/v1/users/#{user.get('id')}/commoninterests?include=verifications"
contentType: "application/json"
dataType: 'jsonp'
success: (resp) ->
user.commoninterestsobject = new CommonInterests resp.data
complete: -> cb
@clarkdave
Copy link

function loadScript(url, fn) {
var script = document.createElement('script');
script.async = true;
script.src = '//' + url;

var entry = document.getElementsByTagName('script')[0];
entry.parentNode.insertBefore(script, entry);

script.onload = script.onreadystatechange = function() {
  var rdyState = script.readyState;

  if (!rdyState || /complete|loaded/.test(script.readyState)) {
    fn();
    script.onload = null;
    script.onreadystatechange = null;
  }
};

}

/**

  • Load a stylesheet from the provided url
    */
    function loadStylesheet(url) {
    var link = document.createElement('link');
    link.rel = 'stylesheet';
    link.type = 'text/css';
    link.href = ('https:' == document.location.protocol ? 'https' : 'http') + '://' + url;

    var entry = document.getElementsByTagName('script')[0];
    entry.parentNode.insertBefore(link, entry);
    }

    /**

  • Check at frequent intervals to determine if the browser has loaded and

  • applied our CSS styles. Run the fn callback when this has occured.
    */
    function whenCSSReady(fn) {
    var testElem = document.createElement('span');

    testElem.id = 'prizgo-css-ready';
    testElem.style = 'color: #fff';

    var entry = document.getElementsByTagName('script')[0];
    entry.parentNode.insertBefore(testElem, entry);

    (function poll() {
    var node = document.getElementById('css-ready');
    var value;
    if (window.getComputedStyle) {
    value = document.defaultView.getComputedStyle(testElem, null).getPropertyValue('color');
    } else if (node.currentStyle) {
    value = node.currentStyle.color;
    }
    if (value && value === 'rgb(186, 218, 85)' || value.toLowerCase() === '#bada55') {
    fn();
    } else {
    setTimeout(poll, 500);
    }
    })();
    }

@clarkdave
Copy link

function loadScript(url, fn) {
  var script = document.createElement('script');
  script.async = true;
  script.src = '//' + url;

  var entry = document.getElementsByTagName('script')[0];
  entry.parentNode.insertBefore(script, entry);

  script.onload = script.onreadystatechange = function() {
    var rdyState = script.readyState;

    if (!rdyState || /complete|loaded/.test(script.readyState)) {
      fn();
      script.onload = null;
      script.onreadystatechange = null;
    }
  };
}

/**
 * Load a stylesheet from the provided url
 */
function loadStylesheet(url) {
  var link = document.createElement('link');
  link.rel = 'stylesheet';
  link.type = 'text/css';
  link.href = ('https:' == document.location.protocol ? 'https' : 'http') + '://' + url;

  var entry = document.getElementsByTagName('script')[0];
  entry.parentNode.insertBefore(link, entry);
}

/**
 * Check at frequent intervals to determine if the browser has loaded and
 * applied our CSS styles. Run the fn callback when this has occured.
 */
function whenCSSReady(fn) {
  var testElem = document.createElement('span');

  testElem.id = 'prizgo-css-ready';
  testElem.style = 'color: #fff';

  var entry = document.getElementsByTagName('script')[0];
  entry.parentNode.insertBefore(testElem, entry);

  (function poll() {
    var node = document.getElementById('css-ready');
    var value;
    if (window.getComputedStyle) {
        value = document.defaultView.getComputedStyle(testElem, null).getPropertyValue('color');
    } else if (node.currentStyle) {
        value = node.currentStyle.color;
    }
    if (value && value === 'rgb(186, 218, 85)' || value.toLowerCase() === '#bada55') {
        fn();
    } else {
        setTimeout(poll, 500);
    }
  })();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment