Init.js 6.1 KB

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