Init.js 14 KB

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