Init.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // urlParams is null when used for embedding
  2. window.urlParams = window.urlParams || {};
  3. // isLocalStorage controls access to local storage
  4. window.isLocalStorage = window.isLocalStorage || false;
  5. // Checks for SVG support
  6. window.isSvgBrowser = window.isSvgBrowser || (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 9);
  7. // CUSTOM_PARAMETERS - URLs for save and export
  8. window.EXPORT_URL = window.EXPORT_URL || 'https://exp.draw.io/ImageExport4/export';
  9. window.SAVE_URL = window.SAVE_URL || 'save';
  10. window.OPEN_URL = window.OPEN_URL || 'open';
  11. window.PROXY_URL = window.PROXY_URL || 'proxy';
  12. // Paths and files
  13. window.SHAPES_PATH = window.SHAPES_PATH || 'shapes';
  14. // Path for images inside the diagram
  15. window.GRAPH_IMAGE_PATH = window.GRAPH_IMAGE_PATH || 'img';
  16. window.ICONSEARCH_PATH = window.ICONSEARCH_PATH || (navigator.userAgent.indexOf('MSIE') >= 0 ||
  17. urlParams['dev']) ? 'iconSearch' : 'https://www.draw.io/iconSearch';
  18. window.TEMPLATE_PATH = window.TEMPLATE_PATH || '/templates';
  19. // Directory for i18 files and basename for main i18n file
  20. window.RESOURCES_PATH = window.RESOURCES_PATH || 'resources';
  21. window.RESOURCE_BASE = window.RESOURCE_BASE || RESOURCES_PATH + '/dia';
  22. // URL for logging
  23. window.DRAWIO_LOG_URL = window.DRAWIO_LOG_URL || '';
  24. // Sets the base path, the UI language via URL param and configures the
  25. // supported languages to avoid 404s. The loading of all core language
  26. // resources is disabled as all required resources are in grapheditor.
  27. // properties. Note that in this example the loading of two resource
  28. // files (the special bundle and the default bundle) is disabled to
  29. // save a GET request. This requires that all resources be present in
  30. // the special bundle.
  31. window.mxLoadResources = window.mxLoadResources || false;
  32. window.mxLanguage = window.mxLanguage || (function()
  33. {
  34. var lang = (urlParams['offline'] == '1') ? 'en' : urlParams['lang'];
  35. // Known issue: No JSON object at this point in quirks in IE8
  36. if (lang == null && typeof(JSON) != 'undefined')
  37. {
  38. // Cannot use mxSettings here
  39. if (isLocalStorage)
  40. {
  41. try
  42. {
  43. var value = localStorage.getItem('.drawio-config');
  44. if (value != null)
  45. {
  46. lang = JSON.parse(value).language || null;
  47. }
  48. }
  49. catch (e)
  50. {
  51. // cookies are disabled, attempts to use local storage will cause
  52. // a DOM error at a minimum on Chrome
  53. isLocalStorage = false;
  54. }
  55. }
  56. }
  57. return lang;
  58. })();
  59. // Add new languages here. First entry is translated to [Automatic]
  60. // in the menu defintion in Diagramly.js.
  61. window.mxLanguageMap = window.mxLanguageMap ||
  62. {
  63. 'i18n': '',
  64. 'id' : 'Bahasa Indonesia',
  65. 'ms' : 'Bahasa Melayu',
  66. 'bs' : 'Bosanski',
  67. 'ca' : 'Català',
  68. 'cs' : 'Čeština',
  69. 'da' : 'Dansk',
  70. 'de' : 'Deutsch',
  71. 'et' : 'Eesti',
  72. 'en' : 'English',
  73. 'es' : 'Español',
  74. 'fil' : 'Filipino',
  75. 'fr' : 'Français',
  76. 'it' : 'Italiano',
  77. 'hu' : 'Magyar',
  78. 'nl' : 'Nederlands',
  79. 'no' : 'Norsk',
  80. 'pl' : 'Polski',
  81. 'pt-br' : 'Português (Brasil)',
  82. 'pt' : 'Português (Portugal)',
  83. 'ro' : 'Română',
  84. 'fi' : 'Suomi',
  85. 'sv' : 'Svenska',
  86. 'vi' : 'Tiếng Việt',
  87. 'tr' : 'Türkçe',
  88. 'el' : 'Ελληνικά',
  89. 'ru' : 'Русский',
  90. 'sr' : 'Српски',
  91. 'uk' : 'Українська',
  92. 'he' : 'עברית',
  93. 'ar' : 'العربية',
  94. 'th' : 'ไทย',
  95. 'ko' : '한국어',
  96. 'ja' : '日本語',
  97. 'zh' : '中文(中国)',
  98. 'zh-tw' : '中文(台灣)'
  99. };
  100. if (typeof window.mxBasePath === 'undefined')
  101. {
  102. window.mxBasePath = 'mxgraph';
  103. }
  104. if (window.mxLanguages == null)
  105. {
  106. window.mxLanguages = [];
  107. // Populates the list of supported special language bundles
  108. for (var lang in mxLanguageMap)
  109. {
  110. // Empty means default (ie. browser language), "en" means English (default for unsupported languages)
  111. // Since "en" uses no extension this must not be added to the array of supported language bundles.
  112. if (lang != 'en')
  113. {
  114. window.mxLanguages.push(lang);
  115. }
  116. }
  117. }
  118. /**
  119. * Returns the global UI setting before runngin static draw.io code
  120. */
  121. window.uiTheme = window.uiTheme || (function()
  122. {
  123. var ui = urlParams['ui'];
  124. // Known issue: No JSON object at this point in quirks in IE8
  125. if (ui == null && typeof JSON !== 'undefined')
  126. {
  127. // Cannot use mxSettings here
  128. if (isLocalStorage)
  129. {
  130. try
  131. {
  132. var value = localStorage.getItem('.drawio-config');
  133. if (value != null)
  134. {
  135. ui = JSON.parse(value).ui || null;
  136. }
  137. }
  138. catch (e)
  139. {
  140. // cookies are disabled, attempts to use local storage will cause
  141. // a DOM error at a minimum on Chrome
  142. isLocalStorage = false;
  143. }
  144. }
  145. }
  146. return ui;
  147. })();
  148. /**
  149. * Global function for loading local files via servlet
  150. */
  151. function setCurrentXml(data, filename)
  152. {
  153. if (window.parent != null && window.parent.openFile != null)
  154. {
  155. window.parent.openFile.setData(data, filename);
  156. }
  157. };
  158. /**
  159. * Overrides splash URL parameter via local storage
  160. */
  161. (function()
  162. {
  163. // Known issue: No JSON object at this point in quirks in IE8
  164. if (typeof JSON !== 'undefined')
  165. {
  166. // Cannot use mxSettings here
  167. if (isLocalStorage)
  168. {
  169. try
  170. {
  171. var value = localStorage.getItem('.drawio-config');
  172. var showSplash = true;
  173. if (value != null)
  174. {
  175. showSplash = JSON.parse(value).showStartScreen;
  176. }
  177. // Undefined means true
  178. if (showSplash == false)
  179. {
  180. urlParams['splash'] = '0';
  181. }
  182. }
  183. catch (e)
  184. {
  185. // ignore
  186. }
  187. }
  188. }
  189. })();
  190. // Customizes export URL
  191. var ex = urlParams['export'];
  192. if (ex != null)
  193. {
  194. if (ex.substring(0, 7) != 'http://' && ex.substring(0, 8) != 'https://')
  195. {
  196. ex = 'http://' + ex;
  197. }
  198. EXPORT_URL = ex;
  199. }
  200. // Enables offline mode
  201. if (urlParams['offline'] == '1' || urlParams['demo'] == '1' || urlParams['stealth'] == '1' || urlParams['local'] == '1')
  202. {
  203. urlParams['analytics'] = '0';
  204. urlParams['picker'] = '0';
  205. urlParams['gapi'] = '0';
  206. urlParams['db'] = '0';
  207. urlParams['od'] = '0';
  208. urlParams['gh'] = '0';
  209. }
  210. // Disables math in offline mode
  211. if (urlParams['offline'] == '1' || urlParams['local'] == '1')
  212. {
  213. urlParams['math'] = '0';
  214. }
  215. // Lightbox enabled chromeless mode
  216. if (urlParams['lightbox'] == '1')
  217. {
  218. urlParams['chrome'] = '0';
  219. }
  220. // Adds hard-coded logging domain for draw.io domains
  221. var host = window.location.host;
  222. var searchString = 'draw.io';
  223. var position = host.length - searchString.length;
  224. var lastIndex = host.lastIndexOf(searchString, position);
  225. if (lastIndex !== -1 && lastIndex === position && host != 'test.draw.io')
  226. {
  227. // endsWith polyfill
  228. window.DRAWIO_LOG_URL = 'https://log.draw.io';
  229. }