~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/contrib/PlotKit/PlotKit.js

  • Committer: Guilherme Salgado
  • Date: 2010-04-28 15:11:56 UTC
  • mfrom: (10795 launchpad)
  • mto: This revision was merged to the branch mainline in revision 10969.
  • Revision ID: salgado@canonical.com-20100428151156-5cedwvi9b0f478mj
mergeĀ fromĀ mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***
2
 
 
3
 
PlotKit Autoload Javascript Module.
4
 
 
5
 
This file was adapted from MochiKit.
6
 
See <http://mochikit.com/> for documentation, downloads, license, etc.
7
 
(c) 2005 Bob Ippolito.  All rights Reserved.
8
 
 
9
 
Modified by Alastair Tse, 2006, for PlotKit.
10
 
 
11
 
***/
12
 
 
13
 
if (typeof(PlotKit) == 'undefined') {
14
 
    PlotKit = {};
15
 
}
16
 
 
17
 
if (typeof(PlotKit.PlotKit) == 'undefined') {
18
 
    PlotKit.PlotKit = {};
19
 
}
20
 
 
21
 
PlotKit.PlotKit.NAME = "PlotKit.PlotKit";
22
 
PlotKit.PlotKit.VERSION = "0.9.1";
23
 
PlotKit.PlotKit.__repr__ = function () {
24
 
    return "[" + this.NAME + " " + this.VERSION + "]";
25
 
};
26
 
 
27
 
PlotKit.PlotKit.toString = function () {
28
 
    return this.__repr__();
29
 
};
30
 
 
31
 
PlotKit.PlotKit.SUBMODULES = [
32
 
    "Base",
33
 
    "Layout",
34
 
    "Canvas",
35
 
    "SVG",
36
 
    "SweetCanvas",
37
 
    "SweetSVG",
38
 
    "EasyPlot"
39
 
];
40
 
 
41
 
if (typeof(JSAN) != 'undefined' || typeof(dojo) != 'undefined') {
42
 
    if (typeof(dojo) != 'undefined') {
43
 
        dojo.provide('PlotKit.PlotKit');
44
 
        dojo.require("PlotKit.*");
45
 
    }
46
 
    if (typeof(JSAN) != 'undefined') {
47
 
        // hopefully this makes it easier for static analysis?
48
 
        JSAN.use("PlotKit.Base", []);
49
 
        JSAN.use("PlotKit.Layout", []);
50
 
        JSAN.use("PlotKit.Canvas", []);
51
 
        JSAN.use("PlotKit.SweetCanvas", []);
52
 
        JSAN.use("PlotKit.SVG", []);
53
 
        JSAN.use("PlotKit.SweetSVG", []);
54
 
    }
55
 
    (function () {
56
 
        var extend = MochiKit.Base.extend;
57
 
        var self = PlotKit.PlotKit;
58
 
        var modules = self.SUBMODULES;
59
 
        var EXPORT = [];
60
 
        var EXPORT_OK = [];
61
 
        var EXPORT_TAGS = {};
62
 
        var i, k, m, all;
63
 
        for (i = 0; i < modules.length; i++) {
64
 
            m = PlotKit[modules[i]];
65
 
            extend(EXPORT, m.EXPORT);
66
 
            extend(EXPORT_OK, m.EXPORT_OK);
67
 
            for (k in m.EXPORT_TAGS) {
68
 
                EXPORT_TAGS[k] = extend(EXPORT_TAGS[k], m.EXPORT_TAGS[k]);
69
 
            }
70
 
            all = m.EXPORT_TAGS[":all"];
71
 
            if (!all) {
72
 
                all = extend(null, m.EXPORT, m.EXPORT_OK);
73
 
            }
74
 
            var j;
75
 
            for (j = 0; j < all.length; j++) {
76
 
                k = all[j];
77
 
                self[k] = m[k];
78
 
            }
79
 
        }
80
 
        self.EXPORT = EXPORT;
81
 
        self.EXPORT_OK = EXPORT_OK;
82
 
        self.EXPORT_TAGS = EXPORT_TAGS;
83
 
    }());
84
 
    
85
 
} else {
86
 
    if (typeof(PlotKit.__compat__) == 'undefined') {
87
 
        PlotKit.__compat__ = true;
88
 
    }
89
 
    (function () {
90
 
        if (typeof(document) == "undefined") {
91
 
              return;
92
 
        }
93
 
        
94
 
        var scripts = document.getElementsByTagName("script");
95
 
        var kXULNSURI = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
96
 
        var base = null;
97
 
        var baseElem = null;
98
 
        var allScripts = {};
99
 
        var i;
100
 
        for (i = 0; i < scripts.length; i++) {
101
 
            var src = scripts[i].getAttribute("src");
102
 
            if (!src) {
103
 
                continue;
104
 
            }
105
 
            allScripts[src] = true;
106
 
            if (src.match(/PlotKit.js$/)) {
107
 
                base = src.substring(0, src.lastIndexOf('PlotKit.js'));
108
 
                baseElem = scripts[i];
109
 
            }
110
 
 
111
 
        }
112
 
 
113
 
        if (base === null) {
114
 
            return;
115
 
        }
116
 
        var modules = PlotKit.PlotKit.SUBMODULES;
117
 
        for (var i = 0; i < modules.length; i++) {
118
 
            if (PlotKit[modules[i]]) {
119
 
                continue;
120
 
            }
121
 
            var uri = base + modules[i] + '.js';
122
 
            if (uri in allScripts) {
123
 
                continue;
124
 
            }
125
 
            if (document.documentElement &&
126
 
                document.documentElement.namespaceURI == kXULNSURI) {
127
 
                // XUL
128
 
                var s = document.createElementNS(kXULNSURI, 'script');
129
 
                s.setAttribute("id", "PlotKit_" + base + modules[i]);
130
 
                s.setAttribute("src", uri);
131
 
                s.setAttribute("type", "application/x-javascript");
132
 
                baseElem.parentNode.appendChild(s);
133
 
            } else {
134
 
                // HTML
135
 
                /*
136
 
                    DOM can not be used here because Safari does
137
 
                    deferred loading of scripts unless they are
138
 
                    in the document or inserted with document.write
139
 
 
140
 
                    This is not XHTML compliant.  If you want XHTML
141
 
                    compliance then you must use the packed version of MochiKit
142
 
                    or include each script individually (basically unroll
143
 
                    these document.write calls into your XHTML source)
144
 
 
145
 
                */
146
 
                document.write('<script src="' + uri +
147
 
                    '" type="text/javascript"></script>');
148
 
            }
149
 
        };
150
 
    })();
151
 
}