Editor.js 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141
  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. if (h > dh - 64)
  611. {
  612. elt.style.overflowY = 'auto';
  613. }
  614. h = Math.min(h, dh - 64);
  615. // Increments zIndex to put subdialogs and background over existing dialogs and background
  616. if (editorUi.dialogs.length > 0)
  617. {
  618. this.zIndex += editorUi.dialogs.length * 2;
  619. }
  620. var div = editorUi.createDiv('geDialog');
  621. div.style.width = w + 'px';
  622. div.style.height = h + 'px';
  623. div.style.left = left + 'px';
  624. div.style.top = top + 'px';
  625. div.style.zIndex = this.zIndex;
  626. if (this.bg == null)
  627. {
  628. this.bg = editorUi.createDiv('background');
  629. this.bg.style.position = 'absolute';
  630. this.bg.style.background = 'white';
  631. this.bg.style.left = '0px';
  632. this.bg.style.top = '0px';
  633. this.bg.style.bottom = '0px';
  634. this.bg.style.right = '0px';
  635. this.bg.style.zIndex = this.zIndex - 2;
  636. mxUtils.setOpacity(this.bg, this.bgOpacity);
  637. if (mxClient.IS_QUIRKS)
  638. {
  639. new mxDivResizer(this.bg);
  640. }
  641. }
  642. if (modal)
  643. {
  644. document.body.appendChild(this.bg);
  645. }
  646. div.appendChild(elt);
  647. document.body.appendChild(div);
  648. if (closable)
  649. {
  650. var img = document.createElement('img');
  651. img.setAttribute('src', Dialog.prototype.closeImage);
  652. img.setAttribute('title', mxResources.get('close'));
  653. img.className = 'geDialogClose';
  654. img.style.top = (top + 14) + 'px';
  655. img.style.left = (left + w + 38 - dx) + 'px';
  656. img.style.zIndex = this.zIndex;
  657. mxEvent.addListener(img, 'click', mxUtils.bind(this, function()
  658. {
  659. editorUi.hideDialog(true);
  660. }));
  661. document.body.appendChild(img);
  662. this.dialogImg = img;
  663. mxEvent.addGestureListeners(this.bg, null, null, mxUtils.bind(this, function(evt)
  664. {
  665. editorUi.hideDialog(true);
  666. }));
  667. }
  668. this.onDialogClose = onClose;
  669. this.container = div;
  670. editorUi.editor.fireEvent(new mxEventObject('showDialog'));
  671. };
  672. /**
  673. *
  674. */
  675. Dialog.prototype.zIndex = mxPopupMenu.prototype.zIndex - 1;
  676. /**
  677. *
  678. */
  679. Dialog.prototype.noColorImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/nocolor.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOkEzRDlBMUUwODYxMTExRTFCMzA4RDdDMjJBMEMxRDM3IiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOkEzRDlBMUUxODYxMTExRTFCMzA4RDdDMjJBMEMxRDM3Ij4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6QTNEOUExREU4NjExMTFFMUIzMDhEN0MyMkEwQzFEMzciIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6QTNEOUExREY4NjExMTFFMUIzMDhEN0MyMkEwQzFEMzciLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz5xh3fmAAAABlBMVEX////MzMw46qqDAAAAGElEQVR42mJggAJGKGAYIIGBth8KAAIMAEUQAIElnLuQAAAAAElFTkSuQmCC';
  680. /**
  681. *
  682. */
  683. Dialog.prototype.closeImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/close.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJAQMAAADaX5RTAAAABlBMVEV7mr3///+wksspAAAAAnRSTlP/AOW3MEoAAAAdSURBVAgdY9jXwCDDwNDRwHCwgeExmASygSL7GgB12QiqNHZZIwAAAABJRU5ErkJggg==';
  684. /**
  685. *
  686. */
  687. 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==';
  688. /**
  689. *
  690. */
  691. Dialog.prototype.lockedImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/locked.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAMAAABhq6zVAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MzdDMDZCODExNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MzdDMDZCODIxNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDozN0MwNkI3RjE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDozN0MwNkI4MDE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PvqMCFYAAAAVUExURZmZmb+/v7KysqysrMzMzLGxsf///4g8N1cAAAAHdFJOU////////wAaSwNGAAAAPElEQVR42lTMQQ4AIQgEwUa0//9kTQirOweYOgDqAMbZUr10AGlAwx4/BJ2QJ4U0L5brYjovvpv32xZgAHZaATFtMbu4AAAAAElFTkSuQmCC';
  692. /**
  693. *
  694. */
  695. Dialog.prototype.unlockedImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/unlocked.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAMAAABhq6zVAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MzdDMDZCN0QxNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MzdDMDZCN0UxNzIxMTFFNUI0RTk5NTg4OTcyMUUyODEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDozN0MwNkI3QjE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDozN0MwNkI3QzE3MjExMUU1QjRFOTk1ODg5NzIxRTI4MSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PkKMpVwAAAAYUExURZmZmbKysr+/v6ysrOXl5czMzLGxsf///zHN5lwAAAAIdFJOU/////////8A3oO9WQAAADxJREFUeNpUzFESACAEBNBVsfe/cZJU+8Mzs8CIABCidtfGOndnYsT40HDSiCcbPdoJo10o9aI677cpwACRoAF3dFNlswAAAABJRU5ErkJggg==';
  696. /**
  697. * Removes the dialog from the DOM.
  698. */
  699. Dialog.prototype.bgOpacity = 80;
  700. /**
  701. * Removes the dialog from the DOM.
  702. */
  703. Dialog.prototype.close = function(cancel)
  704. {
  705. if (this.onDialogClose != null)
  706. {
  707. this.onDialogClose(cancel);
  708. this.onDialogClose = null;
  709. }
  710. if (this.dialogImg != null)
  711. {
  712. this.dialogImg.parentNode.removeChild(this.dialogImg);
  713. this.dialogImg = null;
  714. }
  715. if (this.bg != null && this.bg.parentNode != null)
  716. {
  717. this.bg.parentNode.removeChild(this.bg);
  718. }
  719. this.container.parentNode.removeChild(this.container);
  720. };
  721. /**
  722. * Constructs a new print dialog.
  723. */
  724. var PrintDialog = function(editorUi, title)
  725. {
  726. this.create(editorUi, title);
  727. };
  728. /**
  729. * Constructs a new print dialog.
  730. */
  731. PrintDialog.prototype.create = function(editorUi)
  732. {
  733. var graph = editorUi.editor.graph;
  734. var row, td;
  735. var table = document.createElement('table');
  736. table.style.width = '100%';
  737. table.style.height = '100%';
  738. var tbody = document.createElement('tbody');
  739. row = document.createElement('tr');
  740. var onePageCheckBox = document.createElement('input');
  741. onePageCheckBox.setAttribute('type', 'checkbox');
  742. td = document.createElement('td');
  743. td.setAttribute('colspan', '2');
  744. td.style.fontSize = '10pt';
  745. td.appendChild(onePageCheckBox);
  746. var span = document.createElement('span');
  747. mxUtils.write(span, ' ' + mxResources.get('fitPage'));
  748. td.appendChild(span);
  749. mxEvent.addListener(span, 'click', function(evt)
  750. {
  751. onePageCheckBox.checked = !onePageCheckBox.checked;
  752. pageCountCheckBox.checked = !onePageCheckBox.checked;
  753. mxEvent.consume(evt);
  754. });
  755. mxEvent.addListener(onePageCheckBox, 'change', function()
  756. {
  757. pageCountCheckBox.checked = !onePageCheckBox.checked;
  758. });
  759. row.appendChild(td);
  760. tbody.appendChild(row);
  761. row = row.cloneNode(false);
  762. var pageCountCheckBox = document.createElement('input');
  763. pageCountCheckBox.setAttribute('type', 'checkbox');
  764. td = document.createElement('td');
  765. td.style.fontSize = '10pt';
  766. td.appendChild(pageCountCheckBox);
  767. var span = document.createElement('span');
  768. mxUtils.write(span, ' ' + mxResources.get('posterPrint') + ':');
  769. td.appendChild(span);
  770. mxEvent.addListener(span, 'click', function(evt)
  771. {
  772. pageCountCheckBox.checked = !pageCountCheckBox.checked;
  773. onePageCheckBox.checked = !pageCountCheckBox.checked;
  774. mxEvent.consume(evt);
  775. });
  776. row.appendChild(td);
  777. var pageCountInput = document.createElement('input');
  778. pageCountInput.setAttribute('value', '1');
  779. pageCountInput.setAttribute('type', 'number');
  780. pageCountInput.setAttribute('min', '1');
  781. pageCountInput.setAttribute('size', '4');
  782. pageCountInput.setAttribute('disabled', 'disabled');
  783. pageCountInput.style.width = '50px';
  784. td = document.createElement('td');
  785. td.style.fontSize = '10pt';
  786. td.appendChild(pageCountInput);
  787. mxUtils.write(td, ' ' + mxResources.get('pages') + ' (max)');
  788. row.appendChild(td);
  789. tbody.appendChild(row);
  790. mxEvent.addListener(pageCountCheckBox, 'change', function()
  791. {
  792. if (pageCountCheckBox.checked)
  793. {
  794. pageCountInput.removeAttribute('disabled');
  795. }
  796. else
  797. {
  798. pageCountInput.setAttribute('disabled', 'disabled');
  799. }
  800. onePageCheckBox.checked = !pageCountCheckBox.checked;
  801. });
  802. row = row.cloneNode(false);
  803. td = document.createElement('td');
  804. mxUtils.write(td, mxResources.get('pageScale') + ':');
  805. row.appendChild(td);
  806. td = document.createElement('td');
  807. var pageScaleInput = document.createElement('input');
  808. pageScaleInput.setAttribute('value', '100 %');
  809. pageScaleInput.setAttribute('size', '5');
  810. pageScaleInput.style.width = '50px';
  811. td.appendChild(pageScaleInput);
  812. row.appendChild(td);
  813. tbody.appendChild(row);
  814. row = document.createElement('tr');
  815. td = document.createElement('td');
  816. td.colSpan = 2;
  817. td.style.paddingTop = '20px';
  818. td.setAttribute('align', 'right');
  819. // Overall scale for print-out to account for print borders in dialogs etc
  820. function preview(print)
  821. {
  822. var autoOrigin = onePageCheckBox.checked || pageCountCheckBox.checked;
  823. var printScale = parseInt(pageScaleInput.value) / 100;
  824. if (isNaN(printScale))
  825. {
  826. printScale = 1;
  827. pageScaleInput.value = '100%';
  828. }
  829. // Workaround to match available paper size in actual print output
  830. printScale *= 0.75;
  831. var pf = graph.pageFormat || mxConstants.PAGE_FORMAT_A4_PORTRAIT;
  832. var scale = 1 / graph.pageScale;
  833. if (autoOrigin)
  834. {
  835. var pageCount = (onePageCheckBox.checked) ? 1 : parseInt(pageCountInput.value);
  836. if (!isNaN(pageCount))
  837. {
  838. scale = mxUtils.getScaleForPageCount(pageCount, graph, pf);
  839. }
  840. }
  841. // Negative coordinates are cropped or shifted if page visible
  842. var gb = graph.getGraphBounds();
  843. var border = 0;
  844. var x0 = 0;
  845. var y0 = 0;
  846. // Applies print scale
  847. pf = mxRectangle.fromRectangle(pf);
  848. pf.width = Math.ceil(pf.width * printScale);
  849. pf.height = Math.ceil(pf.height * printScale);
  850. scale *= printScale;
  851. // Starts at first visible page
  852. if (!autoOrigin && graph.pageVisible)
  853. {
  854. var layout = graph.getPageLayout();
  855. x0 -= layout.x * pf.width;
  856. y0 -= layout.y * pf.height;
  857. }
  858. else
  859. {
  860. autoOrigin = true;
  861. }
  862. var preview = PrintDialog.createPrintPreview(graph, scale, pf, border, x0, y0, autoOrigin);
  863. preview.open();
  864. if (print)
  865. {
  866. PrintDialog.printPreview(preview);
  867. }
  868. };
  869. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  870. {
  871. editorUi.hideDialog();
  872. });
  873. cancelBtn.className = 'geBtn';
  874. if (editorUi.editor.cancelFirst)
  875. {
  876. td.appendChild(cancelBtn);
  877. }
  878. if (PrintDialog.previewEnabled)
  879. {
  880. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  881. {
  882. editorUi.hideDialog();
  883. preview(false);
  884. });
  885. previewBtn.className = 'geBtn';
  886. td.appendChild(previewBtn);
  887. }
  888. var printBtn = mxUtils.button(mxResources.get((!PrintDialog.previewEnabled) ? 'ok' : 'print'), function()
  889. {
  890. editorUi.hideDialog();
  891. preview(true);
  892. });
  893. printBtn.className = 'geBtn gePrimaryBtn';
  894. td.appendChild(printBtn);
  895. if (!editorUi.editor.cancelFirst)
  896. {
  897. td.appendChild(cancelBtn);
  898. }
  899. row.appendChild(td);
  900. tbody.appendChild(row);
  901. table.appendChild(tbody);
  902. this.container = table;
  903. };
  904. /**
  905. * Constructs a new print dialog.
  906. */
  907. PrintDialog.printPreview = function(preview)
  908. {
  909. if (preview.wnd != null)
  910. {
  911. var printFn = function()
  912. {
  913. preview.wnd.focus();
  914. preview.wnd.print();
  915. preview.wnd.close();
  916. };
  917. // Workaround for Google Chrome which needs a bit of a
  918. // delay in order to render the SVG contents
  919. // Needs testing in production
  920. if (mxClient.IS_GC)
  921. {
  922. window.setTimeout(printFn, 500);
  923. }
  924. else
  925. {
  926. printFn();
  927. }
  928. }
  929. };
  930. /**
  931. * Constructs a new print dialog.
  932. */
  933. PrintDialog.createPrintPreview = function(graph, scale, pf, border, x0, y0, autoOrigin)
  934. {
  935. var preview = new mxPrintPreview(graph, scale, pf, border, x0, y0);
  936. preview.title = mxResources.get('preview');
  937. preview.printBackgroundImage = true;
  938. preview.autoOrigin = autoOrigin;
  939. var bg = graph.background;
  940. if (bg == null || bg == '' || bg == mxConstants.NONE)
  941. {
  942. bg = '#ffffff';
  943. }
  944. preview.backgroundColor = bg;
  945. var writeHead = preview.writeHead;
  946. // Adds a border in the preview
  947. preview.writeHead = function(doc)
  948. {
  949. writeHead.apply(this, arguments);
  950. doc.writeln('<style type="text/css">');
  951. doc.writeln('@media screen {');
  952. doc.writeln(' body > div { padding:30px;box-sizing:content-box; }');
  953. doc.writeln('}');
  954. doc.writeln('</style>');
  955. };
  956. return preview;
  957. };
  958. /**
  959. * Specifies if the preview button should be enabled. Default is true.
  960. */
  961. PrintDialog.previewEnabled = true;
  962. /**
  963. * Constructs a new page setup dialog.
  964. */
  965. var PageSetupDialog = function(editorUi)
  966. {
  967. var graph = editorUi.editor.graph;
  968. var row, td;
  969. var table = document.createElement('table');
  970. table.style.width = '100%';
  971. table.style.height = '100%';
  972. var tbody = document.createElement('tbody');
  973. row = document.createElement('tr');
  974. td = document.createElement('td');
  975. td.style.verticalAlign = 'top';
  976. td.style.fontSize = '10pt';
  977. mxUtils.write(td, mxResources.get('paperSize') + ':');
  978. row.appendChild(td);
  979. td = document.createElement('td');
  980. td.style.verticalAlign = 'top';
  981. td.style.fontSize = '10pt';
  982. var accessor = PageSetupDialog.addPageFormatPanel(td, 'pagesetupdialog', graph.pageFormat);
  983. row.appendChild(td);
  984. tbody.appendChild(row);
  985. row = document.createElement('tr');
  986. td = document.createElement('td');
  987. mxUtils.write(td, mxResources.get('background') + ':');
  988. row.appendChild(td);
  989. td = document.createElement('td');
  990. td.style.whiteSpace = 'nowrap';
  991. var backgroundInput = document.createElement('input');
  992. backgroundInput.setAttribute('type', 'text');
  993. var backgroundButton = document.createElement('button');
  994. backgroundButton.style.width = '18px';
  995. backgroundButton.style.height = '18px';
  996. backgroundButton.style.marginRight = '20px';
  997. backgroundButton.style.backgroundPosition = 'center center';
  998. backgroundButton.style.backgroundRepeat = 'no-repeat';
  999. var newBackgroundColor = graph.background;
  1000. function updateBackgroundColor()
  1001. {
  1002. if (newBackgroundColor == null || newBackgroundColor == mxConstants.NONE)
  1003. {
  1004. backgroundButton.style.backgroundColor = '';
  1005. backgroundButton.style.backgroundImage = 'url(\'' + Dialog.prototype.noColorImage + '\')';
  1006. }
  1007. else
  1008. {
  1009. backgroundButton.style.backgroundColor = newBackgroundColor;
  1010. backgroundButton.style.backgroundImage = '';
  1011. }
  1012. };
  1013. updateBackgroundColor();
  1014. mxEvent.addListener(backgroundButton, 'click', function(evt)
  1015. {
  1016. editorUi.pickColor(newBackgroundColor || 'none', function(color)
  1017. {
  1018. newBackgroundColor = color;
  1019. updateBackgroundColor();
  1020. });
  1021. mxEvent.consume(evt);
  1022. });
  1023. td.appendChild(backgroundButton);
  1024. mxUtils.write(td, mxResources.get('gridSize') + ':');
  1025. var gridSizeInput = document.createElement('input');
  1026. gridSizeInput.setAttribute('type', 'number');
  1027. gridSizeInput.setAttribute('min', '0');
  1028. gridSizeInput.style.width = '40px';
  1029. gridSizeInput.style.marginLeft = '6px';
  1030. gridSizeInput.value = graph.getGridSize();
  1031. td.appendChild(gridSizeInput);
  1032. mxEvent.addListener(gridSizeInput, 'change', function()
  1033. {
  1034. var value = parseInt(gridSizeInput.value);
  1035. gridSizeInput.value = Math.max(1, (isNaN(value)) ? graph.getGridSize() : value);
  1036. });
  1037. row.appendChild(td);
  1038. tbody.appendChild(row);
  1039. row = document.createElement('tr');
  1040. td = document.createElement('td');
  1041. mxUtils.write(td, mxResources.get('image') + ':');
  1042. row.appendChild(td);
  1043. td = document.createElement('td');
  1044. var changeImageLink = document.createElement('a');
  1045. changeImageLink.style.textDecoration = 'underline';
  1046. changeImageLink.style.cursor = 'pointer';
  1047. changeImageLink.style.color = '#a0a0a0';
  1048. var newBackgroundImage = graph.backgroundImage;
  1049. function updateBackgroundImage()
  1050. {
  1051. if (newBackgroundImage == null)
  1052. {
  1053. changeImageLink.removeAttribute('title');
  1054. changeImageLink.style.fontSize = '';
  1055. changeImageLink.innerHTML = mxResources.get('change') + '...';
  1056. }
  1057. else
  1058. {
  1059. changeImageLink.setAttribute('title', newBackgroundImage.src);
  1060. changeImageLink.style.fontSize = '11px';
  1061. changeImageLink.innerHTML = newBackgroundImage.src.substring(0, 42) + '...';
  1062. }
  1063. };
  1064. mxEvent.addListener(changeImageLink, 'click', function(evt)
  1065. {
  1066. editorUi.showBackgroundImageDialog(function(image)
  1067. {
  1068. newBackgroundImage = image;
  1069. updateBackgroundImage();
  1070. });
  1071. mxEvent.consume(evt);
  1072. });
  1073. updateBackgroundImage();
  1074. td.appendChild(changeImageLink);
  1075. row.appendChild(td);
  1076. tbody.appendChild(row);
  1077. row = document.createElement('tr');
  1078. td = document.createElement('td');
  1079. td.colSpan = 2;
  1080. td.style.paddingTop = '16px';
  1081. td.setAttribute('align', 'right');
  1082. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1083. {
  1084. editorUi.hideDialog();
  1085. });
  1086. cancelBtn.className = 'geBtn';
  1087. if (editorUi.editor.cancelFirst)
  1088. {
  1089. td.appendChild(cancelBtn);
  1090. }
  1091. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  1092. {
  1093. editorUi.hideDialog();
  1094. editorUi.setPageFormat(accessor.get());
  1095. if (graph.background != newBackgroundColor)
  1096. {
  1097. editorUi.setBackgroundColor(newBackgroundColor);
  1098. }
  1099. if (graph.backgroundImage !== newBackgroundImage)
  1100. {
  1101. editorUi.setBackgroundImage(newBackgroundImage);
  1102. }
  1103. if (graph.gridSize !== gridSizeInput.value)
  1104. {
  1105. graph.setGridSize(parseInt(gridSizeInput.value));
  1106. }
  1107. });
  1108. applyBtn.className = 'geBtn gePrimaryBtn';
  1109. td.appendChild(applyBtn);
  1110. if (!editorUi.editor.cancelFirst)
  1111. {
  1112. td.appendChild(cancelBtn);
  1113. }
  1114. row.appendChild(td);
  1115. tbody.appendChild(row);
  1116. table.appendChild(tbody);
  1117. this.container = table;
  1118. };
  1119. /**
  1120. *
  1121. */
  1122. PageSetupDialog.addPageFormatPanel = function(div, namePostfix, pageFormat, pageFormatListener)
  1123. {
  1124. var formatName = 'format-' + namePostfix;
  1125. var portraitCheckBox = document.createElement('input');
  1126. portraitCheckBox.setAttribute('name', formatName);
  1127. portraitCheckBox.setAttribute('type', 'radio');
  1128. portraitCheckBox.setAttribute('value', 'portrait');
  1129. var landscapeCheckBox = document.createElement('input');
  1130. landscapeCheckBox.setAttribute('name', formatName);
  1131. landscapeCheckBox.setAttribute('type', 'radio');
  1132. landscapeCheckBox.setAttribute('value', 'landscape');
  1133. var paperSizeSelect = document.createElement('select');
  1134. paperSizeSelect.style.marginBottom = '8px';
  1135. paperSizeSelect.style.width = '202px';
  1136. var formatDiv = document.createElement('div');
  1137. formatDiv.style.marginLeft = '4px';
  1138. formatDiv.style.width = '210px';
  1139. formatDiv.style.height = '24px';
  1140. portraitCheckBox.style.marginRight = '6px';
  1141. formatDiv.appendChild(portraitCheckBox);
  1142. var portraitSpan = document.createElement('span');
  1143. portraitSpan.style.maxWidth = '100px';
  1144. mxUtils.write(portraitSpan, mxResources.get('portrait'));
  1145. formatDiv.appendChild(portraitSpan);
  1146. landscapeCheckBox.style.marginLeft = '10px';
  1147. landscapeCheckBox.style.marginRight = '6px';
  1148. formatDiv.appendChild(landscapeCheckBox);
  1149. var landscapeSpan = document.createElement('span');
  1150. landscapeSpan.style.width = '100px';
  1151. mxUtils.write(landscapeSpan, mxResources.get('landscape'));
  1152. formatDiv.appendChild(landscapeSpan)
  1153. var customDiv = document.createElement('div');
  1154. customDiv.style.marginLeft = '4px';
  1155. customDiv.style.width = '210px';
  1156. customDiv.style.height = '24px';
  1157. var widthInput = document.createElement('input');
  1158. widthInput.setAttribute('size', '7');
  1159. widthInput.setAttribute('value', pageFormat.width);
  1160. widthInput.style.textAlign = 'right';
  1161. customDiv.appendChild(widthInput);
  1162. mxUtils.write(customDiv, ' in x ');
  1163. var heightInput = document.createElement('input');
  1164. heightInput.setAttribute('size', '7');
  1165. heightInput.setAttribute('value', pageFormat.height);
  1166. heightInput.style.textAlign = 'right';
  1167. customDiv.appendChild(heightInput);
  1168. mxUtils.write(customDiv, ' in');
  1169. formatDiv.style.display = 'none';
  1170. customDiv.style.display = 'none';
  1171. var pf = new Object();
  1172. var formats = PageSetupDialog.getFormats();
  1173. for (var i = 0; i < formats.length; i++)
  1174. {
  1175. var f = formats[i];
  1176. pf[f.key] = f;
  1177. var paperSizeOption = document.createElement('option');
  1178. paperSizeOption.setAttribute('value', f.key);
  1179. mxUtils.write(paperSizeOption, f.title);
  1180. paperSizeSelect.appendChild(paperSizeOption);
  1181. }
  1182. var customSize = false;
  1183. function listener(sender, evt, force)
  1184. {
  1185. if (force || (widthInput != document.activeElement && heightInput != document.activeElement))
  1186. {
  1187. var detected = false;
  1188. for (var i = 0; i < formats.length; i++)
  1189. {
  1190. var f = formats[i];
  1191. // Special case where custom was chosen
  1192. if (customSize)
  1193. {
  1194. if (f.key == 'custom')
  1195. {
  1196. paperSizeSelect.value = f.key;
  1197. customSize = false;
  1198. }
  1199. }
  1200. else if (f.format != null)
  1201. {
  1202. // Fixes wrong values for previous A4 and A5 page sizes
  1203. if (f.key == 'a4')
  1204. {
  1205. if (pageFormat.width == 826)
  1206. {
  1207. pageFormat = mxRectangle.fromRectangle(pageFormat);
  1208. pageFormat.width = 827;
  1209. }
  1210. else if (pageFormat.height == 826)
  1211. {
  1212. pageFormat = mxRectangle.fromRectangle(pageFormat);
  1213. pageFormat.height = 827;
  1214. }
  1215. }
  1216. else if (f.key == 'a5')
  1217. {
  1218. if (pageFormat.width == 584)
  1219. {
  1220. pageFormat = mxRectangle.fromRectangle(pageFormat);
  1221. pageFormat.width = 583;
  1222. }
  1223. else if (pageFormat.height == 584)
  1224. {
  1225. pageFormat = mxRectangle.fromRectangle(pageFormat);
  1226. pageFormat.height = 583;
  1227. }
  1228. }
  1229. if (pageFormat.width == f.format.width && pageFormat.height == f.format.height)
  1230. {
  1231. paperSizeSelect.value = f.key;
  1232. portraitCheckBox.setAttribute('checked', 'checked');
  1233. portraitCheckBox.defaultChecked = true;
  1234. portraitCheckBox.checked = true;
  1235. landscapeCheckBox.removeAttribute('checked');
  1236. landscapeCheckBox.defaultChecked = false;
  1237. landscapeCheckBox.checked = false;
  1238. detected = true;
  1239. }
  1240. else if (pageFormat.width == f.format.height && pageFormat.height == f.format.width)
  1241. {
  1242. paperSizeSelect.value = f.key;
  1243. portraitCheckBox.removeAttribute('checked');
  1244. portraitCheckBox.defaultChecked = false;
  1245. portraitCheckBox.checked = false;
  1246. landscapeCheckBox.setAttribute('checked', 'checked');
  1247. landscapeCheckBox.defaultChecked = true;
  1248. landscapeCheckBox.checked = true;
  1249. detected = true;
  1250. }
  1251. }
  1252. }
  1253. // Selects custom format which is last in list
  1254. if (!detected)
  1255. {
  1256. widthInput.value = pageFormat.width / 100;
  1257. heightInput.value =pageFormat.height / 100;
  1258. paperSizeOption.setAttribute('selected', 'selected');
  1259. portraitCheckBox.setAttribute('checked', 'checked');
  1260. portraitCheckBox.defaultChecked = true;
  1261. formatDiv.style.display = 'none';
  1262. customDiv.style.display = '';
  1263. }
  1264. else
  1265. {
  1266. formatDiv.style.display = '';
  1267. customDiv.style.display = 'none';
  1268. }
  1269. }
  1270. };
  1271. listener();
  1272. div.appendChild(paperSizeSelect);
  1273. mxUtils.br(div);
  1274. div.appendChild(formatDiv);
  1275. div.appendChild(customDiv);
  1276. var currentPageFormat = pageFormat;
  1277. var update = function()
  1278. {
  1279. var f = pf[paperSizeSelect.value];
  1280. if (f.format != null)
  1281. {
  1282. widthInput.value = f.format.width / 100;
  1283. heightInput.value = f.format.height / 100;
  1284. customDiv.style.display = 'none';
  1285. formatDiv.style.display = '';
  1286. }
  1287. else
  1288. {
  1289. formatDiv.style.display = 'none';
  1290. customDiv.style.display = '';
  1291. }
  1292. var newPageFormat = new mxRectangle(0, 0,
  1293. Math.floor(parseFloat(widthInput.value) * 100),
  1294. Math.floor(parseFloat(heightInput.value) * 100));
  1295. if (paperSizeSelect.value != 'custom' && landscapeCheckBox.checked)
  1296. {
  1297. newPageFormat = new mxRectangle(0, 0, newPageFormat.height, newPageFormat.width);
  1298. }
  1299. if (newPageFormat.width != currentPageFormat.width || newPageFormat.height != currentPageFormat.height)
  1300. {
  1301. currentPageFormat = newPageFormat;
  1302. if (pageFormatListener != null)
  1303. {
  1304. pageFormatListener(currentPageFormat);
  1305. }
  1306. }
  1307. };
  1308. mxEvent.addListener(portraitSpan, 'click', function(evt)
  1309. {
  1310. portraitCheckBox.checked = true;
  1311. update();
  1312. mxEvent.consume(evt);
  1313. });
  1314. mxEvent.addListener(landscapeSpan, 'click', function(evt)
  1315. {
  1316. landscapeCheckBox.checked = true;
  1317. update();
  1318. mxEvent.consume(evt);
  1319. });
  1320. mxEvent.addListener(widthInput, 'blur', update);
  1321. mxEvent.addListener(widthInput, 'click', update);
  1322. mxEvent.addListener(heightInput, 'blur', update);
  1323. mxEvent.addListener(heightInput, 'click', update);
  1324. mxEvent.addListener(landscapeCheckBox, 'change', update);
  1325. mxEvent.addListener(portraitCheckBox, 'change', update);
  1326. mxEvent.addListener(paperSizeSelect, 'change', function()
  1327. {
  1328. // Handles special case where custom was chosen
  1329. customSize = paperSizeSelect.value == 'custom';
  1330. update();
  1331. });
  1332. update();
  1333. return {set: function(value)
  1334. {
  1335. pageFormat = value;
  1336. listener(null, null, true);
  1337. },get: function()
  1338. {
  1339. return currentPageFormat;
  1340. }, widthInput: widthInput,
  1341. heightInput: heightInput};
  1342. };
  1343. /**
  1344. *
  1345. */
  1346. PageSetupDialog.getFormats = function()
  1347. {
  1348. return [{key: 'letter', title: 'US-Letter (8,5" x 11")', format: mxConstants.PAGE_FORMAT_LETTER_PORTRAIT},
  1349. {key: 'legal', title: 'US-Legal (8,5" x 14")', format: new mxRectangle(0, 0, 850, 1400)},
  1350. {key: 'tabloid', title: 'US-Tabloid (279 mm x 432 mm)', format: new mxRectangle(0, 0, 1100, 1700)},
  1351. {key: 'a0', title: 'A0 (841 mm x 1189 mm)', format: new mxRectangle(0, 0, 3300, 4681)},
  1352. {key: 'a1', title: 'A1 (594 mm x 841 mm)', format: new mxRectangle(0, 0, 2339, 3300)},
  1353. {key: 'a2', title: 'A2 (420 mm x 594 mm)', format: new mxRectangle(0, 0, 1654, 2336)},
  1354. {key: 'a3', title: 'A3 (297 mm x 420 mm)', format: new mxRectangle(0, 0, 1169, 1654)},
  1355. {key: 'a4', title: 'A4 (210 mm x 297 mm)', format: mxConstants.PAGE_FORMAT_A4_PORTRAIT},
  1356. {key: 'a5', title: 'A5 (148 mm x 210 mm)', format: new mxRectangle(0, 0, 583, 827)},
  1357. {key: 'a6', title: 'A6 (105 mm x 148 mm)', format: new mxRectangle(0, 0, 413, 583)},
  1358. {key: 'a7', title: 'A7 (74 mm x 105 mm)', format: new mxRectangle(0, 0, 291, 413)},
  1359. {key: 'custom', title: mxResources.get('custom'), format: null}];
  1360. };
  1361. /**
  1362. * Static overrides
  1363. */
  1364. (function()
  1365. {
  1366. // Uses HTML for background pages (to support grid background image)
  1367. mxGraphView.prototype.validateBackgroundPage = function()
  1368. {
  1369. var graph = this.graph;
  1370. if (graph.container != null && !graph.transparentBackground)
  1371. {
  1372. if (graph.pageVisible)
  1373. {
  1374. var bounds = this.getBackgroundPageBounds();
  1375. if (this.backgroundPageShape == null)
  1376. {
  1377. // Finds first element in graph container
  1378. var firstChild = graph.container.firstChild;
  1379. while (firstChild != null && firstChild.nodeType != mxConstants.NODETYPE_ELEMENT)
  1380. {
  1381. firstChild = firstChild.nextSibling;
  1382. }
  1383. if (firstChild != null)
  1384. {
  1385. this.backgroundPageShape = this.createBackgroundPageShape(bounds);
  1386. this.backgroundPageShape.scale = 1;
  1387. // Shadow filter causes problems in outline window in quirks mode. IE8 standards
  1388. // also has known rendering issues inside mxWindow but not using shadow is worse.
  1389. this.backgroundPageShape.isShadow = !mxClient.IS_QUIRKS;
  1390. this.backgroundPageShape.dialect = mxConstants.DIALECT_STRICTHTML;
  1391. this.backgroundPageShape.init(graph.container);
  1392. // Required for the browser to render the background page in correct order
  1393. firstChild.style.position = 'absolute';
  1394. graph.container.insertBefore(this.backgroundPageShape.node, firstChild);
  1395. this.backgroundPageShape.redraw();
  1396. this.backgroundPageShape.node.className = 'geBackgroundPage';
  1397. // Adds listener for double click handling on background
  1398. mxEvent.addListener(this.backgroundPageShape.node, 'dblclick',
  1399. mxUtils.bind(this, function(evt)
  1400. {
  1401. graph.dblClick(evt);
  1402. })
  1403. );
  1404. // Adds basic listeners for graph event dispatching outside of the
  1405. // container and finishing the handling of a single gesture
  1406. mxEvent.addGestureListeners(this.backgroundPageShape.node,
  1407. mxUtils.bind(this, function(evt)
  1408. {
  1409. graph.fireMouseEvent(mxEvent.MOUSE_DOWN, new mxMouseEvent(evt));
  1410. }),
  1411. mxUtils.bind(this, function(evt)
  1412. {
  1413. // Hides the tooltip if mouse is outside container
  1414. if (graph.tooltipHandler != null && graph.tooltipHandler.isHideOnHover())
  1415. {
  1416. graph.tooltipHandler.hide();
  1417. }
  1418. if (graph.isMouseDown && !mxEvent.isConsumed(evt))
  1419. {
  1420. graph.fireMouseEvent(mxEvent.MOUSE_MOVE, new mxMouseEvent(evt));
  1421. }
  1422. }),
  1423. mxUtils.bind(this, function(evt)
  1424. {
  1425. graph.fireMouseEvent(mxEvent.MOUSE_UP, new mxMouseEvent(evt));
  1426. })
  1427. );
  1428. }
  1429. }
  1430. else
  1431. {
  1432. this.backgroundPageShape.scale = 1;
  1433. this.backgroundPageShape.bounds = bounds;
  1434. this.backgroundPageShape.redraw();
  1435. }
  1436. }
  1437. else if (this.backgroundPageShape != null)
  1438. {
  1439. this.backgroundPageShape.destroy();
  1440. this.backgroundPageShape = null;
  1441. }
  1442. this.validateBackgroundStyles();
  1443. }
  1444. };
  1445. // Updates the CSS of the background to draw the grid
  1446. mxGraphView.prototype.validateBackgroundStyles = function()
  1447. {
  1448. var graph = this.graph;
  1449. var color = (graph.background == null || graph.background == mxConstants.NONE) ? '#ffffff' : graph.background;
  1450. var gridColor = (this.gridColor != color.toLowerCase()) ? this.gridColor : '#ffffff';
  1451. var image = 'none';
  1452. var position = '';
  1453. if (graph.isGridEnabled())
  1454. {
  1455. var phase = 10;
  1456. if (mxClient.IS_SVG)
  1457. {
  1458. // Generates the SVG required for drawing the dynamic grid
  1459. image = unescape(encodeURIComponent(this.createSvgGrid(gridColor)));
  1460. image = (window.btoa) ? btoa(image) : Base64.encode(image, true);
  1461. image = 'url(' + 'data:image/svg+xml;base64,' + image + ')'
  1462. phase = graph.gridSize * this.scale * this.gridSteps;
  1463. }
  1464. else
  1465. {
  1466. // Fallback to grid wallpaper with fixed size
  1467. image = 'url(' + this.gridImage + ')';
  1468. }
  1469. var x0 = 0;
  1470. var y0 = 0;
  1471. if (graph.view.backgroundPageShape != null)
  1472. {
  1473. var bds = this.getBackgroundPageBounds();
  1474. x0 = 1 + bds.x;
  1475. y0 = 1 + bds.y;
  1476. }
  1477. // Computes the offset to maintain origin for grid
  1478. position = -Math.round(phase - mxUtils.mod(this.translate.x * this.scale - x0, phase)) + 'px ' +
  1479. -Math.round(phase - mxUtils.mod(this.translate.y * this.scale - y0, phase)) + 'px';
  1480. }
  1481. var canvas = graph.view.canvas;
  1482. if (canvas.ownerSVGElement != null)
  1483. {
  1484. canvas = canvas.ownerSVGElement;
  1485. }
  1486. if (graph.view.backgroundPageShape != null)
  1487. {
  1488. graph.view.backgroundPageShape.node.style.backgroundPosition = position;
  1489. graph.view.backgroundPageShape.node.style.backgroundImage = image;
  1490. graph.view.backgroundPageShape.node.style.backgroundColor = color;
  1491. graph.container.className = 'geDiagramContainer geDiagramBackdrop';
  1492. canvas.style.backgroundImage = 'none';
  1493. canvas.style.backgroundColor = '';
  1494. }
  1495. else
  1496. {
  1497. graph.container.className = 'geDiagramContainer';
  1498. canvas.style.backgroundPosition = position;
  1499. canvas.style.backgroundColor = color;
  1500. canvas.style.backgroundImage = image;
  1501. }
  1502. };
  1503. // Returns the SVG required for painting the background grid.
  1504. mxGraphView.prototype.createSvgGrid = function(color)
  1505. {
  1506. var tmp = this.graph.gridSize * this.scale;
  1507. while (tmp < this.minGridSize)
  1508. {
  1509. tmp *= 2;
  1510. }
  1511. var tmp2 = this.gridSteps * tmp;
  1512. // Small grid lines
  1513. var d = [];
  1514. for (var i = 1; i < this.gridSteps; i++)
  1515. {
  1516. var tmp3 = i * tmp;
  1517. d.push('M 0 ' + tmp3 + ' L ' + tmp2 + ' ' + tmp3 + ' M ' + tmp3 + ' 0 L ' + tmp3 + ' ' + tmp2);
  1518. }
  1519. // KNOWN: Rounding errors for certain scales (eg. 144%, 121% in Chrome, FF and Safari). Workaround
  1520. // in Chrome is to use 100% for the svg size, but this results in blurred grid for large diagrams.
  1521. var size = tmp2;
  1522. var svg = '<svg width="' + size + '" height="' + size + '" xmlns="' + mxConstants.NS_SVG + '">' +
  1523. '<defs><pattern id="grid" width="' + tmp2 + '" height="' + tmp2 + '" patternUnits="userSpaceOnUse">' +
  1524. '<path d="' + d.join(' ') + '" fill="none" stroke="' + color + '" opacity="0.2" stroke-width="1"/>' +
  1525. '<path d="M ' + tmp2 + ' 0 L 0 0 0 ' + tmp2 + '" fill="none" stroke="' + color + '" stroke-width="1"/>' +
  1526. '</pattern></defs><rect width="100%" height="100%" fill="url(#grid)"/></svg>';
  1527. return svg;
  1528. };
  1529. // Adds panning for the grid with no page view and disabled scrollbars
  1530. var mxGraphPanGraph = mxGraph.prototype.panGraph;
  1531. mxGraph.prototype.panGraph = function(dx, dy)
  1532. {
  1533. mxGraphPanGraph.apply(this, arguments);
  1534. if (this.shiftPreview1 != null)
  1535. {
  1536. var canvas = this.view.canvas;
  1537. if (canvas.ownerSVGElement != null)
  1538. {
  1539. canvas = canvas.ownerSVGElement;
  1540. }
  1541. var phase = this.gridSize * this.view.scale * this.view.gridSteps;
  1542. var position = -Math.round(phase - mxUtils.mod(this.view.translate.x * this.view.scale + dx, phase)) + 'px ' +
  1543. -Math.round(phase - mxUtils.mod(this.view.translate.y * this.view.scale + dy, phase)) + 'px';
  1544. canvas.style.backgroundPosition = position;
  1545. }
  1546. };
  1547. // Draws page breaks only within the page
  1548. mxGraph.prototype.updatePageBreaks = function(visible, width, height)
  1549. {
  1550. var scale = this.view.scale;
  1551. var tr = this.view.translate;
  1552. var fmt = this.pageFormat;
  1553. var ps = scale * this.pageScale;
  1554. var bounds2 = this.view.getBackgroundPageBounds();
  1555. width = bounds2.width;
  1556. height = bounds2.height;
  1557. var bounds = new mxRectangle(scale * tr.x, scale * tr.y, fmt.width * ps, fmt.height * ps);
  1558. // Does not show page breaks if the scale is too small
  1559. visible = visible && Math.min(bounds.width, bounds.height) > this.minPageBreakDist;
  1560. var horizontalCount = (visible) ? Math.ceil(height / bounds.height) - 1 : 0;
  1561. var verticalCount = (visible) ? Math.ceil(width / bounds.width) - 1 : 0;
  1562. var right = bounds2.x + width;
  1563. var bottom = bounds2.y + height;
  1564. if (this.horizontalPageBreaks == null && horizontalCount > 0)
  1565. {
  1566. this.horizontalPageBreaks = [];
  1567. }
  1568. if (this.verticalPageBreaks == null && verticalCount > 0)
  1569. {
  1570. this.verticalPageBreaks = [];
  1571. }
  1572. var drawPageBreaks = mxUtils.bind(this, function(breaks)
  1573. {
  1574. if (breaks != null)
  1575. {
  1576. var count = (breaks == this.horizontalPageBreaks) ? horizontalCount : verticalCount;
  1577. for (var i = 0; i <= count; i++)
  1578. {
  1579. var pts = (breaks == this.horizontalPageBreaks) ?
  1580. [new mxPoint(Math.round(bounds2.x), Math.round(bounds2.y + (i + 1) * bounds.height)),
  1581. new mxPoint(Math.round(right), Math.round(bounds2.y + (i + 1) * bounds.height))] :
  1582. [new mxPoint(Math.round(bounds2.x + (i + 1) * bounds.width), Math.round(bounds2.y)),
  1583. new mxPoint(Math.round(bounds2.x + (i + 1) * bounds.width), Math.round(bottom))];
  1584. if (breaks[i] != null)
  1585. {
  1586. breaks[i].points = pts;
  1587. breaks[i].redraw();
  1588. }
  1589. else
  1590. {
  1591. var pageBreak = new mxPolyline(pts, this.pageBreakColor);
  1592. pageBreak.dialect = this.dialect;
  1593. pageBreak.isDashed = this.pageBreakDashed;
  1594. pageBreak.pointerEvents = false;
  1595. pageBreak.init(this.view.backgroundPane);
  1596. pageBreak.redraw();
  1597. breaks[i] = pageBreak;
  1598. }
  1599. }
  1600. for (var i = count; i < breaks.length; i++)
  1601. {
  1602. breaks[i].destroy();
  1603. }
  1604. breaks.splice(count, breaks.length - count);
  1605. }
  1606. });
  1607. drawPageBreaks(this.horizontalPageBreaks);
  1608. drawPageBreaks(this.verticalPageBreaks);
  1609. };
  1610. // Disables removing relative children from parents
  1611. var mxGraphHandlerShouldRemoveCellsFromParent = mxGraphHandler.prototype.shouldRemoveCellsFromParent;
  1612. mxGraphHandler.prototype.shouldRemoveCellsFromParent = function(parent, cells, evt)
  1613. {
  1614. for (var i = 0; i < cells.length; i++)
  1615. {
  1616. if (this.graph.getModel().isVertex(cells[i]))
  1617. {
  1618. var geo = this.graph.getCellGeometry(cells[i]);
  1619. if (geo != null && geo.relative)
  1620. {
  1621. return false;
  1622. }
  1623. }
  1624. }
  1625. return mxGraphHandlerShouldRemoveCellsFromParent.apply(this, arguments);
  1626. };
  1627. // Overrides to ignore hotspot only for target terminal
  1628. var mxConnectionHandlerCreateMarker = mxConnectionHandler.prototype.createMarker;
  1629. mxConnectionHandler.prototype.createMarker = function()
  1630. {
  1631. var marker = mxConnectionHandlerCreateMarker.apply(this, arguments);
  1632. marker.intersects = mxUtils.bind(this, function(state, evt)
  1633. {
  1634. if (this.isConnecting())
  1635. {
  1636. return true;
  1637. }
  1638. return mxCellMarker.prototype.intersects.apply(marker, arguments);
  1639. });
  1640. return marker;
  1641. };
  1642. // Creates background page shape
  1643. mxGraphView.prototype.createBackgroundPageShape = function(bounds)
  1644. {
  1645. return new mxRectangleShape(bounds, '#ffffff', '#cacaca');
  1646. };
  1647. // Fits the number of background pages to the graph
  1648. mxGraphView.prototype.getBackgroundPageBounds = function()
  1649. {
  1650. var gb = this.getGraphBounds();
  1651. // Computes unscaled, untranslated graph bounds
  1652. var x = (gb.width > 0) ? gb.x / this.scale - this.translate.x : 0;
  1653. var y = (gb.height > 0) ? gb.y / this.scale - this.translate.y : 0;
  1654. var w = gb.width / this.scale;
  1655. var h = gb.height / this.scale;
  1656. var fmt = this.graph.pageFormat;
  1657. var ps = this.graph.pageScale;
  1658. var pw = fmt.width * ps;
  1659. var ph = fmt.height * ps;
  1660. var x0 = Math.floor(Math.min(0, x) / pw);
  1661. var y0 = Math.floor(Math.min(0, y) / ph);
  1662. var xe = Math.ceil(Math.max(1, x + w) / pw);
  1663. var ye = Math.ceil(Math.max(1, y + h) / ph);
  1664. var rows = xe - x0;
  1665. var cols = ye - y0;
  1666. var bounds = new mxRectangle(this.scale * (this.translate.x + x0 * pw), this.scale *
  1667. (this.translate.y + y0 * ph), this.scale * rows * pw, this.scale * cols * ph);
  1668. return bounds;
  1669. };
  1670. // Add panning for background page in VML
  1671. var graphPanGraph = mxGraph.prototype.panGraph;
  1672. mxGraph.prototype.panGraph = function(dx, dy)
  1673. {
  1674. graphPanGraph.apply(this, arguments);
  1675. if ((this.dialect != mxConstants.DIALECT_SVG && this.view.backgroundPageShape != null) &&
  1676. (!this.useScrollbarsForPanning || !mxUtils.hasScrollbars(this.container)))
  1677. {
  1678. this.view.backgroundPageShape.node.style.marginLeft = dx + 'px';
  1679. this.view.backgroundPageShape.node.style.marginTop = dy + 'px';
  1680. }
  1681. };
  1682. /**
  1683. * Consumes click events for disabled menu items.
  1684. */
  1685. var mxPopupMenuAddItem = mxPopupMenu.prototype.addItem;
  1686. mxPopupMenu.prototype.addItem = function(title, image, funct, parent, iconCls, enabled)
  1687. {
  1688. var result = mxPopupMenuAddItem.apply(this, arguments);
  1689. if (enabled != null && !enabled)
  1690. {
  1691. mxEvent.addListener(result, 'mousedown', function(evt)
  1692. {
  1693. mxEvent.consume(evt);
  1694. });
  1695. }
  1696. return result;
  1697. };
  1698. // Selects ancestors before descendants
  1699. var graphHandlerGetInitialCellForEvent = mxGraphHandler.prototype.getInitialCellForEvent;
  1700. mxGraphHandler.prototype.getInitialCellForEvent = function(me)
  1701. {
  1702. var model = this.graph.getModel();
  1703. var psel = model.getParent(this.graph.getSelectionCell());
  1704. var cell = graphHandlerGetInitialCellForEvent.apply(this, arguments);
  1705. var parent = model.getParent(cell);
  1706. if (psel == null || (psel != cell && psel != parent))
  1707. {
  1708. while (!this.graph.isCellSelected(cell) && !this.graph.isCellSelected(parent) &&
  1709. model.isVertex(parent) && !this.graph.isContainer(parent))
  1710. {
  1711. cell = parent;
  1712. parent = this.graph.getModel().getParent(cell);
  1713. }
  1714. }
  1715. return cell;
  1716. };
  1717. // Selection is delayed to mouseup if ancestor is selected
  1718. var graphHandlerIsDelayedSelection = mxGraphHandler.prototype.isDelayedSelection;
  1719. mxGraphHandler.prototype.isDelayedSelection = function(cell, me)
  1720. {
  1721. var result = graphHandlerIsDelayedSelection.apply(this, arguments);
  1722. if (!result)
  1723. {
  1724. var model = this.graph.getModel();
  1725. var parent = model.getParent(cell);
  1726. while (parent != null)
  1727. {
  1728. // Inconsistency for unselected parent swimlane is intended for easier moving
  1729. // of stack layouts where the container title section is too far away
  1730. if (this.graph.isCellSelected(parent) && model.isVertex(parent))
  1731. {
  1732. result = true;
  1733. break;
  1734. }
  1735. parent = model.getParent(parent);
  1736. }
  1737. }
  1738. return result;
  1739. };
  1740. // Delayed selection of parent group
  1741. mxGraphHandler.prototype.selectDelayed = function(me)
  1742. {
  1743. if (!this.graph.popupMenuHandler.isPopupTrigger(me))
  1744. {
  1745. var cell = me.getCell();
  1746. if (cell == null)
  1747. {
  1748. cell = this.cell;
  1749. }
  1750. // Selects folded cell for hit on folding icon
  1751. var state = this.graph.view.getState(cell)
  1752. if (state != null && me.isSource(state.control))
  1753. {
  1754. this.graph.selectCellForEvent(cell, me.getEvent());
  1755. }
  1756. else
  1757. {
  1758. var model = this.graph.getModel();
  1759. var parent = model.getParent(cell);
  1760. while (!this.graph.isCellSelected(parent) && model.isVertex(parent))
  1761. {
  1762. cell = parent;
  1763. parent = model.getParent(cell);
  1764. }
  1765. this.graph.selectCellForEvent(cell, me.getEvent());
  1766. }
  1767. }
  1768. };
  1769. // Returns last selected ancestor
  1770. mxPopupMenuHandler.prototype.getCellForPopupEvent = function(me)
  1771. {
  1772. var cell = me.getCell();
  1773. var model = this.graph.getModel();
  1774. var parent = model.getParent(cell);
  1775. while (model.isVertex(parent) && !this.graph.isContainer(parent))
  1776. {
  1777. if (this.graph.isCellSelected(parent))
  1778. {
  1779. cell = parent;
  1780. }
  1781. parent = model.getParent(parent);
  1782. }
  1783. return cell;
  1784. };
  1785. })();