~jonas-drange/online-services-common-js/navbar-autocomplete

« back to all changes in this revision

Viewing changes to build/unity/unity.js

  • Committer: Stephen Stewart
  • Date: 2014-02-22 23:57:25 UTC
  • mfrom: (18.1.2 trunk)
  • Revision ID: stephen.stewart@canonical.com-20140222235725-iw6f15t9umws19xd
mergeĀ lp:~stephen-stewart/online-services-common-js/remove-u1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
YUI.add('unity', function (Y, NAME) {
2
 
 
3
 
"use strict";
4
 
/*global external */
5
 
    var init_callbacks = [],
6
 
    ns = Y.namespace("Unity");
7
 
 
8
 
ns.ready = false;
9
 
 
10
 
function unityReady() {
11
 
    ns.ready = true;
12
 
    init_callbacks.reverse();
13
 
    while (init_callbacks.length > 0) {
14
 
        var callback = init_callbacks.pop();
15
 
        callback();
16
 
    }
17
 
}
18
 
 
19
 
/* Initialise Unity Webapps integration.  Should only be called once. */
20
 
ns.init = function init(parameters) {
21
 
    if (typeof external !== "undefined" && external && external.getUnityObject) {
22
 
        var Unity = external.getUnityObject(1.0);
23
 
        ns.Unity = Unity;
24
 
        if (parameters.onInit) {
25
 
            ns.onInit(parameters.onInit);
26
 
        }
27
 
        parameters.onInit = unityReady;
28
 
        Unity.init(parameters);
29
 
    }
30
 
};
31
 
 
32
 
/* Add a callback that will be fired when Unity Webapps
33
 
 * integration is enabled.  If integration has already been
34
 
 * enabled, then the callback will be run immediately. */
35
 
ns.onInit = function onInit(callback) {
36
 
    if (ns.ready) {
37
 
        callback();
38
 
    } else {
39
 
        init_callbacks.push(callback);
40
 
    }
41
 
};
42
 
 
43
 
 
44
 
}, '@VERSION@', {"requires": []});