Init.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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']) && window.location.protocol != 'file:' ? '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. // 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. 'bg' : 'Bulgarian',
  66. 'ca' : 'Català',
  67. 'cs' : 'Čeština',
  68. 'da' : 'Dansk',
  69. 'de' : 'Deutsch',
  70. 'et' : 'Eesti',
  71. 'en' : 'English',
  72. 'es' : 'Español',
  73. 'fil' : 'Filipino',
  74. 'fr' : 'Français',
  75. 'it' : 'Italiano',
  76. 'hu' : 'Magyar',
  77. 'nl' : 'Nederlands',
  78. 'no' : 'Norsk',
  79. 'pl' : 'Polski',
  80. 'pt-br' : 'Português (Brasil)',
  81. 'pt' : 'Português (Portugal)',
  82. 'ro' : 'Română',
  83. 'fi' : 'Suomi',
  84. 'sv' : 'Svenska',
  85. 'vi' : 'Tiếng Việt',
  86. 'tr' : 'Türkçe',
  87. 'el' : 'Ελληνικά',
  88. 'ru' : 'Русский',
  89. 'sr' : 'Српски',
  90. 'uk' : 'Українська',
  91. 'he' : 'עברית',
  92. 'ar' : 'العربية',
  93. 'th' : 'ไทย',
  94. 'ko' : '한국어',
  95. 'ja' : '日本語',
  96. 'zh' : '中文(中国)',
  97. 'zh-tw' : '中文(台灣)'
  98. };
  99. if (typeof window.mxBasePath === 'undefined')
  100. {
  101. window.mxBasePath = 'mxgraph';
  102. }
  103. if (window.mxLanguages == null)
  104. {
  105. window.mxLanguages = [];
  106. // Populates the list of supported special language bundles
  107. for (var lang in mxLanguageMap)
  108. {
  109. // Empty means default (ie. browser language), "en" means English (default for unsupported languages)
  110. // Since "en" uses no extension this must not be added to the array of supported language bundles.
  111. if (lang != 'en')
  112. {
  113. window.mxLanguages.push(lang);
  114. }
  115. }
  116. }
  117. /**
  118. * Returns the global UI setting before runngin static draw.io code
  119. */
  120. window.uiTheme = window.uiTheme || (function()
  121. {
  122. var ui = urlParams['ui'];
  123. // Known issue: No JSON object at this point in quirks in IE8
  124. if (ui == null && typeof JSON !== 'undefined')
  125. {
  126. // Cannot use mxSettings here
  127. if (isLocalStorage)
  128. {
  129. try
  130. {
  131. var value = localStorage.getItem('.drawio-config');
  132. if (value != null)
  133. {
  134. ui = JSON.parse(value).ui || null;
  135. }
  136. }
  137. catch (e)
  138. {
  139. // cookies are disabled, attempts to use local storage will cause
  140. // a DOM error at a minimum on Chrome
  141. isLocalStorage = false;
  142. }
  143. }
  144. }
  145. return ui;
  146. })();
  147. /**
  148. * Global function for loading local files via servlet
  149. */
  150. function setCurrentXml(data, filename)
  151. {
  152. if (window.parent != null && window.parent.openFile != null)
  153. {
  154. window.parent.openFile.setData(data, filename);
  155. }
  156. };
  157. /**
  158. * Overrides splash URL parameter via local storage
  159. */
  160. (function()
  161. {
  162. // Known issue: No JSON object at this point in quirks in IE8
  163. if (typeof JSON !== 'undefined')
  164. {
  165. // Cannot use mxSettings here
  166. if (isLocalStorage)
  167. {
  168. try
  169. {
  170. var value = localStorage.getItem('.drawio-config');
  171. var showSplash = true;
  172. if (value != null)
  173. {
  174. showSplash = JSON.parse(value).showStartScreen;
  175. }
  176. // Undefined means true
  177. if (showSplash == false)
  178. {
  179. urlParams['splash'] = '0';
  180. }
  181. }
  182. catch (e)
  183. {
  184. // ignore
  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. // URL for logging
  199. window.DRAWIO_LOG_URL = window.DRAWIO_LOG_URL || '';
  200. //Adds hard-coded logging domain for draw.io domains
  201. var host = window.location.host;
  202. if (host != 'test.draw.io')
  203. {
  204. var searchString = 'draw.io';
  205. var position = host.length - searchString.length;
  206. var lastIndex = host.lastIndexOf(searchString, position);
  207. if (lastIndex !== -1 && lastIndex === position)
  208. {
  209. window.DRAWIO_LOG_URL = 'https://log.draw.io';
  210. }
  211. }
  212. })();
  213. // Enables offline mode
  214. if (urlParams['offline'] == '1' || urlParams['demo'] == '1' || urlParams['stealth'] == '1' || urlParams['local'] == '1')
  215. {
  216. urlParams['analytics'] = '0';
  217. urlParams['picker'] = '0';
  218. urlParams['gapi'] = '0';
  219. urlParams['db'] = '0';
  220. urlParams['od'] = '0';
  221. urlParams['gh'] = '0';
  222. urlParams['tr'] = '0';
  223. }
  224. // Disables math in offline mode
  225. if (urlParams['offline'] == '1' || urlParams['local'] == '1')
  226. {
  227. urlParams['math'] = '0';
  228. }
  229. // Lightbox enabled chromeless mode
  230. if (urlParams['lightbox'] == '1')
  231. {
  232. urlParams['chrome'] = '0';
  233. }