This repository has been archived by the owner on Sep 19, 2024. It is now read-only.
forked from jsxgraph/jsxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadjsxgraph.js
253 lines (211 loc) · 9.13 KB
/
loadjsxgraph.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
Copyright 2008-2018
Matthias Ehmann,
Michael Gerhaeuser,
Carsten Miller,
Bianca Valentin,
Alfred Wassermann,
Peter Wilfahrt
This file is part of JSXGraph.
JSXGraph is free software dual licensed under the GNU LGPL or MIT License.
You can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version
OR
* MIT License: https://github.com/jsxgraph/jsxgraph/blob/master/LICENSE.MIT
JSXGraph is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License and
the MIT License along with JSXGraph. If not, see <http://www.gnu.org/licenses/>
and <http://opensource.org/licenses/MIT/>.
*/
/*global JXG: true, document: true*/
/*jslint nomen: true, plusplus: true, regexp: true*/
/* depends:
*/
/**
* JSXGraph namespace. Holds all classes, objects, functions and variables belonging to JSXGraph
* to reduce the risk of interfering with other JavaScript code.
* @namespace
*/
var JXG = {},
define;
(function () {
"use strict";
// check and table are initialized at the end of the iife
var i, s, n, arr, table,
waitlist = [],
checkwaitlist = true,
checkJXG = function () {
return JXG;
},
makeCheck = function (s) {
var a = s.split('.');
return function () {
var i, r = JXG;
if (!r) {
return r;
}
for (i = 0; i < a.length; i++) {
r = r[a[i]];
if (!r) {
break;
}
}
return r;
};
};
define = function (deps, factory) {
var i, oldlength, undef,
resDeps = [],
inc = true;
if (deps === undef) {
deps = [];
}
window.wait = waitlist;
if (factory === undef) {
factory = function () {};
}
for (i = 0; i < deps.length; i++) {
resDeps.push(table[deps[i]]());
if (!resDeps[i]) {
inc = false;
break;
}
}
if (inc) {
factory.apply(this, resDeps);
} else if (checkwaitlist) {
waitlist.push([deps, factory]);
}
if (checkwaitlist) {
// don't go through the waitlist while we're going through the waitlist
checkwaitlist = false;
oldlength = 0;
// go through the waitlist until no more modules can be loaded
while (oldlength !== waitlist.length) {
oldlength = waitlist.length;
// go through the waitlist, look if another module can be initialized
for (i = 0; i < waitlist.length; i++) {
if (define.apply(this, waitlist[i])) {
waitlist.splice(i, 1);
}
}
}
checkwaitlist = true;
}
return inc;
};
JXG.isMetroApp = function () {
return typeof window === 'object' && window.clientInformation && window.clientInformation.appVersion && window.clientInformation.appVersion.indexOf('MSAppHost') > -1;
};
JXG.require = function (libraryName) {
if (JXG.isMetroApp()) { // avoid inline code manipulation in Windows apps -- isMetroApp can't be used it is not yet available at this point
var scriptElement = document.createElement("script");
var typeAttribute = document.createAttribute("type");
typeAttribute.nodeValue = "text/javascript";
var srcAttribute = document.createAttribute("src");
srcAttribute.nodeValue = libraryName;
scriptElement.setAttributeNode(typeAttribute);
scriptElement.setAttributeNode(srcAttribute);
var headElement = document.getElementsByTagName("head")[0];
headElement.appendChild(scriptElement);
} else {
document.write('<script type="text/javascript" src="' + libraryName + '"><\/script>');
}
};
JXG.baseFiles = 'jxg,base/constants,utils/type,utils/xml,utils/env,utils/event,utils/expect,math/math,math/numerics,math/statistics,math/symbolic,math/geometry,math/poly,math/complex,renderer/abstract,renderer/no,reader/file,parser/geonext,base/board,options,jsxgraph,base/element,base/coordselement,base/coords,base/point,base/line,base/group,base/circle,element/conic,base/polygon,base/curve,element/arc,element/sector,base/composition,element/composition,base/text,base/image,element/slider,element/measure,base/chart,base/transformation,base/turtle,utils/color,base/ticks,utils/zip,utils/base64,utils/uuid,utils/encoding,server/server,element/locus,parser/datasource,parser/ca,parser/jessiecode,utils/dump,renderer/svg,renderer/vml,renderer/canvas,renderer/no,element/comb,element/slopetriangle,math/qdt,element/checkbox,element/input,element/button';
JXG.requirePath = '';
for (i = 0; i < document.getElementsByTagName("script").length; i++) {
s = document.getElementsByTagName("script")[i];
if (s.src && s.src.match(/loadjsxgraph\.js(\?.*)?$/)) {
JXG.requirePath = s.src.replace(/loadjsxgraph\.js(\?.*)?$/, '');
arr = JXG.baseFiles.split(',');
for (n = 0; n < arr.length; n++) {
JXG.require(JXG.requirePath + arr[n] + '.js');
}
}
}
JXG.baseFiles = null;
JXG.serverBase = JXG.requirePath + 'server/';
// This is a table with functions which check the availability
// of certain namespaces, functions and classes. With this structure
// we are able to get a rough check if a specific dependency is available.
table = {
'jsxgraph': checkJXG,
'jxg': checkJXG,
'options': makeCheck('Options'),
'base/board': makeCheck('Board'),
'base/chart': checkJXG,
'base/circle': checkJXG,
'base/composition': makeCheck('Composition'),
'base/constants': checkJXG,
'base/coords': makeCheck('Coords'),
'base/coordselement': makeCheck('CoordsElement'),
'base/curve': checkJXG,
'base/element': makeCheck('GeometryElement'),
'base/group': checkJXG,
'base/image': checkJXG,
'base/line': checkJXG,
'base/point': checkJXG,
'base/polygon': checkJXG,
'base/text': checkJXG,
'base/ticks': checkJXG,
'base/transformation': checkJXG,
'base/turtle': checkJXG,
'element/arc': checkJXG,
'element/centroid': checkJXG,
'element/composition': checkJXG,
'element/conic': checkJXG,
'element/locus': checkJXG,
'element/measure': checkJXG,
'element/sector': checkJXG,
'element/slider': checkJXG,
'element/square': checkJXG,
'element/triangle': checkJXG,
'element/checkbox': checkJXG,
'element/input': checkJXG,
'element/button': checkJXG,
'math/bst': makeCheck('Math.BST'),
'math/qdt': makeCheck('Math.Quadtree'),
'math/complex': makeCheck('Complex'),
'math/geometry': makeCheck('Math.Geometry'),
'math/math': makeCheck('Math'),
'math/numerics': makeCheck('Math.Numerics'),
'math/poly': makeCheck('Math.Poly'),
'math/statistics': makeCheck('Math.Statistics'),
'math/symbolic': makeCheck('Math.Symbolic'),
'parser/datasource': makeCheck('DataSource'),
'parser/geonext': makeCheck('GeonextParser'),
'parser/ca': makeCheck('CA'),
'parser/jessiecode': makeCheck('JessieCode'),
'reader/cinderella': makeCheck('CinderellaReader'),
'reader/file': makeCheck('FileReader'),
'reader/geogebra': makeCheck('GeogebraReader'),
'reader/geonext': makeCheck('GeonextReader'),
'reader/graph': makeCheck('GraphReader'),
'reader/intergeo': makeCheck('IntergeoReader'),
'reader/sketch': makeCheck('SketchReader'),
'reader/tracenpoche': makeCheck('TracenpocheReader'),
'renderer/abstract': makeCheck('AbstractRenderer'),
'renderer/canvas': makeCheck('CanvasRenderer'),
'renderer/no': makeCheck('NoRenderer'),
'renderer/svg': makeCheck('SVGRenderer'),
'renderer/vml': makeCheck('VMLRenderer'),
'server/server': makeCheck('Server'),
'utils/base64': makeCheck('Util.Base64'),
'utils/color': checkJXG,
'utils/dump': makeCheck('Dump'),
'utils/encoding': makeCheck('Util.UTF8'),
'utils/env': checkJXG,
'utils/event': makeCheck('EventEmitter'),
'utils/expect': makeCheck('Expect'),
'utils/type': checkJXG,
'utils/uuid': makeCheck('Util'),
'utils/xml': makeCheck('XML'),
'utils/zip': makeCheck('Util')
};
}());