Editor.js 45 KB

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