1/**
2 * Copyright (c) 2006-2021, JGraph Ltd
3 * Copyright (c) 2006-2021, draw.io AG
4 */
5
6// urlParams is null when used for embedding
7window.urlParams = window.urlParams || {};
8
9// isLocalStorage controls access to local storage
10window.isLocalStorage = window.isLocalStorage || false;
11
12// Disables loading settings in configured mode
13window.mxLoadSettings = window.mxLoadSettings || urlParams['configure'] != '1';
14
15// Checks for SVG support
16window.isSvgBrowser = true;
17
18// CUSTOM_PARAMETERS - URLs for save and export
19window.DRAWIO_BASE_URL = window.DRAWIO_BASE_URL || ((/.*\.draw\.io$/.test(window.location.hostname)) || (/.*\.diagrams\.net$/.test(window.location.hostname)) ?
20	window.location.protocol + '//' + window.location.hostname : 'https://app.diagrams.net');
21window.DRAWIO_LIGHTBOX_URL = window.DRAWIO_LIGHTBOX_URL || 'https://viewer.diagrams.net';
22window.EXPORT_URL = window.EXPORT_URL || 'https://convert.diagrams.net/node/export';
23window.PLANT_URL = window.PLANT_URL || 'https://plant-aws.diagrams.net';
24window.DRAW_MATH_URL = window.DRAW_MATH_URL || window.DRAWIO_BASE_URL + '/math';
25window.VSD_CONVERT_URL = window.VSD_CONVERT_URL || 'https://convert.diagrams.net/VsdConverter/api/converter';
26window.EMF_CONVERT_URL = window.EMF_CONVERT_URL || 'https://convert.diagrams.net/emf2png/convertEMF';
27window.REALTIME_URL = window.REALTIME_URL || 'cache';
28window.DRAWIO_GITLAB_URL = window.DRAWIO_GITLAB_URL || 'https://gitlab.com';
29window.DRAWIO_GITLAB_ID = window.DRAWIO_GITLAB_ID || 'c9b9d3fcdce2dec7abe3ab21ad8123d89ac272abb7d0883f08923043e80f3e36';
30window.DRAWIO_GITHUB_URL = window.DRAWIO_GITHUB_URL || 'https://github.com';
31window.DRAWIO_GITHUB_API_URL = window.DRAWIO_GITHUB_API_URL || 'https://api.github.com';
32window.DRAWIO_GITHUB_ID = window.DRAWIO_GITHUB_ID || '4f88e2ec436d76c2ee6e';
33window.DRAWIO_DROPBOX_ID = window.DRAWIO_DROPBOX_ID || 'libwls2fa9szdji';
34window.SAVE_URL = window.SAVE_URL || 'save';
35window.OPEN_URL = window.OPEN_URL || 'import';
36window.PROXY_URL = window.PROXY_URL || 'proxy';
37window.DRAWIO_VIEWER_URL = window.DRAWIO_VIEWER_URL || null;
38window.NOTIFICATIONS_URL = window.NOTIFICATIONS_URL || 'https://www.draw.io/notifications';
39
40// Paths and files
41window.SHAPES_PATH = window.SHAPES_PATH || 'shapes';
42// Path for images inside the diagram
43window.GRAPH_IMAGE_PATH = window.GRAPH_IMAGE_PATH || 'img';
44window.ICONSEARCH_PATH = window.ICONSEARCH_PATH || (((navigator.userAgent != null && navigator.userAgent.indexOf('MSIE') >= 0) ||
45	urlParams['dev']) && window.location.protocol != 'file:' ? 'iconSearch' : window.DRAWIO_BASE_URL + '/iconSearch');
46window.TEMPLATE_PATH = window.TEMPLATE_PATH || 'templates';
47window.NEW_DIAGRAM_CATS_PATH = window.NEW_DIAGRAM_CATS_PATH || 'newDiagramCats';
48window.PLUGINS_BASE_PATH = window.PLUGINS_BASE_PATH || '';
49
50// Directory for i18 files and basename for main i18n file
51window.RESOURCES_PATH = window.RESOURCES_PATH || 'resources';
52window.RESOURCE_BASE = window.RESOURCE_BASE || RESOURCES_PATH + '/dia';
53
54// Specifies global configuration via variable
55window.DRAWIO_CONFIG = window.DRAWIO_CONFIG || null;
56
57// Sets the base path, the UI language via URL param and configures the
58// supported languages to avoid 404s. The loading of all core language
59// resources is disabled as all required resources are in grapheditor.
60// properties. Note that in this example the loading of two resource
61// files (the special bundle and the default bundle) is disabled to
62// save a GET request. This requires that all resources be present in
63// the special bundle.
64window.mxLoadResources = window.mxLoadResources || false;
65window.mxLanguage = window.mxLanguage || (function()
66{
67	var lang = urlParams['lang'];
68
69	// Known issue: No JSON object at this point in quirks in IE8
70	if (lang == null && typeof(JSON) != 'undefined')
71	{
72		// Cannot use mxSettings here
73		if (isLocalStorage)
74		{
75			try
76			{
77				var value = localStorage.getItem('.drawio-config');
78
79				if (value != null)
80				{
81					lang = JSON.parse(value).language || null;
82				}
83
84				if (!lang && window.mxIsElectron)
85				{
86					lang = require('@electron/remote').app.getLocale();
87
88					if (lang != null)
89			    	{
90			    		var dash = lang.indexOf('-');
91
92			    		if (dash >= 0)
93			    		{
94			    			lang = lang.substring(0, dash);
95			    		}
96
97			    		lang = lang.toLowerCase();
98			    	}
99				}
100			}
101			catch (e)
102			{
103				// cookies are disabled, attempts to use local storage will cause
104				// a DOM error at a minimum on Chrome
105				isLocalStorage = false;
106			}
107		}
108	}
109
110	return lang;
111})();
112
113// Add new languages here. First entry is translated to [Automatic]
114// in the menu defintion in Diagramly.js.
115window.mxLanguageMap = window.mxLanguageMap ||
116{
117	'i18n': '',
118	'id' : 'Bahasa Indonesia',
119	'ms' : 'Bahasa Melayu',
120	'bs' : 'Bosanski',
121	'bg' : 'Bulgarian',
122	'ca' : 'Català',
123	'cs' : 'Čeština',
124	'da' : 'Dansk',
125	'de' : 'Deutsch',
126	'et' : 'Eesti',
127	'en' : 'English',
128	'es' : 'Español',
129	'eu' : 'Euskara',
130	'fil' : 'Filipino',
131	'fr' : 'Français',
132	'gl' : 'Galego',
133	'it' : 'Italiano',
134	'hu' : 'Magyar',
135	'nl' : 'Nederlands',
136	'no' : 'Norsk',
137	'pl' : 'Polski',
138	'pt-br' : 'Português (Brasil)',
139	'pt' : 'Português (Portugal)',
140	'ro' : 'Română',
141	'fi' : 'Suomi',
142	'sv' : 'Svenska',
143	'vi' : 'Tiếng Việt',
144	'tr' : 'Türkçe',
145	'el' : 'Ελληνικά',
146	'ru' : 'Русский',
147	'sr' : 'Српски',
148	'uk' : 'Українська',
149	'he' : 'עברית',
150	'ar' : 'العربية',
151	'fa' : 'فارسی',
152	'th' : 'ไทย',
153	'ko' : '한국어',
154	'ja' : '日本語',
155	'zh' : '简体中文',
156	'zh-tw' : '繁體中文'
157};
158
159if (typeof window.mxBasePath === 'undefined')
160{
161	window.mxBasePath = 'mxgraph';
162	window.mxImageBasePath = 'mxgraph/images';
163}
164
165if (window.mxLanguages == null)
166{
167	window.mxLanguages = [];
168
169	// Populates the list of supported special language bundles
170	for (var lang in mxLanguageMap)
171	{
172		// Empty means default (ie. browser language), "en" means English (default for unsupported languages)
173		// Since "en" uses no extension this must not be added to the array of supported language bundles.
174		if (lang != 'en')
175		{
176			window.mxLanguages.push(lang);
177		}
178	}
179}
180
181//Disable Google Drive when running in a WebView (e.g, MS Teams App) Since auth doesn't work with disallowd_useragent
182//[For MS Teams only] TODO Check if other apps are affected also (android and iOS)
183if (urlParams['extAuth'] == '1' && /((iPhone|iPod|iPad).*AppleWebKit(?!.*Version)|; wv)/i.test(navigator.userAgent))
184{
185	urlParams['gapi'] = '0';
186	urlParams['noDevice'] = '1';
187	//Force viewer only
188	//TODO This should always be for MS Teams only
189	if (urlParams['lightbox'] != '1')
190	{
191		urlParams['lightbox'] = '1';
192		urlParams['layers'] = '1';
193		urlParams['viewerOnlyMsg'] = '1';
194	}
195}
196
197// Uses lightbox mode on viewer domain
198if (window.location.hostname == DRAWIO_LIGHTBOX_URL.substring(DRAWIO_LIGHTBOX_URL.indexOf('//') + 2))
199{
200	urlParams['lightbox'] = '1';
201}
202
203// Lightbox enables chromeless mode
204if (urlParams['lightbox'] == '1')
205{
206	urlParams['chrome'] = '0';
207}
208
209// Embed inline is embed mode and sketch UI
210if (urlParams['embedInline'] == '1')
211{
212	urlParams['embed'] = '1';
213	urlParams['ui'] = 'sketch';
214	urlParams['plugins'] = '0';
215	urlParams['proto'] = 'json';
216	urlParams['prefetchFonts'] = '1';
217}
218
219/**
220 * Returns the global UI setting before running static draw.io code
221 */
222window.uiTheme = window.uiTheme || (function()
223{
224	var ui = urlParams['ui'];
225
226	//Use Sketch theme for MS Teams (and any future extAuth) by default
227	if (urlParams['extAuth'] == '1')
228	{
229		ui = 'sketch';
230	}
231
232	// Known issue: No JSON object at this point in quirks in IE8
233	if (ui == null && isLocalStorage && typeof JSON !== 'undefined' && urlParams['lightbox'] != '1')
234	{
235		try
236		{
237			var value = localStorage.getItem('.drawio-config');
238
239			if (value != null)
240			{
241				ui = JSON.parse(value).ui || null;
242			}
243		}
244		catch (e)
245		{
246			// cookies are disabled, attempts to use local storage will cause
247			// a DOM error at a minimum on Chrome
248			isLocalStorage = false;
249		}
250	}
251
252	// Uses minimal theme on small screens
253	try
254	{
255		if (ui == null)
256		{
257	        var iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
258
259	        if (iw <= 768)
260	        {
261				if (urlParams['pages'] == null)
262				{
263					urlParams['pages'] = '1';
264				}
265
266				ui = 'sketch';
267	        }
268		}
269	}
270	catch (e)
271	{
272		// ignore
273	}
274
275	// Redirects sketch UI to min UI with sketch URL parameter
276	if (ui == 'sketch')
277	{
278		urlParams['sketch'] = '1';
279		ui = 'min';
280	}
281
282	return ui;
283})();
284
285/**
286 * Global function for loading local files via servlet
287 */
288function setCurrentXml(data, filename)
289{
290	if (window.parent != null && window.parent.openFile != null)
291	{
292		window.parent.openFile.setData(data, filename);
293	}
294};
295
296/**
297 * Overrides splash URL parameter via local storage
298 */
299(function()
300{
301	// Known issue: No JSON object at this point in quirks in IE8
302	if (typeof JSON !== 'undefined')
303	{
304		// Cannot use mxSettings here
305		if (isLocalStorage)
306		{
307			try
308			{
309				var value = localStorage.getItem('.drawio-config');
310				var showSplash = true;
311
312				if (value != null)
313				{
314					showSplash = JSON.parse(value).showStartScreen;
315				}
316
317				// Undefined means true
318				if (showSplash == false)
319				{
320					urlParams['splash'] = '0';
321				}
322			}
323			catch (e)
324			{
325				// ignore
326			}
327		}
328	}
329
330	// Customizes export URL
331	var ex = urlParams['export'];
332
333	if (ex != null)
334	{
335		ex = decodeURIComponent(ex);
336
337		if (ex.substring(0, 7) != 'http://' &&  ex.substring(0, 8) != 'https://')
338		{
339			ex = 'http://' + ex;
340		}
341
342		EXPORT_URL = ex;
343	}
344
345	// Customizes gitlab URL
346	var glUrl = urlParams['gitlab'];
347
348	if (glUrl != null)
349	{
350		glUrl = decodeURIComponent(glUrl);
351
352		if (glUrl.substring(0, 7) != 'http://' &&  glUrl.substring(0, 8) != 'https://')
353		{
354			glUrl = 'http://' + glUrl;
355		}
356
357		DRAWIO_GITLAB_URL = glUrl;
358	}
359
360	var glId = urlParams['gitlab-id'];
361
362	if (glId != null)
363	{
364		DRAWIO_GITLAB_ID = glId;
365	}
366
367	// URL for logging
368	window.DRAWIO_LOG_URL = window.DRAWIO_LOG_URL || '';
369
370	//Adds hard-coded logging domain for draw.io domains
371	var host = window.location.host;
372
373	if (host != 'test.draw.io')
374	{
375		var searchString = 'diagrams.net';
376		var position = host.length - searchString.length;
377		var lastIndex = host.lastIndexOf(searchString, position);
378
379		if (lastIndex !== -1 && lastIndex === position)
380		{
381			window.DRAWIO_LOG_URL = 'https://log.diagrams.net';
382		}
383		else
384		{
385			// For atlas integrations
386			var searchString = 'draw.io';
387			var position = host.length - searchString.length;
388			var lastIndex = host.lastIndexOf(searchString, position);
389
390			if (lastIndex !== -1 && lastIndex === position)
391			{
392				window.DRAWIO_LOG_URL = 'https://log.draw.io';
393			}
394		}
395	}
396})();
397
398// Enables offline mode
399if (urlParams['offline'] == '1' || urlParams['demo'] == '1' ||
400		urlParams['stealth'] == '1' || urlParams['local'] == '1' || urlParams['lockdown'] == '1')
401{
402	urlParams['picker'] = '0';
403	urlParams['gapi'] = '0';
404	urlParams['db'] = '0';
405	urlParams['od'] = '0';
406	urlParams['gh'] = '0';
407	urlParams['gl'] = '0';
408	urlParams['tr'] = '0';
409}
410// Do not insert code between above and below blocks
411// se mode. Ensure this comes after the block above.
412if (window.location.hostname == 'se.diagrams.net')
413{
414	urlParams['db'] = '0';
415	urlParams['od'] = '0';
416	urlParams['gh'] = '0';
417	urlParams['gl'] = '0';
418	urlParams['tr'] = '0';
419	urlParams['plugins'] = '0';
420	urlParams['mode'] = 'google';
421	urlParams['lockdown'] = '1'; // Do not want to apply lockdown true to above block
422
423	window.DRAWIO_GOOGLE_APP_ID = window.DRAWIO_GOOGLE_APP_ID || '184079235871';
424	window.DRAWIO_GOOGLE_CLIENT_ID = window.DRAWIO_GOOGLE_CLIENT_ID || '184079235871-pjf5nn0lff27lk8qf0770gmffiv9gt61.apps.googleusercontent.com';
425}
426
427// Disables Trello client by default
428if (urlParams['mode'] == 'trello')
429{
430	urlParams['tr'] = '1';
431}
432
433// Uses embed mode on embed domain
434if (window.location.hostname == 'embed.diagrams.net')
435{
436	urlParams['embed'] = '1';
437}
438
439// Fallback for cases where the hash property is not available
440if ((window.location.hash == null || window.location.hash.length <= 1) &&
441	urlParams['open'] != null)
442{
443	window.location.hash = urlParams['open'];
444}
445