Editor.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. /**
  2. * Copyright (c) 2006-2017, JGraph Ltd
  3. * Copyright (c) 2006-2017, Gaudenz Alder
  4. */
  5. (function()
  6. {
  7. /**
  8. * Specifies the app name. Default is document.title.
  9. */
  10. Editor.prototype.appName = 'draw.io';
  11. /**
  12. * Used in the GraphViewer lightbox.
  13. */
  14. Editor.closeImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAADzN3VRAAAApVBMVEUAAAD////k5OT///8AAAB1dXXMzMz9/f39/f37+/v5+fn+/v7///9iYmJaWlqFhYWnp6ejo6OHh4f////////////////7+/v5+fnx8fH///8AAAD///8bGxv7+/v5+fkoKCghISFDQ0MYGBjh4eHY2Njb29tQUFBvb29HR0c/Pz82NjYrKyu/v78SEhLu7u7s7OzV1dVVVVU7OzsVFRXAv78QEBBzqehMAAAAG3RSTlMAA/7p/vz5xZlrTiPL/v78+/v7+OXd2TYQDs8L70ZbAAABKUlEQVQoz3VS13LCMBBUXHChd8iukDslQChJ/v/TchaG4cXS+OSb1c7trU7V60OpdRz2ZtNZL4zXNlcN8BEtSG6+NxIXkeRPoBuQ1cjvZ31/VJFB10ISli6diYfH8iYO3WUNCcNlB0gTrXOtkxTo0O1aKKiBBMhhv2MNBQKoiA5wxlZo0JDzD3AYKbWacyj3fs01wxey0pyEP+R8pWKWXoqtIZ0DDg5pbki9krEKOa6LVDQsdoXEsi46Zqh69KFz7B1u7Hb2yDV8firXDKBlZ4UFiswKGRhXTS93/ECK7yxnJ3+S3y/ThpO+cfSD017nqa18aasabU0/t7d+tk0/1oMEJ1NaD67iwdF68OabFSLn+eHb0+vjy+uk8br9fdrftH0O2menfd7+AQfYM/lNjoDHAAAAAElFTkSuQmCC' : IMAGE_PATH + '/delete.png';
  15. /**
  16. *
  17. */
  18. Editor.plusImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/plus.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9S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+vr6+/v///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGRUCYcEgspkwjEKhUVJ1QsBNp0xm2VixiSOMRvlxFGAcTJook5eEHIhQcwpWIkAFQECkNy9AQWFwyEAkPRQ4FAwQIE2llQQAh+QQJCgAvACwAAAAADAAMAIVNcY5SdZFigptph6BvjKN0kKd8lquAmq+EnbGGn7KHn7ONpLaOpbearr+csMCdscCescGhtMOnuMauvsuzws60w862xdC9ytW/y9a/zNbCztjG0drH0tvK1N3M1t7N19/U3ePb4uff5urj6Ozk6e3l6u7m6u7o7PDq7vDt8PPv8vTw8vTw8/X19vf6+vv///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGQ8CXcEgsvlytVUplJLJIpSEDUESFTELBwSgCCQEV42kjDFiMo4uQsDB2MkLHoEHUTD7DRAHC8VAiZ0QSCgYIDxhNiUEAOw==';
  23. /**
  24. * Used in the GraphViewer lightbox.
  25. */
  26. Editor.tweetImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAARlJREFUeNpi/P//PwM1ABMDlQDVDGKAeo0biMXwKOMD4ilA/AiInwDxfCBWBeIgINYDmwE1yB2Ir0Alsbl6JchONPwNiC8CsTPIDJjXuIBYG4gPAnE8EDMjGaQCxGFYLOAEYlYg/o3sNSkgfo1k2ykgLgRiIyAOwOIaGE6CmwE1SA6IZ0BNR1f8GY9BXugG2UMN+YtHEzr+Aw0OFINYgHgdCYaA8HUgZkM3CASEoYb9ItKgapQkhGQQKC0dJdKQx1CLsRoEArpAvAuI3+Ix5B8Q+2AkaiyZVgGId+MwBBQhKVhzB9QgKyDuAOJ90BSLzZBzQOyCK5uxQNnXoGlJHogfIOU7UCI9C8SbgHgjEP/ElRkZB115BBBgAPbkvQ/azcC0AAAAAElFTkSuQmCC' : IMAGE_PATH + '/tweet.png';
  27. /**
  28. * Used in the GraphViewer lightbox.
  29. */
  30. Editor.facebookImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAARVBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADc6ur3AAAAFnRSTlMAYmRg2KVCC/oPq0uAcVQtHtvZuoYh/a7JUAAAAGJJREFUGNOlzkkOgCAMQNEvagvigBP3P6pRNoCJG/+myVu0RdsqxcQqQ/NFVkKQgqwDzoJ2WKajoB66atcAa0GjX0D8lJHwNGfknYJzY77LDtDZ+L74j0z26pZI2yYlMN9TL17xEd+fl1D+AAAAAElFTkSuQmCC' : IMAGE_PATH + '/facebook.png';
  31. /**
  32. * Blank 1x1 pixel transparent PNG image.
  33. */
  34. Editor.blankImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==';
  35. /**
  36. * Contains the default XML for an empty diagram.
  37. */
  38. Editor.defaultCsvValue = '##\n' +
  39. '## Example CSV import. Use ## for comments and # for configuration. Paste CSV below.\n' +
  40. '## The following names are reserved and should not be used (or ignored):\n' +
  41. '## id, tooltip, placeholder(s), link and label (see below)\n' +
  42. '##\n' +
  43. '#\n' +
  44. '## Node label with placeholders and HTML.\n' +
  45. '## Default is \'%name_of_first_column%\'.\n' +
  46. '#\n' +
  47. '# label: %name%<br><i style="color:gray;">%position%</i><br><a href="mailto:%email%">Email</a>\n' +
  48. '#\n' +
  49. '## Node style (placeholders are replaced once).\n' +
  50. '## Default is the current style for nodes.\n' +
  51. '#\n' +
  52. '# style: label;image=%image%;whiteSpace=wrap;html=1;rounded=1;fillColor=%fill%;strokeColor=%stroke%;\n' +
  53. '#\n' +
  54. '## Uses the given column name as the identity for cells (updates existing cells).\n' +
  55. '## Default is no identity (empty value or -).\n' +
  56. '#\n' +
  57. '# identity: -\n' +
  58. '#\n' +
  59. '## Connections between rows ("from": source colum, "to": target column).\n' +
  60. '## Label, style and invert are optional. Defaults are \'\', current style and false.\n' +
  61. '## The target column may contain a comma-separated list of values.\n' +
  62. '## Multiple connect entries are allowed.\n' +
  63. '#\n' +
  64. '# connect: {"from": "manager", "to": "name", "invert": true, "label": "manages", \\\n' +
  65. '# "style": "curved=1;endArrow=blockThin;endFill=1;fontSize=11;"}\n' +
  66. '# connect: {"from": "refs", "to": "id", "style": "curved=1;fontSize=11;"}\n' +
  67. '#\n' +
  68. '## Node width. Possible value are px or auto. Default is auto.\n' +
  69. '#\n' +
  70. '# width: auto\n' +
  71. '#\n' +
  72. '## Node height. Possible value are px or auto. Default is auto.\n' +
  73. '#\n' +
  74. '# height: auto\n' +
  75. '#\n' +
  76. '## Padding for autosize. Default is 0.\n' +
  77. '#\n' +
  78. '# padding: -26\n' +
  79. '#\n' +
  80. '## Comma-separated list of ignored columns for metadata. (These can be\n' +
  81. '## used for connections and styles but will not be added as metadata.)\n' +
  82. '#\n' +
  83. '# ignore: id,image,fill,stroke\n' +
  84. '#\n' +
  85. '## Column to be renamed to link attribute (used as link).\n' +
  86. '#\n' +
  87. '# link: url\n' +
  88. '#\n' +
  89. '## Spacing between nodes. Default is 40.\n' +
  90. '#\n' +
  91. '# nodespacing: 40\n' +
  92. '#\n' +
  93. '## Spacing between parallel edges. Default is 40.\n' +
  94. '#\n' +
  95. '# edgespacing: 40\n' +
  96. '#\n' +
  97. '## Name of layout. Possible values are auto, none, verticaltree, horizontaltree,\n' +
  98. '## verticalflow, horizontalflow, organic, circle. Default is auto.\n' +
  99. '#\n' +
  100. '# layout: auto\n' +
  101. '#\n' +
  102. '## ---- CSV below this line. First line are column names. ----\n' +
  103. 'name,position,id,location,manager,email,fill,stroke,refs,url,image\n' +
  104. 'Evan Miller,CFO,emi,Office 1,,me@example.com,#dae8fc,#6c8ebf,,https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-9-2-128.png\n' +
  105. 'Edward Morrison,Brand Manager,emo,Office 2,Evan Miller,me@example.com,#d5e8d4,#82b366,,https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-10-3-128.png\n' +
  106. 'Ron Donovan,System Admin,rdo,Office 3,Evan Miller,me@example.com,#d5e8d4,#82b366,"emo,tva",https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-2-128.png\n' +
  107. 'Tessa Valet,HR Director,tva,Office 4,Evan Miller,me@example.com,#d5e8d4,#82b366,,https://www.draw.io,https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-3-128.png\n';
  108. /**
  109. * Global configuration of the Editor. Possible configuration values are:
  110. *
  111. * - presetColors: array of color codes for upper palette, default is ColorDialog.prototype.presetColors (no leading #)
  112. * - defaultColors: array of color codes for the lower palette, default is ColorDialog.prototype.defaultColors (no leading #)
  113. * - defaultFonts: array of available font family names, default is Menus.prototype.defaultFonts
  114. * - defaultColorSchemes: array of array of available color schemes, default is StyleFormatPanel.prototype.defaultColorSchemes
  115. *
  116. * (code)
  117. * Editor.configure({defaultFonts: ['Helvetica', 'Verdana', 'Times New Roman', 'Garamond',
  118. * 'Comic Sans MS', 'Courier New', 'Georgia', 'Lucida Console', 'Tahoma'],
  119. * presetColors: ['E6D0DE', 'CDA2BE', 'B5739D', 'E1D5E7', 'C3ABD0', 'A680B8', 'D4E1F5',
  120. * 'A9C4EB', '7EA6E0', 'D5E8D4', '9AC7BF', '67AB9F', 'D5E8D4', 'B9E0A5', '97D077', 'FFF2CC',
  121. * 'FFE599', 'FFD966', 'FFF4C3', 'FFCE9F', 'FFB570', 'F8CECC', 'F19C99', 'EA6B66'],
  122. * defaultColorSchemes: [[null, {fill: '#f5f5f5', stroke: '#666666'},
  123. * {fill: '#dae8fc', stroke: '#6c8ebf'}, {fill: '#d5e8d4', stroke: '#82b366'},
  124. * {fill: '#ffe6cc', stroke: '#d79b00'}, {fill: '#fff2cc', stroke: '#d6b656'},
  125. * {fill: '#f8cecc', stroke: '#b85450'}, {fill: '#e1d5e7', stroke: '#9673a6'}],
  126. * [null,
  127. * {fill: '#f5f5f5', stroke: '#666666', gradient: '#b3b3b3'},
  128. * {fill: '#dae8fc', stroke: '#6c8ebf', gradient: '#7ea6e0'},
  129. * {fill: '#d5e8d4', stroke: '#82b366', gradient: '#97d077'},
  130. * {fill: '#ffcd28', stroke: '#d79b00', gradient: '#ffa500'},
  131. * {fill: '#fff2cc', stroke: '#d6b656', gradient: '#ffd966'},
  132. * {fill: '#f8cecc', stroke: '#b85450', gradient: '#ea6b66'},
  133. * {fill: '#e6d0de', stroke: '#996185', gradient: '#d5739d'}],
  134. * [null, {fill: '#eeeeee', stroke: '#36393d'},
  135. * {fill: '#f9f7ed', stroke: '#36393d'}, {fill: '#ffcc99', stroke: '#36393d'},
  136. * {fill: '#cce5ff', stroke: '#36393d'}, {fill: '#ffff88', stroke: '#36393d'},
  137. * {fill: '#cdeb8b', stroke: '#36393d'}, {fill: '#ffcccc', stroke: '#36393d'}]]});
  138. * (end)
  139. */
  140. Editor.configure = function(config)
  141. {
  142. // LATER: DefaultFont and DefaultFontSize should override Graph's stylesheet,
  143. // default edge and vertex styles would have to be set before loading mxSettings
  144. ColorDialog.prototype.presetColors = config.presetColors || ColorDialog.prototype.presetColors;
  145. ColorDialog.prototype.defaultColors = config.defaultColors || ColorDialog.prototype.defaultColors;
  146. Menus.prototype.defaultFonts = config.defaultFonts || Menus.prototype.defaultFonts;
  147. StyleFormatPanel.prototype.defaultColorSchemes = config.defaultColorSchemes || StyleFormatPanel.prototype.defaultColorSchemes;
  148. };
  149. /**
  150. * Executes the first step for connecting to Google Drive.
  151. */
  152. Editor.prototype.editButtonLink = (urlParams['edit'] != null) ? decodeURIComponent(urlParams['edit']) : null;
  153. /**
  154. *
  155. */
  156. if (urlParams['dev'] == '1')
  157. {
  158. Editor.prototype.editBlankUrl = Editor.prototype.editBlankUrl + '&dev=1';
  159. Editor.prototype.editBlankFallbackUrl = Editor.prototype.editBlankFallbackUrl + '&dev=1';
  160. }
  161. /**
  162. * Adds support for old stylesheets and compressed files
  163. */
  164. var editorSetGraphXml = Editor.prototype.setGraphXml;
  165. Editor.prototype.setGraphXml = function(node)
  166. {
  167. node = (node != null && node.nodeName != 'mxlibrary') ? this.extractGraphModel(node) : null;
  168. if (node != null)
  169. {
  170. // Checks input for parser errors
  171. var errs = node.getElementsByTagName('parsererror');
  172. if (errs != null && errs.length > 0)
  173. {
  174. var elt = errs[0];
  175. var divs = elt.getElementsByTagName('div');
  176. if (divs != null && divs.length > 0)
  177. {
  178. elt = divs[0];
  179. }
  180. throw {message: mxUtils.getTextContent(elt)};
  181. }
  182. else if (node.nodeName == 'mxGraphModel')
  183. {
  184. var style = node.getAttribute('style') || 'default-style2';
  185. // Decodes the style if required
  186. if (urlParams['embed'] != '1' && (style == null || style == ''))
  187. {
  188. var node2 = (this.graph.themes != null) ?
  189. this.graph.themes['default-old'] :
  190. mxUtils.load(STYLE_PATH + '/default-old.xml').getDocumentElement();
  191. if (node2 != null)
  192. {
  193. var dec2 = new mxCodec(node2.ownerDocument);
  194. dec2.decode(node2, this.graph.getStylesheet());
  195. }
  196. }
  197. else if (style != this.graph.currentStyle)
  198. {
  199. var node2 = (this.graph.themes != null) ?
  200. this.graph.themes[style] :
  201. mxUtils.load(STYLE_PATH + '/' + style + '.xml').getDocumentElement()
  202. if (node2 != null)
  203. {
  204. var dec2 = new mxCodec(node2.ownerDocument);
  205. dec2.decode(node2, this.graph.getStylesheet());
  206. }
  207. }
  208. this.graph.currentStyle = style;
  209. this.graph.mathEnabled = (urlParams['math'] == '1' || node.getAttribute('math') == '1');
  210. var bgImg = node.getAttribute('backgroundImage');
  211. if (bgImg != null)
  212. {
  213. bgImg = JSON.parse(bgImg);
  214. this.graph.setBackgroundImage(new mxImage(bgImg.src, bgImg.width, bgImg.height));
  215. }
  216. else
  217. {
  218. this.graph.setBackgroundImage(null);
  219. }
  220. mxClient.NO_FO = (this.graph.mathEnabled) ? true : this.originalNoForeignObject;
  221. this.graph.setShadowVisible(node.getAttribute('shadow') == '1', false);
  222. }
  223. // Calls updateGraphComponents
  224. editorSetGraphXml.apply(this, arguments);
  225. }
  226. else
  227. {
  228. throw {
  229. message: mxResources.get('notADiagramFile') || 'Invalid data',
  230. toString: function() { return this.message; }
  231. };
  232. }
  233. };
  234. /**
  235. * Adds persistent style to file
  236. */
  237. var editorGetGraphXml = Editor.prototype.getGraphXml;
  238. Editor.prototype.getGraphXml = function(ignoreSelection)
  239. {
  240. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  241. var node = editorGetGraphXml.apply(this, arguments);
  242. // Adds the current style
  243. if (this.graph.currentStyle != null && this.graph.currentStyle != 'default-style2')
  244. {
  245. node.setAttribute('style', this.graph.currentStyle);
  246. }
  247. // Adds the background image
  248. if (this.graph.backgroundImage != null)
  249. {
  250. node.setAttribute('backgroundImage', JSON.stringify(this.graph.backgroundImage));
  251. }
  252. node.setAttribute('math', (this.graph.mathEnabled) ? '1' : '0');
  253. node.setAttribute('shadow', (this.graph.shadowVisible) ? '1' : '0');
  254. return node;
  255. };
  256. /**
  257. * Helper function to extract the graph model XML node.
  258. */
  259. Editor.prototype.isDataSvg = function(svg)
  260. {
  261. try
  262. {
  263. var svgRoot = mxUtils.parseXml(svg).documentElement;
  264. var tmp = svgRoot.getAttribute('content');
  265. if (tmp != null)
  266. {
  267. if (tmp != null && tmp.charAt(0) != '<' && tmp.charAt(0) != '%')
  268. {
  269. tmp = unescape((window.atob) ? atob(tmp) : Base64.decode(cont, tmp));
  270. }
  271. if (tmp != null && tmp.charAt(0) == '%')
  272. {
  273. tmp = decodeURIComponent(tmp);
  274. }
  275. if (tmp != null && tmp.length > 0)
  276. {
  277. var node = mxUtils.parseXml(tmp).documentElement;
  278. return node.nodeName == 'mxfile' || node.nodeName == 'mxGraphModel';
  279. }
  280. }
  281. }
  282. catch (e)
  283. {
  284. // ignore
  285. }
  286. return false;
  287. };
  288. /**
  289. * Helper function to extract the graph model XML node.
  290. */
  291. Editor.prototype.extractGraphModel = function(node, allowMxFile)
  292. {
  293. if (node != null && typeof(pako) !== 'undefined')
  294. {
  295. var tmp = node.ownerDocument.getElementsByTagName('div');
  296. var divs = [];
  297. if (tmp != null && tmp.length > 0)
  298. {
  299. for (var i = 0; i < tmp.length; i++)
  300. {
  301. if (tmp[i].getAttribute('class') == 'mxgraph')
  302. {
  303. divs.push(tmp[i]);
  304. break;
  305. }
  306. }
  307. }
  308. if (divs.length > 0)
  309. {
  310. var data = divs[0].getAttribute('data-mxgraph');
  311. if (data != null)
  312. {
  313. var config = JSON.parse(data);
  314. if (config != null && config.xml != null)
  315. {
  316. var doc2 = mxUtils.parseXml(config.xml);
  317. node = doc2.documentElement;
  318. }
  319. }
  320. else
  321. {
  322. var divs2 = divs[0].getElementsByTagName('div');
  323. if (divs2.length > 0)
  324. {
  325. var data = mxUtils.getTextContent(divs2[0]);
  326. data = this.graph.decompress(data);
  327. if (data.length > 0)
  328. {
  329. var doc2 = mxUtils.parseXml(data);
  330. node = doc2.documentElement;
  331. }
  332. }
  333. }
  334. }
  335. }
  336. if (node != null && node.nodeName == 'svg')
  337. {
  338. var tmp = node.getAttribute('content');
  339. if (tmp != null && tmp.charAt(0) != '<' && tmp.charAt(0) != '%')
  340. {
  341. tmp = unescape((window.atob) ? atob(tmp) : Base64.decode(cont, tmp));
  342. }
  343. if (tmp != null && tmp.charAt(0) == '%')
  344. {
  345. tmp = decodeURIComponent(tmp);
  346. }
  347. if (tmp != null && tmp.length > 0)
  348. {
  349. node = mxUtils.parseXml(tmp).documentElement;
  350. }
  351. else
  352. {
  353. throw {message: mxResources.get('notADiagramFile')};
  354. }
  355. }
  356. if (node != null && !allowMxFile)
  357. {
  358. var diagramNode = null;
  359. if (node.nodeName == 'diagram')
  360. {
  361. diagramNode = node;
  362. }
  363. else if (node.nodeName == 'mxfile')
  364. {
  365. var diagrams = node.getElementsByTagName('diagram');
  366. if (diagrams.length > 0)
  367. {
  368. diagramNode = diagrams[Math.max(0, Math.min(diagrams.length - 1, urlParams['page'] || 0))];
  369. }
  370. }
  371. if (diagramNode != null)
  372. {
  373. var tmp = this.graph.decompress(mxUtils.getTextContent(diagramNode));
  374. if (tmp != null && tmp.length > 0)
  375. {
  376. node = mxUtils.parseXml(tmp).documentElement;
  377. }
  378. }
  379. }
  380. if (node != null && node.nodeName != 'mxGraphModel' && (!allowMxFile || node.nodeName != 'mxfile'))
  381. {
  382. node = null;
  383. }
  384. return node;
  385. };
  386. /**
  387. * Overrides reset graph.
  388. */
  389. var editorResetGraph = Editor.prototype.resetGraph;
  390. Editor.prototype.resetGraph = function()
  391. {
  392. this.graph.mathEnabled = (urlParams['math'] == '1');
  393. this.graph.view.x0 = null;
  394. this.graph.view.y0 = null;
  395. mxClient.NO_FO = (this.graph.mathEnabled) ? true : this.originalNoForeignObject;
  396. editorResetGraph.apply(this, arguments);
  397. };
  398. /**
  399. * Math support.
  400. */
  401. Editor.prototype.originalNoForeignObject = mxClient.NO_FO;
  402. var editorUpdateGraphComponents = Editor.prototype.updateGraphComponents;
  403. Editor.prototype.updateGraphComponents = function()
  404. {
  405. editorUpdateGraphComponents.apply(this, arguments);
  406. mxClient.NO_FO = (this.graph.mathEnabled && Editor.MathJaxRender != null) ? true : this.originalNoForeignObject;
  407. };
  408. /**
  409. * Initializes math typesetting and loads respective code.
  410. */
  411. Editor.initMath = function(src, config)
  412. {
  413. src = (src != null) ? src : 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_HTMLorMML';
  414. Editor.mathJaxQueue = [];
  415. Editor.doMathJaxRender = function(container)
  416. {
  417. MathJax.Hub.Queue(['Typeset', MathJax.Hub, container]);
  418. };
  419. // Disables global typesetting and messages on startup, adds queue for
  420. // asynchronous rendering while MathJax is loading
  421. window.MathJax =
  422. {
  423. skipStartupTypeset: true,
  424. showMathMenu: false,
  425. messageStyle: 'none',
  426. AuthorInit: function ()
  427. {
  428. // Specification recommends using SVG over HTML-CSS if browser is known
  429. // Check if too inconsistent with image export and print output
  430. MathJax.Hub.Config(config || {
  431. jax: ['input/TeX', 'input/MathML', 'input/AsciiMath', 'output/HTML-CSS'],
  432. extensions: ['tex2jax.js', 'mml2jax.js', 'asciimath2jax.js'],
  433. TeX: {
  434. extensions: ['AMSmath.js', 'AMSsymbols.js', 'noErrors.js', 'noUndefined.js']
  435. },
  436. // Ignores math in in-place editor
  437. tex2jax: {
  438. ignoreClass: 'mxCellEditor'
  439. },
  440. asciimath2jax: {
  441. ignoreClass: 'mxCellEditor'
  442. }
  443. });
  444. MathJax.Hub.Register.StartupHook('Begin', function()
  445. {
  446. for (var i = 0; i < Editor.mathJaxQueue.length; i++)
  447. {
  448. Editor.doMathJaxRender(Editor.mathJaxQueue[i]);
  449. }
  450. });
  451. }
  452. };
  453. // Adds global enqueue method for async rendering
  454. Editor.MathJaxRender = function(container)
  455. {
  456. // Initial rendering when MathJax finished loading
  457. if (typeof(MathJax) !== 'undefined' && typeof(MathJax.Hub) !== 'undefined')
  458. {
  459. Editor.doMathJaxRender(container);
  460. }
  461. else
  462. {
  463. Editor.mathJaxQueue.push(container);
  464. }
  465. };
  466. // Adds global clear queue method
  467. Editor.MathJaxClear = function()
  468. {
  469. Editor.mathJaxQueue = [];
  470. };
  471. // Updates typeset after changes
  472. var editorInit = Editor.prototype.init;
  473. Editor.prototype.init = function()
  474. {
  475. editorInit.apply(this, arguments);
  476. this.graph.addListener(mxEvent.SIZE, mxUtils.bind(this, function(sender, evt)
  477. {
  478. if (this.graph.mathEnabled)
  479. {
  480. Editor.MathJaxRender(this.graph.container);
  481. }
  482. }));
  483. };
  484. var tags = document.getElementsByTagName('script');
  485. if (tags != null && tags.length > 0)
  486. {
  487. var script = document.createElement('script');
  488. script.type = 'text/javascript';
  489. script.src = src;
  490. tags[0].parentNode.appendChild(script);
  491. }
  492. };
  493. /**
  494. * Return array of string values, or NULL if CSV string not well formed.
  495. */
  496. Editor.prototype.csvToArray = function(text)
  497. {
  498. var re_valid = /^\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*(?:,\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*)*$/;
  499. var re_value = /(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g;
  500. // Return NULL if input string is not well formed CSV string.
  501. if (!re_valid.test(text)) return null;
  502. var a = []; // Initialize array to receive values.
  503. text.replace(re_value, // "Walk" the string using replace with callback.
  504. function(m0, m1, m2, m3) {
  505. // Remove backslash from \' in single quoted values.
  506. if (m1 !== undefined) a.push(m1.replace(/\\'/g, "'"));
  507. // Remove backslash from \" in double quoted values.
  508. else if (m2 !== undefined) a.push(m2.replace(/\\"/g, '"'));
  509. else if (m3 !== undefined) a.push(m3);
  510. return ''; // Return empty string.
  511. });
  512. // Handle special case of empty last value.
  513. if (/,\s*$/.test(text)) a.push('');
  514. return a;
  515. };
  516. /**
  517. * Adds persistence for recent colors
  518. */
  519. if (window.ColorDialog)
  520. {
  521. var colorDialogAddRecentColor = ColorDialog.addRecentColor;
  522. ColorDialog.addRecentColor = function(color, max)
  523. {
  524. colorDialogAddRecentColor.apply(this, arguments);
  525. mxSettings.setRecentColors(ColorDialog.recentColors);
  526. mxSettings.save();
  527. };
  528. var colorDialogResetRecentColors = ColorDialog.resetRecentColors;
  529. ColorDialog.resetRecentColors = function()
  530. {
  531. colorDialogResetRecentColors.apply(this, arguments);
  532. mxSettings.setRecentColors(ColorDialog.recentColors);
  533. mxSettings.save();
  534. };
  535. }
  536. // Overridden to add edit shape option
  537. if (window.StyleFormatPanel != null)
  538. {
  539. var formatInit = Format.prototype.init;
  540. Format.prototype.init = function()
  541. {
  542. formatInit.apply(this, arguments);
  543. var ui = this.editorUi;
  544. ui.editor.addListener('fileLoaded', this.update);
  545. };
  546. var formatRefresh = Format.prototype.refresh;
  547. Format.prototype.refresh = function()
  548. {
  549. var ui = this.editorUi;
  550. if (ui.getCurrentFile() != null || urlParams['embed'] == '1')
  551. {
  552. formatRefresh.apply(this, arguments);
  553. }
  554. else
  555. {
  556. this.clear();
  557. }
  558. };
  559. /**
  560. * Adds autosave and math typesetting options.
  561. */
  562. var diagramFormatPanelAddOptions = DiagramFormatPanel.prototype.addOptions;
  563. DiagramFormatPanel.prototype.addOptions = function(div)
  564. {
  565. div = diagramFormatPanelAddOptions.apply(this, arguments);
  566. var ui = this.editorUi;
  567. var editor = ui.editor;
  568. var graph = editor.graph;
  569. if (graph.isEnabled())
  570. {
  571. var file = ui.getCurrentFile();
  572. if (file != null && file.isAutosaveOptional())
  573. {
  574. var opt = this.createOption(mxResources.get('autosave'), function()
  575. {
  576. return ui.editor.autosave;
  577. }, function(checked)
  578. {
  579. ui.editor.setAutosave(checked);
  580. },
  581. {
  582. install: function(apply)
  583. {
  584. this.listener = function()
  585. {
  586. apply(ui.editor.autosave);
  587. };
  588. ui.editor.addListener('autosaveChanged', this.listener);
  589. },
  590. destroy: function()
  591. {
  592. ui.editor.removeListener(this.listener);
  593. }
  594. });
  595. div.appendChild(opt);
  596. }
  597. }
  598. return div;
  599. };
  600. /**
  601. * Configures global color schemes.
  602. */
  603. StyleFormatPanel.prototype.defaultColorSchemes = [[null, {fill: '#f5f5f5', stroke: '#666666'},
  604. {fill: '#dae8fc', stroke: '#6c8ebf'}, {fill: '#d5e8d4', stroke: '#82b366'},
  605. {fill: '#ffe6cc', stroke: '#d79b00'}, {fill: '#fff2cc', stroke: '#d6b656'},
  606. {fill: '#f8cecc', stroke: '#b85450'}, {fill: '#e1d5e7', stroke: '#9673a6'}],
  607. [null,
  608. {fill: '#f5f5f5', stroke: '#666666', gradient: '#b3b3b3'},
  609. {fill: '#dae8fc', stroke: '#6c8ebf', gradient: '#7ea6e0'},
  610. {fill: '#d5e8d4', stroke: '#82b366', gradient: '#97d077'},
  611. {fill: '#ffcd28', stroke: '#d79b00', gradient: '#ffa500'},
  612. {fill: '#fff2cc', stroke: '#d6b656', gradient: '#ffd966'},
  613. {fill: '#f8cecc', stroke: '#b85450', gradient: '#ea6b66'},
  614. {fill: '#e6d0de', stroke: '#996185', gradient: '#d5739d'}],
  615. [null, {fill: '#eeeeee', stroke: '#36393d'},
  616. {fill: '#f9f7ed', stroke: '#36393d'}, {fill: '#ffcc99', stroke: '#36393d'},
  617. {fill: '#cce5ff', stroke: '#36393d'}, {fill: '#ffff88', stroke: '#36393d'},
  618. {fill: '#cdeb8b', stroke: '#36393d'}, {fill: '#ffcccc', stroke: '#36393d'}]];
  619. /**
  620. * Adds predefiend styles.
  621. */
  622. var StyleFormatPanelInit = StyleFormatPanel.prototype.init;
  623. StyleFormatPanel.prototype.init = function()
  624. {
  625. // TODO: Update sstate in Format
  626. var sstate = this.format.createSelectionState();
  627. if (sstate.style.shape != 'image')
  628. {
  629. this.container.appendChild(this.addStyles(this.createPanel()));
  630. }
  631. StyleFormatPanelInit.apply(this, arguments);
  632. };
  633. /**
  634. * Overridden to add copy and paste style.
  635. */
  636. var styleFormatPanelAddStyleOps = StyleFormatPanel.prototype.addStyleOps;
  637. StyleFormatPanel.prototype.addStyleOps = function(div)
  638. {
  639. var btn = mxUtils.button(mxResources.get('copyStyle'), mxUtils.bind(this, function(evt)
  640. {
  641. this.editorUi.actions.get('copyStyle').funct();
  642. }));
  643. btn.setAttribute('title', mxResources.get('copyStyle') + ' (' + this.editorUi.actions.get('copyStyle').shortcut + ')');
  644. btn.style.marginBottom = '2px';
  645. btn.style.width = '100px';
  646. btn.style.marginRight = '2px';
  647. div.appendChild(btn);
  648. var btn = mxUtils.button(mxResources.get('pasteStyle'), mxUtils.bind(this, function(evt)
  649. {
  650. this.editorUi.actions.get('pasteStyle').funct();
  651. }));
  652. btn.setAttribute('title', mxResources.get('pasteStyle') + ' (' + this.editorUi.actions.get('pasteStyle').shortcut + ')');
  653. btn.style.marginBottom = '2px';
  654. btn.style.width = '100px';
  655. div.appendChild(btn);
  656. mxUtils.br(div);
  657. return styleFormatPanelAddStyleOps.apply(this, arguments);
  658. };
  659. /**
  660. * Creates the buttons for the predefined styles.
  661. */
  662. StyleFormatPanel.prototype.addStyles = function(div)
  663. {
  664. var graph = this.editorUi.editor.graph;
  665. var picker = document.createElement('div');
  666. picker.style.whiteSpace = 'normal';
  667. picker.style.paddingLeft = '24px';
  668. picker.style.paddingRight = '20px';
  669. div.style.paddingLeft = '16px';
  670. div.style.paddingBottom = '6px';
  671. div.style.position = 'relative';
  672. div.appendChild(picker);
  673. var stylenames = ['plain-gray', 'plain-blue', 'plain-green', 'plain-turquoise',
  674. 'plain-orange', 'plain-yellow', 'plain-red', 'plain-pink', 'plain-purple', 'gray',
  675. 'blue', 'green', 'turquoise', 'orange', 'yellow', 'red', 'pink', 'purple'];
  676. function updateScheme(colorsets)
  677. {
  678. function addButton(colorset)
  679. {
  680. var btn = mxUtils.button('', function(evt)
  681. {
  682. graph.getModel().beginUpdate();
  683. try
  684. {
  685. var cells = graph.getSelectionCells();
  686. for (var i = 0; i < cells.length; i++)
  687. {
  688. var style = graph.getModel().getStyle(cells[i]);
  689. for (var j = 0; j < stylenames.length; j++)
  690. {
  691. style = mxUtils.removeStylename(style, stylenames[j]);
  692. }
  693. if (colorset != null)
  694. {
  695. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, colorset['fill']);
  696. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, colorset['stroke']);
  697. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, colorset['gradient']);
  698. }
  699. else
  700. {
  701. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, '#ffffff');
  702. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, '#000000');
  703. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, null);
  704. }
  705. graph.getModel().setStyle(cells[i], style);
  706. }
  707. }
  708. finally
  709. {
  710. graph.getModel().endUpdate();
  711. }
  712. })
  713. btn.style.width = '36px';
  714. btn.style.height = '30px';
  715. btn.style.margin = '0px 6px 6px 0px';
  716. if (colorset != null)
  717. {
  718. if (colorset['gradient'] != null)
  719. {
  720. if (mxClient.IS_IE && (mxClient.IS_QUIRKS || document.documentMode < 10))
  721. {
  722. btn.style.filter = 'progid:DXImageTransform.Microsoft.Gradient('+
  723. 'StartColorStr=\'' + colorset['fill'] +
  724. '\', EndColorStr=\'' + colorset['gradient'] + '\', GradientType=0)';
  725. }
  726. else
  727. {
  728. btn.style.backgroundImage = 'linear-gradient(' + colorset['fill'] + ' 0px,' +
  729. colorset['gradient'] + ' 100%)';
  730. }
  731. }
  732. else
  733. {
  734. btn.style.backgroundColor = colorset['fill'];
  735. }
  736. btn.style.border = '1px solid ' + colorset['stroke'];
  737. }
  738. else
  739. {
  740. btn.style.backgroundColor = '#ffffff';
  741. btn.style.border = '1px solid #000000';
  742. }
  743. picker.appendChild(btn);
  744. };
  745. picker.innerHTML = '';
  746. for (var i = 0; i < colorsets.length; i++)
  747. {
  748. if (i > 0 && mxUtils.mod(i, 4) == 0)
  749. {
  750. mxUtils.br(picker);
  751. }
  752. addButton(colorsets[i]);
  753. }
  754. };
  755. if (this.editorUi.currentScheme == null)
  756. {
  757. this.editorUi.currentScheme = 0;
  758. }
  759. var left = document.createElement('div');
  760. left.style.cssText = 'position:absolute;left:10px;top:8px;bottom:8px;width:20px;margin:4px;opacity:0.5;' +
  761. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ4eHh3d3d1dXVxcXF2dnZ2dnZ2dnZxcXF2dnYmb3w1AAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADRJREFUCNdjwACMAmBKaiGYs2oJmLPKAZ3DabU8AMRTXpUKopislqFyVzCAuUZgikkBZjoAcMYLnp53P/UAAAAASUVORK5CYII=);';
  762. mxEvent.addListener(left, 'click', mxUtils.bind(this, function()
  763. {
  764. this.editorUi.currentScheme = mxUtils.mod(this.editorUi.currentScheme - 1, this.defaultColorSchemes.length);
  765. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  766. }));
  767. var right = document.createElement('div');
  768. right.style.cssText = 'position:absolute;left:202px;top:8px;bottom:8px;width:20px;margin:4px;opacity:0.5;' +
  769. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnYBuwCcAAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADZJREFUCNdjQAOMAmBKaiGY8loF5rKswsZlrVo8AUiFrTICcbIWK8A5DF1gDoMymMPApIAwHwCS0Qx/U7qCBQAAAABJRU5ErkJggg==);';
  770. if (this.defaultColorSchemes.length > 1)
  771. {
  772. div.appendChild(left);
  773. div.appendChild(right);
  774. }
  775. mxEvent.addListener(right, 'click', mxUtils.bind(this, function()
  776. {
  777. this.editorUi.currentScheme = mxUtils.mod(this.editorUi.currentScheme + 1, this.defaultColorSchemes.length);
  778. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  779. }));
  780. // Hover state
  781. function addHoverState(elt)
  782. {
  783. mxEvent.addListener(elt, 'mouseenter', function()
  784. {
  785. elt.style.opacity = '1';
  786. });
  787. mxEvent.addListener(elt, 'mouseleave', function()
  788. {
  789. elt.style.opacity = '0.5';
  790. });
  791. };
  792. addHoverState(left);
  793. addHoverState(right);
  794. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  795. return div;
  796. };
  797. StyleFormatPanel.prototype.addEditOps = function(div)
  798. {
  799. var ss = this.format.getSelectionState();
  800. var btn = null;
  801. if (this.editorUi.editor.graph.getSelectionCount() == 1)
  802. {
  803. btn = mxUtils.button(mxResources.get('editStyle'), mxUtils.bind(this, function(evt)
  804. {
  805. this.editorUi.actions.get('editStyle').funct();
  806. }));
  807. btn.setAttribute('title', mxResources.get('editStyle') + ' (' + this.editorUi.actions.get('editStyle').shortcut + ')');
  808. btn.style.width = '202px';
  809. btn.style.marginBottom = '2px';
  810. div.appendChild(btn);
  811. }
  812. var graph = this.editorUi.editor.graph;
  813. var state = graph.view.getState(graph.getSelectionCell());
  814. if (graph.getSelectionCount() == 1 && state != null && state.shape != null && state.shape.stencil != null)
  815. {
  816. var btn2 = mxUtils.button(mxResources.get('editShape'), mxUtils.bind(this, function(evt)
  817. {
  818. this.editorUi.actions.get('editShape').funct();
  819. }));
  820. btn2.setAttribute('title', mxResources.get('editShape'));
  821. btn2.style.marginBottom = '2px';
  822. if (btn == null)
  823. {
  824. btn2.style.width = '202px';
  825. }
  826. else
  827. {
  828. btn.style.width = '100px';
  829. btn2.style.width = '100px';
  830. btn2.style.marginLeft = '2px';
  831. }
  832. div.appendChild(btn2);
  833. }
  834. else if (ss.image)
  835. {
  836. var btn2 = mxUtils.button(mxResources.get('editImage'), mxUtils.bind(this, function(evt)
  837. {
  838. this.editorUi.actions.get('image').funct();
  839. }));
  840. btn2.setAttribute('title', mxResources.get('editImage'));
  841. btn2.style.marginBottom = '2px';
  842. if (btn == null)
  843. {
  844. btn2.style.width = '202px';
  845. }
  846. else
  847. {
  848. btn.style.width = '100px';
  849. btn2.style.width = '100px';
  850. btn2.style.marginLeft = '2px';
  851. }
  852. div.appendChild(btn2);
  853. }
  854. return div;
  855. };
  856. }
  857. /**
  858. * Changes the default stylename so that it matches the old named style
  859. * if one was specified in the XML.
  860. */
  861. Graph.prototype.defaultThemeName = 'default-style2';
  862. /**
  863. * Contains the last XML that was pasted.
  864. */
  865. Graph.prototype.lastPasteXml = null;
  866. /**
  867. * Contains the number of times the last XML was pasted.
  868. */
  869. Graph.prototype.pasteCounter = 0;
  870. /**
  871. * Graph Overrides
  872. */
  873. Graph.prototype.defaultScrollbars = urlParams['sb'] != '0';
  874. /**
  875. * Specifies if the page should be visible for new files. Default is true.
  876. */
  877. Graph.prototype.defaultPageVisible = urlParams['pv'] != '0';
  878. /**
  879. * Specifies if the page should be visible for new files. Default is true.
  880. */
  881. Graph.prototype.shadowId = 'dropShadow';
  882. /**
  883. * Enables move of bends/segments without selecting.
  884. */
  885. Graph.prototype.edgeMode = urlParams['edge'] != 'move';
  886. /**
  887. * Adds rack child layout style.
  888. */
  889. var graphInit = Graph.prototype.init;
  890. Graph.prototype.init = function()
  891. {
  892. graphInit.apply(this, arguments);
  893. // Override insert location for current mouse point
  894. var mouseEvent = null;
  895. function setMouseEvent(evt)
  896. {
  897. mouseEvent = evt;
  898. // Workaround for member not found in IE8-
  899. if (mxClient.IS_QUIRKS || document.documentMode == 7 || document.documentMode == 8)
  900. {
  901. mouseEvent = mxUtils.clone(evt);
  902. }
  903. };
  904. mxEvent.addListener(this.container, 'mouseenter', setMouseEvent);
  905. mxEvent.addListener(this.container, 'mousemove', setMouseEvent);
  906. mxEvent.addListener(this.container, 'mouseleave', function(evt)
  907. {
  908. mouseEvent = null;
  909. });
  910. // Extends getInsertPoint to use the current mouse location
  911. this.isMouseInsertPoint = function()
  912. {
  913. return mouseEvent != null;
  914. };
  915. var getInsertPoint = this.getInsertPoint;
  916. this.getInsertPoint = function()
  917. {
  918. if (mouseEvent != null)
  919. {
  920. return this.getPointForEvent(mouseEvent);
  921. }
  922. return getInsertPoint.apply(this, arguments);
  923. };
  924. var layoutManagerGetLayout = this.layoutManager.getLayout;
  925. this.layoutManager.getLayout = function(cell)
  926. {
  927. var state = this.graph.view.getState(cell);
  928. var style = (state != null) ? state.style : this.graph.getCellStyle(cell);
  929. // mxRackContainer may be undefined as it is dynamically loaded at render time
  930. if (typeof(mxRackContainer) != 'undefined' && style['childLayout'] == 'rack')
  931. {
  932. var rackLayout = new mxStackLayout(this.graph, false);
  933. rackLayout.setChildGeometry = function(child, geo)
  934. {
  935. var unitSize = 20;
  936. geo.height = Math.max(geo.height, unitSize);
  937. if (geo.height / unitSize > 1)
  938. {
  939. var mod = geo.height % unitSize;
  940. geo.height += mod > unitSize / 2 ? (unitSize - mod) : -mod;
  941. }
  942. this.graph.getModel().setGeometry(child, geo);
  943. };
  944. rackLayout.fill = true;
  945. rackLayout.unitSize = mxRackContainer.unitSize | 20;
  946. rackLayout.marginLeft = style['marginLeft'] || 0;
  947. rackLayout.marginRight = style['marginRight'] || 0;
  948. rackLayout.marginTop = style['marginTop'] || 0;
  949. rackLayout.marginBottom = style['marginBottom'] || 0;
  950. rackLayout.resizeParent = false;
  951. return rackLayout;
  952. }
  953. return layoutManagerGetLayout.apply(this, arguments);
  954. }
  955. };
  956. /**
  957. * Sets default style (used in editor.get/setGraphXml below)
  958. */
  959. var graphLoadStylesheet = Graph.prototype.loadStylesheet;
  960. Graph.prototype.loadStylesheet = function()
  961. {
  962. graphLoadStylesheet.apply(this, arguments);
  963. this.currentStyle = 'default-style2';
  964. };
  965. /**
  966. * Adds a shadow filter to the given svg root.
  967. */
  968. Graph.prototype.addSvgShadow = function(svgRoot, group, createOnly)
  969. {
  970. createOnly = (createOnly != null) ? createOnly : false;
  971. var svgDoc = svgRoot.ownerDocument;
  972. var filter = (svgDoc.createElementNS != null) ?
  973. svgDoc.createElementNS(mxConstants.NS_SVG, 'filter') : svgDoc.createElement('filter');
  974. filter.setAttribute('id', this.shadowId);
  975. var blur = (svgDoc.createElementNS != null) ?
  976. svgDoc.createElementNS(mxConstants.NS_SVG, 'feGaussianBlur') : svgDoc.createElement('feGaussianBlur');
  977. blur.setAttribute('in', 'SourceAlpha');
  978. blur.setAttribute('stdDeviation', '1.7');
  979. blur.setAttribute('result', 'blur');
  980. filter.appendChild(blur);
  981. var offset = (svgDoc.createElementNS != null) ?
  982. svgDoc.createElementNS(mxConstants.NS_SVG, 'feOffset') : svgDoc.createElement('feOffset');
  983. offset.setAttribute('in', 'blur');
  984. offset.setAttribute('dx', '3');
  985. offset.setAttribute('dy', '3');
  986. offset.setAttribute('result', 'offsetBlur');
  987. filter.appendChild(offset);
  988. var flood = (svgDoc.createElementNS != null) ?
  989. svgDoc.createElementNS(mxConstants.NS_SVG, 'feFlood') : svgDoc.createElement('feFlood');
  990. flood.setAttribute('flood-color', '#3D4574');
  991. flood.setAttribute('flood-opacity', '0.4');
  992. flood.setAttribute('result', 'offsetColor');
  993. filter.appendChild(flood);
  994. var composite = (svgDoc.createElementNS != null) ?
  995. svgDoc.createElementNS(mxConstants.NS_SVG, 'feComposite') : svgDoc.createElement('feComposite');
  996. composite.setAttribute('in', 'offsetColor');
  997. composite.setAttribute('in2', 'offsetBlur');
  998. composite.setAttribute('operator', 'in');
  999. composite.setAttribute('result', 'offsetBlur');
  1000. filter.appendChild(composite);
  1001. var feBlend = (svgDoc.createElementNS != null) ?
  1002. svgDoc.createElementNS(mxConstants.NS_SVG, 'feBlend') : svgDoc.createElement('feBlend');
  1003. feBlend.setAttribute('in', 'SourceGraphic');
  1004. feBlend.setAttribute('in2', 'offsetBlur');
  1005. filter.appendChild(feBlend);
  1006. // Creates defs element if not available
  1007. var defs = svgRoot.getElementsByTagName('defs');
  1008. var defsElt = null;
  1009. if (defs.length == 0)
  1010. {
  1011. defsElt = (svgDoc.createElementNS != null) ?
  1012. svgDoc.createElementNS(mxConstants.NS_SVG, 'defs') : svgDoc.createElement('defs');
  1013. if (svgRoot.firstChild != null)
  1014. {
  1015. svgRoot.insertBefore(defsElt, svgRoot.firstChild);
  1016. }
  1017. else
  1018. {
  1019. svgRoot.appendChild(defsElt);
  1020. }
  1021. }
  1022. else
  1023. {
  1024. defsElt = defs[0];
  1025. }
  1026. defsElt.appendChild(filter);
  1027. if (!createOnly)
  1028. {
  1029. (group || svgRoot.getElementsByTagName('g')[0]).setAttribute('filter', 'url(#' + this.shadowId + ')');
  1030. if (!isNaN(parseInt(svgRoot.getAttribute('width'))))
  1031. {
  1032. svgRoot.setAttribute('width', parseInt(svgRoot.getAttribute('width')) + 6);
  1033. svgRoot.setAttribute('height', parseInt(svgRoot.getAttribute('height')) + 6);
  1034. }
  1035. }
  1036. return filter;
  1037. };
  1038. /**
  1039. * Loads the stylesheet for this graph.
  1040. */
  1041. Graph.prototype.setShadowVisible = function(value, fireEvent)
  1042. {
  1043. if (mxClient.IS_SVG)
  1044. {
  1045. fireEvent = (fireEvent != null) ? fireEvent : true;
  1046. this.shadowVisible = value;
  1047. if (this.shadowVisible)
  1048. {
  1049. this.view.getDrawPane().setAttribute('filter', 'url(#' + this.shadowId + ')');
  1050. }
  1051. else
  1052. {
  1053. this.view.getDrawPane().removeAttribute('filter');
  1054. }
  1055. if (fireEvent)
  1056. {
  1057. this.fireEvent(new mxEventObject('shadowVisibleChanged'));
  1058. }
  1059. }
  1060. };
  1061. /**
  1062. * Selects first unlocked layer if one exists
  1063. */
  1064. Graph.prototype.selectUnlockedLayer = function()
  1065. {
  1066. if (this.defaultParent == null)
  1067. {
  1068. var childCount = this.model.getChildCount(this.model.root);
  1069. var cell = null;
  1070. var index = 0;
  1071. do
  1072. {
  1073. cell = this.model.getChildAt(this.model.root, index);
  1074. } while (index++ < childCount && mxUtils.getValue(this.getCellStyle(cell), 'locked', '0') == '1')
  1075. if (cell != null)
  1076. {
  1077. this.setDefaultParent(cell);
  1078. }
  1079. }
  1080. };
  1081. /**
  1082. * Specifies special libraries that are loaded via dynamic JS. Add cases
  1083. * where the filename cannot be worked out from the package name. The
  1084. * standard scheme for this mapping is stencils/packagename.xml. If there
  1085. * are multiple XML files, any JS files or any anomalies in the filename or
  1086. * directory that contains the file, then an entry must be added here and
  1087. * in EmbedServlet2 for the loading of the shapes to work.
  1088. */
  1089. // Required to avoid 404 for mockup.xml since naming of mxgraph.mockup.anchor does not contain
  1090. // buttons even though it is defined in the mxMockupButtons.js file. This could only be fixed
  1091. // with aliases for existing shapes or aliases for basenames, but this is essentially the same.
  1092. mxStencilRegistry.libraries['mockup'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  1093. mxStencilRegistry.libraries['arrows2'] = [SHAPES_PATH + '/mxArrows.js'];
  1094. mxStencilRegistry.libraries['bpmn'] = [SHAPES_PATH + '/bpmn/mxBpmnShape2.js', STENCIL_PATH + '/bpmn.xml'];
  1095. mxStencilRegistry.libraries['er'] = [SHAPES_PATH + '/er/mxER.js'];
  1096. mxStencilRegistry.libraries['ios'] = [SHAPES_PATH + '/mockup/mxMockupiOS.js'];
  1097. mxStencilRegistry.libraries['rackGeneral'] = [SHAPES_PATH + '/rack/mxRack.js', STENCIL_PATH + '/rack/general.xml'];
  1098. mxStencilRegistry.libraries['rackF5'] = [STENCIL_PATH + '/rack/f5.xml'];
  1099. mxStencilRegistry.libraries['lean_mapping'] = [SHAPES_PATH + '/mxLeanMap.js', STENCIL_PATH + '/lean_mapping.xml'];
  1100. mxStencilRegistry.libraries['basic'] = [SHAPES_PATH + '/mxBasic.js', STENCIL_PATH + '/basic.xml'];
  1101. mxStencilRegistry.libraries['ios7icons'] = [STENCIL_PATH + '/ios7/icons.xml'];
  1102. mxStencilRegistry.libraries['ios7ui'] = [SHAPES_PATH + '/ios7/mxIOS7Ui.js', STENCIL_PATH + '/ios7/misc.xml'];
  1103. mxStencilRegistry.libraries['android'] = [SHAPES_PATH + '/mxAndroid.js', STENCIL_PATH + '/android/android.xml'];
  1104. mxStencilRegistry.libraries['electrical/transmission'] = [SHAPES_PATH + '/mxElectrical.js', STENCIL_PATH + '/electrical/transmission.xml'];
  1105. mxStencilRegistry.libraries['mockup/buttons'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  1106. mxStencilRegistry.libraries['mockup/containers'] = [SHAPES_PATH + '/mockup/mxMockupContainers.js'];
  1107. mxStencilRegistry.libraries['mockup/forms'] = [SHAPES_PATH + '/mockup/mxMockupForms.js'];
  1108. mxStencilRegistry.libraries['mockup/graphics'] = [SHAPES_PATH + '/mockup/mxMockupGraphics.js', STENCIL_PATH + '/mockup/misc.xml'];
  1109. mxStencilRegistry.libraries['mockup/markup'] = [SHAPES_PATH + '/mockup/mxMockupMarkup.js'];
  1110. mxStencilRegistry.libraries['mockup/misc'] = [SHAPES_PATH + '/mockup/mxMockupMisc.js', STENCIL_PATH + '/mockup/misc.xml'];
  1111. mxStencilRegistry.libraries['mockup/navigation'] = [SHAPES_PATH + '/mockup/mxMockupNavigation.js', STENCIL_PATH + '/mockup/misc.xml'];
  1112. mxStencilRegistry.libraries['mockup/text'] = [SHAPES_PATH + '/mockup/mxMockupText.js'];
  1113. mxStencilRegistry.libraries['floorplan'] = [SHAPES_PATH + '/mxFloorplan.js', STENCIL_PATH + '/floorplan.xml'];
  1114. mxStencilRegistry.libraries['bootstrap'] = [SHAPES_PATH + '/mxBootstrap.js', STENCIL_PATH + '/bootstrap.xml'];
  1115. mxStencilRegistry.libraries['gmdl'] = [SHAPES_PATH + '/mxGmdl.js', STENCIL_PATH + '/gmdl.xml'];
  1116. mxStencilRegistry.libraries['cabinets'] = [SHAPES_PATH + '/mxCabinets.js', STENCIL_PATH + '/cabinets.xml'];
  1117. mxStencilRegistry.libraries['archimate'] = [SHAPES_PATH + '/mxArchiMate.js'];
  1118. mxStencilRegistry.libraries['archimate3'] = [SHAPES_PATH + '/mxArchiMate3.js'];
  1119. mxStencilRegistry.libraries['sysml'] = [SHAPES_PATH + '/mxSysML.js'];
  1120. mxStencilRegistry.libraries['eip'] = [SHAPES_PATH + '/mxEip.js', STENCIL_PATH + '/eip.xml'];
  1121. mxStencilRegistry.libraries['networks'] = [SHAPES_PATH + '/mxNetworks.js', STENCIL_PATH + '/networks.xml'];
  1122. mxStencilRegistry.libraries['aws3d'] = [SHAPES_PATH + '/mxAWS3D.js', STENCIL_PATH + '/aws3d.xml'];
  1123. mxStencilRegistry.libraries['pid2inst'] = [SHAPES_PATH + '/pid2/mxPidInstruments.js'];
  1124. mxStencilRegistry.libraries['pid2misc'] = [SHAPES_PATH + '/pid2/mxPidMisc.js', STENCIL_PATH + '/pid/misc.xml'];
  1125. mxStencilRegistry.libraries['pid2valves'] = [SHAPES_PATH + '/pid2/mxPidValves.js'];
  1126. mxStencilRegistry.libraries['pidFlowSensors'] = [STENCIL_PATH + '/pid/flow_sensors.xml'];
  1127. // Triggers dynamic loading for markers
  1128. mxMarker.getPackageForType = function(type)
  1129. {
  1130. var name = null;
  1131. if (type != null && type.length > 0)
  1132. {
  1133. if (type.substring(0, 2) == 'ER')
  1134. {
  1135. name = 'mxgraph.er';
  1136. }
  1137. else if (type.substring(0, 5) == 'sysML')
  1138. {
  1139. name = 'mxgraph.sysml';
  1140. }
  1141. }
  1142. return name;
  1143. };
  1144. var mxMarkerCreateMarker = mxMarker.createMarker;
  1145. mxMarker.createMarker = function(canvas, shape, type, pe, unitX, unitY, size, source, sw, filled)
  1146. {
  1147. if (type != null)
  1148. {
  1149. var f = mxMarker.markers[type];
  1150. if (f == null)
  1151. {
  1152. var name = this.getPackageForType(type);
  1153. if (name != null)
  1154. {
  1155. mxStencilRegistry.getStencil(name);
  1156. }
  1157. }
  1158. }
  1159. return mxMarkerCreateMarker.apply(this, arguments);
  1160. };
  1161. })();