Editor.js 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098
  1. /**
  2. * Copyright (c) 2006-2012, JGraph Ltd
  3. */
  4. /**
  5. * Editor constructor executed on page load.
  6. */
  7. Editor = function(chromeless, themes, model, graph)
  8. {
  9. mxEventSource.call(this);
  10. this.chromeless = (chromeless != null) ? chromeless : this.chromeless;
  11. this.initStencilRegistry();
  12. this.graph = graph || this.createGraph(themes, model);
  13. this.undoManager = this.createUndoManager();
  14. this.status = '';
  15. this.getOrCreateFilename = function()
  16. {
  17. return this.filename || mxResources.get('drawing', [Editor.pageCounter]) + '.xml';
  18. };
  19. this.getFilename = function()
  20. {
  21. return this.filename;
  22. };
  23. // Sets the status and fires a statusChanged event
  24. this.setStatus = function(value)
  25. {
  26. this.status = value;
  27. this.fireEvent(new mxEventObject('statusChanged'));
  28. };
  29. // Returns the current status
  30. this.getStatus = function()
  31. {
  32. return this.status;
  33. };
  34. // Updates modified state if graph changes
  35. this.graphChangeListener = function(sender, eventObject)
  36. {
  37. var edit = (eventObject != null) ? eventObject.getProperty('edit') : null;
  38. if (edit == null || !edit.ignoreEdit)
  39. {
  40. this.setModified(true);
  41. }
  42. };
  43. this.graph.getModel().addListener(mxEvent.CHANGE, mxUtils.bind(this, function()
  44. {
  45. this.graphChangeListener.apply(this, arguments);
  46. }));
  47. // Sets persistent graph state defaults
  48. this.graph.resetViewOnRootChange = false;
  49. this.init();
  50. };
  51. /**
  52. * Counts open editor tabs (must be global for cross-window access)
  53. */
  54. Editor.pageCounter = 0;
  55. // Cross-domain window access is not allowed in FF, so if we
  56. // were opened from another domain then this will fail.
  57. (function()
  58. {
  59. try
  60. {
  61. var op = window;
  62. while (op.opener != null && typeof op.opener.Editor !== 'undefined' &&
  63. !isNaN(op.opener.Editor.pageCounter) &&
  64. // Workaround for possible infinite loop in FF https://drawio.atlassian.net/browse/DS-795
  65. op.opener != op)
  66. {
  67. op = op.opener;
  68. }
  69. // Increments the counter in the first opener in the chain
  70. if (op != null)
  71. {
  72. op.Editor.pageCounter++;
  73. Editor.pageCounter = op.Editor.pageCounter;
  74. }
  75. }
  76. catch (e)
  77. {
  78. // ignore
  79. }
  80. })();
  81. /**
  82. * Specifies if local storage should be used (eg. on the iPad which has no filesystem)
  83. */
  84. Editor.useLocalStorage = typeof(Storage) != 'undefined' && mxClient.IS_IOS;
  85. /**
  86. * Images below are for lightbox and embedding toolbars.
  87. */
  88. Editor.helpImage = (mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAXVBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC5BxTwAAAAH3RSTlMAlUF8boNQIE0LBgOgkGlHNSwqFIx/dGVUOjApmV9ezNACSAAAAIVJREFUGNNtjNsOgzAMQ5NeoVcKDAZs+//PXLKI8YKlWvaRU7jXuFpb9qsbdK05XILUiE8JHQox1Pv3OgFUzf1AGqWqUg+QBwLF0YAeegBlCNgRWOpB5vUfTCmeoHQ/wNdy0jLH/cM+b+wLTw4n/7ACEmHVVy8h6qy8V7MNcGowWpsNbvUFcGUEdSi1s/oAAAAASUVORK5CYII=' :
  89. IMAGE_PATH + '/help.png';
  90. /**
  91. * Sets the default font size.
  92. */
  93. Editor.checkmarkImage = (mxClient.IS_SVG) ? 'data:image/gif;base64,R0lGODlhFQAVAMQfAGxsbHx8fIqKioaGhvb29nJycvr6+sDAwJqamltbW5OTk+np6YGBgeTk5Ly8vJiYmP39/fLy8qWlpa6ursjIyOLi4vj4+N/f3+3t7fT09LCwsHZ2dubm5r6+vmZmZv///yH/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS4wLWMwNjAgNjEuMTM0Nzc3LCAyMDEwLzAyLzEyLTE3OjMyOjAwICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6OEY4NTZERTQ5QUFBMTFFMUE5MTVDOTM5MUZGMTE3M0QiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6OEY4NTZERTU5QUFBMTFFMUE5MTVDOTM5MUZGMTE3M0QiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4Rjg1NkRFMjlBQUExMUUxQTkxNUM5MzkxRkYxMTczRCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4Rjg1NkRFMzlBQUExMUUxQTkxNUM5MzkxRkYxMTczRCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PgH//v38+/r5+Pf29fTz8vHw7+7t7Ovq6ejn5uXk4+Lh4N/e3dzb2tnY19bV1NPS0dDPzs3My8rJyMfGxcTDwsHAv769vLu6ubi3trW0s7KxsK+urayrqqmop6alpKOioaCfnp2cm5qZmJeWlZSTkpGQj46NjIuKiYiHhoWEg4KBgH9+fXx7enl4d3Z1dHNycXBvbm1sa2ppaGdmZWRjYmFgX15dXFtaWVhXVlVUU1JRUE9OTUxLSklIR0ZFRENCQUA/Pj08Ozo5ODc2NTQzMjEwLy4tLCsqKSgnJiUkIyIhIB8eHRwbGhkYFxYVFBMSERAPDg0MCwoJCAcGBQQDAgEAACH5BAEAAB8ALAAAAAAVABUAAAVI4CeOZGmeaKqubKtylktSgCOLRyLd3+QJEJnh4VHcMoOfYQXQLBcBD4PA6ngGlIInEHEhPOANRkaIFhq8SuHCE1Hb8Lh8LgsBADs=' :
  94. IMAGE_PATH + '/checkmark.gif';
  95. /**
  96. * Images below are for lightbox and embedding toolbars.
  97. */
  98. Editor.maximizeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVBAMAAABbObilAAAAElBMVEUAAAAAAAAAAAAAAAAAAAAAAADgKxmiAAAABXRSTlMA758vX1Pw3BoAAABJSURBVAjXY8AJQkODGBhUQ0MhbAUGBiYY24CBgRnGFmZgMISwgwwDGRhEhVVBbAVmEQYGRwMmBjIAQi/CTIRd6G5AuA3dzYQBAHj0EFdHkvV4AAAAAElFTkSuQmCC';
  99. /**
  100. * Specifies the image URL to be used for the transparent background.
  101. */
  102. Editor.zoomOutImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVBAMAAABbObilAAAAElBMVEUAAAAAAAAsLCxxcXEhISFgYGChjTUxAAAAAXRSTlMAQObYZgAAAEdJREFUCNdjIAMwCQrB2YKCggJQJqMwA7MglK1owMBgqABVApITgLJZXFxgbIQ4Qj3CHIT5ggoIe5kgNkM1KSDYKBKqxPkDAPo5BAZBE54hAAAAAElFTkSuQmCC';
  103. /**
  104. * Specifies the image URL to be used for the transparent background.
  105. */
  106. Editor.zoomInImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVBAMAAABbObilAAAAElBMVEUAAAAAAAAsLCwhISFxcXFgYGBavKaoAAAAAXRSTlMAQObYZgAAAElJREFUCNdjIAMwCQrB2YKCggJQJqMIA4sglK3owMzgqABVwsDMwCgAZTMbG8PYCHGEeoQ5CPMFFRD2MkFshmpSQLBRJFSJ8wcAEqcEM2uhl2MAAAAASUVORK5CYII=';
  107. /**
  108. * Specifies the image URL to be used for the transparent background.
  109. */
  110. Editor.zoomFitImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVBAMAAABbObilAAAAD1BMVEUAAAAAAAAwMDBwcHBgYGC1xl09AAAAAXRSTlMAQObYZgAAAEFJREFUCNdjIAMwCQrB2YKCggJQJqMwA7MglK1owMBgqABVApITwMdGqEeYgzBfUAFhLxPEZqgmBQQbRUKFOH8AAK5OA3lA+FFOAAAAAElFTkSuQmCC';
  111. /**
  112. * Specifies the image URL to be used for the transparent background.
  113. */
  114. Editor.layersImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVCAMAAACeyVWkAAAAaVBMVEUAAAAgICAICAgdHR0PDw8WFhYICAgLCwsXFxcvLy8ODg4uLi4iIiIqKiokJCQYGBgKCgonJycFBQUCAgIqKiocHBwcHBwODg4eHh4cHBwnJycJCQkUFBQqKiojIyMuLi4ZGRkgICAEBATOWYXAAAAAGnRSTlMAD7+fnz8/H7/ff18/77+vr5+fn39/b28fH2xSoKsAAACQSURBVBjTrYxJEsMgDARZZMAY73sgCcn/HxnhKtnk7j6oRq0psfuoyndZ/SuODkHPLzfVT6KeyPePnJ7KrnkRjWMXTn4SMnN8mXe2SSM3ts8L/ZUxxrbAULSYJJULE0Iw9pjpenoICcgcX61mGgTgtCv9Be99pzCoDhNQWQnchD1mup5++CYGcoQexajZbfwAj/0MD8ZOaUgAAAAASUVORK5CYII=';
  115. /**
  116. * Specifies the image URL to be used for the transparent background.
  117. */
  118. Editor.previousImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP+gvaeTAAAAh0lEQVQ4je3UsQnCUBCA4U8hpa1NsoEjpHQJS0dxADdwEMuMIJkgA1hYChbGQgMi+JC8q4L/AB/vDu7x74cWWEZhJU44RmA1zujR5GIbXF9YNrjD/Q0bDRY4fEBZ4P4LlgTnCbAf84pUM8/9hY08tMUtEoQ1LpEgrNBFglChFXR6Q6GfwwR6AGKJMF74Vtt3AAAAAElFTkSuQmCC';
  119. /**
  120. * Specifies the image URL to be used for the transparent background.
  121. */
  122. Editor.nextImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP+gvaeTAAAAi0lEQVQ4jeXUIQ7CUAwA0MeGxWI2yylwnALJUdBcgYvM7QYLmjOQIAkIPmJZghiIvypoUtX0tfnJL38X5ZfaEgUeUcManFBHgS0SLlhHggk3bCPBhCf2keCQR8wjwYTDp6YiZxJmOU1jGw7vGALescuBxsArNlOwd/CM1VSM/ut1qCIw+uOwiMJ+OF4CQzBCXm3hyAAAAABJRU5ErkJggg==';
  123. /**
  124. * Specifies the image URL to be used for the transparent background.
  125. */
  126. Editor.zoomOutLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAilBMVEUAAAD////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////2N2iNAAAALXRSTlMA+vTcKMM96GRBHwXxi0YaX1HLrKWhiHpWEOnOr52Vb2xKSDcT19PKv5l/Ngdk8+viAAABJklEQVQ4y4WT2XaDMAxEvWD2nSSUNEnTJN3r//+9Sj7ILAY6L0ijC4ONYVZRpo6cByrz2YKSUGorGTpz71lPVHvT+avoB5wIkU/mxk8veceSuNoLg44IzziXjvpih72wKQnm8yc2UoiP/LAd8jQfe2Xf4Pq+2EyYIvv9wbzHHCgwxDdlBtWZOdqDfTCVgqpygQpsZaojVAVc9UjQxnAJDIBhiQv84tq3gMQCAVTxVoSibXJf8tMuc7e1TB/DCmejBNg/w1Y3c+AM5vv4w7xM59/oXamrHaLVqPQ+OTCnmMZxgz0SdL5zji0/ld6j88qGa5KIiBB6WeJGKfUKwSMKLuXgvl1TW0tm5R9UQL/efSDYsnzxD8CinhBsTTdugJatKpJwf8v+ADb8QmvW7AeAAAAAAElFTkSuQmCC';
  127. /**
  128. * Specifies the image URL to be used for the transparent background.
  129. */
  130. Editor.zoomInLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAilBMVEUAAAD////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////2N2iNAAAALXRSTlMA+vTcKMM96GRBHwXxi0YaX1HLrKWhiHpWEOnOr52Vb2xKSDcT19PKv5l/Ngdk8+viAAABKElEQVQ4y4WT6WKCMBCENwkBwn2oFKvWqr3L+79es4EkQIDOH2d3Pxk2ABiJlB8JCXjqw4LikHVGLHTm3nM3UeVN5690GBBN0GwyV/3kkrUQR+WeKnREeKpzaXWd77CmJiXGfPIEI4V4yQ9TIW/ntlcMBe731Vts9w5TWG8F5j3mQI4hvrKpdGeYA7CX9qAcl650gVJartxRuhyHVghF8idQAIbFLvCLu28BsQEC6aKtCK6Pyb3JT7PmbmtNH8Ny56CotD/2qOs5cJbuffxgXmCib+xddVU5RNOhkvvkhTlFehzVWCOh3++MYElOhfdovaImnRYVmqDdsuhNp1QrBBE6uGC2+3ZNjGdg5B94oD+9uyVgWT79BwAxEBTWdOu3bWBVgsn/N/AHUD9IC01Oe40AAAAASUVORK5CYII=';
  131. /**
  132. * Specifies the image URL to be used for the transparent background.
  133. */
  134. Editor.actualSizeLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAilBMVEUAAAD////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////2N2iNAAAALXRSTlMA+vTcKMM96GRBHwXxi0YaX1HLrKWhiHpWEOnOr52Vb2xKSDcT19PKv5l/Ngdk8+viAAABIUlEQVQ4y4WT2XqDIBCFBxDc9yTWNEnTJN3r+79eGT4BEbXnaubMr8dBBaM450dCQp4LWFAascGIRd48eB4cNYE7f6XjgGiCFs5c+dml6CFN6j1V6IQIlHPpdV/usKcmJcV88gQTRXjLD9Mhb+fWq8YG9/uCmTCFjeeDeY85UGKIUGUuqzN42kv7oCouq9oHamlzVR1lVfpAIu1QVRiW+sAv7r4FpAYIZZVsRXB9TP5Dfpo1d1trCgzz1iiptH/sUbdz4CzN9+mLeXHn3+hdddd4RDegsrvzwZwSs2GLPRJidAqCLTlVwaMPqpYMWjTWBB2WRW86pVkhSKyDK2bdt2tmagZG4sBD/evdLQHLEvQfAOKRoLCmG1FAB6uKmby+gz+REDn7O5+EwQAAAABJRU5ErkJggg==';
  135. /**
  136. * Specifies the image URL to be used for the transparent background.
  137. */
  138. Editor.printLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAXVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////9RKvvlAAAAHnRSTlMAydnl77qbMLT093H7K4Nd4Ktn082+lYt5bkklEgP44nQSAAAApUlEQVQ4y73P2Q6DIBRF0cOgbRHHzhP//5m9mBAQKjG1cT0Yc7ITAMu1LNQgUZiQ2DYoNQ0sCQb6qgHAfRx48opq3J9AZ6xuF7uOew8Ik1OsCZRS2UAC9V+D9a+QZYxNA45YFQftPtSkATOhw7dAc0vPBwKWiIOjP0JZ0yMuQJ27g36DipOUsqRAM0dR8KD1/ILHaHSE/w8DIx09E3g/BTce6rHUB5sAPKvfF+JdAAAAAElFTkSuQmCC';
  139. /**
  140. * Specifies the image URL to be used for the transparent background.
  141. */
  142. Editor.layersLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAmVBMVEUAAAD////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+/v7///+bnZkkAAAAMnRSTlMABPr8ByiD88KsTi/rvJb272mjeUA1CuPe1M/KjVxYHxMP6KZ0S9nYzGRGGRaznpGIbzaGUf0AAAHESURBVDjLbZLZYoIwEEVDgLCjbKIgAlqXqt3m/z+uNwu1rcyDhjl3ktnYL7OY254C0VX3yWFZfzDrOClbbgKxi0YDHjwl4jbnRkXxJS/C1YP3DbBhD1n7Ex4uaAqdVDb3yJ/4J/3nJD2to/ngQz/DfUvzMp4JJ5sSCaF5oXmemgQDfDxzbi+Kq4sU+vNcuAmx94JtyOP2DD4Epz2asWSCz4Z/4fECxyNj9zC9xNLHcdPEO+awDKeSaUu0W4twZQiO2hYVisTR3RCtK/c1X6t4xMEpiGqXqVntEBLolkZZsKY4QtwH6jzq67dEHlJysB1aNOD3XT7n1UkasQN59L4yC2RELMDSeCRtz3yV22Ub3ozIUTknYx8JWqDdQxbUes98cR2kZtUSveF/bAhcedwEWmlxIkpZUy4XOCb6VBjjxHvbwo/1lBAHHi2JCr0NI570QhyHq/DhJoE2lLgyA4RVe6KmZ47O/3b86MCP0HWa73A8/C3SUc5Qc1ajt6fgpXJ+RGpMvDSchepZDOOQRcZVIKcK90x2D7etqtI+56+u6n3sPriO6nfphitR4+O2m3EbM7lh3me1FM1o+LMI887rN+s3/wZdTFlpNVJiOAAAAABJRU5ErkJggg==';
  143. /**
  144. * Specifies the image URL to be used for the transparent background.
  145. */
  146. Editor.closeLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAUVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////8IN+deAAAAGnRSTlMAuvAIg/dDM/QlOeuFhj0S5s4vKgzjxJRQNiLSey0AAADNSURBVDjLfZLbEoMgDEQjRRRs1XqX///QNmOHJSnjPkHOGR7IEmeoGtJZstnwjqbRfIsmgEdtPCqe9Ynz7ZSc07rE2QiSc+qv8TvjRXA2PDUm3dpe82iJhOEUfxJJo3aCv+jKmRmH4lcCjCjeh9GWOdL/GZZkXH3PYYDrHBnfc4D/RVZf5sjoC1was+Y6HQxwaUxFvq/a0Pv343VCTxfBSRiB+ab3M3eiQZXmMNBJ3Y8pGRZtYQ7DgHMXJEdPLTaN/qBjzJOBc3nmNcbsA16bMR0oLqf+AAAAAElFTkSuQmCC';
  147. /**
  148. * Specifies the image URL to be used for the transparent background.
  149. */
  150. Editor.editLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAgMAAAAOFJJnAAAACVBMVEUAAAD///////9zeKVjAAAAAnRSTlMAgJsrThgAAABcSURBVBjThc6xDcAgDATAd8MQTEPW8TRUmYCGnzLRYyOlIV+dZFtvkICTFGqiJEzAG0/Uje9oL+e5Vu4F5yUYJxxqGKhQZ0eBvmgwYQLQaARKD1hbiPyDR0QOeAC31EyNe5X/kAAAAABJRU5ErkJggg==';
  151. /**
  152. * Specifies the image URL to be used for the transparent background.
  153. */
  154. Editor.previousLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAPFBMVEUAAAD////////////////////////////////////////////////////////////////////////////YSWgTAAAAE3RSTlMA7fci493c0MW8uJ6CZks4MxQHEZL6ewAAAFZJREFUOMvdkskRgDAMA4lDwg2B7b9XOlge/KKvdsa25KFb5XlRvxXC/DNBEv8IFNjBgGdDgXtFgTyhwDXiQAUHCvwa4Uv6mR6UR+1led2mVonvl+tML45qCQNQLIx7AAAAAElFTkSuQmCC';
  155. /**
  156. * Specifies the image URL to be used for the transparent background.
  157. */
  158. Editor.nextLargeImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAPFBMVEUAAAD////////////////////////////////////////////////////////////////////////////YSWgTAAAAE3RSTlMA7fci493c0MW8uJ6CZks4MxQHEZL6ewAAAFRJREFUOMvd0skRgCAQBVEFwQ0V7fxzNQP6wI05v6pZ/kyj1b7FNgik2gQzzLcAwiUAigHOTwDHK4A1CmB5BJANJG1hQ9qafYcqFlZP3IFc9eVGrR+iIgkDQRUXIAAAAABJRU5ErkJggg==';
  159. // Editor inherits from mxEventSource
  160. mxUtils.extend(Editor, mxEventSource);
  161. /**
  162. * Stores initial state of mxClient.NO_FO.
  163. */
  164. Editor.prototype.originalNoForeignObject = mxClient.NO_FO;
  165. /**
  166. * Specifies the image URL to be used for the transparent background.
  167. */
  168. Editor.prototype.transparentImage = (mxClient.IS_SVG) ? 'data:image/gif;base64,R0lGODlhMAAwAIAAAP///wAAACH5BAEAAAAALAAAAAAwADAAAAIxhI+py+0Po5y02ouz3rz7D4biSJbmiabqyrbuC8fyTNf2jef6zvf+DwwKh8Si8egpAAA7' :
  169. IMAGE_PATH + '/transparent.gif';
  170. /**
  171. * Specifies if the canvas should be extended in all directions. Default is true.
  172. */
  173. Editor.prototype.extendCanvas = true;
  174. /**
  175. * Specifies if the app should run in chromeless mode. Default is false.
  176. * This default is only used if the contructor argument is null.
  177. */
  178. Editor.prototype.chromeless = false;
  179. /**
  180. * Specifies the order of OK/Cancel buttons in dialogs. Default is true.
  181. * Cancel first is used on Macs, Windows/Confluence uses cancel last.
  182. */
  183. Editor.prototype.cancelFirst = true;
  184. /**
  185. * Specifies if the editor is enabled. Default is true.
  186. */
  187. Editor.prototype.enabled = true;
  188. /**
  189. * Contains the name which was used for the last save. Default value is null.
  190. */
  191. Editor.prototype.filename = null;
  192. /**
  193. * Contains the current modified state of the diagram. This is false for
  194. * new diagrams and after the diagram was saved.
  195. */
  196. Editor.prototype.modified = false;
  197. /**
  198. * Specifies if the diagram should be saved automatically if possible. Default
  199. * is true.
  200. */
  201. Editor.prototype.autosave = true;
  202. /**
  203. * Specifies the top spacing for the initial page view. Default is 0.
  204. */
  205. Editor.prototype.initialTopSpacing = 0;
  206. /**
  207. * Specifies the app name. Default is document.title.
  208. */
  209. Editor.prototype.appName = document.title;
  210. /**
  211. *
  212. */
  213. Editor.prototype.editBlankUrl = window.location.protocol + '//' + window.location.host + '/?client=1';
  214. /**
  215. *
  216. */
  217. Editor.prototype.editBlankFallbackUrl = window.location.protocol + '//' + window.location.host + '/?create=drawdata&splash=0';
  218. /**
  219. * Initializes the environment.
  220. */
  221. Editor.prototype.init = function() { };
  222. /**
  223. * Sets the XML node for the current diagram.
  224. */
  225. Editor.prototype.setAutosave = function(value)
  226. {
  227. this.autosave = value;
  228. this.fireEvent(new mxEventObject('autosaveChanged'));
  229. };
  230. /**
  231. *
  232. */
  233. Editor.prototype.getEditBlankUrl = function(params, fallback)
  234. {
  235. return ((fallback) ? this.editBlankFallbackUrl : this.editBlankUrl) + params;
  236. }
  237. /**
  238. *
  239. */
  240. Editor.prototype.editAsNew = function(xml, title)
  241. {
  242. var p = (title != null) ? '&title=' + encodeURIComponent(title) : '';
  243. if (typeof window.postMessage !== 'undefined' && (document.documentMode == null || document.documentMode >= 10))
  244. {
  245. var wnd = null;
  246. var receive = mxUtils.bind(this, function(evt)
  247. {
  248. if (evt.data == 'ready' && evt.source == wnd)
  249. {
  250. wnd.postMessage(xml, '*');
  251. mxEvent.removeListener(window, 'message', receive);
  252. }
  253. });
  254. mxEvent.addListener(window, 'message', receive);
  255. wnd = window.open(this.getEditBlankUrl(p, false));
  256. }
  257. else
  258. {
  259. // Data is pulled from global variable after tab loads
  260. window.drawdata = xml;
  261. window.open(this.getEditBlankUrl(p, true));
  262. }
  263. };
  264. /**
  265. * Sets the XML node for the current diagram.
  266. */
  267. Editor.prototype.createGraph = function(themes, model)
  268. {
  269. var graph = new Graph(null, model, null, null, themes);
  270. graph.transparentBackground = false;
  271. // Opens all links in a new window while editing
  272. if (!this.chromeless)
  273. {
  274. graph.isBlankLink = function(href)
  275. {
  276. return !this.isExternalProtocol(href);
  277. };
  278. }
  279. return graph;
  280. };
  281. /**
  282. * Sets the XML node for the current diagram.
  283. */
  284. Editor.prototype.resetGraph = function()
  285. {
  286. this.graph.gridEnabled = !this.chromeless || urlParams['grid'] == '1';
  287. this.graph.graphHandler.guidesEnabled = true;
  288. this.graph.setTooltips(true);
  289. this.graph.setConnectable(true);
  290. this.graph.foldingEnabled = true;
  291. this.graph.scrollbars = this.graph.defaultScrollbars;
  292. this.graph.pageVisible = this.graph.defaultPageVisible;
  293. this.graph.pageBreaksVisible = this.graph.pageVisible;
  294. this.graph.preferPageSize = this.graph.pageBreaksVisible;
  295. this.graph.background = this.graph.defaultGraphBackground;
  296. this.graph.pageScale = mxGraph.prototype.pageScale;
  297. this.graph.pageFormat = mxGraph.prototype.pageFormat;
  298. this.updateGraphComponents();
  299. this.graph.view.setScale(1);
  300. };
  301. /**
  302. * Sets the XML node for the current diagram.
  303. */
  304. Editor.prototype.readGraphState = function(node)
  305. {
  306. this.graph.gridEnabled = node.getAttribute('grid') != '0' && (!this.chromeless || urlParams['grid'] == '1');
  307. this.graph.gridSize = parseFloat(node.getAttribute('gridSize')) || mxGraph.prototype.gridSize;
  308. this.graph.graphHandler.guidesEnabled = node.getAttribute('guides') != '0';
  309. this.graph.setTooltips(node.getAttribute('tooltips') != '0');
  310. this.graph.setConnectable(node.getAttribute('connect') != '0');
  311. this.graph.connectionArrowsEnabled = node.getAttribute('arrows') != '0';
  312. this.graph.foldingEnabled = node.getAttribute('fold') != '0';
  313. if (this.chromeless && this.graph.foldingEnabled)
  314. {
  315. this.graph.foldingEnabled = urlParams['nav'] == '1';
  316. this.graph.cellRenderer.forceControlClickHandler = this.graph.foldingEnabled;
  317. }
  318. var ps = node.getAttribute('pageScale');
  319. if (ps != null)
  320. {
  321. this.graph.pageScale = ps;
  322. }
  323. else
  324. {
  325. this.graph.pageScale = mxGraph.prototype.pageScale;
  326. }
  327. if (!this.graph.lightbox)
  328. {
  329. var pv = node.getAttribute('page');
  330. if (pv != null)
  331. {
  332. this.graph.pageVisible = (pv != '0');
  333. }
  334. else
  335. {
  336. this.graph.pageVisible = this.graph.defaultPageVisible;
  337. }
  338. }
  339. else
  340. {
  341. this.graph.pageVisible = false;
  342. }
  343. this.graph.pageBreaksVisible = this.graph.pageVisible;
  344. this.graph.preferPageSize = this.graph.pageBreaksVisible;
  345. var pw = node.getAttribute('pageWidth');
  346. var ph = node.getAttribute('pageHeight');
  347. if (pw != null && ph != null)
  348. {
  349. this.graph.pageFormat = new mxRectangle(0, 0, parseFloat(pw), parseFloat(ph));
  350. }
  351. // Loads the persistent state settings
  352. var bg = node.getAttribute('background');
  353. if (bg != null && bg.length > 0)
  354. {
  355. this.graph.background = bg;
  356. }
  357. else
  358. {
  359. this.graph.background = this.graph.defaultGraphBackground;
  360. }
  361. };
  362. /**
  363. * Sets the XML node for the current diagram.
  364. */
  365. Editor.prototype.setGraphXml = function(node)
  366. {
  367. if (node != null)
  368. {
  369. var dec = new mxCodec(node.ownerDocument);
  370. if (node.nodeName == 'mxGraphModel')
  371. {
  372. this.graph.model.beginUpdate();
  373. try
  374. {
  375. this.graph.model.clear();
  376. this.graph.view.scale = 1;
  377. this.readGraphState(node);
  378. this.updateGraphComponents();
  379. dec.decode(node, this.graph.getModel());
  380. }
  381. finally
  382. {
  383. this.graph.model.endUpdate();
  384. }
  385. this.fireEvent(new mxEventObject('resetGraphView'));
  386. }
  387. else if (node.nodeName == 'root')
  388. {
  389. this.resetGraph();
  390. // Workaround for invalid XML output in Firefox 20 due to bug in mxUtils.getXml
  391. var wrapper = dec.document.createElement('mxGraphModel');
  392. wrapper.appendChild(node);
  393. dec.decode(wrapper, this.graph.getModel());
  394. this.updateGraphComponents();
  395. this.fireEvent(new mxEventObject('resetGraphView'));
  396. }
  397. else
  398. {
  399. throw {
  400. message: mxResources.get('cannotOpenFile'),
  401. node: node,
  402. toString: function() { return this.message; }
  403. };
  404. }
  405. }
  406. else
  407. {
  408. this.resetGraph();
  409. this.graph.model.clear();
  410. this.fireEvent(new mxEventObject('resetGraphView'));
  411. }
  412. };
  413. /**
  414. * Returns the XML node that represents the current diagram.
  415. */
  416. Editor.prototype.getGraphXml = function(ignoreSelection)
  417. {
  418. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  419. var node = null;
  420. if (ignoreSelection)
  421. {
  422. var enc = new mxCodec(mxUtils.createXmlDocument());
  423. node = enc.encode(this.graph.getModel());
  424. }
  425. else
  426. {
  427. node = this.graph.encodeCells(mxUtils.sortCells(this.graph.model.getTopmostCells(
  428. this.graph.getSelectionCells())));
  429. }
  430. if (this.graph.view.translate.x != 0 || this.graph.view.translate.y != 0)
  431. {
  432. node.setAttribute('dx', Math.round(this.graph.view.translate.x * 100) / 100);
  433. node.setAttribute('dy', Math.round(this.graph.view.translate.y * 100) / 100);
  434. }
  435. node.setAttribute('grid', (this.graph.isGridEnabled()) ? '1' : '0');
  436. node.setAttribute('gridSize', this.graph.gridSize);
  437. node.setAttribute('guides', (this.graph.graphHandler.guidesEnabled) ? '1' : '0');
  438. node.setAttribute('tooltips', (this.graph.tooltipHandler.isEnabled()) ? '1' : '0');
  439. node.setAttribute('connect', (this.graph.connectionHandler.isEnabled()) ? '1' : '0');
  440. node.setAttribute('arrows', (this.graph.connectionArrowsEnabled) ? '1' : '0');
  441. node.setAttribute('fold', (this.graph.foldingEnabled) ? '1' : '0');
  442. node.setAttribute('page', (this.graph.pageVisible) ? '1' : '0');
  443. node.setAttribute('pageScale', this.graph.pageScale);
  444. node.setAttribute('pageWidth', this.graph.pageFormat.width);
  445. node.setAttribute('pageHeight', this.graph.pageFormat.height);
  446. if (this.graph.background != null)
  447. {
  448. node.setAttribute('background', this.graph.background);
  449. }
  450. return node;
  451. };
  452. /**
  453. * Keeps the graph container in sync with the persistent graph state
  454. */
  455. Editor.prototype.updateGraphComponents = function()
  456. {
  457. var graph = this.graph;
  458. if (graph.container != null)
  459. {
  460. graph.view.validateBackground();
  461. graph.container.style.overflow = (graph.scrollbars) ? 'auto' : 'hidden';
  462. this.fireEvent(new mxEventObject('updateGraphComponents'));
  463. }
  464. };
  465. /**
  466. * Sets the modified flag.
  467. */
  468. Editor.prototype.setModified = function(value)
  469. {
  470. this.modified = value;
  471. };
  472. /**
  473. * Sets the filename.
  474. */
  475. Editor.prototype.setFilename = function(value)
  476. {
  477. this.filename = value;
  478. };
  479. /**
  480. * Creates and returns a new undo manager.
  481. */
  482. Editor.prototype.createUndoManager = function()
  483. {
  484. var graph = this.graph;
  485. var undoMgr = new mxUndoManager();
  486. this.undoListener = function(sender, evt)
  487. {
  488. undoMgr.undoableEditHappened(evt.getProperty('edit'));
  489. };
  490. // Installs the command history
  491. var listener = mxUtils.bind(this, function(sender, evt)
  492. {
  493. this.undoListener.apply(this, arguments);
  494. });
  495. graph.getModel().addListener(mxEvent.UNDO, listener);
  496. graph.getView().addListener(mxEvent.UNDO, listener);
  497. // Keeps the selection in sync with the history
  498. var undoHandler = function(sender, evt)
  499. {
  500. var cand = graph.getSelectionCellsForChanges(evt.getProperty('edit').changes);
  501. var model = graph.getModel();
  502. var cells = [];
  503. for (var i = 0; i < cand.length; i++)
  504. {
  505. if ((model.isVertex(cand[i]) || model.isEdge(cand[i])) && graph.view.getState(cand[i]) != null)
  506. {
  507. cells.push(cand[i]);
  508. }
  509. }
  510. graph.setSelectionCells(cells);
  511. };
  512. undoMgr.addListener(mxEvent.UNDO, undoHandler);
  513. undoMgr.addListener(mxEvent.REDO, undoHandler);
  514. return undoMgr;
  515. };
  516. /**
  517. * Adds basic stencil set (no namespace).
  518. */
  519. Editor.prototype.initStencilRegistry = function() { };
  520. /**
  521. * Creates and returns a new undo manager.
  522. */
  523. Editor.prototype.destroy = function()
  524. {
  525. if (this.graph != null)
  526. {
  527. this.graph.destroy();
  528. this.graph = null;
  529. }
  530. };
  531. /**
  532. * Class for asynchronously opening a new window and loading a file at the same
  533. * time. This acts as a bridge between the open dialog and the new editor.
  534. */
  535. OpenFile = function(done)
  536. {
  537. this.producer = null;
  538. this.consumer = null;
  539. this.done = done;
  540. this.args = null;
  541. };
  542. /**
  543. * Registers the editor from the new window.
  544. */
  545. OpenFile.prototype.setConsumer = function(value)
  546. {
  547. this.consumer = value;
  548. this.execute();
  549. };
  550. /**
  551. * Sets the data from the loaded file.
  552. */
  553. OpenFile.prototype.setData = function()
  554. {
  555. this.args = arguments;
  556. this.execute();
  557. };
  558. /**
  559. * Displays an error message.
  560. */
  561. OpenFile.prototype.error = function(msg)
  562. {
  563. this.cancel(true);
  564. mxUtils.alert(msg);
  565. };
  566. /**
  567. * Consumes the data.
  568. */
  569. OpenFile.prototype.execute = function()
  570. {
  571. if (this.consumer != null && this.args != null)
  572. {
  573. this.cancel(false);
  574. this.consumer.apply(this, this.args);
  575. }
  576. };
  577. /**
  578. * Cancels the operation.
  579. */
  580. OpenFile.prototype.cancel = function(cancel)
  581. {
  582. if (this.done != null)
  583. {
  584. this.done((cancel != null) ? cancel : true);
  585. }
  586. };
  587. /**
  588. * Basic dialogs that are available in the viewer (print dialog).
  589. */
  590. function Dialog(editorUi, elt, w, h, modal, closable, onClose)
  591. {
  592. var dx = 0;
  593. if (mxClient.IS_VML && (document.documentMode == null || document.documentMode < 8))
  594. {
  595. // Adds padding as a workaround for box model in older IE versions
  596. // This needs to match the total padding of geDialog in CSS
  597. dx = 80;
  598. }
  599. w += dx;
  600. h += dx;
  601. var dh = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
  602. var left = Math.max(1, Math.round((document.body.scrollWidth - w - 64) / 2));
  603. var top = Math.max(1, Math.round((dh - h - editorUi.footerHeight) / 3));
  604. // Keeps window size inside available space
  605. if (!mxClient.IS_QUIRKS)
  606. {
  607. elt.style.maxHeight = '100%';
  608. }
  609. w = Math.min(w, document.body.scrollWidth - 64);
  610. h = Math.min(h, dh - 64);
  611. // Increments zIndex to put subdialogs and background over existing dialogs and background
  612. if (editorUi.dialogs.length > 0)
  613. {
  614. this.zIndex += editorUi.dialogs.length * 2;
  615. }
  616. var div = editorUi.createDiv('geDialog');
  617. div.style.width = w + 'px';
  618. div.style.height = h + 'px';
  619. div.style.left = left + 'px';
  620. div.style.top = top + 'px';
  621. div.style.zIndex = this.zIndex;
  622. if (this.bg == null)
  623. {
  624. this.bg = editorUi.createDiv('background');
  625. this.bg.style.position = 'absolute';
  626. this.bg.style.background = 'white';
  627. this.bg.style.left = '0px';
  628. this.bg.style.top = '0px';
  629. this.bg.style.bottom = '0px';
  630. this.bg.style.right = '0px';
  631. this.bg.style.zIndex = this.zIndex - 2;
  632. mxUtils.setOpacity(this.bg, this.bgOpacity);
  633. if (mxClient.IS_QUIRKS)
  634. {
  635. new mxDivResizer(this.bg);
  636. }
  637. }
  638. if (modal)
  639. {
  640. document.body.appendChild(this.bg);
  641. }
  642. div.appendChild(elt);
  643. document.body.appendChild(div);
  644. if (closable)
  645. {
  646. var img = document.createElement('img');
  647. img.setAttribute('src', Dialog.prototype.closeImage);
  648. img.setAttribute('title', mxResources.get('close'));
  649. img.className = 'geDialogClose';
  650. img.style.top = (top + 14) + 'px';
  651. img.style.left = (left + w + 38 - dx) + 'px';
  652. img.style.zIndex = this.zIndex;
  653. mxEvent.addListener(img, 'click', mxUtils.bind(this, function()
  654. {
  655. editorUi.hideDialog(true);
  656. }));
  657. document.body.appendChild(img);
  658. this.dialogImg = img;
  659. mxEvent.addGestureListeners(this.bg, null, null, mxUtils.bind(this, function(evt)
  660. {
  661. editorUi.hideDialog(true);
  662. }));
  663. }
  664. this.onDialogClose = onClose;
  665. this.container = div;
  666. editorUi.editor.fireEvent(new mxEventObject('showDialog'));
  667. };
  668. /**
  669. *
  670. */
  671. Dialog.prototype.zIndex = mxPopupMenu.prototype.zIndex - 1;
  672. /**
  673. *
  674. */
  675. Dialog.prototype.noColorImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/nocolor.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOkEzRDlBMUUwODYxMTExRTFCMzA4RDdDMjJBMEMxRDM3IiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOkEzRDlBMUUxODYxMTExRTFCMzA4RDdDMjJBMEMxRDM3Ij4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6QTNEOUExREU4NjExMTFFMUIzMDhEN0MyMkEwQzFEMzciIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6QTNEOUExREY4NjExMTFFMUIzMDhEN0MyMkEwQzFEMzciLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz5xh3fmAAAABlBMVEX////MzMw46qqDAAAAGElEQVR42mJggAJGKGAYIIGBth8KAAIMAEUQAIElnLuQAAAAAElFTkSuQmCC';
  676. /**
  677. *
  678. */
  679. Dialog.prototype.closeImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/close.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJAQMAAADaX5RTAAAABlBMVEV7mr3///+wksspAAAAAnRSTlP/AOW3MEoAAAAdSURBVAgdY9jXwCDDwNDRwHCwgeExmASygSL7GgB12QiqNHZZIwAAAABJRU5ErkJggg==';
  680. /**
  681. *
  682. */
  683. Dialog.prototype.clearImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/clear.gif' : 'data:image/gif;base64,R0lGODlhDQAKAIABAMDAwP///yH/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS4wLWMwNjAgNjEuMTM0Nzc3LCAyMDEwLzAyLzEyLTE3OjMyOjAwICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6OUIzOEM1NzI4NjEyMTFFMUEzMkNDMUE3NjZERDE2QjIiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6OUIzOEM1NzM4NjEyMTFFMUEzMkNDMUE3NjZERDE2QjIiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo5QjM4QzU3MDg2MTIxMUUxQTMyQ0MxQTc2NkREMTZCMiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo5QjM4QzU3MTg2MTIxMUUxQTMyQ0MxQTc2NkREMTZCMiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PgH//v38+/r5+Pf29fTz8vHw7+7t7Ovq6ejn5uXk4+Lh4N/e3dzb2tnY19bV1NPS0dDPzs3My8rJyMfGxcTDwsHAv769vLu6ubi3trW0s7KxsK+urayrqqmop6alpKOioaCfnp2cm5qZmJeWlZSTkpGQj46NjIuKiYiHhoWEg4KBgH9+fXx7enl4d3Z1dHNycXBvbm1sa2ppaGdmZWRjYmFgX15dXFtaWVhXVlVUU1JRUE9OTUxLSklIR0ZFRENCQUA/Pj08Ozo5ODc2NTQzMjEwLy4tLCsqKSgnJiUkIyIhIB8eHRwbGhkYFxYVFBMSERAPDg0MCwoJCAcGBQQDAgEAACH5BAEAAAEALAAAAAANAAoAAAIXTGCJebD9jEOTqRlttXdrB32PJ2ncyRQAOw==';
  684. /**
  685. *
  686. */
  687. Dialog.prototype.lockedImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/locked.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAMAAABhq6zVAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MzdDMDZCODExNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MzdDMDZCODIxNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDozN0MwNkI3RjE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDozN0MwNkI4MDE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PvqMCFYAAAAVUExURZmZmb+/v7KysqysrMzMzLGxsf///4g8N1cAAAAHdFJOU////////wAaSwNGAAAAPElEQVR42lTMQQ4AIQgEwUa0//9kTQirOweYOgDqAMbZUr10AGlAwx4/BJ2QJ4U0L5brYjovvpv32xZgAHZaATFtMbu4AAAAAElFTkSuQmCC';
  688. /**
  689. *
  690. */
  691. Dialog.prototype.unlockedImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/unlocked.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAMAAABhq6zVAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MzdDMDZCN0QxNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MzdDMDZCN0UxNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDozN0MwNkI3QjE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDozN0MwNkI3QzE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PkKMpVwAAAAYUExURZmZmbKysr+/v6ysrOXl5czMzLGxsf///zHN5lwAAAAIdFJOU/////////8A3oO9WQAAADxJREFUeNpUzFESACAEBNBVsfe/cZJU+8Mzs8CIABCidtfGOndnYsT40HDSiCcbPdoJo10o9aI677cpwACRoAF3dFNlswAAAABJRU5ErkJggg==';
  692. /**
  693. * Removes the dialog from the DOM.
  694. */
  695. Dialog.prototype.bgOpacity = 80;
  696. /**
  697. * Removes the dialog from the DOM.
  698. */
  699. Dialog.prototype.close = function(cancel)
  700. {
  701. if (this.onDialogClose != null)
  702. {
  703. this.onDialogClose(cancel);
  704. this.onDialogClose = null;
  705. }
  706. if (this.dialogImg != null)
  707. {
  708. this.dialogImg.parentNode.removeChild(this.dialogImg);
  709. this.dialogImg = null;
  710. }
  711. if (this.bg != null && this.bg.parentNode != null)
  712. {
  713. this.bg.parentNode.removeChild(this.bg);
  714. }
  715. this.container.parentNode.removeChild(this.container);
  716. };
  717. /**
  718. * Constructs a new print dialog.
  719. */
  720. var PrintDialog = function(editorUi, title)
  721. {
  722. this.create(editorUi, title);
  723. };
  724. /**
  725. * Constructs a new print dialog.
  726. */
  727. PrintDialog.prototype.create = function(editorUi)
  728. {
  729. var graph = editorUi.editor.graph;
  730. var row, td;
  731. var table = document.createElement('table');
  732. table.style.width = '100%';
  733. table.style.height = '100%';
  734. var tbody = document.createElement('tbody');
  735. row = document.createElement('tr');
  736. var onePageCheckBox = document.createElement('input');
  737. onePageCheckBox.setAttribute('type', 'checkbox');
  738. td = document.createElement('td');
  739. td.setAttribute('colspan', '2');
  740. td.style.fontSize = '10pt';
  741. td.appendChild(onePageCheckBox);
  742. var span = document.createElement('span');
  743. mxUtils.write(span, ' ' + mxResources.get('fitPage'));
  744. td.appendChild(span);
  745. mxEvent.addListener(span, 'click', function(evt)
  746. {
  747. onePageCheckBox.checked = !onePageCheckBox.checked;
  748. pageCountCheckBox.checked = !onePageCheckBox.checked;
  749. mxEvent.consume(evt);
  750. });
  751. mxEvent.addListener(onePageCheckBox, 'change', function()
  752. {
  753. pageCountCheckBox.checked = !onePageCheckBox.checked;
  754. });
  755. row.appendChild(td);
  756. tbody.appendChild(row);
  757. row = row.cloneNode(false);
  758. var pageCountCheckBox = document.createElement('input');
  759. pageCountCheckBox.setAttribute('type', 'checkbox');
  760. td = document.createElement('td');
  761. td.style.fontSize = '10pt';
  762. td.appendChild(pageCountCheckBox);
  763. var span = document.createElement('span');
  764. mxUtils.write(span, ' ' + mxResources.get('posterPrint') + ':');
  765. td.appendChild(span);
  766. mxEvent.addListener(span, 'click', function(evt)
  767. {
  768. pageCountCheckBox.checked = !pageCountCheckBox.checked;
  769. onePageCheckBox.checked = !pageCountCheckBox.checked;
  770. mxEvent.consume(evt);
  771. });
  772. row.appendChild(td);
  773. var pageCountInput = document.createElement('input');
  774. pageCountInput.setAttribute('value', '1');
  775. pageCountInput.setAttribute('type', 'number');
  776. pageCountInput.setAttribute('min', '1');
  777. pageCountInput.setAttribute('size', '4');
  778. pageCountInput.setAttribute('disabled', 'disabled');
  779. pageCountInput.style.width = '50px';
  780. td = document.createElement('td');
  781. td.style.fontSize = '10pt';
  782. td.appendChild(pageCountInput);
  783. mxUtils.write(td, ' ' + mxResources.get('pages') + ' (max)');
  784. row.appendChild(td);
  785. tbody.appendChild(row);
  786. mxEvent.addListener(pageCountCheckBox, 'change', function()
  787. {
  788. if (pageCountCheckBox.checked)
  789. {
  790. pageCountInput.removeAttribute('disabled');
  791. }
  792. else
  793. {
  794. pageCountInput.setAttribute('disabled', 'disabled');
  795. }
  796. onePageCheckBox.checked = !pageCountCheckBox.checked;
  797. });
  798. row = row.cloneNode(false);
  799. td = document.createElement('td');
  800. mxUtils.write(td, mxResources.get('pageScale') + ':');
  801. row.appendChild(td);
  802. td = document.createElement('td');
  803. var pageScaleInput = document.createElement('input');
  804. pageScaleInput.setAttribute('value', '100 %');
  805. pageScaleInput.setAttribute('size', '5');
  806. pageScaleInput.style.width = '50px';
  807. td.appendChild(pageScaleInput);
  808. row.appendChild(td);
  809. tbody.appendChild(row);
  810. row = document.createElement('tr');
  811. td = document.createElement('td');
  812. td.colSpan = 2;
  813. td.style.paddingTop = '20px';
  814. td.setAttribute('align', 'right');
  815. // Overall scale for print-out to account for print borders in dialogs etc
  816. function preview(print)
  817. {
  818. var autoOrigin = onePageCheckBox.checked || pageCountCheckBox.checked;
  819. var printScale = parseInt(pageScaleInput.value) / 100;
  820. if (isNaN(printScale))
  821. {
  822. printScale = 1;
  823. pageScaleInput.value = '100%';
  824. }
  825. // Workaround to match available paper size in actual print output
  826. printScale *= 0.75;
  827. var pf = graph.pageFormat || mxConstants.PAGE_FORMAT_A4_PORTRAIT;
  828. var scale = 1 / graph.pageScale;
  829. if (autoOrigin)
  830. {
  831. var pageCount = (onePageCheckBox.checked) ? 1 : parseInt(pageCountInput.value);
  832. if (!isNaN(pageCount))
  833. {
  834. scale = mxUtils.getScaleForPageCount(pageCount, graph, pf);
  835. }
  836. }
  837. // Negative coordinates are cropped or shifted if page visible
  838. var gb = graph.getGraphBounds();
  839. var border = 0;
  840. var x0 = 0;
  841. var y0 = 0;
  842. // Applies print scale
  843. pf = mxRectangle.fromRectangle(pf);
  844. pf.width = Math.ceil(pf.width * printScale);
  845. pf.height = Math.ceil(pf.height * printScale);
  846. scale *= printScale;
  847. // Starts at first visible page
  848. if (!autoOrigin && graph.pageVisible)
  849. {
  850. var layout = graph.getPageLayout();
  851. x0 -= layout.x * pf.width;
  852. y0 -= layout.y * pf.height;
  853. }
  854. else
  855. {
  856. autoOrigin = true;
  857. }
  858. var preview = PrintDialog.createPrintPreview(graph, scale, pf, border, x0, y0, autoOrigin);
  859. preview.open();
  860. if (print)
  861. {
  862. PrintDialog.printPreview(preview);
  863. }
  864. };
  865. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  866. {
  867. editorUi.hideDialog();
  868. });
  869. cancelBtn.className = 'geBtn';
  870. if (editorUi.editor.cancelFirst)
  871. {
  872. td.appendChild(cancelBtn);
  873. }
  874. if (PrintDialog.previewEnabled)
  875. {
  876. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  877. {
  878. editorUi.hideDialog();
  879. preview(false);
  880. });
  881. previewBtn.className = 'geBtn';
  882. td.appendChild(previewBtn);
  883. }
  884. var printBtn = mxUtils.button(mxResources.get((!PrintDialog.previewEnabled) ? 'ok' : 'print'), function()
  885. {
  886. editorUi.hideDialog();
  887. preview(true);
  888. });
  889. printBtn.className = 'geBtn gePrimaryBtn';
  890. td.appendChild(printBtn);
  891. if (!editorUi.editor.cancelFirst)
  892. {
  893. td.appendChild(cancelBtn);
  894. }
  895. row.appendChild(td);
  896. tbody.appendChild(row);
  897. table.appendChild(tbody);
  898. this.container = table;
  899. };
  900. /**
  901. * Constructs a new print dialog.
  902. */
  903. PrintDialog.printPreview = function(preview)
  904. {
  905. if (preview.wnd != null)
  906. {
  907. var printFn = function()
  908. {
  909. preview.wnd.focus();
  910. preview.wnd.print();
  911. preview.wnd.close();
  912. };
  913. // Workaround for Google Chrome which needs a bit of a
  914. // delay in order to render the SVG contents
  915. // Needs testing in production
  916. if (mxClient.IS_GC)
  917. {
  918. window.setTimeout(printFn, 500);
  919. }
  920. else
  921. {
  922. printFn();
  923. }
  924. }
  925. };
  926. /**
  927. * Constructs a new print dialog.
  928. */
  929. PrintDialog.createPrintPreview = function(graph, scale, pf, border, x0, y0, autoOrigin)
  930. {
  931. var preview = new mxPrintPreview(graph, scale, pf, border, x0, y0);
  932. preview.title = mxResources.get('preview');
  933. preview.printBackgroundImage = true;
  934. preview.autoOrigin = autoOrigin;
  935. var bg = graph.background;
  936. if (bg == null || bg == '' || bg == mxConstants.NONE)
  937. {
  938. bg = '#ffffff';
  939. }
  940. preview.backgroundColor = bg;
  941. var writeHead = preview.writeHead;
  942. // Adds a border in the preview
  943. preview.writeHead = function(doc)
  944. {
  945. writeHead.apply(this, arguments);
  946. doc.writeln('<style type="text/css">');
  947. doc.writeln('@media screen {');
  948. doc.writeln(' body > div { padding:30px;box-sizing:content-box; }');
  949. doc.writeln('}');
  950. doc.writeln('</style>');
  951. };
  952. return preview;
  953. };
  954. /**
  955. * Specifies if the preview button should be enabled. Default is true.
  956. */
  957. PrintDialog.previewEnabled = true;
  958. /**
  959. * Constructs a new page setup dialog.
  960. */
  961. var PageSetupDialog = function(editorUi)
  962. {
  963. var graph = editorUi.editor.graph;
  964. var row, td;
  965. var table = document.createElement('table');
  966. table.style.width = '100%';
  967. table.style.height = '100%';
  968. var tbody = document.createElement('tbody');
  969. row = document.createElement('tr');
  970. td = document.createElement('td');
  971. td.style.verticalAlign = 'top';
  972. td.style.fontSize = '10pt';
  973. mxUtils.write(td, mxResources.get('paperSize') + ':');
  974. row.appendChild(td);
  975. td = document.createElement('td');
  976. td.style.verticalAlign = 'top';
  977. td.style.fontSize = '10pt';
  978. var accessor = PageSetupDialog.addPageFormatPanel(td, 'pagesetupdialog', graph.pageFormat);
  979. row.appendChild(td);
  980. tbody.appendChild(row);
  981. row = document.createElement('tr');
  982. td = document.createElement('td');
  983. mxUtils.write(td, mxResources.get('background') + ':');
  984. row.appendChild(td);
  985. td = document.createElement('td');
  986. td.style.whiteSpace = 'nowrap';
  987. var backgroundInput = document.createElement('input');
  988. backgroundInput.setAttribute('type', 'text');
  989. var backgroundButton = document.createElement('button');
  990. backgroundButton.style.width = '18px';
  991. backgroundButton.style.height = '18px';
  992. backgroundButton.style.marginRight = '20px';
  993. backgroundButton.style.backgroundPosition = 'center center';
  994. backgroundButton.style.backgroundRepeat = 'no-repeat';
  995. var newBackgroundColor = graph.background;
  996. function updateBackgroundColor()
  997. {
  998. if (newBackgroundColor == null || newBackgroundColor == mxConstants.NONE)
  999. {
  1000. backgroundButton.style.backgroundColor = '';
  1001. backgroundButton.style.backgroundImage = 'url(\'' + Dialog.prototype.noColorImage + '\')';
  1002. }
  1003. else
  1004. {
  1005. backgroundButton.style.backgroundColor = newBackgroundColor;
  1006. backgroundButton.style.backgroundImage = '';
  1007. }
  1008. };
  1009. updateBackgroundColor();
  1010. mxEvent.addListener(backgroundButton, 'click', function(evt)
  1011. {
  1012. editorUi.pickColor(newBackgroundColor || 'none', function(color)
  1013. {
  1014. newBackgroundColor = color;
  1015. updateBackgroundColor();
  1016. });
  1017. mxEvent.consume(evt);
  1018. });
  1019. td.appendChild(backgroundButton);
  1020. mxUtils.write(td, mxResources.get('gridSize') + ':');
  1021. var gridSizeInput = document.createElement('input');
  1022. gridSizeInput.setAttribute('type', 'number');
  1023. gridSizeInput.setAttribute('min', '0');
  1024. gridSizeInput.style.width = '40px';
  1025. gridSizeInput.style.marginLeft = '6px';
  1026. gridSizeInput.value = graph.getGridSize();
  1027. td.appendChild(gridSizeInput);
  1028. mxEvent.addListener(gridSizeInput, 'change', function()
  1029. {
  1030. var value = parseInt(gridSizeInput.value);
  1031. gridSizeInput.value = Math.max(1, (isNaN(value)) ? graph.getGridSize() : value);
  1032. });
  1033. row.appendChild(td);
  1034. tbody.appendChild(row);
  1035. row = document.createElement('tr');
  1036. td = document.createElement('td');
  1037. mxUtils.write(td, mxResources.get('image') + ':');
  1038. row.appendChild(td);
  1039. td = document.createElement('td');
  1040. var changeImageLink = document.createElement('a');
  1041. changeImageLink.style.textDecoration = 'underline';
  1042. changeImageLink.style.cursor = 'pointer';
  1043. changeImageLink.style.color = '#a0a0a0';
  1044. var newBackgroundImage = graph.backgroundImage;
  1045. function updateBackgroundImage()
  1046. {
  1047. if (newBackgroundImage == null)
  1048. {
  1049. changeImageLink.removeAttribute('title');
  1050. changeImageLink.style.fontSize = '';
  1051. changeImageLink.innerHTML = mxResources.get('change') + '...';
  1052. }
  1053. else
  1054. {
  1055. changeImageLink.setAttribute('title', newBackgroundImage.src);
  1056. changeImageLink.style.fontSize = '11px';
  1057. changeImageLink.innerHTML = newBackgroundImage.src.substring(0, 42) + '...';
  1058. }
  1059. };
  1060. mxEvent.addListener(changeImageLink, 'click', function(evt)
  1061. {
  1062. editorUi.showBackgroundImageDialog(function(image)
  1063. {
  1064. newBackgroundImage = image;
  1065. updateBackgroundImage();
  1066. });
  1067. mxEvent.consume(evt);
  1068. });
  1069. updateBackgroundImage();
  1070. td.appendChild(changeImageLink);
  1071. row.appendChild(td);
  1072. tbody.appendChild(row);
  1073. row = document.createElement('tr');
  1074. td = document.createElement('td');
  1075. td.colSpan = 2;
  1076. td.style.paddingTop = '16px';
  1077. td.setAttribute('align', 'right');
  1078. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1079. {
  1080. editorUi.hideDialog();
  1081. });
  1082. cancelBtn.className = 'geBtn';
  1083. if (editorUi.editor.cancelFirst)
  1084. {
  1085. td.appendChild(cancelBtn);
  1086. }
  1087. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  1088. {
  1089. editorUi.hideDialog();
  1090. editorUi.setPageFormat(accessor.get());
  1091. if (graph.background != newBackgroundColor)
  1092. {
  1093. editorUi.setBackgroundColor(newBackgroundColor);
  1094. }
  1095. if (graph.backgroundImage !== newBackgroundImage)
  1096. {
  1097. editorUi.setBackgroundImage(newBackgroundImage);
  1098. }
  1099. if (graph.gridSize !== gridSizeInput.value)
  1100. {
  1101. graph.setGridSize(parseInt(gridSizeInput.value));
  1102. }
  1103. });
  1104. applyBtn.className = 'geBtn gePrimaryBtn';
  1105. td.appendChild(applyBtn);
  1106. if (!editorUi.editor.cancelFirst)
  1107. {
  1108. td.appendChild(cancelBtn);
  1109. }
  1110. row.appendChild(td);
  1111. tbody.appendChild(row);
  1112. table.appendChild(tbody);
  1113. this.container = table;
  1114. };
  1115. /**
  1116. *
  1117. */
  1118. PageSetupDialog.addPageFormatPanel = function(div, namePostfix, pageFormat, pageFormatListener)
  1119. {
  1120. var formatName = 'format-' + namePostfix;
  1121. var portraitCheckBox = document.createElement('input');
  1122. portraitCheckBox.setAttribute('name', formatName);
  1123. portraitCheckBox.setAttribute('type', 'radio');
  1124. portraitCheckBox.setAttribute('value', 'portrait');
  1125. var landscapeCheckBox = document.createElement('input');
  1126. landscapeCheckBox.setAttribute('name', formatName);
  1127. landscapeCheckBox.setAttribute('type', 'radio');
  1128. landscapeCheckBox.setAttribute('value', 'landscape');
  1129. var paperSizeSelect = document.createElement('select');
  1130. paperSizeSelect.style.marginBottom = '8px';
  1131. paperSizeSelect.style.width = '202px';
  1132. var formatDiv = document.createElement('div');
  1133. formatDiv.style.marginLeft = '4px';
  1134. formatDiv.style.width = '210px';
  1135. formatDiv.style.height = '24px';
  1136. portraitCheckBox.style.marginRight = '6px';
  1137. formatDiv.appendChild(portraitCheckBox);
  1138. var portraitSpan = document.createElement('span');
  1139. portraitSpan.style.maxWidth = '100px';
  1140. mxUtils.write(portraitSpan, mxResources.get('portrait'));
  1141. formatDiv.appendChild(portraitSpan);
  1142. landscapeCheckBox.style.marginLeft = '10px';
  1143. landscapeCheckBox.style.marginRight = '6px';
  1144. formatDiv.appendChild(landscapeCheckBox);
  1145. var landscapeSpan = document.createElement('span');
  1146. landscapeSpan.style.width = '100px';
  1147. mxUtils.write(landscapeSpan, mxResources.get('landscape'));
  1148. formatDiv.appendChild(landscapeSpan)
  1149. var customDiv = document.createElement('div');
  1150. customDiv.style.marginLeft = '4px';
  1151. customDiv.style.width = '210px';
  1152. customDiv.style.height = '24px';
  1153. var widthInput = document.createElement('input');
  1154. widthInput.setAttribute('size', '6');
  1155. widthInput.setAttribute('value', pageFormat.width);
  1156. customDiv.appendChild(widthInput);
  1157. mxUtils.write(customDiv, ' x ');
  1158. var heightInput = document.createElement('input');
  1159. heightInput.setAttribute('size', '6');
  1160. heightInput.setAttribute('value', pageFormat.height);
  1161. customDiv.appendChild(heightInput);
  1162. mxUtils.write(customDiv, ' pt');
  1163. formatDiv.style.display = 'none';
  1164. customDiv.style.display = 'none';
  1165. var pf = new Object();
  1166. var formats = PageSetupDialog.getFormats();
  1167. for (var i = 0; i < formats.length; i++)
  1168. {
  1169. var f = formats[i];
  1170. pf[f.key] = f;
  1171. var paperSizeOption = document.createElement('option');
  1172. paperSizeOption.setAttribute('value', f.key);
  1173. mxUtils.write(paperSizeOption, f.title);
  1174. paperSizeSelect.appendChild(paperSizeOption);
  1175. }
  1176. var customSize = false;
  1177. function listener(sender, evt, force)
  1178. {
  1179. if (force || (widthInput != document.activeElement && heightInput != document.activeElement))
  1180. {
  1181. var detected = false;
  1182. for (var i = 0; i < formats.length; i++)
  1183. {
  1184. var f = formats[i];
  1185. // Special case where custom was chosen
  1186. if (customSize)
  1187. {
  1188. if (f.key == 'custom')
  1189. {
  1190. paperSizeSelect.value = f.key;
  1191. customSize = false;
  1192. }
  1193. }
  1194. else if (f.format != null)
  1195. {
  1196. if (pageFormat.width == f.format.width && pageFormat.height == f.format.height)
  1197. {
  1198. paperSizeSelect.value = f.key;
  1199. portraitCheckBox.setAttribute('checked', 'checked');
  1200. portraitCheckBox.defaultChecked = true;
  1201. portraitCheckBox.checked = true;
  1202. landscapeCheckBox.removeAttribute('checked');
  1203. landscapeCheckBox.defaultChecked = false;
  1204. landscapeCheckBox.checked = false;
  1205. detected = true;
  1206. }
  1207. else if (pageFormat.width == f.format.height && pageFormat.height == f.format.width)
  1208. {
  1209. paperSizeSelect.value = f.key;
  1210. portraitCheckBox.removeAttribute('checked');
  1211. portraitCheckBox.defaultChecked = false;
  1212. portraitCheckBox.checked = false;
  1213. landscapeCheckBox.setAttribute('checked', 'checked');
  1214. landscapeCheckBox.defaultChecked = true;
  1215. landscapeCheckBox.checked = true;
  1216. detected = true;
  1217. }
  1218. }
  1219. }
  1220. // Selects custom format which is last in list
  1221. if (!detected)
  1222. {
  1223. widthInput.value = pageFormat.width;
  1224. heightInput.value = pageFormat.height;
  1225. paperSizeOption.setAttribute('selected', 'selected');
  1226. portraitCheckBox.setAttribute('checked', 'checked');
  1227. portraitCheckBox.defaultChecked = true;
  1228. formatDiv.style.display = 'none';
  1229. customDiv.style.display = '';
  1230. }
  1231. else
  1232. {
  1233. formatDiv.style.display = '';
  1234. customDiv.style.display = 'none';
  1235. }
  1236. }
  1237. };
  1238. listener();
  1239. div.appendChild(paperSizeSelect);
  1240. mxUtils.br(div);
  1241. div.appendChild(formatDiv);
  1242. div.appendChild(customDiv);
  1243. var currentPageFormat = pageFormat;
  1244. var update = function()
  1245. {
  1246. var f = pf[paperSizeSelect.value];
  1247. if (f.format != null)
  1248. {
  1249. widthInput.value = f.format.width;
  1250. heightInput.value = f.format.height;
  1251. customDiv.style.display = 'none';
  1252. formatDiv.style.display = '';
  1253. }
  1254. else
  1255. {
  1256. formatDiv.style.display = 'none';
  1257. customDiv.style.display = '';
  1258. }
  1259. var newPageFormat = new mxRectangle(0, 0, parseInt(widthInput.value), parseInt(heightInput.value));
  1260. if (paperSizeSelect.value != 'custom' && landscapeCheckBox.checked)
  1261. {
  1262. newPageFormat = new mxRectangle(0, 0, newPageFormat.height, newPageFormat.width);
  1263. }
  1264. if (newPageFormat.width != currentPageFormat.width || newPageFormat.height != currentPageFormat.height)
  1265. {
  1266. currentPageFormat = newPageFormat;
  1267. if (pageFormatListener != null)
  1268. {
  1269. pageFormatListener(currentPageFormat);
  1270. }
  1271. }
  1272. };
  1273. mxEvent.addListener(portraitSpan, 'click', function(evt)
  1274. {
  1275. portraitCheckBox.checked = true;
  1276. update();
  1277. mxEvent.consume(evt);
  1278. });
  1279. mxEvent.addListener(landscapeSpan, 'click', function(evt)
  1280. {
  1281. landscapeCheckBox.checked = true;
  1282. update();
  1283. mxEvent.consume(evt);
  1284. });
  1285. mxEvent.addListener(widthInput, 'blur', update);
  1286. mxEvent.addListener(widthInput, 'click', update);
  1287. mxEvent.addListener(heightInput, 'blur', update);
  1288. mxEvent.addListener(heightInput, 'click', update);
  1289. mxEvent.addListener(landscapeCheckBox, 'change', update);
  1290. mxEvent.addListener(portraitCheckBox, 'change', update);
  1291. mxEvent.addListener(paperSizeSelect, 'change', function()
  1292. {
  1293. // Handles special case where custom was chosen
  1294. customSize = paperSizeSelect.value == 'custom';
  1295. update();
  1296. });
  1297. update();
  1298. return {set: function(value)
  1299. {
  1300. pageFormat = value;
  1301. listener(null, null, true);
  1302. },get: function()
  1303. {
  1304. return currentPageFormat;
  1305. }, widthInput: widthInput,
  1306. heightInput: heightInput};
  1307. };
  1308. /**
  1309. *
  1310. */
  1311. PageSetupDialog.getFormats = function()
  1312. {
  1313. return [{key: 'letter', title: 'US-Letter (8,5" x 11")', format: mxConstants.PAGE_FORMAT_LETTER_PORTRAIT},
  1314. {key: 'legal', title: 'US-Legal (8,5" x 14")', format: new mxRectangle(0, 0, 850, 1400)},
  1315. {key: 'tabloid', title: 'US-Tabloid (279 mm x 432 mm)', format: new mxRectangle(0, 0, 1100, 1700)},
  1316. {key: 'a3', title: 'A3 (297 mm x 420 mm)', format: new mxRectangle(0, 0, 1169, 1652)},
  1317. {key: 'a4', title: 'A4 (210 mm x 297 mm)', format: mxConstants.PAGE_FORMAT_A4_PORTRAIT},
  1318. {key: 'a5', title: 'A5 (148 mm x 210 mm)', format: new mxRectangle(0, 0, 584, 826)},
  1319. {key: 'custom', title: mxResources.get('custom'), format: null}];
  1320. };
  1321. /**
  1322. * Static overrides
  1323. */
  1324. (function()
  1325. {
  1326. // Uses HTML for background pages (to support grid background image)
  1327. mxGraphView.prototype.validateBackgroundPage = function()
  1328. {
  1329. var graph = this.graph;
  1330. if (graph.container != null && !graph.transparentBackground)
  1331. {
  1332. if (graph.pageVisible)
  1333. {
  1334. var bounds = this.getBackgroundPageBounds();
  1335. if (this.backgroundPageShape == null)
  1336. {
  1337. // Finds first element in graph container
  1338. var firstChild = graph.container.firstChild;
  1339. while (firstChild != null && firstChild.nodeType != mxConstants.NODETYPE_ELEMENT)
  1340. {
  1341. firstChild = firstChild.nextSibling;
  1342. }
  1343. if (firstChild != null)
  1344. {
  1345. this.backgroundPageShape = this.createBackgroundPageShape(bounds);
  1346. this.backgroundPageShape.scale = 1;
  1347. // Shadow filter causes problems in outline window in quirks mode. IE8 standards
  1348. // also has known rendering issues inside mxWindow but not using shadow is worse.
  1349. this.backgroundPageShape.isShadow = !mxClient.IS_QUIRKS;
  1350. this.backgroundPageShape.dialect = mxConstants.DIALECT_STRICTHTML;
  1351. this.backgroundPageShape.init(graph.container);
  1352. // Required for the browser to render the background page in correct order
  1353. firstChild.style.position = 'absolute';
  1354. graph.container.insertBefore(this.backgroundPageShape.node, firstChild);
  1355. this.backgroundPageShape.redraw();
  1356. this.backgroundPageShape.node.className = 'geBackgroundPage';
  1357. // Adds listener for double click handling on background
  1358. mxEvent.addListener(this.backgroundPageShape.node, 'dblclick',
  1359. mxUtils.bind(this, function(evt)
  1360. {
  1361. graph.dblClick(evt);
  1362. })
  1363. );
  1364. // Adds basic listeners for graph event dispatching outside of the
  1365. // container and finishing the handling of a single gesture
  1366. mxEvent.addGestureListeners(this.backgroundPageShape.node,
  1367. mxUtils.bind(this, function(evt)
  1368. {
  1369. graph.fireMouseEvent(mxEvent.MOUSE_DOWN, new mxMouseEvent(evt));
  1370. }),
  1371. mxUtils.bind(this, function(evt)
  1372. {
  1373. // Hides the tooltip if mouse is outside container
  1374. if (graph.tooltipHandler != null && graph.tooltipHandler.isHideOnHover())
  1375. {
  1376. graph.tooltipHandler.hide();
  1377. }
  1378. if (graph.isMouseDown && !mxEvent.isConsumed(evt))
  1379. {
  1380. graph.fireMouseEvent(mxEvent.MOUSE_MOVE, new mxMouseEvent(evt));
  1381. }
  1382. }),
  1383. mxUtils.bind(this, function(evt)
  1384. {
  1385. graph.fireMouseEvent(mxEvent.MOUSE_UP, new mxMouseEvent(evt));
  1386. })
  1387. );
  1388. }
  1389. }
  1390. else
  1391. {
  1392. this.backgroundPageShape.scale = 1;
  1393. this.backgroundPageShape.bounds = bounds;
  1394. this.backgroundPageShape.redraw();
  1395. }
  1396. }
  1397. else if (this.backgroundPageShape != null)
  1398. {
  1399. this.backgroundPageShape.destroy();
  1400. this.backgroundPageShape = null;
  1401. }
  1402. this.validateBackgroundStyles();
  1403. }
  1404. };
  1405. // Updates the CSS of the background to draw the grid
  1406. mxGraphView.prototype.validateBackgroundStyles = function()
  1407. {
  1408. var graph = this.graph;
  1409. var color = (graph.background == null || graph.background == mxConstants.NONE) ? '#ffffff' : graph.background;
  1410. var gridColor = (this.gridColor != color.toLowerCase()) ? this.gridColor : '#ffffff';
  1411. var image = 'none';
  1412. var position = '';
  1413. if (graph.isGridEnabled())
  1414. {
  1415. var phase = 10;
  1416. if (mxClient.IS_SVG)
  1417. {
  1418. // Generates the SVG required for drawing the dynamic grid
  1419. image = unescape(encodeURIComponent(this.createSvgGrid(gridColor)));
  1420. image = (window.btoa) ? btoa(image) : Base64.encode(image, true);
  1421. image = 'url(' + 'data:image/svg+xml;base64,' + image + ')'
  1422. phase = graph.gridSize * this.scale * this.gridSteps;
  1423. }
  1424. else
  1425. {
  1426. // Fallback to grid wallpaper with fixed size
  1427. image = 'url(' + this.gridImage + ')';
  1428. }
  1429. var x0 = 0;
  1430. var y0 = 0;
  1431. if (graph.view.backgroundPageShape != null)
  1432. {
  1433. var bds = this.getBackgroundPageBounds();
  1434. x0 = 1 + bds.x;
  1435. y0 = 1 + bds.y;
  1436. }
  1437. // Computes the offset to maintain origin for grid
  1438. position = -Math.round(phase - mxUtils.mod(this.translate.x * this.scale - x0, phase)) + 'px ' +
  1439. -Math.round(phase - mxUtils.mod(this.translate.y * this.scale - y0, phase)) + 'px';
  1440. }
  1441. var canvas = graph.view.canvas;
  1442. if (canvas.ownerSVGElement != null)
  1443. {
  1444. canvas = canvas.ownerSVGElement;
  1445. }
  1446. if (graph.view.backgroundPageShape != null)
  1447. {
  1448. graph.view.backgroundPageShape.node.style.backgroundPosition = position;
  1449. graph.view.backgroundPageShape.node.style.backgroundImage = image;
  1450. graph.view.backgroundPageShape.node.style.backgroundColor = color;
  1451. graph.container.className = 'geDiagramContainer geDiagramBackdrop';
  1452. canvas.style.backgroundImage = 'none';
  1453. canvas.style.backgroundColor = '';
  1454. }
  1455. else
  1456. {
  1457. graph.container.className = 'geDiagramContainer';
  1458. canvas.style.backgroundPosition = position;
  1459. canvas.style.backgroundColor = color;
  1460. canvas.style.backgroundImage = image;
  1461. }
  1462. };
  1463. // Returns the SVG required for painting the background grid.
  1464. mxGraphView.prototype.createSvgGrid = function(color)
  1465. {
  1466. var tmp = this.graph.gridSize * this.scale;
  1467. while (tmp < this.minGridSize)
  1468. {
  1469. tmp *= 2;
  1470. }
  1471. var tmp2 = this.gridSteps * tmp;
  1472. // Small grid lines
  1473. var d = [];
  1474. for (var i = 1; i < this.gridSteps; i++)
  1475. {
  1476. var tmp3 = i * tmp;
  1477. d.push('M 0 ' + tmp3 + ' L ' + tmp2 + ' ' + tmp3 + ' M ' + tmp3 + ' 0 L ' + tmp3 + ' ' + tmp2);
  1478. }
  1479. // KNOWN: Rounding errors for certain scales (eg. 144%, 121% in Chrome, FF and Safari). Workaround
  1480. // in Chrome is to use 100% for the svg size, but this results in blurred grid for large diagrams.
  1481. var size = tmp2;
  1482. var svg = '<svg width="' + size + '" height="' + size + '" xmlns="' + mxConstants.NS_SVG + '">' +
  1483. '<defs><pattern id="grid" width="' + tmp2 + '" height="' + tmp2 + '" patternUnits="userSpaceOnUse">' +
  1484. '<path d="' + d.join(' ') + '" fill="none" stroke="' + color + '" opacity="0.2" stroke-width="1"/>' +
  1485. '<path d="M ' + tmp2 + ' 0 L 0 0 0 ' + tmp2 + '" fill="none" stroke="' + color + '" stroke-width="1"/>' +
  1486. '</pattern></defs><rect width="100%" height="100%" fill="url(#grid)"/></svg>';
  1487. return svg;
  1488. };
  1489. // Adds panning for the grid with no page view and disabled scrollbars
  1490. var mxGraphPanGraph = mxGraph.prototype.panGraph;
  1491. mxGraph.prototype.panGraph = function(dx, dy)
  1492. {
  1493. mxGraphPanGraph.apply(this, arguments);
  1494. if (this.shiftPreview1 != null)
  1495. {
  1496. var canvas = this.view.canvas;
  1497. if (canvas.ownerSVGElement != null)
  1498. {
  1499. canvas = canvas.ownerSVGElement;
  1500. }
  1501. var phase = this.gridSize * this.view.scale * this.view.gridSteps;
  1502. var position = -Math.round(phase - mxUtils.mod(this.view.translate.x * this.view.scale + dx, phase)) + 'px ' +
  1503. -Math.round(phase - mxUtils.mod(this.view.translate.y * this.view.scale + dy, phase)) + 'px';
  1504. canvas.style.backgroundPosition = position;
  1505. }
  1506. };
  1507. // Draws page breaks only within the page
  1508. mxGraph.prototype.updatePageBreaks = function(visible, width, height)
  1509. {
  1510. var scale = this.view.scale;
  1511. var tr = this.view.translate;
  1512. var fmt = this.pageFormat;
  1513. var ps = scale * this.pageScale;
  1514. var bounds2 = this.view.getBackgroundPageBounds();
  1515. width = bounds2.width;
  1516. height = bounds2.height;
  1517. var bounds = new mxRectangle(scale * tr.x, scale * tr.y, fmt.width * ps, fmt.height * ps);
  1518. // Does not show page breaks if the scale is too small
  1519. visible = visible && Math.min(bounds.width, bounds.height) > this.minPageBreakDist;
  1520. var horizontalCount = (visible) ? Math.ceil(height / bounds.height) - 1 : 0;
  1521. var verticalCount = (visible) ? Math.ceil(width / bounds.width) - 1 : 0;
  1522. var right = bounds2.x + width;
  1523. var bottom = bounds2.y + height;
  1524. if (this.horizontalPageBreaks == null && horizontalCount > 0)
  1525. {
  1526. this.horizontalPageBreaks = [];
  1527. }
  1528. if (this.verticalPageBreaks == null && verticalCount > 0)
  1529. {
  1530. this.verticalPageBreaks = [];
  1531. }
  1532. var drawPageBreaks = mxUtils.bind(this, function(breaks)
  1533. {
  1534. if (breaks != null)
  1535. {
  1536. var count = (breaks == this.horizontalPageBreaks) ? horizontalCount : verticalCount;
  1537. for (var i = 0; i <= count; i++)
  1538. {
  1539. var pts = (breaks == this.horizontalPageBreaks) ?
  1540. [new mxPoint(Math.round(bounds2.x), Math.round(bounds2.y + (i + 1) * bounds.height)),
  1541. new mxPoint(Math.round(right), Math.round(bounds2.y + (i + 1) * bounds.height))] :
  1542. [new mxPoint(Math.round(bounds2.x + (i + 1) * bounds.width), Math.round(bounds2.y)),
  1543. new mxPoint(Math.round(bounds2.x + (i + 1) * bounds.width), Math.round(bottom))];
  1544. if (breaks[i] != null)
  1545. {
  1546. breaks[i].points = pts;
  1547. breaks[i].redraw();
  1548. }
  1549. else
  1550. {
  1551. var pageBreak = new mxPolyline(pts, this.pageBreakColor);
  1552. pageBreak.dialect = this.dialect;
  1553. pageBreak.isDashed = this.pageBreakDashed;
  1554. pageBreak.pointerEvents = false;
  1555. pageBreak.init(this.view.backgroundPane);
  1556. pageBreak.redraw();
  1557. breaks[i] = pageBreak;
  1558. }
  1559. }
  1560. for (var i = count; i < breaks.length; i++)
  1561. {
  1562. breaks[i].destroy();
  1563. }
  1564. breaks.splice(count, breaks.length - count);
  1565. }
  1566. });
  1567. drawPageBreaks(this.horizontalPageBreaks);
  1568. drawPageBreaks(this.verticalPageBreaks);
  1569. };
  1570. // Disables removing relative children from parents
  1571. var mxGraphHandlerShouldRemoveCellsFromParent = mxGraphHandler.prototype.shouldRemoveCellsFromParent;
  1572. mxGraphHandler.prototype.shouldRemoveCellsFromParent = function(parent, cells, evt)
  1573. {
  1574. for (var i = 0; i < cells.length; i++)
  1575. {
  1576. if (this.graph.getModel().isVertex(cells[i]))
  1577. {
  1578. var geo = this.graph.getCellGeometry(cells[i]);
  1579. if (geo != null && geo.relative)
  1580. {
  1581. return false;
  1582. }
  1583. }
  1584. }
  1585. return mxGraphHandlerShouldRemoveCellsFromParent.apply(this, arguments);
  1586. };
  1587. // Overrides to ignore hotspot only for target terminal
  1588. var mxConnectionHandlerCreateMarker = mxConnectionHandler.prototype.createMarker;
  1589. mxConnectionHandler.prototype.createMarker = function()
  1590. {
  1591. var marker = mxConnectionHandlerCreateMarker.apply(this, arguments);
  1592. marker.intersects = mxUtils.bind(this, function(state, evt)
  1593. {
  1594. if (this.isConnecting())
  1595. {
  1596. return true;
  1597. }
  1598. return mxCellMarker.prototype.intersects.apply(marker, arguments);
  1599. });
  1600. return marker;
  1601. };
  1602. // Creates background page shape
  1603. mxGraphView.prototype.createBackgroundPageShape = function(bounds)
  1604. {
  1605. return new mxRectangleShape(bounds, '#ffffff', '#cacaca');
  1606. };
  1607. // Fits the number of background pages to the graph
  1608. mxGraphView.prototype.getBackgroundPageBounds = function()
  1609. {
  1610. var gb = this.getGraphBounds();
  1611. // Computes unscaled, untranslated graph bounds
  1612. var x = (gb.width > 0) ? gb.x / this.scale - this.translate.x : 0;
  1613. var y = (gb.height > 0) ? gb.y / this.scale - this.translate.y : 0;
  1614. var w = gb.width / this.scale;
  1615. var h = gb.height / this.scale;
  1616. var fmt = this.graph.pageFormat;
  1617. var ps = this.graph.pageScale;
  1618. var pw = fmt.width * ps;
  1619. var ph = fmt.height * ps;
  1620. var x0 = Math.floor(Math.min(0, x) / pw);
  1621. var y0 = Math.floor(Math.min(0, y) / ph);
  1622. var xe = Math.ceil(Math.max(1, x + w) / pw);
  1623. var ye = Math.ceil(Math.max(1, y + h) / ph);
  1624. var rows = xe - x0;
  1625. var cols = ye - y0;
  1626. var bounds = new mxRectangle(this.scale * (this.translate.x + x0 * pw), this.scale *
  1627. (this.translate.y + y0 * ph), this.scale * rows * pw, this.scale * cols * ph);
  1628. return bounds;
  1629. };
  1630. // Add panning for background page in VML
  1631. var graphPanGraph = mxGraph.prototype.panGraph;
  1632. mxGraph.prototype.panGraph = function(dx, dy)
  1633. {
  1634. graphPanGraph.apply(this, arguments);
  1635. if ((this.dialect != mxConstants.DIALECT_SVG && this.view.backgroundPageShape != null) &&
  1636. (!this.useScrollbarsForPanning || !mxUtils.hasScrollbars(this.container)))
  1637. {
  1638. this.view.backgroundPageShape.node.style.marginLeft = dx + 'px';
  1639. this.view.backgroundPageShape.node.style.marginTop = dy + 'px';
  1640. }
  1641. };
  1642. /**
  1643. * Consumes click events for disabled menu items.
  1644. */
  1645. var mxPopupMenuAddItem = mxPopupMenu.prototype.addItem;
  1646. mxPopupMenu.prototype.addItem = function(title, image, funct, parent, iconCls, enabled)
  1647. {
  1648. var result = mxPopupMenuAddItem.apply(this, arguments);
  1649. if (enabled != null && !enabled)
  1650. {
  1651. mxEvent.addListener(result, 'mousedown', function(evt)
  1652. {
  1653. mxEvent.consume(evt);
  1654. });
  1655. }
  1656. return result;
  1657. };
  1658. // Selects ancestors before descendants
  1659. var graphHandlerGetInitialCellForEvent = mxGraphHandler.prototype.getInitialCellForEvent;
  1660. mxGraphHandler.prototype.getInitialCellForEvent = function(me)
  1661. {
  1662. var model = this.graph.getModel();
  1663. var psel = model.getParent(this.graph.getSelectionCell());
  1664. var cell = graphHandlerGetInitialCellForEvent.apply(this, arguments);
  1665. var parent = model.getParent(cell);
  1666. if (psel == null || (psel != cell && psel != parent))
  1667. {
  1668. while (!this.graph.isCellSelected(cell) && !this.graph.isCellSelected(parent) &&
  1669. model.isVertex(parent) && !this.graph.isContainer(parent))
  1670. {
  1671. cell = parent;
  1672. parent = this.graph.getModel().getParent(cell);
  1673. }
  1674. }
  1675. return cell;
  1676. };
  1677. // Selection is delayed to mouseup if ancestor is selected
  1678. var graphHandlerIsDelayedSelection = mxGraphHandler.prototype.isDelayedSelection;
  1679. mxGraphHandler.prototype.isDelayedSelection = function(cell, me)
  1680. {
  1681. var result = graphHandlerIsDelayedSelection.apply(this, arguments);
  1682. if (!result)
  1683. {
  1684. var model = this.graph.getModel();
  1685. var parent = model.getParent(cell);
  1686. while (parent != null)
  1687. {
  1688. // Inconsistency for unselected parent swimlane is intended for easier moving
  1689. // of stack layouts where the container title section is too far away
  1690. if (this.graph.isCellSelected(parent) && model.isVertex(parent))
  1691. {
  1692. result = true;
  1693. break;
  1694. }
  1695. parent = model.getParent(parent);
  1696. }
  1697. }
  1698. return result;
  1699. };
  1700. // Delayed selection of parent group
  1701. mxGraphHandler.prototype.selectDelayed = function(me)
  1702. {
  1703. if (!this.graph.popupMenuHandler.isPopupTrigger(me))
  1704. {
  1705. var cell = me.getCell();
  1706. if (cell == null)
  1707. {
  1708. cell = this.cell;
  1709. }
  1710. // Selects folded cell for hit on folding icon
  1711. var state = this.graph.view.getState(cell)
  1712. if (state != null && me.isSource(state.control))
  1713. {
  1714. this.graph.selectCellForEvent(cell, me.getEvent());
  1715. }
  1716. else
  1717. {
  1718. var model = this.graph.getModel();
  1719. var parent = model.getParent(cell);
  1720. while (!this.graph.isCellSelected(parent) && model.isVertex(parent))
  1721. {
  1722. cell = parent;
  1723. parent = model.getParent(cell);
  1724. }
  1725. this.graph.selectCellForEvent(cell, me.getEvent());
  1726. }
  1727. }
  1728. };
  1729. // Returns last selected ancestor
  1730. mxPopupMenuHandler.prototype.getCellForPopupEvent = function(me)
  1731. {
  1732. var cell = me.getCell();
  1733. var model = this.graph.getModel();
  1734. var parent = model.getParent(cell);
  1735. while (model.isVertex(parent) && !this.graph.isContainer(parent))
  1736. {
  1737. if (this.graph.isCellSelected(parent))
  1738. {
  1739. cell = parent;
  1740. }
  1741. parent = model.getParent(parent);
  1742. }
  1743. return cell;
  1744. };
  1745. })();