Editor.js 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  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+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXN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6+/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. this.graph.addListener(mxEvent.SIZE, mxUtils.bind(this, function(sender, evt)
  476. {
  477. if (this.graph.mathEnabled)
  478. {
  479. Editor.MathJaxRender(this.graph.container);
  480. }
  481. }));
  482. };
  483. var tags = document.getElementsByTagName('script');
  484. if (tags != null && tags.length > 0)
  485. {
  486. var script = document.createElement('script');
  487. script.type = 'text/javascript';
  488. script.src = src;
  489. tags[0].parentNode.appendChild(script);
  490. }
  491. };
  492. /**
  493. * Return array of string values, or NULL if CSV string not well formed.
  494. */
  495. Editor.prototype.csvToArray = function(text)
  496. {
  497. var re_valid = /^\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*(?:,\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*)*$/;
  498. var re_value = /(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g;
  499. // Return NULL if input string is not well formed CSV string.
  500. if (!re_valid.test(text)) return null;
  501. var a = []; // Initialize array to receive values.
  502. text.replace(re_value, // "Walk" the string using replace with callback.
  503. function(m0, m1, m2, m3) {
  504. // Remove backslash from \' in single quoted values.
  505. if (m1 !== undefined) a.push(m1.replace(/\\'/g, "'"));
  506. // Remove backslash from \" in double quoted values.
  507. else if (m2 !== undefined) a.push(m2.replace(/\\"/g, '"'));
  508. else if (m3 !== undefined) a.push(m3);
  509. return ''; // Return empty string.
  510. });
  511. // Handle special case of empty last value.
  512. if (/,\s*$/.test(text)) a.push('');
  513. return a;
  514. };
  515. /**
  516. * Adds persistence for recent colors
  517. */
  518. if (window.ColorDialog)
  519. {
  520. var colorDialogAddRecentColor = ColorDialog.addRecentColor;
  521. ColorDialog.addRecentColor = function(color, max)
  522. {
  523. colorDialogAddRecentColor.apply(this, arguments);
  524. mxSettings.setRecentColors(ColorDialog.recentColors);
  525. mxSettings.save();
  526. };
  527. var colorDialogResetRecentColors = ColorDialog.resetRecentColors;
  528. ColorDialog.resetRecentColors = function()
  529. {
  530. colorDialogResetRecentColors.apply(this, arguments);
  531. mxSettings.setRecentColors(ColorDialog.recentColors);
  532. mxSettings.save();
  533. };
  534. }
  535. // Overridden to add edit shape option
  536. if (window.StyleFormatPanel != null)
  537. {
  538. var formatInit = Format.prototype.init;
  539. Format.prototype.init = function()
  540. {
  541. formatInit.apply(this, arguments);
  542. var ui = this.editorUi;
  543. ui.editor.addListener('fileLoaded', this.update);
  544. };
  545. var formatRefresh = Format.prototype.refresh;
  546. Format.prototype.refresh = function()
  547. {
  548. var ui = this.editorUi;
  549. if (ui.getCurrentFile() != null || urlParams['embed'] == '1')
  550. {
  551. formatRefresh.apply(this, arguments);
  552. }
  553. else
  554. {
  555. this.clear();
  556. }
  557. };
  558. /**
  559. * Adds autosave and math typesetting options.
  560. */
  561. var diagramFormatPanelAddOptions = DiagramFormatPanel.prototype.addOptions;
  562. DiagramFormatPanel.prototype.addOptions = function(div)
  563. {
  564. div = diagramFormatPanelAddOptions.apply(this, arguments);
  565. var ui = this.editorUi;
  566. var editor = ui.editor;
  567. var graph = editor.graph;
  568. if (graph.isEnabled())
  569. {
  570. var file = ui.getCurrentFile();
  571. if (file != null && file.isAutosaveOptional())
  572. {
  573. var opt = this.createOption(mxResources.get('autosave'), function()
  574. {
  575. return ui.editor.autosave;
  576. }, function(checked)
  577. {
  578. ui.editor.setAutosave(checked);
  579. },
  580. {
  581. install: function(apply)
  582. {
  583. this.listener = function()
  584. {
  585. apply(ui.editor.autosave);
  586. };
  587. ui.editor.addListener('autosaveChanged', this.listener);
  588. },
  589. destroy: function()
  590. {
  591. ui.editor.removeListener(this.listener);
  592. }
  593. });
  594. div.appendChild(opt);
  595. }
  596. }
  597. return div;
  598. };
  599. /**
  600. * Configures global color schemes.
  601. */
  602. StyleFormatPanel.prototype.defaultColorSchemes = [[null, {fill: '#f5f5f5', stroke: '#666666'},
  603. {fill: '#dae8fc', stroke: '#6c8ebf'}, {fill: '#d5e8d4', stroke: '#82b366'},
  604. {fill: '#ffe6cc', stroke: '#d79b00'}, {fill: '#fff2cc', stroke: '#d6b656'},
  605. {fill: '#f8cecc', stroke: '#b85450'}, {fill: '#e1d5e7', stroke: '#9673a6'}],
  606. [null,
  607. {fill: '#f5f5f5', stroke: '#666666', gradient: '#b3b3b3'},
  608. {fill: '#dae8fc', stroke: '#6c8ebf', gradient: '#7ea6e0'},
  609. {fill: '#d5e8d4', stroke: '#82b366', gradient: '#97d077'},
  610. {fill: '#ffcd28', stroke: '#d79b00', gradient: '#ffa500'},
  611. {fill: '#fff2cc', stroke: '#d6b656', gradient: '#ffd966'},
  612. {fill: '#f8cecc', stroke: '#b85450', gradient: '#ea6b66'},
  613. {fill: '#e6d0de', stroke: '#996185', gradient: '#d5739d'}],
  614. [null, {fill: '#eeeeee', stroke: '#36393d'},
  615. {fill: '#f9f7ed', stroke: '#36393d'}, {fill: '#ffcc99', stroke: '#36393d'},
  616. {fill: '#cce5ff', stroke: '#36393d'}, {fill: '#ffff88', stroke: '#36393d'},
  617. {fill: '#cdeb8b', stroke: '#36393d'}, {fill: '#ffcccc', stroke: '#36393d'}]];
  618. /**
  619. * Adds predefiend styles.
  620. */
  621. var StyleFormatPanelInit = StyleFormatPanel.prototype.init;
  622. StyleFormatPanel.prototype.init = function()
  623. {
  624. // TODO: Update sstate in Format
  625. var sstate = this.format.createSelectionState();
  626. if (sstate.style.shape != 'image')
  627. {
  628. this.container.appendChild(this.addStyles(this.createPanel()));
  629. }
  630. StyleFormatPanelInit.apply(this, arguments);
  631. };
  632. /**
  633. * Overridden to add copy and paste style.
  634. */
  635. var styleFormatPanelAddStyleOps = StyleFormatPanel.prototype.addStyleOps;
  636. StyleFormatPanel.prototype.addStyleOps = function(div)
  637. {
  638. var btn = mxUtils.button(mxResources.get('copyStyle'), mxUtils.bind(this, function(evt)
  639. {
  640. this.editorUi.actions.get('copyStyle').funct();
  641. }));
  642. btn.setAttribute('title', mxResources.get('copyStyle') + ' (' + this.editorUi.actions.get('copyStyle').shortcut + ')');
  643. btn.style.marginBottom = '2px';
  644. btn.style.width = '100px';
  645. btn.style.marginRight = '2px';
  646. div.appendChild(btn);
  647. var btn = mxUtils.button(mxResources.get('pasteStyle'), mxUtils.bind(this, function(evt)
  648. {
  649. this.editorUi.actions.get('pasteStyle').funct();
  650. }));
  651. btn.setAttribute('title', mxResources.get('pasteStyle') + ' (' + this.editorUi.actions.get('pasteStyle').shortcut + ')');
  652. btn.style.marginBottom = '2px';
  653. btn.style.width = '100px';
  654. div.appendChild(btn);
  655. mxUtils.br(div);
  656. return styleFormatPanelAddStyleOps.apply(this, arguments);
  657. };
  658. /**
  659. * Creates the buttons for the predefined styles.
  660. */
  661. StyleFormatPanel.prototype.addStyles = function(div)
  662. {
  663. var graph = this.editorUi.editor.graph;
  664. var picker = document.createElement('div');
  665. picker.style.whiteSpace = 'normal';
  666. picker.style.paddingLeft = '24px';
  667. picker.style.paddingRight = '20px';
  668. div.style.paddingLeft = '16px';
  669. div.style.paddingBottom = '6px';
  670. div.style.position = 'relative';
  671. div.appendChild(picker);
  672. var stylenames = ['plain-gray', 'plain-blue', 'plain-green', 'plain-turquoise',
  673. 'plain-orange', 'plain-yellow', 'plain-red', 'plain-pink', 'plain-purple', 'gray',
  674. 'blue', 'green', 'turquoise', 'orange', 'yellow', 'red', 'pink', 'purple'];
  675. function updateScheme(colorsets)
  676. {
  677. function addButton(colorset)
  678. {
  679. var btn = mxUtils.button('', function(evt)
  680. {
  681. graph.getModel().beginUpdate();
  682. try
  683. {
  684. var cells = graph.getSelectionCells();
  685. for (var i = 0; i < cells.length; i++)
  686. {
  687. var style = graph.getModel().getStyle(cells[i]);
  688. for (var j = 0; j < stylenames.length; j++)
  689. {
  690. style = mxUtils.removeStylename(style, stylenames[j]);
  691. }
  692. if (colorset != null)
  693. {
  694. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, colorset['fill']);
  695. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, colorset['stroke']);
  696. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, colorset['gradient']);
  697. }
  698. else
  699. {
  700. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, '#ffffff');
  701. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, '#000000');
  702. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, null);
  703. }
  704. graph.getModel().setStyle(cells[i], style);
  705. }
  706. }
  707. finally
  708. {
  709. graph.getModel().endUpdate();
  710. }
  711. })
  712. btn.style.width = '36px';
  713. btn.style.height = '30px';
  714. btn.style.margin = '0px 6px 6px 0px';
  715. if (colorset != null)
  716. {
  717. if (colorset['gradient'] != null)
  718. {
  719. if (mxClient.IS_IE && (mxClient.IS_QUIRKS || document.documentMode < 10))
  720. {
  721. btn.style.filter = 'progid:DXImageTransform.Microsoft.Gradient('+
  722. 'StartColorStr=\'' + colorset['fill'] +
  723. '\', EndColorStr=\'' + colorset['gradient'] + '\', GradientType=0)';
  724. }
  725. else
  726. {
  727. btn.style.backgroundImage = 'linear-gradient(' + colorset['fill'] + ' 0px,' +
  728. colorset['gradient'] + ' 100%)';
  729. }
  730. }
  731. else
  732. {
  733. btn.style.backgroundColor = colorset['fill'];
  734. }
  735. btn.style.border = '1px solid ' + colorset['stroke'];
  736. }
  737. else
  738. {
  739. btn.style.backgroundColor = '#ffffff';
  740. btn.style.border = '1px solid #000000';
  741. }
  742. picker.appendChild(btn);
  743. };
  744. picker.innerHTML = '';
  745. for (var i = 0; i < colorsets.length; i++)
  746. {
  747. if (i > 0 && mxUtils.mod(i, 4) == 0)
  748. {
  749. mxUtils.br(picker);
  750. }
  751. addButton(colorsets[i]);
  752. }
  753. };
  754. if (this.editorUi.currentScheme == null)
  755. {
  756. this.editorUi.currentScheme = 0;
  757. }
  758. var left = document.createElement('div');
  759. left.style.cssText = 'position:absolute;left:10px;top:8px;bottom:8px;width:20px;margin:4px;opacity:0.5;' +
  760. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ4eHh3d3d1dXVxcXF2dnZ2dnZ2dnZxcXF2dnYmb3w1AAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADRJREFUCNdjwACMAmBKaiGYs2oJmLPKAZ3DabU8AMRTXpUKopislqFyVzCAuUZgikkBZjoAcMYLnp53P/UAAAAASUVORK5CYII=);';
  761. mxEvent.addListener(left, 'click', mxUtils.bind(this, function()
  762. {
  763. this.editorUi.currentScheme = mxUtils.mod(this.editorUi.currentScheme - 1, this.defaultColorSchemes.length);
  764. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  765. }));
  766. var right = document.createElement('div');
  767. right.style.cssText = 'position:absolute;left:202px;top:8px;bottom:8px;width:20px;margin:4px;opacity:0.5;' +
  768. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnYBuwCcAAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADZJREFUCNdjQAOMAmBKaiGY8loF5rKswsZlrVo8AUiFrTICcbIWK8A5DF1gDoMymMPApIAwHwCS0Qx/U7qCBQAAAABJRU5ErkJggg==);';
  769. if (this.defaultColorSchemes.length > 1)
  770. {
  771. div.appendChild(left);
  772. div.appendChild(right);
  773. }
  774. mxEvent.addListener(right, 'click', mxUtils.bind(this, function()
  775. {
  776. this.editorUi.currentScheme = mxUtils.mod(this.editorUi.currentScheme + 1, this.defaultColorSchemes.length);
  777. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  778. }));
  779. // Hover state
  780. function addHoverState(elt)
  781. {
  782. mxEvent.addListener(elt, 'mouseenter', function()
  783. {
  784. elt.style.opacity = '1';
  785. });
  786. mxEvent.addListener(elt, 'mouseleave', function()
  787. {
  788. elt.style.opacity = '0.5';
  789. });
  790. };
  791. addHoverState(left);
  792. addHoverState(right);
  793. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  794. return div;
  795. };
  796. StyleFormatPanel.prototype.addEditOps = function(div)
  797. {
  798. var ss = this.format.getSelectionState();
  799. var btn = null;
  800. if (this.editorUi.editor.graph.getSelectionCount() == 1)
  801. {
  802. btn = mxUtils.button(mxResources.get('editStyle'), mxUtils.bind(this, function(evt)
  803. {
  804. this.editorUi.actions.get('editStyle').funct();
  805. }));
  806. btn.setAttribute('title', mxResources.get('editStyle') + ' (' + this.editorUi.actions.get('editStyle').shortcut + ')');
  807. btn.style.width = '202px';
  808. btn.style.marginBottom = '2px';
  809. div.appendChild(btn);
  810. }
  811. var graph = this.editorUi.editor.graph;
  812. var state = graph.view.getState(graph.getSelectionCell());
  813. if (graph.getSelectionCount() == 1 && state != null && state.shape != null && state.shape.stencil != null)
  814. {
  815. var btn2 = mxUtils.button(mxResources.get('editShape'), mxUtils.bind(this, function(evt)
  816. {
  817. this.editorUi.actions.get('editShape').funct();
  818. }));
  819. btn2.setAttribute('title', mxResources.get('editShape'));
  820. btn2.style.marginBottom = '2px';
  821. if (btn == null)
  822. {
  823. btn2.style.width = '202px';
  824. }
  825. else
  826. {
  827. btn.style.width = '100px';
  828. btn2.style.width = '100px';
  829. btn2.style.marginLeft = '2px';
  830. }
  831. div.appendChild(btn2);
  832. }
  833. else if (ss.image)
  834. {
  835. var btn2 = mxUtils.button(mxResources.get('editImage'), mxUtils.bind(this, function(evt)
  836. {
  837. this.editorUi.actions.get('image').funct();
  838. }));
  839. btn2.setAttribute('title', mxResources.get('editImage'));
  840. btn2.style.marginBottom = '2px';
  841. if (btn == null)
  842. {
  843. btn2.style.width = '202px';
  844. }
  845. else
  846. {
  847. btn.style.width = '100px';
  848. btn2.style.width = '100px';
  849. btn2.style.marginLeft = '2px';
  850. }
  851. div.appendChild(btn2);
  852. }
  853. return div;
  854. };
  855. }
  856. /**
  857. * Changes the default stylename so that it matches the old named style
  858. * if one was specified in the XML.
  859. */
  860. Graph.prototype.defaultThemeName = 'default-style2';
  861. /**
  862. * Contains the last XML that was pasted.
  863. */
  864. Graph.prototype.lastPasteXml = null;
  865. /**
  866. * Contains the number of times the last XML was pasted.
  867. */
  868. Graph.prototype.pasteCounter = 0;
  869. /**
  870. * Graph Overrides
  871. */
  872. Graph.prototype.defaultScrollbars = urlParams['sb'] != '0';
  873. /**
  874. * Specifies if the page should be visible for new files. Default is true.
  875. */
  876. Graph.prototype.defaultPageVisible = urlParams['pv'] != '0';
  877. /**
  878. * Specifies if the page should be visible for new files. Default is true.
  879. */
  880. Graph.prototype.shadowId = 'dropShadow';
  881. /**
  882. * Enables move of bends/segments without selecting.
  883. */
  884. Graph.prototype.edgeMode = urlParams['edge'] != 'move';
  885. /**
  886. * Adds rack child layout style.
  887. */
  888. var graphInit = Graph.prototype.init;
  889. Graph.prototype.init = function()
  890. {
  891. graphInit.apply(this, arguments);
  892. // Override insert location for current mouse point
  893. var mouseEvent = null;
  894. function setMouseEvent(evt)
  895. {
  896. mouseEvent = evt;
  897. // Workaround for member not found in IE8-
  898. if (mxClient.IS_QUIRKS || document.documentMode == 7 || document.documentMode == 8)
  899. {
  900. mouseEvent = mxUtils.clone(evt);
  901. }
  902. };
  903. mxEvent.addListener(this.container, 'mouseenter', setMouseEvent);
  904. mxEvent.addListener(this.container, 'mousemove', setMouseEvent);
  905. mxEvent.addListener(this.container, 'mouseleave', function(evt)
  906. {
  907. mouseEvent = null;
  908. });
  909. // Extends getInsertPoint to use the current mouse location
  910. this.isMouseInsertPoint = function()
  911. {
  912. return mouseEvent != null;
  913. };
  914. var getInsertPoint = this.getInsertPoint;
  915. this.getInsertPoint = function()
  916. {
  917. if (mouseEvent != null)
  918. {
  919. return this.getPointForEvent(mouseEvent);
  920. }
  921. return getInsertPoint.apply(this, arguments);
  922. };
  923. var layoutManagerGetLayout = this.layoutManager.getLayout;
  924. this.layoutManager.getLayout = function(cell)
  925. {
  926. var state = this.graph.view.getState(cell);
  927. var style = (state != null) ? state.style : this.graph.getCellStyle(cell);
  928. // mxRackContainer may be undefined as it is dynamically loaded at render time
  929. if (typeof(mxRackContainer) != 'undefined' && style['childLayout'] == 'rack')
  930. {
  931. var rackLayout = new mxStackLayout(this.graph, false);
  932. rackLayout.setChildGeometry = function(child, geo)
  933. {
  934. var unitSize = 20;
  935. geo.height = Math.max(geo.height, unitSize);
  936. if (geo.height / unitSize > 1)
  937. {
  938. var mod = geo.height % unitSize;
  939. geo.height += mod > unitSize / 2 ? (unitSize - mod) : -mod;
  940. }
  941. this.graph.getModel().setGeometry(child, geo);
  942. };
  943. rackLayout.fill = true;
  944. rackLayout.unitSize = mxRackContainer.unitSize | 20;
  945. rackLayout.marginLeft = style['marginLeft'] || 0;
  946. rackLayout.marginRight = style['marginRight'] || 0;
  947. rackLayout.marginTop = style['marginTop'] || 0;
  948. rackLayout.marginBottom = style['marginBottom'] || 0;
  949. rackLayout.resizeParent = false;
  950. return rackLayout;
  951. }
  952. return layoutManagerGetLayout.apply(this, arguments);
  953. }
  954. };
  955. /**
  956. * Sets default style (used in editor.get/setGraphXml below)
  957. */
  958. var graphLoadStylesheet = Graph.prototype.loadStylesheet;
  959. Graph.prototype.loadStylesheet = function()
  960. {
  961. graphLoadStylesheet.apply(this, arguments);
  962. this.currentStyle = 'default-style2';
  963. };
  964. /**
  965. * Adds a shadow filter to the given svg root.
  966. */
  967. Graph.prototype.addSvgShadow = function(svgRoot, group, createOnly)
  968. {
  969. createOnly = (createOnly != null) ? createOnly : false;
  970. var svgDoc = svgRoot.ownerDocument;
  971. var filter = (svgDoc.createElementNS != null) ?
  972. svgDoc.createElementNS(mxConstants.NS_SVG, 'filter') : svgDoc.createElement('filter');
  973. filter.setAttribute('id', this.shadowId);
  974. var blur = (svgDoc.createElementNS != null) ?
  975. svgDoc.createElementNS(mxConstants.NS_SVG, 'feGaussianBlur') : svgDoc.createElement('feGaussianBlur');
  976. blur.setAttribute('in', 'SourceAlpha');
  977. blur.setAttribute('stdDeviation', '1.7');
  978. blur.setAttribute('result', 'blur');
  979. filter.appendChild(blur);
  980. var offset = (svgDoc.createElementNS != null) ?
  981. svgDoc.createElementNS(mxConstants.NS_SVG, 'feOffset') : svgDoc.createElement('feOffset');
  982. offset.setAttribute('in', 'blur');
  983. offset.setAttribute('dx', '3');
  984. offset.setAttribute('dy', '3');
  985. offset.setAttribute('result', 'offsetBlur');
  986. filter.appendChild(offset);
  987. var flood = (svgDoc.createElementNS != null) ?
  988. svgDoc.createElementNS(mxConstants.NS_SVG, 'feFlood') : svgDoc.createElement('feFlood');
  989. flood.setAttribute('flood-color', '#3D4574');
  990. flood.setAttribute('flood-opacity', '0.4');
  991. flood.setAttribute('result', 'offsetColor');
  992. filter.appendChild(flood);
  993. var composite = (svgDoc.createElementNS != null) ?
  994. svgDoc.createElementNS(mxConstants.NS_SVG, 'feComposite') : svgDoc.createElement('feComposite');
  995. composite.setAttribute('in', 'offsetColor');
  996. composite.setAttribute('in2', 'offsetBlur');
  997. composite.setAttribute('operator', 'in');
  998. composite.setAttribute('result', 'offsetBlur');
  999. filter.appendChild(composite);
  1000. var feBlend = (svgDoc.createElementNS != null) ?
  1001. svgDoc.createElementNS(mxConstants.NS_SVG, 'feBlend') : svgDoc.createElement('feBlend');
  1002. feBlend.setAttribute('in', 'SourceGraphic');
  1003. feBlend.setAttribute('in2', 'offsetBlur');
  1004. filter.appendChild(feBlend);
  1005. // Creates defs element if not available
  1006. var defs = svgRoot.getElementsByTagName('defs');
  1007. var defsElt = null;
  1008. if (defs.length == 0)
  1009. {
  1010. defsElt = (svgDoc.createElementNS != null) ?
  1011. svgDoc.createElementNS(mxConstants.NS_SVG, 'defs') : svgDoc.createElement('defs');
  1012. if (svgRoot.firstChild != null)
  1013. {
  1014. svgRoot.insertBefore(defsElt, svgRoot.firstChild);
  1015. }
  1016. else
  1017. {
  1018. svgRoot.appendChild(defsElt);
  1019. }
  1020. }
  1021. else
  1022. {
  1023. defsElt = defs[0];
  1024. }
  1025. defsElt.appendChild(filter);
  1026. if (!createOnly)
  1027. {
  1028. (group || svgRoot.getElementsByTagName('g')[0]).setAttribute('filter', 'url(#' + this.shadowId + ')');
  1029. if (!isNaN(parseInt(svgRoot.getAttribute('width'))))
  1030. {
  1031. svgRoot.setAttribute('width', parseInt(svgRoot.getAttribute('width')) + 6);
  1032. svgRoot.setAttribute('height', parseInt(svgRoot.getAttribute('height')) + 6);
  1033. }
  1034. }
  1035. return filter;
  1036. };
  1037. /**
  1038. * Loads the stylesheet for this graph.
  1039. */
  1040. Graph.prototype.setShadowVisible = function(value, fireEvent)
  1041. {
  1042. if (mxClient.IS_SVG)
  1043. {
  1044. fireEvent = (fireEvent != null) ? fireEvent : true;
  1045. this.shadowVisible = value;
  1046. if (this.shadowVisible)
  1047. {
  1048. this.view.getDrawPane().setAttribute('filter', 'url(#' + this.shadowId + ')');
  1049. }
  1050. else
  1051. {
  1052. this.view.getDrawPane().removeAttribute('filter');
  1053. }
  1054. if (fireEvent)
  1055. {
  1056. this.fireEvent(new mxEventObject('shadowVisibleChanged'));
  1057. }
  1058. }
  1059. };
  1060. /**
  1061. * Selects first unlocked layer if one exists
  1062. */
  1063. Graph.prototype.selectUnlockedLayer = function()
  1064. {
  1065. if (this.defaultParent == null)
  1066. {
  1067. var childCount = this.model.getChildCount(this.model.root);
  1068. var cell = null;
  1069. var index = 0;
  1070. do
  1071. {
  1072. cell = this.model.getChildAt(this.model.root, index);
  1073. } while (index++ < childCount && mxUtils.getValue(this.getCellStyle(cell), 'locked', '0') == '1')
  1074. if (cell != null)
  1075. {
  1076. this.setDefaultParent(cell);
  1077. }
  1078. }
  1079. };
  1080. /**
  1081. * Specifies special libraries that are loaded via dynamic JS. Add cases
  1082. * where the filename cannot be worked out from the package name. The
  1083. * standard scheme for this mapping is stencils/packagename.xml. If there
  1084. * are multiple XML files, any JS files or any anomalies in the filename or
  1085. * directory that contains the file, then an entry must be added here and
  1086. * in EmbedServlet2 for the loading of the shapes to work.
  1087. */
  1088. // Required to avoid 404 for mockup.xml since naming of mxgraph.mockup.anchor does not contain
  1089. // buttons even though it is defined in the mxMockupButtons.js file. This could only be fixed
  1090. // with aliases for existing shapes or aliases for basenames, but this is essentially the same.
  1091. mxStencilRegistry.libraries['mockup'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  1092. mxStencilRegistry.libraries['arrows2'] = [SHAPES_PATH + '/mxArrows.js'];
  1093. mxStencilRegistry.libraries['bpmn'] = [SHAPES_PATH + '/bpmn/mxBpmnShape2.js', STENCIL_PATH + '/bpmn.xml'];
  1094. mxStencilRegistry.libraries['er'] = [SHAPES_PATH + '/er/mxER.js'];
  1095. mxStencilRegistry.libraries['ios'] = [SHAPES_PATH + '/mockup/mxMockupiOS.js'];
  1096. mxStencilRegistry.libraries['rackGeneral'] = [SHAPES_PATH + '/rack/mxRack.js', STENCIL_PATH + '/rack/general.xml'];
  1097. mxStencilRegistry.libraries['rackF5'] = [STENCIL_PATH + '/rack/f5.xml'];
  1098. mxStencilRegistry.libraries['lean_mapping'] = [SHAPES_PATH + '/mxLeanMap.js', STENCIL_PATH + '/lean_mapping.xml'];
  1099. mxStencilRegistry.libraries['basic'] = [SHAPES_PATH + '/mxBasic.js', STENCIL_PATH + '/basic.xml'];
  1100. mxStencilRegistry.libraries['ios7icons'] = [STENCIL_PATH + '/ios7/icons.xml'];
  1101. mxStencilRegistry.libraries['ios7ui'] = [SHAPES_PATH + '/ios7/mxIOS7Ui.js', STENCIL_PATH + '/ios7/misc.xml'];
  1102. mxStencilRegistry.libraries['android'] = [SHAPES_PATH + '/mxAndroid.js', STENCIL_PATH + '/android/android.xml'];
  1103. mxStencilRegistry.libraries['electrical/transmission'] = [SHAPES_PATH + '/mxElectrical.js', STENCIL_PATH + '/electrical/transmission.xml'];
  1104. mxStencilRegistry.libraries['mockup/buttons'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  1105. mxStencilRegistry.libraries['mockup/containers'] = [SHAPES_PATH + '/mockup/mxMockupContainers.js'];
  1106. mxStencilRegistry.libraries['mockup/forms'] = [SHAPES_PATH + '/mockup/mxMockupForms.js'];
  1107. mxStencilRegistry.libraries['mockup/graphics'] = [SHAPES_PATH + '/mockup/mxMockupGraphics.js', STENCIL_PATH + '/mockup/misc.xml'];
  1108. mxStencilRegistry.libraries['mockup/markup'] = [SHAPES_PATH + '/mockup/mxMockupMarkup.js'];
  1109. mxStencilRegistry.libraries['mockup/misc'] = [SHAPES_PATH + '/mockup/mxMockupMisc.js', STENCIL_PATH + '/mockup/misc.xml'];
  1110. mxStencilRegistry.libraries['mockup/navigation'] = [SHAPES_PATH + '/mockup/mxMockupNavigation.js', STENCIL_PATH + '/mockup/misc.xml'];
  1111. mxStencilRegistry.libraries['mockup/text'] = [SHAPES_PATH + '/mockup/mxMockupText.js'];
  1112. mxStencilRegistry.libraries['floorplan'] = [SHAPES_PATH + '/mxFloorplan.js', STENCIL_PATH + '/floorplan.xml'];
  1113. mxStencilRegistry.libraries['bootstrap'] = [SHAPES_PATH + '/mxBootstrap.js', STENCIL_PATH + '/bootstrap.xml'];
  1114. mxStencilRegistry.libraries['gmdl'] = [SHAPES_PATH + '/mxGmdl.js', STENCIL_PATH + '/gmdl.xml'];
  1115. mxStencilRegistry.libraries['cabinets'] = [SHAPES_PATH + '/mxCabinets.js', STENCIL_PATH + '/cabinets.xml'];
  1116. mxStencilRegistry.libraries['archimate'] = [SHAPES_PATH + '/mxArchiMate.js'];
  1117. mxStencilRegistry.libraries['archimate3'] = [SHAPES_PATH + '/mxArchiMate3.js'];
  1118. mxStencilRegistry.libraries['sysml'] = [SHAPES_PATH + '/mxSysML.js'];
  1119. mxStencilRegistry.libraries['eip'] = [SHAPES_PATH + '/mxEip.js', STENCIL_PATH + '/eip.xml'];
  1120. mxStencilRegistry.libraries['networks'] = [SHAPES_PATH + '/mxNetworks.js', STENCIL_PATH + '/networks.xml'];
  1121. mxStencilRegistry.libraries['aws3d'] = [SHAPES_PATH + '/mxAWS3D.js', STENCIL_PATH + '/aws3d.xml'];
  1122. mxStencilRegistry.libraries['pid2inst'] = [SHAPES_PATH + '/pid2/mxPidInstruments.js'];
  1123. mxStencilRegistry.libraries['pid2misc'] = [SHAPES_PATH + '/pid2/mxPidMisc.js', STENCIL_PATH + '/pid/misc.xml'];
  1124. mxStencilRegistry.libraries['pid2valves'] = [SHAPES_PATH + '/pid2/mxPidValves.js'];
  1125. mxStencilRegistry.libraries['pidFlowSensors'] = [STENCIL_PATH + '/pid/flow_sensors.xml'];
  1126. // Triggers dynamic loading for markers
  1127. mxMarker.getPackageForType = function(type)
  1128. {
  1129. var name = null;
  1130. if (type != null && type.length > 0)
  1131. {
  1132. if (type.substring(0, 2) == 'ER')
  1133. {
  1134. name = 'mxgraph.er';
  1135. }
  1136. else if (type.substring(0, 5) == 'sysML')
  1137. {
  1138. name = 'mxgraph.sysml';
  1139. }
  1140. }
  1141. return name;
  1142. };
  1143. var mxMarkerCreateMarker = mxMarker.createMarker;
  1144. mxMarker.createMarker = function(canvas, shape, type, pe, unitX, unitY, size, source, sw, filled)
  1145. {
  1146. if (type != null)
  1147. {
  1148. var f = mxMarker.markers[type];
  1149. if (f == null)
  1150. {
  1151. var name = this.getPackageForType(type);
  1152. if (name != null)
  1153. {
  1154. mxStencilRegistry.getStencil(name);
  1155. }
  1156. }
  1157. }
  1158. return mxMarkerCreateMarker.apply(this, arguments);
  1159. };
  1160. })();