YesGraph’s Javascript SDK and Superwidget make use of custom jQuery events, allowing you to detect when your users import their contacts, or trigger invites. Here you’ll find a list of the supported events, with an example of how to get started.

As always, feel free to drop us a line with any questions!

Event Description
installed.yesgraph.sdk The Javascript SDK (used by the Superwidget) is installed, authenticated, and ready for use.
installed.yesgraph.superwidget The Superwidget is installed, authenticated, and ready for use.
imported.yesgraph.contacts The user’s contacts have been imported & ranked.
set.yesgraph.recipients The user confirmed recipients to invite (i.e., the user clicked “send” or “add emails”).
Using jQuery

The YesGraph Superwidget depends on jQuery. To work with Superwidget events in your code, you should include jQuery explicitly, as shown in the example below. This will ensure that jQuery loads before your event handlers run.

<html>
<head>
    <title>My Redirect Page</title>
</head>
<body>

    <h1>Redirecting...</h1>

    <script type="text/javascript">
    // Get the target destination from the "state" parameter
    var targetUrl = getUrlParam(location.href, "state");

    if (targetUrl) {
        if (targetUrl.indexOf("//") === -1) { targetUrl = "//" + targetUrl; }
        // Add the hash & url params to the target url
        var extra = [];
        if (location.search) {
            extra.push(location.search.slice(1));
        }
        if (location.hash) {
            extra.push(location.hash.slice(1));
        }
        if (extra.length > 0) {
            targetUrl += "#" + extra.join("&");
        }
        // Redirect to the target destination
        location.href = targetUrl;
    } else {
        // This 'else' clause will likely never be used,
        // but it makes sense to have a sane default.
        location.href = location.origin + location.hash;
    }

    function getUrlParam(url, key) {
        // Get a value from the url query parameters, or from the hash
        var key = key.replace(new RegExp("/[[]/"), "\[").replace(new RegExp("/[]]/"), "\]");
        var regexS = "[\?&#]" + key + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(url);
        if (results == null)
            return "";
        else
            return fullyDecode(results[1]);
    }

    function fullyDecode(str) {
        // Recursively decode a URI component until it's fully decoded
        var decoded = decodeURIComponent(str);
        return decoded == str ? str: fullyDecode(decoded);
    }
    </script>
</body>
</html>