Editor.js 71 KB

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