Editor.js 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145
  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) ? IMAGE_PATH + '/delete.png' : '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+OSb1c7trU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7fDu8fPv8vTz9fb09vf19/j3+Pn4+fn5+vr6+/v///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGRUCYcEgspkwjEKhUVJ1QsBNp0xm2VixiSOMRvlxFGAcTJook5eEHIhQcwpWIkAFQECkNy9AQWFwyEAkPRQ4FAwQIE2llQQAh+QQJCgAvACwAAAAADAAMAIVNcY5SdZFigptph6BvjKN0kKd8lquAmq+EnbGGn7KHn7ONpLaOpbearr+csMCdscCescGhtMOnuMauvsuzws60w862xdC9ytW/y9a/zNbCztjG0drH0tvK1N3M1t7N19/U3ePb4uff5urj6Ozk6e3l6u7m6u7o7PDq7vDt8PPv8vTw8vTw8/X19vf6+vv///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGQ8CXcEgsvlytVUplJLJIpSEDUESFTELBwSgCCQEV42kjDFiMo4uQsDB2MkLHoEHUTD7DRAHC8VAiZ0QSCgYIDxhNiUEAOw==';
  23. /**
  24. * Used in the GraphViewer lightbox.
  25. */
  26. Editor.tweetImage = IMAGE_PATH + '/tweet.png';
  27. /**
  28. * Used in the GraphViewer lightbox.
  29. */
  30. Editor.facebookImage = IMAGE_PATH + '/facebook.png';
  31. /**
  32. * Blank 1x1 pixel transparent PNG image.
  33. */
  34. Editor.blankImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==';
  35. /**
  36. * Blank 1x1 pixel transparent PNG image.
  37. */
  38. Editor.hiResImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAAA+CAMAAACLMWy1AAAAh1BMVEUAAABMTExERERBQUFBQUFFRUVAQEBCQkJAQEA6OjpDQ0NKSkpBQUFBQUFERERERERBQUFCQkJCQkJCQkJJSUlBQUFCQkJDQ0NDQ0NCQkJDQ0NBQUFBQUFCQkJBQUFCQkJCQkJDQ0NCQkJHR0dBQUFCQkJCQkJAQEBCQkJDQ0NAQEBERERCQkIk1hS2AAAAKnRSTlMAAjj96BL7PgQFRwfu3TYazKuVjRXl1V1DPCn1uLGjnWNVIgy9hU40eGqPkM38AAACG0lEQVRYw+2X63KbMBCFzwZblgGDceN74muatpLe//m6MHV3gHGFAv2RjM94MAbxzdnVsQbBDKwH8AH8MDAyafzjqYeyOG04XE7RS8nIRDXg6BlT+rA0nmtAPh+NQRDxIASIMG44rAMrGunBgHwy3uUldxggIStGKp2f+DQc2O4h4eQsX3O2IFB/oEbsjOKbStnjAEA+zJ0ylZTbgvoDn8xNyn6Dbj5Kd4GsNpABa6duQPfSdEj88TgMAhKuCWjAkgmFXPLnsD0pWd3OFGdrMugQII/eOMPEiGOzqPMIeWrcSoMCg71W1pXBPvCP+gS/OdXqQ3uW23+93XGWLl/OaBb805bNcBPoEIcVJsnHzcxpZH86u5KZ9gDby5dQCcnKqdbke4ItI4Tzd7IW9hZQt4EO6GG9b9sYuuK9Wwn8TIr2xKbF2+3Nhr+qxChJ/AI6pIfCu4z4Zowp4ZUNihz79vewzctnHDwTvQO/hCdFBzrUGDOPn2Y/F8YKT4oOATLvlhOznzmBSdFBJWtc58y7r+UVFOCQczy3wpN6pegDqHtsCPTGvH9JuTO0Dyg8icldYPk+RB6g8Aofj4m2EKBvtTmUPD9xDd1pPcSReV2U5iD/ik2yrngtvvqBfPzOvKiDTKTsCdoHZJ7pLLffgTwlJ5vJdtJV2/jiAYaLvLGhMAEDO5QcDg2M/jOw/8Zn+K3ZwJvHT7ZffgC/NvA3zcybTeIfE4EAAAAASUVORK5CYII=' : IMAGE_PATH + '/img-hi-res.png';
  39. /**
  40. * Blank 1x1 pixel transparent PNG image.
  41. */
  42. Editor.loResImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAAA+CAMAAACLMWy1AAAAS1BMVEVAQEAAAAA1NTVBQUFDQ0NDQ0NFRUVERERBQUFBQUFBQUFAQEBBQUFBQUFCQkJCQkJCQkJBQUFCQkJDQ0NDQ0NCQkJCQkJCQkJGRkb5/XqTAAAAGXRSTlP+AAWODlASCsesX+Lc2LyWe3pwa1tCPjohjSJfoAAAAI1JREFUWMPt1MkKhTAMRuG0anvneXr/J71nUypKcdqI/N8yhLMKMZE1CahnClDQzMPB44ED3EgeCubgDWnWQMHpwTtKwTe+UHD4sJ94wbUEHHFGhILlYDeSnsQeabeCgsPBgB0MOZZ9oGA5GJFiJSfUULAfjLjARrhCwX7wh2YCDwVbwZkUBKqFFJRN+wOcwSgR2sREcgAAAABJRU5ErkJggg==' : IMAGE_PATH + '/img-lo-res.png';
  43. /**
  44. * Only needed in browsers with SVG support for export via lightbox toolbar.
  45. */
  46. Editor.cameraLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaHR0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KTMInWQAAA/BJREFUWAnFl0uIjWEYx885buPSuGwmSYwtwsY1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DbRFi99iqSMySdzxXckrazUh23KBVYGIcfNBkTxca0e4ATJ0KukGYVBgr/MnlhPOtQq/ksUfCbzh+EFCjtnCUoHfjhA/OsiTv2HcEvJMELp0VakZDliTmriTdPivxU4VmEhtPrGV+KJhO7ZKt0doFZh1fgZSBWIW2AGEHwg3BUWOnKtH+suqdw07tYMfglCrWPD5mw9qVYuniaXkT0OtWaSuo5LJTY1RBf+roF9X5+y/5qU+DAAAAABJRU5ErkJggg==';
  47. /**
  48. * Default value for custom libraries in mxSettings.
  49. */
  50. Editor.defaultCustomLibraries = [];
  51. /**
  52. * Default value for the CSV import dialog.
  53. */
  54. Editor.defaultCsvValue = '##\n' +
  55. '## Example CSV import. Use ## for comments and # for configuration. Paste CSV below.\n' +
  56. '## The following names are reserved and should not be used (or ignored):\n' +
  57. '## id, tooltip, placeholder(s), link and label (see below)\n' +
  58. '##\n' +
  59. '#\n' +
  60. '## Node label with placeholders and HTML.\n' +
  61. '## Default is \'%name_of_first_column%\'.\n' +
  62. '#\n' +
  63. '# label: %name%<br><i style="color:gray;">%position%</i><br><a href="mailto:%email%">Email</a>\n' +
  64. '#\n' +
  65. '## Node style (placeholders are replaced once).\n' +
  66. '## Default is the current style for nodes.\n' +
  67. '#\n' +
  68. '# style: label;image=%image%;whiteSpace=wrap;html=1;rounded=1;fillColor=%fill%;strokeColor=%stroke%;\n' +
  69. '#\n' +
  70. '## Uses the given column name as the identity for cells (updates existing cells).\n' +
  71. '## Default is no identity (empty value or -).\n' +
  72. '#\n' +
  73. '# identity: -\n' +
  74. '#\n' +
  75. '## Connections between rows ("from": source colum, "to": target column).\n' +
  76. '## Label, style and invert are optional. Defaults are \'\', current style and false.\n' +
  77. '## The target column may contain a comma-separated list of values.\n' +
  78. '## Multiple connect entries are allowed.\n' +
  79. '#\n' +
  80. '# connect: {"from": "manager", "to": "name", "invert": true, "label": "manages", \\\n' +
  81. '# "style": "curved=1;endArrow=blockThin;endFill=1;fontSize=11;"}\n' +
  82. '# connect: {"from": "refs", "to": "id", "style": "curved=1;fontSize=11;"}\n' +
  83. '#\n' +
  84. '## Node width. Possible value are px or auto. Default is auto.\n' +
  85. '#\n' +
  86. '# width: auto\n' +
  87. '#\n' +
  88. '## Node height. Possible value are px or auto. Default is auto.\n' +
  89. '#\n' +
  90. '# height: auto\n' +
  91. '#\n' +
  92. '## Padding for autosize. Default is 0.\n' +
  93. '#\n' +
  94. '# padding: -12\n' +
  95. '#\n' +
  96. '## Comma-separated list of ignored columns for metadata. (These can be\n' +
  97. '## used for connections and styles but will not be added as metadata.)\n' +
  98. '#\n' +
  99. '# ignore: id,image,fill,stroke\n' +
  100. '#\n' +
  101. '## Column to be renamed to link attribute (used as link).\n' +
  102. '#\n' +
  103. '# link: url\n' +
  104. '#\n' +
  105. '## Spacing between nodes. Default is 40.\n' +
  106. '#\n' +
  107. '# nodespacing: 40\n' +
  108. '#\n' +
  109. '## Spacing between parallel edges. Default is 40.\n' +
  110. '#\n' +
  111. '# edgespacing: 40\n' +
  112. '#\n' +
  113. '## Name of layout. Possible values are auto, none, verticaltree, horizontaltree,\n' +
  114. '## verticalflow, horizontalflow, organic, circle. Default is auto.\n' +
  115. '#\n' +
  116. '# layout: auto\n' +
  117. '#\n' +
  118. '## ---- CSV below this line. First line are column names. ----\n' +
  119. 'name,position,id,location,manager,email,fill,stroke,refs,url,image\n' +
  120. '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' +
  121. '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' +
  122. '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' +
  123. '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';
  124. /**
  125. * Global configuration of the Editor
  126. * see https://desk.draw.io/solution/articles/16000058316
  127. *
  128. * For defaultVertexStyle, defaultEdgeStyle and defaultLibraries, this must be called before
  129. * mxSettings.load via global config variable window.mxLoadSettings = false.
  130. */
  131. Editor.configure = function(config)
  132. {
  133. if (config != null)
  134. {
  135. Editor.configVersion = config.version;
  136. Menus.prototype.defaultFonts = config.defaultFonts || Menus.prototype.defaultFonts;
  137. ColorDialog.prototype.presetColors = config.presetColors || ColorDialog.prototype.presetColors;
  138. ColorDialog.prototype.defaultColors = config.defaultColors || ColorDialog.prototype.defaultColors;
  139. StyleFormatPanel.prototype.defaultColorSchemes = config.defaultColorSchemes || StyleFormatPanel.prototype.defaultColorSchemes;
  140. Graph.prototype.defaultEdgeLength = config.defaultEdgeLength || Graph.prototype.defaultEdgeLength;
  141. // Custom CSS injected directly into the page
  142. if (config.css != null)
  143. {
  144. var s = document.createElement('style');
  145. s.setAttribute('type', 'text/css');
  146. s.appendChild(document.createTextNode(config.css));
  147. var t = document.getElementsByTagName('script')[0];
  148. t.parentNode.insertBefore(s, t);
  149. }
  150. // Overrides default libraries
  151. if (config.defaultLibraries != null)
  152. {
  153. Sidebar.prototype.defaultEntries = config.defaultLibraries;
  154. }
  155. // Overrides default custom libraries
  156. if (config.defaultCustomLibraries != null)
  157. {
  158. Editor.defaultCustomLibraries = config.defaultCustomLibraries;
  159. }
  160. // Overrides default vertex style
  161. if (config.defaultVertexStyle != null)
  162. {
  163. Graph.prototype.defaultVertexStyle = config.defaultVertexStyle;
  164. }
  165. // Overrides default edge style
  166. if (config.defaultEdgeStyle != null)
  167. {
  168. Graph.prototype.defaultEdgeStyle = config.defaultEdgeStyle;
  169. }
  170. if (config.emptyDiagramXml)
  171. {
  172. EditorUi.prototype.emptyDiagramXml = config.emptyDiagramXml;
  173. }
  174. if (config.thumbWidth)
  175. {
  176. Sidebar.prototype.thumbWidth = config.thumbWidth;
  177. }
  178. if (config.thumbHeight)
  179. {
  180. Sidebar.prototype.thumbHeight = config.thumbHeight;
  181. }
  182. if (config.emptyLibraryXml)
  183. {
  184. EditorUi.prototype.emptyLibraryXml = config.emptyLibraryXml;
  185. }
  186. if (config.sidebarWidth)
  187. {
  188. EditorUi.prototype.hsplitPosition = config.sidebarWidth;
  189. }
  190. if (config.fontCss)
  191. {
  192. var s = document.createElement('style');
  193. s.setAttribute('type', 'text/css');
  194. s.appendChild(document.createTextNode(config.fontCss));
  195. var t = document.getElementsByTagName('script')[0];
  196. t.parentNode.insertBefore(s, t);
  197. Editor.prototype.fontCss = config.fontCss;
  198. }
  199. if (config.plugins != null)
  200. {
  201. // Required for callback
  202. App.initPluginCallback();
  203. for (var i = 0; i < config.plugins.length; i++)
  204. {
  205. mxscript(config.plugins[i]);
  206. }
  207. }
  208. }
  209. };
  210. /**
  211. * Executes the first step for connecting to Google Drive.
  212. */
  213. Editor.prototype.editButtonLink = (urlParams['edit'] != null) ? decodeURIComponent(urlParams['edit']) : null;
  214. /**
  215. * Adds support for old stylesheets and compressed files
  216. */
  217. var editorSetGraphXml = Editor.prototype.setGraphXml;
  218. Editor.prototype.setGraphXml = function(node)
  219. {
  220. node = (node != null && node.nodeName != 'mxlibrary') ? this.extractGraphModel(node) : null;
  221. if (node != null)
  222. {
  223. // Checks input for parser errors
  224. var errs = node.getElementsByTagName('parsererror');
  225. if (errs != null && errs.length > 0)
  226. {
  227. var elt = errs[0];
  228. var divs = elt.getElementsByTagName('div');
  229. if (divs != null && divs.length > 0)
  230. {
  231. elt = divs[0];
  232. }
  233. throw {message: mxUtils.getTextContent(elt)};
  234. }
  235. else if (node.nodeName == 'mxGraphModel')
  236. {
  237. var style = node.getAttribute('style') || 'default-style2';
  238. // Decodes the style if required
  239. if (urlParams['embed'] != '1' && (style == null || style == ''))
  240. {
  241. var node2 = (this.graph.themes != null) ?
  242. this.graph.themes['default-old'] :
  243. mxUtils.load(STYLE_PATH + '/default-old.xml').getDocumentElement();
  244. if (node2 != null)
  245. {
  246. var dec2 = new mxCodec(node2.ownerDocument);
  247. dec2.decode(node2, this.graph.getStylesheet());
  248. }
  249. }
  250. else if (style != this.graph.currentStyle)
  251. {
  252. var node2 = (this.graph.themes != null) ?
  253. this.graph.themes[style] :
  254. mxUtils.load(STYLE_PATH + '/' + style + '.xml').getDocumentElement()
  255. if (node2 != null)
  256. {
  257. var dec2 = new mxCodec(node2.ownerDocument);
  258. dec2.decode(node2, this.graph.getStylesheet());
  259. }
  260. }
  261. this.graph.currentStyle = style;
  262. this.graph.mathEnabled = (urlParams['math'] == '1' || node.getAttribute('math') == '1');
  263. var bgImg = node.getAttribute('backgroundImage');
  264. if (bgImg != null)
  265. {
  266. bgImg = JSON.parse(bgImg);
  267. this.graph.setBackgroundImage(new mxImage(bgImg.src, bgImg.width, bgImg.height));
  268. }
  269. else
  270. {
  271. this.graph.setBackgroundImage(null);
  272. }
  273. mxClient.NO_FO = (this.graph.mathEnabled) ? true : this.originalNoForeignObject;
  274. this.graph.setShadowVisible(node.getAttribute('shadow') == '1', false);
  275. }
  276. // Calls updateGraphComponents
  277. editorSetGraphXml.apply(this, arguments);
  278. }
  279. else
  280. {
  281. throw {
  282. message: mxResources.get('notADiagramFile') || 'Invalid data',
  283. toString: function() { return this.message; }
  284. };
  285. }
  286. };
  287. /**
  288. * Adds persistent style to file
  289. */
  290. var editorGetGraphXml = Editor.prototype.getGraphXml;
  291. Editor.prototype.getGraphXml = function(ignoreSelection)
  292. {
  293. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  294. var node = editorGetGraphXml.apply(this, arguments);
  295. // Adds the current style
  296. if (this.graph.currentStyle != null && this.graph.currentStyle != 'default-style2')
  297. {
  298. node.setAttribute('style', this.graph.currentStyle);
  299. }
  300. // Adds the background image
  301. if (this.graph.backgroundImage != null)
  302. {
  303. node.setAttribute('backgroundImage', JSON.stringify(this.graph.backgroundImage));
  304. }
  305. node.setAttribute('math', (this.graph.mathEnabled) ? '1' : '0');
  306. node.setAttribute('shadow', (this.graph.shadowVisible) ? '1' : '0');
  307. return node;
  308. };
  309. /**
  310. * Helper function to extract the graph model XML node.
  311. */
  312. Editor.prototype.isDataSvg = function(svg)
  313. {
  314. try
  315. {
  316. var svgRoot = mxUtils.parseXml(svg).documentElement;
  317. var tmp = svgRoot.getAttribute('content');
  318. if (tmp != null)
  319. {
  320. if (tmp != null && tmp.charAt(0) != '<' && tmp.charAt(0) != '%')
  321. {
  322. tmp = unescape((window.atob) ? atob(tmp) : Base64.decode(cont, tmp));
  323. }
  324. if (tmp != null && tmp.charAt(0) == '%')
  325. {
  326. tmp = decodeURIComponent(tmp);
  327. }
  328. if (tmp != null && tmp.length > 0)
  329. {
  330. var node = mxUtils.parseXml(tmp).documentElement;
  331. return node.nodeName == 'mxfile' || node.nodeName == 'mxGraphModel';
  332. }
  333. }
  334. }
  335. catch (e)
  336. {
  337. // ignore
  338. }
  339. return false;
  340. };
  341. /**
  342. * Helper function to extract the graph model XML node.
  343. */
  344. Editor.prototype.extractGraphModel = function(node, allowMxFile)
  345. {
  346. if (node != null && typeof(pako) !== 'undefined')
  347. {
  348. var tmp = node.ownerDocument.getElementsByTagName('div');
  349. var divs = [];
  350. if (tmp != null && tmp.length > 0)
  351. {
  352. for (var i = 0; i < tmp.length; i++)
  353. {
  354. if (tmp[i].getAttribute('class') == 'mxgraph')
  355. {
  356. divs.push(tmp[i]);
  357. break;
  358. }
  359. }
  360. }
  361. if (divs.length > 0)
  362. {
  363. var data = divs[0].getAttribute('data-mxgraph');
  364. if (data != null)
  365. {
  366. var config = JSON.parse(data);
  367. if (config != null && config.xml != null)
  368. {
  369. var doc2 = mxUtils.parseXml(config.xml);
  370. node = doc2.documentElement;
  371. }
  372. }
  373. else
  374. {
  375. var divs2 = divs[0].getElementsByTagName('div');
  376. if (divs2.length > 0)
  377. {
  378. var data = mxUtils.getTextContent(divs2[0]);
  379. data = this.graph.decompress(data);
  380. if (data.length > 0)
  381. {
  382. var doc2 = mxUtils.parseXml(data);
  383. node = doc2.documentElement;
  384. }
  385. }
  386. }
  387. }
  388. }
  389. if (node != null && node.nodeName == 'svg')
  390. {
  391. var tmp = node.getAttribute('content');
  392. if (tmp != null && tmp.charAt(0) != '<' && tmp.charAt(0) != '%')
  393. {
  394. tmp = unescape((window.atob) ? atob(tmp) : Base64.decode(cont, tmp));
  395. }
  396. if (tmp != null && tmp.charAt(0) == '%')
  397. {
  398. tmp = decodeURIComponent(tmp);
  399. }
  400. if (tmp != null && tmp.length > 0)
  401. {
  402. node = mxUtils.parseXml(tmp).documentElement;
  403. }
  404. else
  405. {
  406. throw {message: mxResources.get('notADiagramFile')};
  407. }
  408. }
  409. if (node != null && !allowMxFile)
  410. {
  411. var diagramNode = null;
  412. if (node.nodeName == 'diagram')
  413. {
  414. diagramNode = node;
  415. }
  416. else if (node.nodeName == 'mxfile')
  417. {
  418. var diagrams = node.getElementsByTagName('diagram');
  419. if (diagrams.length > 0)
  420. {
  421. diagramNode = diagrams[Math.max(0, Math.min(diagrams.length - 1, urlParams['page'] || 0))];
  422. }
  423. }
  424. if (diagramNode != null)
  425. {
  426. var tmp = this.graph.decompress(mxUtils.getTextContent(diagramNode));
  427. if (tmp != null && tmp.length > 0)
  428. {
  429. node = mxUtils.parseXml(tmp).documentElement;
  430. }
  431. }
  432. }
  433. if (node != null && node.nodeName != 'mxGraphModel' && (!allowMxFile || node.nodeName != 'mxfile'))
  434. {
  435. node = null;
  436. }
  437. return node;
  438. };
  439. /**
  440. * Overrides reset graph.
  441. */
  442. var editorResetGraph = Editor.prototype.resetGraph;
  443. Editor.prototype.resetGraph = function()
  444. {
  445. this.graph.mathEnabled = (urlParams['math'] == '1');
  446. this.graph.view.x0 = null;
  447. this.graph.view.y0 = null;
  448. mxClient.NO_FO = (this.graph.mathEnabled) ? true : this.originalNoForeignObject;
  449. editorResetGraph.apply(this, arguments);
  450. };
  451. /**
  452. * Math support.
  453. */
  454. Editor.prototype.originalNoForeignObject = mxClient.NO_FO;
  455. var editorUpdateGraphComponents = Editor.prototype.updateGraphComponents;
  456. Editor.prototype.updateGraphComponents = function()
  457. {
  458. editorUpdateGraphComponents.apply(this, arguments);
  459. mxClient.NO_FO = (this.graph.mathEnabled && Editor.MathJaxRender != null) ? true : this.originalNoForeignObject;
  460. };
  461. /**
  462. * Initializes math typesetting and loads respective code.
  463. */
  464. Editor.initMath = function(src, config)
  465. {
  466. src = (src != null) ? src : 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_HTMLorMML';
  467. Editor.mathJaxQueue = [];
  468. Editor.doMathJaxRender = function(container)
  469. {
  470. MathJax.Hub.Queue(['Typeset', MathJax.Hub, container]);
  471. };
  472. // Disables global typesetting and messages on startup, adds queue for
  473. // asynchronous rendering while MathJax is loading
  474. window.MathJax =
  475. {
  476. skipStartupTypeset: true,
  477. showMathMenu: false,
  478. messageStyle: 'none',
  479. AuthorInit: function ()
  480. {
  481. // Specification recommends using SVG over HTML-CSS if browser is known
  482. // Check if too inconsistent with image export and print output
  483. MathJax.Hub.Config(config || {
  484. jax: ['input/TeX', 'input/MathML', 'input/AsciiMath', 'output/HTML-CSS'],
  485. extensions: ['tex2jax.js', 'mml2jax.js', 'asciimath2jax.js'],
  486. TeX: {
  487. extensions: ['AMSmath.js', 'AMSsymbols.js', 'noErrors.js', 'noUndefined.js']
  488. },
  489. // Ignores math in in-place editor
  490. tex2jax: {
  491. ignoreClass: 'mxCellEditor'
  492. },
  493. asciimath2jax: {
  494. ignoreClass: 'mxCellEditor'
  495. }
  496. });
  497. MathJax.Hub.Register.StartupHook('Begin', function()
  498. {
  499. for (var i = 0; i < Editor.mathJaxQueue.length; i++)
  500. {
  501. Editor.doMathJaxRender(Editor.mathJaxQueue[i]);
  502. }
  503. });
  504. }
  505. };
  506. // Adds global enqueue method for async rendering
  507. Editor.MathJaxRender = function(container)
  508. {
  509. // Initial rendering when MathJax finished loading
  510. if (typeof(MathJax) !== 'undefined' && typeof(MathJax.Hub) !== 'undefined')
  511. {
  512. Editor.doMathJaxRender(container);
  513. }
  514. else
  515. {
  516. Editor.mathJaxQueue.push(container);
  517. }
  518. };
  519. // Adds global clear queue method
  520. Editor.MathJaxClear = function()
  521. {
  522. Editor.mathJaxQueue = [];
  523. };
  524. // Updates typeset after changes
  525. var editorInit = Editor.prototype.init;
  526. Editor.prototype.init = function()
  527. {
  528. editorInit.apply(this, arguments);
  529. this.graph.addListener(mxEvent.SIZE, mxUtils.bind(this, function(sender, evt)
  530. {
  531. if (this.graph.mathEnabled)
  532. {
  533. Editor.MathJaxRender(this.graph.container);
  534. }
  535. }));
  536. };
  537. var tags = document.getElementsByTagName('script');
  538. if (tags != null && tags.length > 0)
  539. {
  540. var script = document.createElement('script');
  541. script.type = 'text/javascript';
  542. script.src = src;
  543. tags[0].parentNode.appendChild(script);
  544. }
  545. };
  546. /**
  547. * Return array of string values, or NULL if CSV string not well formed.
  548. */
  549. Editor.prototype.csvToArray = function(text)
  550. {
  551. var re_valid = /^\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*(?:,\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*)*$/;
  552. var re_value = /(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g;
  553. // Return NULL if input string is not well formed CSV string.
  554. if (!re_valid.test(text)) return null;
  555. var a = []; // Initialize array to receive values.
  556. text.replace(re_value, // "Walk" the string using replace with callback.
  557. function(m0, m1, m2, m3) {
  558. // Remove backslash from \' in single quoted values.
  559. if (m1 !== undefined) a.push(m1.replace(/\\'/g, "'"));
  560. // Remove backslash from \" in double quoted values.
  561. else if (m2 !== undefined) a.push(m2.replace(/\\"/g, '"'));
  562. else if (m3 !== undefined) a.push(m3);
  563. return ''; // Return empty string.
  564. });
  565. // Handle special case of empty last value.
  566. if (/,\s*$/.test(text)) a.push('');
  567. return a;
  568. };
  569. /**
  570. * Adds persistence for recent colors
  571. */
  572. if (window.ColorDialog)
  573. {
  574. var colorDialogAddRecentColor = ColorDialog.addRecentColor;
  575. ColorDialog.addRecentColor = function(color, max)
  576. {
  577. colorDialogAddRecentColor.apply(this, arguments);
  578. mxSettings.setRecentColors(ColorDialog.recentColors);
  579. mxSettings.save();
  580. };
  581. var colorDialogResetRecentColors = ColorDialog.resetRecentColors;
  582. ColorDialog.resetRecentColors = function()
  583. {
  584. colorDialogResetRecentColors.apply(this, arguments);
  585. mxSettings.setRecentColors(ColorDialog.recentColors);
  586. mxSettings.save();
  587. };
  588. }
  589. // Overridden to add edit shape option
  590. if (window.StyleFormatPanel != null)
  591. {
  592. var formatInit = Format.prototype.init;
  593. Format.prototype.init = function()
  594. {
  595. formatInit.apply(this, arguments);
  596. this.editorUi.editor.addListener('fileLoaded', this.update);
  597. };
  598. var formatRefresh = Format.prototype.refresh;
  599. Format.prototype.refresh = function()
  600. {
  601. if (this.editorUi.getCurrentFile() != null || urlParams['embed'] == '1' ||
  602. this.editorUi.editor.chromeless)
  603. {
  604. formatRefresh.apply(this, arguments);
  605. }
  606. else
  607. {
  608. this.clear();
  609. }
  610. };
  611. /**
  612. * Add global shadow option.
  613. */
  614. var diagramFormatPanelAddView = DiagramFormatPanel.prototype.addView;
  615. DiagramFormatPanel.prototype.addView = function(div)
  616. {
  617. var div = diagramFormatPanelAddView.apply(this, arguments);
  618. if (mxClient.IS_SVG)
  619. {
  620. var ui = this.editorUi;
  621. var editor = ui.editor;
  622. var graph = editor.graph;
  623. div.appendChild(this.createOption(mxResources.get('shadow'), function()
  624. {
  625. return graph.shadowVisible;
  626. }, function(checked)
  627. {
  628. graph.model.execute(new ChangeShadow(ui, checked));
  629. },
  630. {
  631. install: function(apply)
  632. {
  633. this.listener = function()
  634. {
  635. apply(graph.shadowVisible);
  636. };
  637. ui.addListener('shadowVisibleChanged', this.listener);
  638. },
  639. destroy: function()
  640. {
  641. ui.removeListener(this.listener);
  642. }
  643. }));
  644. }
  645. return div;
  646. };
  647. /**
  648. * Adds autosave and math typesetting options.
  649. */
  650. var diagramFormatPanelAddOptions = DiagramFormatPanel.prototype.addOptions;
  651. DiagramFormatPanel.prototype.addOptions = function(div)
  652. {
  653. div = diagramFormatPanelAddOptions.apply(this, arguments);
  654. var ui = this.editorUi;
  655. var editor = ui.editor;
  656. var graph = editor.graph;
  657. if (graph.isEnabled())
  658. {
  659. var file = ui.getCurrentFile();
  660. if (file != null && file.isAutosaveOptional())
  661. {
  662. var opt = this.createOption(mxResources.get('autosave'), function()
  663. {
  664. return ui.editor.autosave;
  665. }, function(checked)
  666. {
  667. ui.editor.setAutosave(checked);
  668. },
  669. {
  670. install: function(apply)
  671. {
  672. this.listener = function()
  673. {
  674. apply(ui.editor.autosave);
  675. };
  676. ui.editor.addListener('autosaveChanged', this.listener);
  677. },
  678. destroy: function()
  679. {
  680. ui.editor.removeListener(this.listener);
  681. }
  682. });
  683. div.appendChild(opt);
  684. }
  685. }
  686. return div;
  687. };
  688. /**
  689. * Configures global color schemes.
  690. */
  691. StyleFormatPanel.prototype.defaultColorSchemes = [[null, {fill: '#f5f5f5', stroke: '#666666'},
  692. {fill: '#dae8fc', stroke: '#6c8ebf'}, {fill: '#d5e8d4', stroke: '#82b366'},
  693. {fill: '#ffe6cc', stroke: '#d79b00'}, {fill: '#fff2cc', stroke: '#d6b656'},
  694. {fill: '#f8cecc', stroke: '#b85450'}, {fill: '#e1d5e7', stroke: '#9673a6'}],
  695. [null,
  696. {fill: '#f5f5f5', stroke: '#666666', gradient: '#b3b3b3'},
  697. {fill: '#dae8fc', stroke: '#6c8ebf', gradient: '#7ea6e0'},
  698. {fill: '#d5e8d4', stroke: '#82b366', gradient: '#97d077'},
  699. {fill: '#ffcd28', stroke: '#d79b00', gradient: '#ffa500'},
  700. {fill: '#fff2cc', stroke: '#d6b656', gradient: '#ffd966'},
  701. {fill: '#f8cecc', stroke: '#b85450', gradient: '#ea6b66'},
  702. {fill: '#e6d0de', stroke: '#996185', gradient: '#d5739d'}],
  703. [null, {fill: '#eeeeee', stroke: '#36393d'},
  704. {fill: '#f9f7ed', stroke: '#36393d'}, {fill: '#ffcc99', stroke: '#36393d'},
  705. {fill: '#cce5ff', stroke: '#36393d'}, {fill: '#ffff88', stroke: '#36393d'},
  706. {fill: '#cdeb8b', stroke: '#36393d'}, {fill: '#ffcccc', stroke: '#36393d'}]];
  707. /**
  708. * Adds predefiend styles.
  709. */
  710. var styleFormatPanelInit = StyleFormatPanel.prototype.init;
  711. StyleFormatPanel.prototype.init = function()
  712. {
  713. // TODO: Update sstate in Format
  714. var sstate = this.format.createSelectionState();
  715. if (sstate.style.shape != 'image')
  716. {
  717. this.container.appendChild(this.addStyles(this.createPanel()));
  718. }
  719. styleFormatPanelInit.apply(this, arguments);
  720. };
  721. /**
  722. * Overridden to add copy and paste style.
  723. */
  724. var styleFormatPanelAddStyleOps = StyleFormatPanel.prototype.addStyleOps;
  725. StyleFormatPanel.prototype.addStyleOps = function(div)
  726. {
  727. var btn = mxUtils.button(mxResources.get('copyStyle'), mxUtils.bind(this, function(evt)
  728. {
  729. this.editorUi.actions.get('copyStyle').funct();
  730. }));
  731. btn.setAttribute('title', mxResources.get('copyStyle') + ' (' + this.editorUi.actions.get('copyStyle').shortcut + ')');
  732. btn.style.marginBottom = '2px';
  733. btn.style.width = '100px';
  734. btn.style.marginRight = '2px';
  735. div.appendChild(btn);
  736. var btn = mxUtils.button(mxResources.get('pasteStyle'), mxUtils.bind(this, function(evt)
  737. {
  738. this.editorUi.actions.get('pasteStyle').funct();
  739. }));
  740. btn.setAttribute('title', mxResources.get('pasteStyle') + ' (' + this.editorUi.actions.get('pasteStyle').shortcut + ')');
  741. btn.style.marginBottom = '2px';
  742. btn.style.width = '100px';
  743. div.appendChild(btn);
  744. mxUtils.br(div);
  745. return styleFormatPanelAddStyleOps.apply(this, arguments);
  746. };
  747. /**
  748. * Creates the buttons for the predefined styles.
  749. */
  750. StyleFormatPanel.prototype.addStyles = function(div)
  751. {
  752. var graph = this.editorUi.editor.graph;
  753. var picker = document.createElement('div');
  754. picker.style.whiteSpace = 'nowrap';
  755. picker.style.paddingLeft = '24px';
  756. picker.style.paddingRight = '20px';
  757. div.style.paddingLeft = '16px';
  758. div.style.paddingBottom = '6px';
  759. div.style.position = 'relative';
  760. div.appendChild(picker);
  761. var stylenames = ['plain-gray', 'plain-blue', 'plain-green', 'plain-turquoise',
  762. 'plain-orange', 'plain-yellow', 'plain-red', 'plain-pink', 'plain-purple', 'gray',
  763. 'blue', 'green', 'turquoise', 'orange', 'yellow', 'red', 'pink', 'purple'];
  764. function updateScheme(colorsets)
  765. {
  766. function addButton(colorset)
  767. {
  768. var btn = mxUtils.button('', function(evt)
  769. {
  770. graph.getModel().beginUpdate();
  771. try
  772. {
  773. var cells = graph.getSelectionCells();
  774. for (var i = 0; i < cells.length; i++)
  775. {
  776. var style = graph.getModel().getStyle(cells[i]);
  777. for (var j = 0; j < stylenames.length; j++)
  778. {
  779. style = mxUtils.removeStylename(style, stylenames[j]);
  780. }
  781. if (colorset != null)
  782. {
  783. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, colorset['fill']);
  784. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, colorset['stroke']);
  785. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, colorset['gradient']);
  786. }
  787. else
  788. {
  789. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, '#ffffff');
  790. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, '#000000');
  791. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, null);
  792. }
  793. graph.getModel().setStyle(cells[i], style);
  794. }
  795. }
  796. finally
  797. {
  798. graph.getModel().endUpdate();
  799. }
  800. })
  801. btn.className = 'geStyleButton';
  802. btn.style.width = '36px';
  803. btn.style.height = '30px';
  804. btn.style.margin = '0px 6px 6px 0px';
  805. if (colorset != null)
  806. {
  807. if (colorset['gradient'] != null)
  808. {
  809. if (mxClient.IS_IE && (mxClient.IS_QUIRKS || document.documentMode < 10))
  810. {
  811. btn.style.filter = 'progid:DXImageTransform.Microsoft.Gradient('+
  812. 'StartColorStr=\'' + colorset['fill'] +
  813. '\', EndColorStr=\'' + colorset['gradient'] + '\', GradientType=0)';
  814. }
  815. else
  816. {
  817. btn.style.backgroundImage = 'linear-gradient(' + colorset['fill'] + ' 0px,' +
  818. colorset['gradient'] + ' 100%)';
  819. }
  820. }
  821. else
  822. {
  823. btn.style.backgroundColor = colorset['fill'];
  824. }
  825. btn.style.border = '1px solid ' + colorset['stroke'];
  826. }
  827. else
  828. {
  829. btn.style.backgroundColor = '#ffffff';
  830. btn.style.border = '1px solid #000000';
  831. }
  832. picker.appendChild(btn);
  833. };
  834. picker.innerHTML = '';
  835. for (var i = 0; i < colorsets.length; i++)
  836. {
  837. if (i > 0 && mxUtils.mod(i, 4) == 0)
  838. {
  839. mxUtils.br(picker);
  840. }
  841. addButton(colorsets[i]);
  842. }
  843. };
  844. if (this.editorUi.currentScheme == null)
  845. {
  846. this.editorUi.currentScheme = 0;
  847. }
  848. var left = document.createElement('div');
  849. left.style.cssText = 'position:absolute;left:10px;top:8px;bottom:8px;width:20px;margin:4px;opacity:0.5;' +
  850. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ4eHh3d3d1dXVxcXF2dnZ2dnZ2dnZxcXF2dnYmb3w1AAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADRJREFUCNdjwACMAmBKaiGYs2oJmLPKAZ3DabU8AMRTXpUKopislqFyVzCAuUZgikkBZjoAcMYLnp53P/UAAAAASUVORK5CYII=);';
  851. mxEvent.addListener(left, 'click', mxUtils.bind(this, function()
  852. {
  853. this.editorUi.currentScheme = mxUtils.mod(this.editorUi.currentScheme - 1, this.defaultColorSchemes.length);
  854. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  855. }));
  856. var right = document.createElement('div');
  857. right.style.cssText = 'position:absolute;left:202px;top:8px;bottom:8px;width:20px;margin:4px;opacity:0.5;' +
  858. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnYBuwCcAAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADZJREFUCNdjQAOMAmBKaiGY8loF5rKswsZlrVo8AUiFrTICcbIWK8A5DF1gDoMymMPApIAwHwCS0Qx/U7qCBQAAAABJRU5ErkJggg==);';
  859. if (this.defaultColorSchemes.length > 1)
  860. {
  861. div.appendChild(left);
  862. div.appendChild(right);
  863. }
  864. mxEvent.addListener(right, 'click', mxUtils.bind(this, function()
  865. {
  866. this.editorUi.currentScheme = mxUtils.mod(this.editorUi.currentScheme + 1, this.defaultColorSchemes.length);
  867. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  868. }));
  869. // Hover state
  870. function addHoverState(elt)
  871. {
  872. mxEvent.addListener(elt, 'mouseenter', function()
  873. {
  874. elt.style.opacity = '1';
  875. });
  876. mxEvent.addListener(elt, 'mouseleave', function()
  877. {
  878. elt.style.opacity = '0.5';
  879. });
  880. };
  881. addHoverState(left);
  882. addHoverState(right);
  883. updateScheme(this.defaultColorSchemes[this.editorUi.currentScheme]);
  884. return div;
  885. };
  886. StyleFormatPanel.prototype.addEditOps = function(div)
  887. {
  888. var ss = this.format.getSelectionState();
  889. var btn = null;
  890. if (this.editorUi.editor.graph.getSelectionCount() == 1)
  891. {
  892. btn = mxUtils.button(mxResources.get('editStyle'), mxUtils.bind(this, function(evt)
  893. {
  894. this.editorUi.actions.get('editStyle').funct();
  895. }));
  896. btn.setAttribute('title', mxResources.get('editStyle') + ' (' + this.editorUi.actions.get('editStyle').shortcut + ')');
  897. btn.style.width = '202px';
  898. btn.style.marginBottom = '2px';
  899. div.appendChild(btn);
  900. }
  901. var graph = this.editorUi.editor.graph;
  902. var state = graph.view.getState(graph.getSelectionCell());
  903. if (graph.getSelectionCount() == 1 && state != null && state.shape != null && state.shape.stencil != null)
  904. {
  905. var btn2 = mxUtils.button(mxResources.get('editShape'), mxUtils.bind(this, function(evt)
  906. {
  907. this.editorUi.actions.get('editShape').funct();
  908. }));
  909. btn2.setAttribute('title', mxResources.get('editShape'));
  910. btn2.style.marginBottom = '2px';
  911. if (btn == null)
  912. {
  913. btn2.style.width = '202px';
  914. }
  915. else
  916. {
  917. btn.style.width = '100px';
  918. btn2.style.width = '100px';
  919. btn2.style.marginLeft = '2px';
  920. }
  921. div.appendChild(btn2);
  922. }
  923. else if (ss.image)
  924. {
  925. var btn2 = mxUtils.button(mxResources.get('editImage'), mxUtils.bind(this, function(evt)
  926. {
  927. this.editorUi.actions.get('image').funct();
  928. }));
  929. btn2.setAttribute('title', mxResources.get('editImage'));
  930. btn2.style.marginBottom = '2px';
  931. if (btn == null)
  932. {
  933. btn2.style.width = '202px';
  934. }
  935. else
  936. {
  937. btn.style.width = '100px';
  938. btn2.style.width = '100px';
  939. btn2.style.marginLeft = '2px';
  940. }
  941. div.appendChild(btn2);
  942. }
  943. return div;
  944. };
  945. }
  946. /**
  947. * Changes the default stylename so that it matches the old named style
  948. * if one was specified in the XML.
  949. */
  950. Graph.prototype.defaultThemeName = 'default-style2';
  951. /**
  952. * Contains the last XML that was pasted.
  953. */
  954. Graph.prototype.lastPasteXml = null;
  955. /**
  956. * Contains the number of times the last XML was pasted.
  957. */
  958. Graph.prototype.pasteCounter = 0;
  959. /**
  960. * Graph Overrides
  961. */
  962. Graph.prototype.defaultScrollbars = urlParams['sb'] != '0';
  963. /**
  964. * Specifies if the page should be visible for new files. Default is true.
  965. */
  966. Graph.prototype.defaultPageVisible = urlParams['pv'] != '0';
  967. /**
  968. * Specifies if the page should be visible for new files. Default is true.
  969. */
  970. Graph.prototype.shadowId = 'dropShadow';
  971. /**
  972. * Properties for the SVG shadow effect.
  973. */
  974. Graph.prototype.svgShadowColor = '#3D4574';
  975. /**
  976. * Properties for the SVG shadow effect.
  977. */
  978. Graph.prototype.svgShadowOpacity = '0.4';
  979. /**
  980. * Properties for the SVG shadow effect.
  981. */
  982. Graph.prototype.svgShadowBlur = '1.7';
  983. /**
  984. * Properties for the SVG shadow effect.
  985. */
  986. Graph.prototype.svgShadowSize = '3';
  987. /**
  988. * Enables move of bends/segments without selecting.
  989. */
  990. Graph.prototype.edgeMode = urlParams['edge'] != 'move';
  991. /**
  992. * Adds rack child layout style.
  993. */
  994. var graphInit = Graph.prototype.init;
  995. Graph.prototype.init = function()
  996. {
  997. graphInit.apply(this, arguments);
  998. // Override insert location for current mouse point
  999. var mouseEvent = null;
  1000. function setMouseEvent(evt)
  1001. {
  1002. mouseEvent = evt;
  1003. // Workaround for member not found in IE8-
  1004. if (mxClient.IS_QUIRKS || document.documentMode == 7 || document.documentMode == 8)
  1005. {
  1006. mouseEvent = mxUtils.clone(evt);
  1007. }
  1008. };
  1009. mxEvent.addListener(this.container, 'mouseenter', setMouseEvent);
  1010. mxEvent.addListener(this.container, 'mousemove', setMouseEvent);
  1011. mxEvent.addListener(this.container, 'mouseleave', function(evt)
  1012. {
  1013. mouseEvent = null;
  1014. });
  1015. // Extends getInsertPoint to use the current mouse location
  1016. this.isMouseInsertPoint = function()
  1017. {
  1018. return mouseEvent != null;
  1019. };
  1020. var getInsertPoint = this.getInsertPoint;
  1021. this.getInsertPoint = function()
  1022. {
  1023. if (mouseEvent != null)
  1024. {
  1025. return this.getPointForEvent(mouseEvent);
  1026. }
  1027. return getInsertPoint.apply(this, arguments);
  1028. };
  1029. var layoutManagerGetLayout = this.layoutManager.getLayout;
  1030. this.layoutManager.getLayout = function(cell)
  1031. {
  1032. var state = this.graph.view.getState(cell);
  1033. var style = (state != null) ? state.style : this.graph.getCellStyle(cell);
  1034. // mxRackContainer may be undefined as it is dynamically loaded at render time
  1035. if (typeof(mxRackContainer) != 'undefined' && style['childLayout'] == 'rack')
  1036. {
  1037. var rackLayout = new mxStackLayout(this.graph, false);
  1038. rackLayout.setChildGeometry = function(child, geo)
  1039. {
  1040. var unitSize = 20;
  1041. geo.height = Math.max(geo.height, unitSize);
  1042. if (geo.height / unitSize > 1)
  1043. {
  1044. var mod = geo.height % unitSize;
  1045. geo.height += mod > unitSize / 2 ? (unitSize - mod) : -mod;
  1046. }
  1047. this.graph.getModel().setGeometry(child, geo);
  1048. };
  1049. rackLayout.fill = true;
  1050. rackLayout.unitSize = mxRackContainer.unitSize | 20;
  1051. rackLayout.marginLeft = style['marginLeft'] || 0;
  1052. rackLayout.marginRight = style['marginRight'] || 0;
  1053. rackLayout.marginTop = style['marginTop'] || 0;
  1054. rackLayout.marginBottom = style['marginBottom'] || 0;
  1055. rackLayout.resizeParent = false;
  1056. return rackLayout;
  1057. }
  1058. return layoutManagerGetLayout.apply(this, arguments);
  1059. }
  1060. };
  1061. /**
  1062. * Sets default style (used in editor.get/setGraphXml below)
  1063. */
  1064. var graphLoadStylesheet = Graph.prototype.loadStylesheet;
  1065. Graph.prototype.loadStylesheet = function()
  1066. {
  1067. graphLoadStylesheet.apply(this, arguments);
  1068. this.currentStyle = 'default-style2';
  1069. };
  1070. /**
  1071. * Adds support for page links.
  1072. */
  1073. Graph.prototype.isPageLink = function(href)
  1074. {
  1075. return href != null && href.substring(0, 10) == 'data:page/';
  1076. };
  1077. /**
  1078. * Highlights the given cell.
  1079. */
  1080. Graph.prototype.highlightCell = function(cell, color, duration)
  1081. {
  1082. color = (color != null) ? color : mxConstants.DEFAULT_VALID_COLOR;
  1083. duration = (duration != null) ? duration : 1000;
  1084. var state = this.view.getState(cell);
  1085. if (state != null)
  1086. {
  1087. var sw = Math.max(5, mxUtils.getValue(state.style, mxConstants.STYLE_STROKEWIDTH, 1) + 4);
  1088. var hl = new mxCellHighlight(this, color, sw, false);
  1089. hl.highlight(state);
  1090. // Fades out the highlight after a duration
  1091. window.setTimeout(function()
  1092. {
  1093. if (hl.shape != null)
  1094. {
  1095. mxUtils.setPrefixedStyle(hl.shape.node.style, 'transition', 'all 1200ms ease-in-out');
  1096. hl.shape.node.style.opacity = 0;
  1097. }
  1098. // Destroys the highlight after the fade
  1099. window.setTimeout(function()
  1100. {
  1101. hl.destroy();
  1102. }, 1200);
  1103. }, duration);
  1104. }
  1105. };
  1106. /**
  1107. * Adds a shadow filter to the given svg root.
  1108. */
  1109. Graph.prototype.addSvgShadow = function(svgRoot, group, createOnly)
  1110. {
  1111. createOnly = (createOnly != null) ? createOnly : false;
  1112. var svgDoc = svgRoot.ownerDocument;
  1113. var filter = (svgDoc.createElementNS != null) ?
  1114. svgDoc.createElementNS(mxConstants.NS_SVG, 'filter') : svgDoc.createElement('filter');
  1115. filter.setAttribute('id', this.shadowId);
  1116. var blur = (svgDoc.createElementNS != null) ?
  1117. svgDoc.createElementNS(mxConstants.NS_SVG, 'feGaussianBlur') : svgDoc.createElement('feGaussianBlur');
  1118. blur.setAttribute('in', 'SourceAlpha');
  1119. blur.setAttribute('stdDeviation', this.svgShadowBlur);
  1120. blur.setAttribute('result', 'blur');
  1121. filter.appendChild(blur);
  1122. var offset = (svgDoc.createElementNS != null) ?
  1123. svgDoc.createElementNS(mxConstants.NS_SVG, 'feOffset') : svgDoc.createElement('feOffset');
  1124. offset.setAttribute('in', 'blur');
  1125. offset.setAttribute('dx', this.svgShadowSize);
  1126. offset.setAttribute('dy', this.svgShadowSize);
  1127. offset.setAttribute('result', 'offsetBlur');
  1128. filter.appendChild(offset);
  1129. var flood = (svgDoc.createElementNS != null) ?
  1130. svgDoc.createElementNS(mxConstants.NS_SVG, 'feFlood') : svgDoc.createElement('feFlood');
  1131. flood.setAttribute('flood-color', this.svgShadowColor);
  1132. flood.setAttribute('flood-opacity', this.svgShadowOpacity);
  1133. flood.setAttribute('result', 'offsetColor');
  1134. filter.appendChild(flood);
  1135. var composite = (svgDoc.createElementNS != null) ?
  1136. svgDoc.createElementNS(mxConstants.NS_SVG, 'feComposite') : svgDoc.createElement('feComposite');
  1137. composite.setAttribute('in', 'offsetColor');
  1138. composite.setAttribute('in2', 'offsetBlur');
  1139. composite.setAttribute('operator', 'in');
  1140. composite.setAttribute('result', 'offsetBlur');
  1141. filter.appendChild(composite);
  1142. var feBlend = (svgDoc.createElementNS != null) ?
  1143. svgDoc.createElementNS(mxConstants.NS_SVG, 'feBlend') : svgDoc.createElement('feBlend');
  1144. feBlend.setAttribute('in', 'SourceGraphic');
  1145. feBlend.setAttribute('in2', 'offsetBlur');
  1146. filter.appendChild(feBlend);
  1147. // Creates defs element if not available
  1148. var defs = svgRoot.getElementsByTagName('defs');
  1149. var defsElt = null;
  1150. if (defs.length == 0)
  1151. {
  1152. defsElt = (svgDoc.createElementNS != null) ?
  1153. svgDoc.createElementNS(mxConstants.NS_SVG, 'defs') : svgDoc.createElement('defs');
  1154. if (svgRoot.firstChild != null)
  1155. {
  1156. svgRoot.insertBefore(defsElt, svgRoot.firstChild);
  1157. }
  1158. else
  1159. {
  1160. svgRoot.appendChild(defsElt);
  1161. }
  1162. }
  1163. else
  1164. {
  1165. defsElt = defs[0];
  1166. }
  1167. defsElt.appendChild(filter);
  1168. if (!createOnly)
  1169. {
  1170. (group || svgRoot.getElementsByTagName('g')[0]).setAttribute('filter', 'url(#' + this.shadowId + ')');
  1171. if (!isNaN(parseInt(svgRoot.getAttribute('width'))))
  1172. {
  1173. svgRoot.setAttribute('width', parseInt(svgRoot.getAttribute('width')) + 6);
  1174. svgRoot.setAttribute('height', parseInt(svgRoot.getAttribute('height')) + 6);
  1175. }
  1176. }
  1177. return filter;
  1178. };
  1179. /**
  1180. * Loads the stylesheet for this graph.
  1181. */
  1182. Graph.prototype.setShadowVisible = function(value, fireEvent)
  1183. {
  1184. if (mxClient.IS_SVG)
  1185. {
  1186. fireEvent = (fireEvent != null) ? fireEvent : true;
  1187. this.shadowVisible = value;
  1188. if (this.shadowVisible)
  1189. {
  1190. this.view.getDrawPane().setAttribute('filter', 'url(#' + this.shadowId + ')');
  1191. }
  1192. else
  1193. {
  1194. this.view.getDrawPane().removeAttribute('filter');
  1195. }
  1196. if (fireEvent)
  1197. {
  1198. this.fireEvent(new mxEventObject('shadowVisibleChanged'));
  1199. }
  1200. }
  1201. };
  1202. /**
  1203. * Selects first unlocked layer if one exists
  1204. */
  1205. Graph.prototype.selectUnlockedLayer = function()
  1206. {
  1207. if (this.defaultParent == null)
  1208. {
  1209. var childCount = this.model.getChildCount(this.model.root);
  1210. var cell = null;
  1211. var index = 0;
  1212. do
  1213. {
  1214. cell = this.model.getChildAt(this.model.root, index);
  1215. } while (index++ < childCount && mxUtils.getValue(this.getCellStyle(cell), 'locked', '0') == '1')
  1216. if (cell != null)
  1217. {
  1218. this.setDefaultParent(cell);
  1219. }
  1220. }
  1221. };
  1222. /**
  1223. * Specifies special libraries that are loaded via dynamic JS. Add cases
  1224. * where the filename cannot be worked out from the package name. The
  1225. * standard scheme for this mapping is stencils/packagename.xml. If there
  1226. * are multiple XML files, any JS files or any anomalies in the filename or
  1227. * directory that contains the file, then an entry must be added here and
  1228. * in EmbedServlet2 for the loading of the shapes to work.
  1229. */
  1230. // Required to avoid 404 for mockup.xml since naming of mxgraph.mockup.anchor does not contain
  1231. // buttons even though it is defined in the mxMockupButtons.js file. This could only be fixed
  1232. // with aliases for existing shapes or aliases for basenames, but this is essentially the same.
  1233. mxStencilRegistry.libraries['mockup'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  1234. mxStencilRegistry.libraries['arrows2'] = [SHAPES_PATH + '/mxArrows.js'];
  1235. mxStencilRegistry.libraries['atlassian'] = [STENCIL_PATH + '/atlassian.xml'];
  1236. mxStencilRegistry.libraries['bpmn'] = [SHAPES_PATH + '/bpmn/mxBpmnShape2.js', STENCIL_PATH + '/bpmn.xml'];
  1237. mxStencilRegistry.libraries['er'] = [SHAPES_PATH + '/er/mxER.js'];
  1238. mxStencilRegistry.libraries['ios'] = [SHAPES_PATH + '/mockup/mxMockupiOS.js'];
  1239. mxStencilRegistry.libraries['rackGeneral'] = [SHAPES_PATH + '/rack/mxRack.js', STENCIL_PATH + '/rack/general.xml'];
  1240. mxStencilRegistry.libraries['rackF5'] = [STENCIL_PATH + '/rack/f5.xml'];
  1241. mxStencilRegistry.libraries['lean_mapping'] = [SHAPES_PATH + '/mxLeanMap.js', STENCIL_PATH + '/lean_mapping.xml'];
  1242. mxStencilRegistry.libraries['basic'] = [SHAPES_PATH + '/mxBasic.js', STENCIL_PATH + '/basic.xml'];
  1243. mxStencilRegistry.libraries['ios7icons'] = [STENCIL_PATH + '/ios7/icons.xml'];
  1244. mxStencilRegistry.libraries['ios7ui'] = [SHAPES_PATH + '/ios7/mxIOS7Ui.js', STENCIL_PATH + '/ios7/misc.xml'];
  1245. mxStencilRegistry.libraries['android'] = [SHAPES_PATH + '/mxAndroid.js', STENCIL_PATH + '/android/android.xml'];
  1246. mxStencilRegistry.libraries['electrical/transmission'] = [SHAPES_PATH + '/mxElectrical.js', STENCIL_PATH + '/electrical/transmission.xml'];
  1247. mxStencilRegistry.libraries['mockup/buttons'] = [SHAPES_PATH + '/mockup/mxMockupButtons.js'];
  1248. mxStencilRegistry.libraries['mockup/containers'] = [SHAPES_PATH + '/mockup/mxMockupContainers.js'];
  1249. mxStencilRegistry.libraries['mockup/forms'] = [SHAPES_PATH + '/mockup/mxMockupForms.js'];
  1250. mxStencilRegistry.libraries['mockup/graphics'] = [SHAPES_PATH + '/mockup/mxMockupGraphics.js', STENCIL_PATH + '/mockup/misc.xml'];
  1251. mxStencilRegistry.libraries['mockup/markup'] = [SHAPES_PATH + '/mockup/mxMockupMarkup.js'];
  1252. mxStencilRegistry.libraries['mockup/misc'] = [SHAPES_PATH + '/mockup/mxMockupMisc.js', STENCIL_PATH + '/mockup/misc.xml'];
  1253. mxStencilRegistry.libraries['mockup/navigation'] = [SHAPES_PATH + '/mockup/mxMockupNavigation.js', STENCIL_PATH + '/mockup/misc.xml'];
  1254. mxStencilRegistry.libraries['mockup/text'] = [SHAPES_PATH + '/mockup/mxMockupText.js'];
  1255. mxStencilRegistry.libraries['floorplan'] = [SHAPES_PATH + '/mxFloorplan.js', STENCIL_PATH + '/floorplan.xml'];
  1256. mxStencilRegistry.libraries['bootstrap'] = [SHAPES_PATH + '/mxBootstrap.js', STENCIL_PATH + '/bootstrap.xml'];
  1257. mxStencilRegistry.libraries['gmdl'] = [SHAPES_PATH + '/mxGmdl.js', STENCIL_PATH + '/gmdl.xml'];
  1258. mxStencilRegistry.libraries['cabinets'] = [SHAPES_PATH + '/mxCabinets.js', STENCIL_PATH + '/cabinets.xml'];
  1259. mxStencilRegistry.libraries['archimate'] = [SHAPES_PATH + '/mxArchiMate.js'];
  1260. mxStencilRegistry.libraries['archimate3'] = [SHAPES_PATH + '/mxArchiMate3.js'];
  1261. mxStencilRegistry.libraries['sysml'] = [SHAPES_PATH + '/mxSysML.js'];
  1262. mxStencilRegistry.libraries['eip'] = [SHAPES_PATH + '/mxEip.js', STENCIL_PATH + '/eip.xml'];
  1263. mxStencilRegistry.libraries['networks'] = [SHAPES_PATH + '/mxNetworks.js', STENCIL_PATH + '/networks.xml'];
  1264. mxStencilRegistry.libraries['aws3d'] = [SHAPES_PATH + '/mxAWS3D.js', STENCIL_PATH + '/aws3d.xml'];
  1265. mxStencilRegistry.libraries['pid2inst'] = [SHAPES_PATH + '/pid2/mxPidInstruments.js'];
  1266. mxStencilRegistry.libraries['pid2misc'] = [SHAPES_PATH + '/pid2/mxPidMisc.js', STENCIL_PATH + '/pid/misc.xml'];
  1267. mxStencilRegistry.libraries['pid2valves'] = [SHAPES_PATH + '/pid2/mxPidValves.js'];
  1268. mxStencilRegistry.libraries['pidFlowSensors'] = [STENCIL_PATH + '/pid/flow_sensors.xml'];
  1269. // Triggers dynamic loading for markers
  1270. mxMarker.getPackageForType = function(type)
  1271. {
  1272. var name = null;
  1273. if (type != null && type.length > 0)
  1274. {
  1275. if (type.substring(0, 2) == 'ER')
  1276. {
  1277. name = 'mxgraph.er';
  1278. }
  1279. else if (type.substring(0, 5) == 'sysML')
  1280. {
  1281. name = 'mxgraph.sysml';
  1282. }
  1283. }
  1284. return name;
  1285. };
  1286. var mxMarkerCreateMarker = mxMarker.createMarker;
  1287. mxMarker.createMarker = function(canvas, shape, type, pe, unitX, unitY, size, source, sw, filled)
  1288. {
  1289. if (type != null)
  1290. {
  1291. var f = mxMarker.markers[type];
  1292. if (f == null)
  1293. {
  1294. var name = this.getPackageForType(type);
  1295. if (name != null)
  1296. {
  1297. mxStencilRegistry.getStencil(name);
  1298. }
  1299. }
  1300. }
  1301. return mxMarkerCreateMarker.apply(this, arguments);
  1302. };
  1303. /**
  1304. * Constructs a new print dialog.
  1305. */
  1306. PrintDialog.prototype.create = function(editorUi, titleText)
  1307. {
  1308. var graph = editorUi.editor.graph;
  1309. var div = document.createElement('div');
  1310. var title = document.createElement('h3');
  1311. title.style.width = '100%';
  1312. title.style.textAlign = 'center';
  1313. title.style.marginTop = '0px';
  1314. mxUtils.write(title, titleText || mxResources.get('print'));
  1315. div.appendChild(title);
  1316. var pageCount = 1;
  1317. var currentPage = 1;
  1318. // Pages
  1319. var pagesSection = document.createElement('div');
  1320. pagesSection.style.cssText = 'border-bottom:1px solid lightGray;padding-bottom:12px;margin-bottom:12px;';
  1321. var allPagesRadio = document.createElement('input');
  1322. allPagesRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  1323. allPagesRadio.setAttribute('value', 'all');
  1324. allPagesRadio.setAttribute('type', 'radio');
  1325. allPagesRadio.setAttribute('name', 'pages-printdialog');
  1326. pagesSection.appendChild(allPagesRadio);
  1327. var span = document.createElement('span');
  1328. mxUtils.write(span, mxResources.get('printAllPages'));
  1329. pagesSection.appendChild(span);
  1330. mxUtils.br(pagesSection);
  1331. // Pages ... to ...
  1332. var pagesRadio = allPagesRadio.cloneNode(true);
  1333. allPagesRadio.setAttribute('checked', 'checked');
  1334. pagesRadio.setAttribute('value', 'range');
  1335. pagesSection.appendChild(pagesRadio);
  1336. var span = document.createElement('span');
  1337. mxUtils.write(span, mxResources.get('pages') + ':');
  1338. pagesSection.appendChild(span);
  1339. var pagesFromInput = document.createElement('input');
  1340. pagesFromInput.style.cssText = 'margin:0 8px 0 8px;'
  1341. pagesFromInput.setAttribute('value', '1');
  1342. pagesFromInput.setAttribute('type', 'number');
  1343. pagesFromInput.setAttribute('min', '1');
  1344. pagesFromInput.style.width = '50px';
  1345. pagesSection.appendChild(pagesFromInput);
  1346. var span = document.createElement('span');
  1347. mxUtils.write(span, mxResources.get('to'));
  1348. pagesSection.appendChild(span);
  1349. var pagesToInput = pagesFromInput.cloneNode(true);
  1350. pagesSection.appendChild(pagesToInput);
  1351. mxEvent.addListener(pagesFromInput, 'focus', function()
  1352. {
  1353. pagesRadio.checked = true;
  1354. });
  1355. mxEvent.addListener(pagesToInput, 'focus', function()
  1356. {
  1357. pagesRadio.checked = true;
  1358. });
  1359. function validatePageRange()
  1360. {
  1361. pagesToInput.value = Math.max(1, Math.min(pageCount, Math.max(parseInt(pagesToInput.value), parseInt(pagesFromInput.value))));
  1362. pagesFromInput.value = Math.max(1, Math.min(pageCount, Math.min(parseInt(pagesToInput.value), parseInt(pagesFromInput.value))));
  1363. };
  1364. mxEvent.addListener(pagesFromInput, 'change', validatePageRange);
  1365. mxEvent.addListener(pagesToInput, 'change', validatePageRange);
  1366. if (editorUi.pages != null)
  1367. {
  1368. pageCount = editorUi.pages.length;
  1369. if (editorUi.currentPage != null)
  1370. {
  1371. for (var i = 0; i < editorUi.pages.length; i++)
  1372. {
  1373. if (editorUi.currentPage == editorUi.pages[i])
  1374. {
  1375. currentPage = i + 1;
  1376. pagesFromInput.value = currentPage;
  1377. pagesToInput.value = currentPage;
  1378. break;
  1379. }
  1380. }
  1381. }
  1382. }
  1383. pagesFromInput.setAttribute('max', pageCount);
  1384. pagesToInput.setAttribute('max', pageCount);
  1385. if (pageCount > 1)
  1386. {
  1387. div.appendChild(pagesSection);
  1388. }
  1389. // Adjust to ...
  1390. var adjustSection = document.createElement('div');
  1391. adjustSection.style.marginBottom = '10px';
  1392. var adjustRadio = document.createElement('input');
  1393. adjustRadio.style.marginRight = '8px';
  1394. adjustRadio.setAttribute('value', 'adjust');
  1395. adjustRadio.setAttribute('type', 'radio');
  1396. adjustRadio.setAttribute('name', 'printZoom');
  1397. adjustSection.appendChild(adjustRadio);
  1398. var span = document.createElement('span');
  1399. mxUtils.write(span, mxResources.get('adjustTo'));
  1400. adjustSection.appendChild(span);
  1401. var zoomInput = document.createElement('input');
  1402. zoomInput.style.cssText = 'margin:0 8px 0 8px;';
  1403. zoomInput.setAttribute('value', '100 %');
  1404. zoomInput.style.width = '50px';
  1405. adjustSection.appendChild(zoomInput);
  1406. mxEvent.addListener(zoomInput, 'focus', function()
  1407. {
  1408. adjustRadio.checked = true;
  1409. });
  1410. div.appendChild(adjustSection);
  1411. // Fit to ...
  1412. var fitSection = pagesSection.cloneNode(false);
  1413. var fitRadio = adjustRadio.cloneNode(true);
  1414. fitRadio.setAttribute('value', 'fit');
  1415. adjustRadio.setAttribute('checked', 'checked');
  1416. var spanFitRadio = document.createElement('div');
  1417. spanFitRadio.style.cssText = 'display:inline-block;height:100%;vertical-align:top;padding-top:2px;';
  1418. spanFitRadio.appendChild(fitRadio);
  1419. fitSection.appendChild(spanFitRadio);
  1420. var table = document.createElement('table');
  1421. table.style.display = 'inline-block';
  1422. var tbody = document.createElement('tbody');
  1423. var row1 = document.createElement('tr');
  1424. var row2 = row1.cloneNode(true);
  1425. var td1 = document.createElement('td');
  1426. var td2 = td1.cloneNode(true);
  1427. var td3 = td1.cloneNode(true);
  1428. var td4 = td1.cloneNode(true);
  1429. var td5 = td1.cloneNode(true);
  1430. var td6 = td1.cloneNode(true);
  1431. td1.style.textAlign = 'right';
  1432. td4.style.textAlign = 'right';
  1433. mxUtils.write(td1, mxResources.get('fitTo'));
  1434. var sheetsAcrossInput = document.createElement('input');
  1435. sheetsAcrossInput.style.cssText = 'margin:0 8px 0 8px;';
  1436. sheetsAcrossInput.setAttribute('value', '1');
  1437. sheetsAcrossInput.setAttribute('min', '1');
  1438. sheetsAcrossInput.setAttribute('type', 'number');
  1439. sheetsAcrossInput.style.width = '40px';
  1440. td2.appendChild(sheetsAcrossInput);
  1441. var span = document.createElement('span');
  1442. mxUtils.write(span, mxResources.get('fitToSheetsAcross'));
  1443. td3.appendChild(span);
  1444. mxUtils.write(td4, mxResources.get('fitToBy'));
  1445. var sheetsDownInput = sheetsAcrossInput.cloneNode(true);
  1446. td5.appendChild(sheetsDownInput);
  1447. mxEvent.addListener(sheetsAcrossInput, 'focus', function()
  1448. {
  1449. fitRadio.checked = true;
  1450. });
  1451. mxEvent.addListener(sheetsDownInput, 'focus', function()
  1452. {
  1453. fitRadio.checked = true;
  1454. });
  1455. var span = document.createElement('span');
  1456. mxUtils.write(span, mxResources.get('fitToSheetsDown'));
  1457. td6.appendChild(span);
  1458. row1.appendChild(td1);
  1459. row1.appendChild(td2);
  1460. row1.appendChild(td3);
  1461. row2.appendChild(td4);
  1462. row2.appendChild(td5);
  1463. row2.appendChild(td6);
  1464. tbody.appendChild(row1);
  1465. tbody.appendChild(row2);
  1466. table.appendChild(tbody);
  1467. fitSection.appendChild(table);
  1468. div.appendChild(fitSection);
  1469. // Page scale ...
  1470. var pageScaleSection = document.createElement('div');
  1471. var span = document.createElement('div');
  1472. span.style.fontWeight = 'bold';
  1473. span.style.marginBottom = '12px';
  1474. mxUtils.write(span, mxResources.get('paperSize'));
  1475. pageScaleSection.appendChild(span);
  1476. var span = document.createElement('div');
  1477. span.style.marginBottom = '12px';
  1478. var accessor = PageSetupDialog.addPageFormatPanel(span, 'printdialog',
  1479. editorUi.editor.graph.pageFormat || mxConstants.PAGE_FORMAT_A4_PORTRAIT);
  1480. pageScaleSection.appendChild(span);
  1481. var span = document.createElement('span');
  1482. mxUtils.write(span, mxResources.get('pageScale'));
  1483. pageScaleSection.appendChild(span);
  1484. var pageScaleInput = document.createElement('input');
  1485. pageScaleInput.style.cssText = 'margin:0 8px 0 8px;';
  1486. pageScaleInput.setAttribute('value', '100 %');
  1487. pageScaleInput.style.width = '60px';
  1488. pageScaleSection.appendChild(pageScaleInput);
  1489. div.appendChild(pageScaleSection);
  1490. // Buttons
  1491. var buttons = document.createElement('div');
  1492. buttons.style.cssText = 'text-align:right;margin:62px 0 0 0;';
  1493. // Overall scale for print-out to account for print borders in dialogs etc
  1494. function preview(print)
  1495. {
  1496. var printScale = parseInt(pageScaleInput.value) / 100;
  1497. if (isNaN(printScale))
  1498. {
  1499. printScale = 1;
  1500. pageScaleInput.value = '100 %';
  1501. }
  1502. // Workaround to match available paper size in actual print output
  1503. printScale *= 0.75;
  1504. function printGraph(thisGraph, pv, forcePageBreaks)
  1505. {
  1506. // Negative coordinates are cropped or shifted if page visible
  1507. var gb = thisGraph.getGraphBounds();
  1508. var border = 0;
  1509. var x0 = 0;
  1510. var y0 = 0;
  1511. var pf = accessor.get();
  1512. var scale = 1 / thisGraph.pageScale;
  1513. var autoOrigin = fitRadio.checked;
  1514. if (autoOrigin)
  1515. {
  1516. var h = parseInt(sheetsAcrossInput.value);
  1517. var v = parseInt(sheetsDownInput.value);
  1518. scale = Math.min((pf.height * v) / (gb.height / thisGraph.view.scale),
  1519. (pf.width * h) / (gb.width / thisGraph.view.scale));
  1520. }
  1521. else
  1522. {
  1523. scale = parseInt(zoomInput.value) / (100 * thisGraph.pageScale);
  1524. if (isNaN(scale))
  1525. {
  1526. printScale = 1 / thisGraph.pageScale;
  1527. zoomInput.value = '100 %';
  1528. }
  1529. }
  1530. // Applies print scale
  1531. pf = mxRectangle.fromRectangle(pf);
  1532. pf.width = Math.ceil(pf.width * printScale);
  1533. pf.height = Math.ceil(pf.height * printScale);
  1534. scale *= printScale;
  1535. // Starts at first visible page
  1536. if (!autoOrigin && thisGraph.pageVisible)
  1537. {
  1538. var layout = thisGraph.getPageLayout();
  1539. x0 -= layout.x * pf.width;
  1540. y0 -= layout.y * pf.height;
  1541. }
  1542. else
  1543. {
  1544. autoOrigin = true;
  1545. }
  1546. if (pv == null)
  1547. {
  1548. pv = PrintDialog.createPrintPreview(thisGraph, scale, pf, border, x0, y0, autoOrigin);
  1549. pv.pageSelector = false;
  1550. pv.mathEnabled = false;
  1551. var file = editorUi.getCurrentFile();
  1552. if (file != null)
  1553. {
  1554. pv.title = file.getTitle();
  1555. }
  1556. var writeHead = pv.writeHead;
  1557. // Overridden to add custom fonts
  1558. pv.writeHead = function(doc)
  1559. {
  1560. writeHead.apply(this, arguments);
  1561. if (editorUi.editor.fontCss != null)
  1562. {
  1563. doc.writeln('<style type="text/css">');
  1564. doc.writeln(editorUi.editor.fontCss);
  1565. doc.writeln('</style>');
  1566. }
  1567. };
  1568. if (typeof(MathJax) !== 'undefined')
  1569. {
  1570. // Adds class to ignore if math is disabled
  1571. var printPreviewRenderPage = pv.renderPage;
  1572. pv.renderPage = function(w, h, dx, dy, content, pageNumber)
  1573. {
  1574. var result = printPreviewRenderPage.apply(this, arguments);
  1575. if (this.graph.mathEnabled)
  1576. {
  1577. this.mathEnabled = true;
  1578. }
  1579. else
  1580. {
  1581. result.className = 'geDisableMathJax';
  1582. }
  1583. return result;
  1584. };
  1585. }
  1586. pv.open(null, null, forcePageBreaks, true);
  1587. }
  1588. else
  1589. {
  1590. var bg = thisGraph.background;
  1591. if (bg == null || bg == '' || bg == mxConstants.NONE)
  1592. {
  1593. bg = '#ffffff';
  1594. }
  1595. pv.backgroundColor = bg;
  1596. pv.autoOrigin = autoOrigin;
  1597. pv.appendGraph(thisGraph, scale, x0, y0, forcePageBreaks, true);
  1598. }
  1599. return pv;
  1600. };
  1601. var pagesFrom = pagesFromInput.value;
  1602. var pagesTo = pagesToInput.value;
  1603. var ignorePages = !allPagesRadio.checked;
  1604. var pv = null;
  1605. if (ignorePages)
  1606. {
  1607. ignorePages = pagesFrom == currentPage && pagesTo == currentPage;
  1608. }
  1609. if (!ignorePages && editorUi.pages != null && editorUi.pages.length)
  1610. {
  1611. var i0 = 0;
  1612. var imax = editorUi.pages.length - 1;
  1613. if (!allPagesRadio.checked)
  1614. {
  1615. i0 = parseInt(pagesFrom) - 1;
  1616. imax = parseInt(pagesTo) - 1;
  1617. }
  1618. for (var i = i0; i <= imax; i++)
  1619. {
  1620. var page = editorUi.pages[i];
  1621. var tempGraph = (page == editorUi.currentPage) ? graph : null;
  1622. if (tempGraph == null)
  1623. {
  1624. tempGraph = editorUi.createTemporaryGraph(graph.getStylesheet());
  1625. // Restores graph settings that are relevant for printing
  1626. var pageVisible = true;
  1627. var mathEnabled = false;
  1628. var bg = null;
  1629. var bgImage = null;
  1630. if (page.viewState == null && page.mapping == null)
  1631. {
  1632. // Workaround to extract view state from XML node
  1633. // This changes the state of the page and parses
  1634. // the XML for the graph model even if not needed.
  1635. if (page.root == null)
  1636. {
  1637. editorUi.updatePageRoot(page);
  1638. }
  1639. }
  1640. if (page.viewState != null)
  1641. {
  1642. pageVisible = page.viewState.pageVisible;
  1643. mathEnabled = page.viewState.mathEnabled;
  1644. bg = page.viewState.background;
  1645. bgImage = page.viewState.backgroundImage;
  1646. }
  1647. else if (page.mapping != null && page.mapping.diagramMap != null)
  1648. {
  1649. // Default pageVisible in realtime is true
  1650. mathEnabled = page.mapping.diagramMap.get('mathEnabled') != '0';
  1651. bg = page.mapping.diagramMap.get('background');
  1652. var temp = page.mapping.diagramMap.get('backgroundImage');
  1653. bgImage = (temp != null && temp.length > 0) ? JSON.parse(temp) : null;
  1654. }
  1655. tempGraph.background = bg;
  1656. tempGraph.backgroundImage = (bgImage != null) ? new mxImage(bgImage.src, bgImage.width, bgImage.height) : null;
  1657. tempGraph.pageVisible = pageVisible;
  1658. tempGraph.mathEnabled = mathEnabled;
  1659. // Redirects placeholders to current page
  1660. var graphGetGlobalVariable = tempGraph.getGlobalVariable;
  1661. tempGraph.getGlobalVariable = function(name)
  1662. {
  1663. if (name == 'page')
  1664. {
  1665. return page.getName();
  1666. }
  1667. else if (name == 'pagenumber')
  1668. {
  1669. return i + 1;
  1670. }
  1671. return graphGetGlobalVariable.apply(this, arguments);
  1672. };
  1673. document.body.appendChild(tempGraph.container);
  1674. editorUi.updatePageRoot(page);
  1675. tempGraph.model.setRoot(page.root);
  1676. }
  1677. pv = printGraph(tempGraph, pv, i != imax);
  1678. if (tempGraph != graph)
  1679. {
  1680. tempGraph.container.parentNode.removeChild(tempGraph.container);
  1681. }
  1682. }
  1683. }
  1684. else
  1685. {
  1686. pv = printGraph(graph);
  1687. }
  1688. if (pv.mathEnabled)
  1689. {
  1690. var doc = pv.wnd.document;
  1691. doc.writeln('<script type="text/x-mathjax-config">');
  1692. doc.writeln('MathJax.Hub.Config({');
  1693. doc.writeln('messageStyle: "none",');
  1694. doc.writeln('jax: ["input/TeX", "input/MathML", "input/AsciiMath", "output/HTML-CSS"],');
  1695. doc.writeln('extensions: ["tex2jax.js", "mml2jax.js", "asciimath2jax.js"],');
  1696. doc.writeln('TeX: {');
  1697. doc.writeln('extensions: ["AMSmath.js", "AMSsymbols.js", "noErrors.js", "noUndefined.js"]');
  1698. doc.writeln('},');
  1699. // Ignores math in in-place editor
  1700. doc.writeln('tex2jax: {');
  1701. doc.writeln(' ignoreClass: "geDisableMathJax"');
  1702. doc.writeln('},');
  1703. doc.writeln('asciimath2jax: {');
  1704. doc.writeln(' ignoreClass: "geDisableMathJax"');
  1705. doc.writeln('}');
  1706. doc.writeln('});');
  1707. // Adds asynchronous printing when MathJax finished rendering
  1708. if (print)
  1709. {
  1710. doc.writeln('MathJax.Hub.Queue(function () {');
  1711. doc.writeln('window.print();');
  1712. doc.writeln('});');
  1713. }
  1714. doc.writeln('</script>');
  1715. doc.writeln('<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>');
  1716. }
  1717. pv.closeDocument();
  1718. if (!pv.mathEnabled && print)
  1719. {
  1720. PrintDialog.printPreview(pv);
  1721. }
  1722. };
  1723. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1724. {
  1725. editorUi.hideDialog();
  1726. });
  1727. cancelBtn.className = 'geBtn';
  1728. if (editorUi.editor.cancelFirst)
  1729. {
  1730. buttons.appendChild(cancelBtn);
  1731. }
  1732. if (!editorUi.isOffline())
  1733. {
  1734. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  1735. {
  1736. window.open('https://desk.draw.io/support/solutions/articles/16000048947');
  1737. });
  1738. helpBtn.className = 'geBtn';
  1739. buttons.appendChild(helpBtn);
  1740. }
  1741. if (PrintDialog.previewEnabled)
  1742. {
  1743. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  1744. {
  1745. editorUi.hideDialog();
  1746. preview(false);
  1747. });
  1748. previewBtn.className = 'geBtn';
  1749. buttons.appendChild(previewBtn);
  1750. }
  1751. var printBtn = mxUtils.button(mxResources.get((!PrintDialog.previewEnabled) ? 'ok' : 'print'), function()
  1752. {
  1753. editorUi.hideDialog();
  1754. preview(true);
  1755. });
  1756. printBtn.className = 'geBtn gePrimaryBtn';
  1757. buttons.appendChild(printBtn);
  1758. if (!editorUi.editor.cancelFirst)
  1759. {
  1760. buttons.appendChild(cancelBtn);
  1761. }
  1762. div.appendChild(buttons);
  1763. this.container = div;
  1764. };
  1765. })();
  1766. /**
  1767. * Change types
  1768. */
  1769. function ChangeShadow(ui, visible)
  1770. {
  1771. this.ui = ui;
  1772. this.visible = visible;
  1773. this.previous = this.visible;
  1774. }
  1775. /**
  1776. * Implementation of the undoable page rename.
  1777. */
  1778. ChangeShadow.prototype.execute = function()
  1779. {
  1780. this.visible = this.previous;
  1781. this.previous = this.ui.editor.graph.shadowVisible;
  1782. this.ui.editor.graph.setShadowVisible(this.visible);
  1783. };
  1784. //Registers codec for ChangePageSetup
  1785. (function()
  1786. {
  1787. var codec = new mxObjectCodec(new ChangeShadow(), ['ui', 'previous']);
  1788. /**
  1789. * Function: afterDecode
  1790. *
  1791. * Restores the state by assigning the previous value.
  1792. */
  1793. codec.afterDecode = function(dec, node, obj)
  1794. {
  1795. obj.previous = obj.visible;
  1796. return obj;
  1797. };
  1798. mxCodecRegistry.register(codec);
  1799. })();