Init.js 6.1 KB

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